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(
3333 } yield {
3434 validationResult.fold(
3535 error => handleImportTopValidationError(error, block, importResult),
36- _ => {
37- measureBlockMetrics(importResult)
38- importResult
39- }
36+ _ => importResult
4037 )
4138 }
4239 }
@@ -81,14 +78,6 @@ class BlockImport(
8178 }
8279 }
8380
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-
9281 private def handleImportTopValidationError (
9382 error : ValidationBeforeExecError ,
9483 block : Block ,
Original file line number Diff line number Diff line change @@ -130,11 +130,13 @@ class LedgerImpl(
130130 val hash = currentBestBlock.header.hash
131131 blockchain.getChainWeightByHash(hash) match {
132132 case Some (weight) =>
133- if (isPossibleNewBestBlock(block.header, currentBestBlock.header)) {
133+ val importResult = if (isPossibleNewBestBlock(block.header, currentBestBlock.header)) {
134134 blockImport.importToTop(block, currentBestBlock, weight)
135135 } else {
136136 blockImport.reorganise(block, currentBestBlock, weight)
137137 }
138+ importResult.foreach(measureBlockMetrics)
139+ importResult
138140
139141 case None =>
140142 Future .successful(BlockImportFailed (s " Couldn't get total difficulty for current best block with hash: $hash" ))
@@ -154,6 +156,16 @@ class LedgerImpl(
154156 override def resolveBranch (headers : NonEmptyList [BlockHeader ]): BranchResolutionResult =
155157 branchResolution.resolveBranch(headers)
156158
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+
157169}
158170
159171object Ledger {
You can’t perform that action at this time.
0 commit comments