use of org.hyperledger.besu.ethereum.mainnet.ProtocolSpec in project besu by hyperledger.
the class BlockchainReferenceTestTools method executeTest.
public static void executeTest(final BlockchainReferenceTestCaseSpec spec) {
final BlockHeader genesisBlockHeader = spec.getGenesisBlockHeader();
final MutableWorldState worldState = spec.getWorldStateArchive().getMutable(genesisBlockHeader.getStateRoot(), genesisBlockHeader.getHash()).get();
assertThat(worldState.rootHash()).isEqualTo(genesisBlockHeader.getStateRoot());
final ProtocolSchedule schedule = REFERENCE_TEST_PROTOCOL_SCHEDULES.getByName(spec.getNetwork());
final MutableBlockchain blockchain = spec.getBlockchain();
final ProtocolContext context = spec.getProtocolContext();
for (final BlockchainReferenceTestCaseSpec.CandidateBlock candidateBlock : spec.getCandidateBlocks()) {
if (!candidateBlock.isExecutable()) {
return;
}
try {
final Block block = candidateBlock.getBlock();
final ProtocolSpec protocolSpec = schedule.getByBlockNumber(block.getHeader().getNumber());
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
final HeaderValidationMode validationMode = "NoProof".equalsIgnoreCase(spec.getSealEngine()) ? HeaderValidationMode.LIGHT : HeaderValidationMode.FULL;
final boolean imported = blockImporter.importBlock(context, block, validationMode, validationMode);
assertThat(imported).isEqualTo(candidateBlock.isValid());
} catch (final RLPException e) {
assertThat(candidateBlock.isValid()).isFalse();
}
}
Assertions.assertThat(blockchain.getChainHeadHash()).isEqualTo(spec.getLastBlockHash());
}
use of org.hyperledger.besu.ethereum.mainnet.ProtocolSpec in project besu by hyperledger.
the class CliqueProtocolScheduleTest method protocolSpecsAreCreatedAtBlockDefinedInJson.
@Test
public void protocolSpecsAreCreatedAtBlockDefinedInJson() {
final String jsonInput = "{\"config\": " + "{\"chainId\": 4,\n" + "\"homesteadBlock\": 1,\n" + "\"eip150Block\": 2,\n" + "\"eip158Block\": 3,\n" + "\"byzantiumBlock\": 1035301}" + "}";
final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
final ProtocolSchedule protocolSchedule = CliqueProtocolSchedule.create(config, NODE_KEY, false, EvmConfiguration.DEFAULT);
final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockNumber(1);
final ProtocolSpec tangerineWhistleSpec = protocolSchedule.getByBlockNumber(2);
final ProtocolSpec spuriousDragonSpec = protocolSchedule.getByBlockNumber(3);
final ProtocolSpec byzantiumSpec = protocolSchedule.getByBlockNumber(1035301);
assertThat(homesteadSpec.equals(tangerineWhistleSpec)).isFalse();
assertThat(tangerineWhistleSpec.equals(spuriousDragonSpec)).isFalse();
assertThat(spuriousDragonSpec.equals(byzantiumSpec)).isFalse();
}
use of org.hyperledger.besu.ethereum.mainnet.ProtocolSpec in project besu by hyperledger.
the class MergeProtocolScheduleTest method protocolSpecsAreCreatedAtBlockDefinedInJson.
@Test
public void protocolSpecsAreCreatedAtBlockDefinedInJson() {
final String jsonInput = "{\"config\": " + "{\"chainId\": 1,\n" + "\"homesteadBlock\": 1,\n" + "\"LondonBlock\": 1559}" + "}";
final GenesisConfigOptions config = GenesisConfigFile.fromConfig(jsonInput).getConfigOptions();
final ProtocolSchedule protocolSchedule = MergeProtocolSchedule.create(config, false);
final ProtocolSpec homesteadSpec = protocolSchedule.getByBlockNumber(1);
final ProtocolSpec londonSpec = protocolSchedule.getByBlockNumber(1559);
assertThat(homesteadSpec.equals(londonSpec)).isFalse();
assertThat(homesteadSpec.getFeeMarket().implementsBaseFee()).isFalse();
assertThat(londonSpec.getFeeMarket().implementsBaseFee()).isTrue();
}
use of org.hyperledger.besu.ethereum.mainnet.ProtocolSpec in project besu by hyperledger.
the class MergeProtocolScheduleTest method parametersAlignWithMainnetWithAdjustments.
@Test
public void parametersAlignWithMainnetWithAdjustments() {
final ProtocolSpec london = MergeProtocolSchedule.create(GenesisConfigFile.DEFAULT.getConfigOptions(), false).getByBlockNumber(0);
assertThat(london.getName()).isEqualTo("Frontier");
assertThat(london.getBlockReward()).isEqualTo(Wei.ZERO);
assertThat(london.isSkipZeroBlockRewards()).isEqualTo(true);
Bytes diffOp = Bytes.fromHexString("0x44");
var op = london.getEvm().operationAtOffset(Code.createLegacyCode(diffOp, Hash.hash(diffOp)), 0);
assertThat(op).isInstanceOf(PrevRanDaoOperation.class);
}
use of org.hyperledger.besu.ethereum.mainnet.ProtocolSpec in project besu by hyperledger.
the class EthGetMinerDataByBlockHash method createMinerDataResult.
public static MinerDataResult createMinerDataResult(final BlockWithMetadata<TransactionWithMetadata, Hash> block, final ProtocolSchedule protocolSchedule, final BlockchainQueries blockchainQueries) {
final BlockHeader blockHeader = block.getHeader();
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(blockHeader.getNumber());
final Wei staticBlockReward = protocolSpec.getBlockReward();
final Wei transactionFee = block.getTransactions().stream().map(t -> blockchainQueries.transactionReceiptByTransactionHash(t.getTransaction().getHash()).map(receipt -> receipt.getTransaction().getEffectiveGasPrice(receipt.getBaseFee()).multiply(receipt.getGasUsed())).orElse(Wei.ZERO)).reduce(Wei.ZERO, BaseUInt256Value::add);
final Wei uncleInclusionReward = staticBlockReward.multiply(block.getOmmers().size()).divide(32);
final Wei netBlockReward = staticBlockReward.add(transactionFee).add(uncleInclusionReward);
final List<UncleRewardResult> uncleRewards = new ArrayList<>();
blockchainQueries.getBlockchain().getBlockByNumber(block.getHeader().getNumber()).ifPresent(blockBody -> blockBody.getBody().getOmmers().forEach(header -> uncleRewards.add(ImmutableUncleRewardResult.builder().hash(header.getHash().toHexString()).coinbase(header.getCoinbase().toHexString()).build())));
return ImmutableMinerDataResult.builder().netBlockReward(netBlockReward.toHexString()).staticBlockReward(staticBlockReward.toHexString()).transactionFee(transactionFee.toHexString()).uncleInclusionReward(uncleInclusionReward.toHexString()).uncleRewards(uncleRewards).coinbase(blockHeader.getCoinbase().toHexString()).extraData(blockHeader.getExtraData().toHexString()).difficulty(blockHeader.getDifficulty().toHexString()).totalDifficulty(block.getTotalDifficulty().toHexString()).build();
}
Aggregations