Skip to content

Commit f8f3689

Browse files
author
Christos KK Loverdos
committed
BlockGenerator: make difficulty consensus-polymorphic
1 parent f9047fb commit f8f3689

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/main/scala/io/iohk/ethereum/consensus/atomixraft/blocks/AtomixRaftBlockGenerator.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class AtomixRaftBlockGenerator(
2020
blockTimestampProvider
2121
) {
2222

23+
protected def calculateDifficulty(blockNumber: BigInt, parent: Block, blockTimestamp: Long): BigInt = 0
24+
2325
def withBlockTimestampProvider(blockTimestampProvider: BlockTimestampProvider): AtomixRaftBlockGenerator =
2426
new AtomixRaftBlockGenerator(
2527
blockchain,

src/main/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSkeleton.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ abstract class BlockGeneratorSkeleton(
3838

3939
protected val blockCacheSize = consensusConfig.blockCacheSize
4040

41-
protected val difficulty = new DifficultyCalculator(blockchainConfig)
42-
4341
protected val cache: AtomicReference[List[PendingBlockAndState]] = new AtomicReference(Nil)
4442

4543
protected def newBlockBody(transactions: Seq[SignedTransaction], x: X): BlockBody
4644

45+
protected def calculateDifficulty(blockNumber: BigInt, parent: Block, blockTimestamp: Long): BigInt
46+
4747
protected def defaultPrepareHeader(
4848
blockNumber: BigInt,
4949
parent: Block,
@@ -60,7 +60,7 @@ abstract class BlockGeneratorSkeleton(
6060
transactionsRoot = ByteString.empty,
6161
receiptsRoot = ByteString.empty,
6262
logsBloom = ByteString.empty,
63-
difficulty = difficulty.calculateDifficulty(blockNumber, blockTimestamp, parent.header),
63+
difficulty = calculateDifficulty(blockNumber, parent, blockTimestamp),
6464
number = blockNumber,
6565
gasLimit = calculateGasLimit(parent.header.gasLimit),
6666
gasUsed = 0,

src/main/scala/io/iohk/ethereum/consensus/ethash/blocks/EthashBlockGenerator.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class EthashBlockGeneratorImpl(
3838
blockTimestampProvider
3939
) with EthashBlockGenerator {
4040

41+
protected val difficulty = new DifficultyCalculator(blockchainConfig)
42+
43+
protected def calculateDifficulty(blockNumber: BigInt, parent: Block, blockTimestamp: Long): BigInt =
44+
difficulty.calculateDifficulty(blockNumber, blockTimestamp, parent.header)
45+
4146
protected def newBlockBody(transactions: Seq[SignedTransaction], x: Ommers): BlockBody =
4247
BlockBody(transactions, x)
4348

0 commit comments

Comments
 (0)