Skip to content

Commit ebc0d7c

Browse files
committed
[ETCM-49] Fix block measuring
1 parent 34196d9 commit ebc0d7c

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

src/main/scala/io/iohk/ethereum/blockchain/sync/regular/BlockImporter.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import cats.data.NonEmptyList
66
import cats.instances.future._
77
import cats.instances.list._
88
import cats.syntax.apply._
9-
import io.iohk.ethereum.blockchain.sync.BlockMetrics
109
import io.iohk.ethereum.blockchain.sync.regular.BlockBroadcasterActor.BroadcastBlocks
1110
import io.iohk.ethereum.crypto.kec256
1211
import io.iohk.ethereum.domain.{Block, Blockchain, SignedTransaction}
@@ -126,10 +125,7 @@ class BlockImporter(
126125
}
127126

128127
errorOpt match {
129-
case None => {
130-
importedBlocks.map(block => BlockMetrics.measure(block, blockchain.getBlockByHash))
131-
Running
132-
}
128+
case None => Running
133129
case Some(err) =>
134130
log.error("Block import error {}", err)
135131
val notImportedBlocks = blocks.drop(importedBlocks.size)

src/main/scala/io/iohk/ethereum/ledger/BlockImport.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class BlockImport(
6666
result.toString
6767
})
6868

69+
if (importedBlocks.nonEmpty) {
70+
importedBlocks.map(
71+
blockData => BlockMetrics.measure(blockData.block, blockchain.getBlockByHash)
72+
)
73+
}
74+
6975
result
7076

7177
case None =>

src/main/scala/io/iohk/ethereum/blockchain/sync/BlockMetrics.scala renamed to src/main/scala/io/iohk/ethereum/ledger/BlockMetrics.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.iohk.ethereum.blockchain.sync
1+
package io.iohk.ethereum.ledger
22

33
import akka.util.ByteString
44
import com.google.common.util.concurrent.AtomicDouble

src/test/scala/io/iohk/ethereum/blockchain/sync/regular/RegularSyncSpec.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ class RegularSyncSpec extends RegularSyncFixtures with WordSpecLike with BeforeA
170170
implicit val ec: ExecutionContext = system.dispatcher
171171
override lazy val blockchain: BlockchainImpl = stub[BlockchainImpl]
172172
(blockchain.getBestBlockNumber _).when().onCall(() => ledger.bestBlock.number)
173-
// Just to bypass metrics needs
174-
(blockchain.getBlockByHash _).when(*).returns(None)
175173
override lazy val ledger: TestLedgerImpl = new FakeLedgerImpl()
176174
override lazy val syncConfig = defaultSyncConfig.copy(
177175
blockHeadersPerRequest = 5,

src/test/scala/io/iohk/ethereum/ledger/BlockImportSpec.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class BlockImportSpec extends FlatSpec with Matchers with ScalaFutures {
4949
val emptyWorld: InMemoryWorldStateProxy = BlockchainImpl(storagesInstance.storages)
5050
.getWorldStateProxy(-1, UInt256.Zero, None, noEmptyAccounts = false, ethCompatibleStorage = true)
5151

52+
// Just to bypass metrics needs
53+
(blockchain.getBlockByHash _).when(*).returns(None)
54+
5255
(blockQueue.enqueueBlock _).expects(block, bestNum).returning(Some(Leaf(hash, newTd)))
5356
(blockQueue.getBranch _).expects(hash, true).returning(List(block))
5457

0 commit comments

Comments
 (0)