File tree Expand file tree Collapse file tree 2 files changed +14
-13
lines changed
src/main/scala/io/iohk/ethereum/ledger Expand file tree Collapse file tree 2 files changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -33,10 +33,7 @@ class BlockImport(
33
33
} yield {
34
34
validationResult.fold(
35
35
error => handleImportTopValidationError(error, block, importResult),
36
- _ => {
37
- measureBlockMetrics(importResult)
38
- importResult
39
- }
36
+ _ => importResult
40
37
)
41
38
}
42
39
}
@@ -81,14 +78,6 @@ class BlockImport(
81
78
}
82
79
}
83
80
84
- private def measureBlockMetrics (importResult : BlockImportResult ): Unit = {
85
- importResult match {
86
- case BlockImportedToTop (blockImportData) =>
87
- blockImportData.foreach(blockData => BlockMetrics .measure(blockData.block, blockchain.getBlockByHash))
88
- case _ => ()
89
- }
90
- }
91
-
92
81
private def handleImportTopValidationError (
93
82
error : ValidationBeforeExecError ,
94
83
block : Block ,
Original file line number Diff line number Diff line change @@ -130,11 +130,13 @@ class LedgerImpl(
130
130
val hash = currentBestBlock.header.hash
131
131
blockchain.getChainWeightByHash(hash) match {
132
132
case Some (weight) =>
133
- if (isPossibleNewBestBlock(block.header, currentBestBlock.header)) {
133
+ val importResult = if (isPossibleNewBestBlock(block.header, currentBestBlock.header)) {
134
134
blockImport.importToTop(block, currentBestBlock, weight)
135
135
} else {
136
136
blockImport.reorganise(block, currentBestBlock, weight)
137
137
}
138
+ importResult.foreach(measureBlockMetrics)
139
+ importResult
138
140
139
141
case None =>
140
142
Future .successful(BlockImportFailed (s " Couldn't get total difficulty for current best block with hash: $hash" ))
@@ -154,6 +156,16 @@ class LedgerImpl(
154
156
override def resolveBranch (headers : NonEmptyList [BlockHeader ]): BranchResolutionResult =
155
157
branchResolution.resolveBranch(headers)
156
158
159
+ private def measureBlockMetrics (importResult : BlockImportResult ): Unit = {
160
+ importResult match {
161
+ case BlockImportedToTop (blockImportData) =>
162
+ blockImportData.foreach(blockData => BlockMetrics .measure(blockData.block, blockchain.getBlockByHash))
163
+ case ChainReorganised (_, newBranch, _) =>
164
+ newBranch.foreach(block => BlockMetrics .measure(block, blockchain.getBlockByHash))
165
+ case _ => ()
166
+ }
167
+ }
168
+
157
169
}
158
170
159
171
object Ledger {
You can’t perform that action at this time.
0 commit comments