|
|
|
@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.mainnet.headervalidationrules; |
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
|
|
|
|
|
import org.hyperledger.besu.config.experimental.ExperimentalEIPs; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeader; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; |
|
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; |
|
|
|
@ -35,6 +36,7 @@ import java.util.Arrays; |
|
|
|
|
import java.util.Collection; |
|
|
|
|
|
|
|
|
|
import org.apache.tuweni.units.bigints.UInt256; |
|
|
|
|
import org.junit.After; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.runner.RunWith; |
|
|
|
|
import org.junit.runners.Parameterized; |
|
|
|
@ -68,6 +70,11 @@ public class ProofOfWorkValidationRuleTest { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@After |
|
|
|
|
public void reset() { |
|
|
|
|
ExperimentalEIPs.eip1559Enabled = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void validatesValidBlocks() { |
|
|
|
|
assertThat(validationRule.validate(blockHeader, parentHeader)).isTrue(); |
|
|
|
@ -139,6 +146,61 @@ public class ProofOfWorkValidationRuleTest { |
|
|
|
|
assertThat(validationRule.validate(header, parentHeader)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void failsWithNonEip1559BlockAfterFork() { |
|
|
|
|
final ProofOfWorkValidationRule proofOfWorkValidationRule = |
|
|
|
|
new ProofOfWorkValidationRule( |
|
|
|
|
new EpochCalculator.DefaultEpochCalculator(), true, PoWHasher.ETHASH_LIGHT); |
|
|
|
|
|
|
|
|
|
final BlockHeaderBuilder headerBuilder = |
|
|
|
|
BlockHeaderBuilder.fromHeader(blockHeader) |
|
|
|
|
.difficulty(Difficulty.ONE) |
|
|
|
|
.blockHeaderFunctions(mainnetBlockHashFunction()) |
|
|
|
|
.timestamp(1); |
|
|
|
|
final BlockHeader preHeader = headerBuilder.buildBlockHeader(); |
|
|
|
|
final Hash headerHash = validationRule.hashHeader(preHeader); |
|
|
|
|
|
|
|
|
|
PoWSolution solution = |
|
|
|
|
PoWHasher.ETHASH_LIGHT.hash( |
|
|
|
|
preHeader.getNonce(), |
|
|
|
|
preHeader.getNumber(), |
|
|
|
|
new EpochCalculator.DefaultEpochCalculator(), |
|
|
|
|
headerHash); |
|
|
|
|
|
|
|
|
|
final BlockHeader header = headerBuilder.mixHash(solution.getMixHash()).buildBlockHeader(); |
|
|
|
|
|
|
|
|
|
ExperimentalEIPs.eip1559Enabled = true; |
|
|
|
|
|
|
|
|
|
assertThat(proofOfWorkValidationRule.validate(header, parentHeader)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void failsWithEip1559BlockBeforeFork() { |
|
|
|
|
final ProofOfWorkValidationRule proofOfWorkValidationRule = |
|
|
|
|
new ProofOfWorkValidationRule( |
|
|
|
|
new EpochCalculator.DefaultEpochCalculator(), false, PoWHasher.ETHASH_LIGHT); |
|
|
|
|
|
|
|
|
|
final BlockHeaderBuilder headerBuilder = |
|
|
|
|
BlockHeaderBuilder.fromHeader(blockHeader) |
|
|
|
|
.difficulty(Difficulty.ONE) |
|
|
|
|
.baseFee(10L) |
|
|
|
|
.blockHeaderFunctions(mainnetBlockHashFunction()) |
|
|
|
|
.timestamp(1); |
|
|
|
|
final BlockHeader preHeader = headerBuilder.buildBlockHeader(); |
|
|
|
|
final Hash headerHash = validationRule.hashHeader(preHeader); |
|
|
|
|
|
|
|
|
|
PoWSolution solution = |
|
|
|
|
PoWHasher.ETHASH_LIGHT.hash( |
|
|
|
|
preHeader.getNonce(), |
|
|
|
|
preHeader.getNumber(), |
|
|
|
|
new EpochCalculator.DefaultEpochCalculator(), |
|
|
|
|
headerHash); |
|
|
|
|
|
|
|
|
|
final BlockHeader header = headerBuilder.mixHash(solution.getMixHash()).buildBlockHeader(); |
|
|
|
|
|
|
|
|
|
assertThat(proofOfWorkValidationRule.validate(header, parentHeader)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private BlockHeaderFunctions mainnetBlockHashFunction() { |
|
|
|
|
final ProtocolSchedule protocolSchedule = ProtocolScheduleFixture.MAINNET; |
|
|
|
|
return ScheduleBasedBlockHeaderFunctions.create(protocolSchedule); |
|
|
|
|