Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/main/scala/io/iohk/ethereum/ledger/BlockImport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ class BlockImport(
} yield {
validationResult.fold(
error => handleImportTopValidationError(error, block, importResult),
_ => {
measureBlockMetrics(importResult)
importResult
}
_ => importResult
)
}
}
Expand Down Expand Up @@ -81,14 +78,6 @@ class BlockImport(
}
}

private def measureBlockMetrics(importResult: BlockImportResult): Unit = {
importResult match {
case BlockImportedToTop(blockImportData) =>
blockImportData.foreach(blockData => BlockMetrics.measure(blockData.block, blockchain.getBlockByHash))
case _ => ()
}
}

private def handleImportTopValidationError(
error: ValidationBeforeExecError,
block: Block,
Expand Down
14 changes: 13 additions & 1 deletion src/main/scala/io/iohk/ethereum/ledger/Ledger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ class LedgerImpl(
val hash = currentBestBlock.header.hash
blockchain.getChainWeightByHash(hash) match {
case Some(weight) =>
if (isPossibleNewBestBlock(block.header, currentBestBlock.header)) {
val importResult = if (isPossibleNewBestBlock(block.header, currentBestBlock.header)) {
blockImport.importToTop(block, currentBestBlock, weight)
} else {
blockImport.reorganise(block, currentBestBlock, weight)
}
importResult.foreach(measureBlockMetrics)
importResult

case None =>
Future.successful(BlockImportFailed(s"Couldn't get total difficulty for current best block with hash: $hash"))
Expand All @@ -154,6 +156,16 @@ class LedgerImpl(
override def resolveBranch(headers: NonEmptyList[BlockHeader]): BranchResolutionResult =
branchResolution.resolveBranch(headers)

private def measureBlockMetrics(importResult: BlockImportResult): Unit = {
importResult match {
case BlockImportedToTop(blockImportData) =>
blockImportData.foreach(blockData => BlockMetrics.measure(blockData.block, blockchain.getBlockByHash))
case ChainReorganised(_, newBranch, _) =>
newBranch.foreach(block => BlockMetrics.measure(block, blockchain.getBlockByHash))
case _ => ()
}
}

}

object Ledger {
Expand Down