@@ -5,15 +5,14 @@ import io.iohk.ethereum.consensus.validators.BlockHeaderError.HeaderParentNotFou
55import io .iohk .ethereum .domain ._
66import io .iohk .ethereum .ledger .BlockExecutionError .ValidationBeforeExecError
77import io .iohk .ethereum .ledger .BlockQueue .Leaf
8- import io .iohk .ethereum .utils .{BlockchainConfig , ByteStringUtils , Logger }
8+ import io .iohk .ethereum .utils .{ByteStringUtils , Logger }
99import org .bouncycastle .util .encoders .Hex
1010
1111import scala .concurrent .{ExecutionContext , Future }
1212
1313class BlockImport (
1414 blockchain : BlockchainImpl ,
1515 blockQueue : BlockQueue ,
16- blockchainConfig : BlockchainConfig ,
1716 blockValidation : BlockValidation ,
1817 blockExecution : BlockExecution ,
1918 validationContext : ExecutionContext // Can't be implicit because of importToTop method and ambiguous of executionContext
@@ -34,7 +33,10 @@ class BlockImport(
3433 } yield {
3534 validationResult.fold(
3635 error => handleImportTopValidationError(error, block, importResult),
37- _ => importResult
36+ _ => {
37+ measureBlockMetrics(importResult)
38+ importResult
39+ }
3840 )
3941 }
4042 }
@@ -72,17 +74,21 @@ class BlockImport(
7274 }
7375 )
7476
75- if (importedBlocks.nonEmpty) {
76- importedBlocks.foreach(blockData => BlockMetrics .measure(blockData.block, blockchain.getBlockByHash))
77- }
78-
7977 result
8078
8179 case None =>
8280 BlockImportFailed (s " Newly enqueued block with hash: ${block.header.hash} is not part of a known branch " )
8381 }
8482 }
8583
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+
8692 private def handleImportTopValidationError (
8793 error : ValidationBeforeExecError ,
8894 block : Block ,
0 commit comments