Skip to content

Commit ac0a4f4

Browse files
author
Nicolas Tallar
committed
[FIX] Add mocked miner validations
1 parent db81a4d commit ac0a4f4

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/main/scala/io/iohk/ethereum/consensus/ConsensusBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ trait StdConsensusBuilder extends ConsensusBuilder {
2727
protected def buildEthashConsensus(): ethash.EthashConsensus = {
2828
val specificConfig = ethash.EthashConfig(mantisConfig)
2929
val fullConfig = newConfig(specificConfig)
30-
val validators = EthashValidators(blockchainConfig)
30+
val validators = EthashValidators(blockchainConfig, consensusConfig.protocol)
3131
val consensus = EthashConsensus(vm, blockchain, blockchainConfig, fullConfig, validators)
3232
consensus
3333
}

src/main/scala/io/iohk/ethereum/consensus/ConsensusConfig.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ object ConsensusConfig extends Logger {
3636

3737

3838
final val AllowedProtocols = Set(
39-
Protocol.Names.Ethash
39+
Protocol.Names.Ethash,
40+
Protocol.Names.MockedPow
4041
)
4142

4243
final val AllowedProtocolsError = (s: String) Keys.Consensus +

src/main/scala/io/iohk/ethereum/consensus/ethash/validators/EthashValidators.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ trait EthashValidators extends Validators {
4444
}
4545

4646
object EthashValidators {
47-
def apply(blockchainConfig: BlockchainConfig): EthashValidators = {
48-
val blockHeaderValidator: EthashBlockHeaderValidator = new EthashBlockHeaderValidator(blockchainConfig)
47+
def apply(blockchainConfig: BlockchainConfig, protocol: Protocol): EthashValidators = {
48+
val blockHeaderValidator: BlockHeaderValidator =
49+
if(protocol == Protocol.MockedPow) new MockedBlockHeaderValidator(blockchainConfig)
50+
else new EthashBlockHeaderValidator(blockchainConfig)
4951

5052
new StdEthashValidators(
5153
StdBlockValidator,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.iohk.ethereum.consensus.ethash
2+
package validators
3+
4+
import io.iohk.ethereum.consensus.difficulty.DifficultyCalculator
5+
import io.iohk.ethereum.consensus.ethash.difficulty.EthashDifficultyCalculator
6+
import io.iohk.ethereum.consensus.validators.{ BlockHeaderError, BlockHeaderValid, BlockHeaderValidatorSkeleton }
7+
import io.iohk.ethereum.domain.BlockHeader
8+
import io.iohk.ethereum.utils.BlockchainConfig
9+
10+
/**
11+
* A block header validator for Ethash.
12+
*/
13+
class MockedBlockHeaderValidator(blockchainConfig: BlockchainConfig) extends BlockHeaderValidatorSkeleton(blockchainConfig) {
14+
15+
protected def difficulty: DifficultyCalculator = new EthashDifficultyCalculator(blockchainConfig)
16+
17+
def validateEvenMore(blockHeader: BlockHeader, parentHeader: BlockHeader): Either[BlockHeaderError, BlockHeaderValid] =
18+
Right(BlockHeaderValid)
19+
20+
}
21+

0 commit comments

Comments
 (0)