Search in sources :

Example 1 with ProtocolSpec

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());
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) BlockImporter(org.hyperledger.besu.ethereum.core.BlockImporter) BlockchainReferenceTestCaseSpec(org.hyperledger.besu.ethereum.referencetests.BlockchainReferenceTestCaseSpec) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) RLPException(org.hyperledger.besu.ethereum.rlp.RLPException) ProtocolContext(org.hyperledger.besu.ethereum.ProtocolContext) Block(org.hyperledger.besu.ethereum.core.Block) MutableBlockchain(org.hyperledger.besu.ethereum.chain.MutableBlockchain) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) HeaderValidationMode(org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode)

Example 2 with ProtocolSpec

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();
}
Also used : ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) Test(org.junit.Test)

Example 3 with ProtocolSpec

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();
}
Also used : ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) Test(org.junit.Test)

Example 4 with ProtocolSpec

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);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) Test(org.junit.Test)

Example 5 with ProtocolSpec

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();
}
Also used : ImmutableMinerDataResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableMinerDataResult) BaseUInt256Value(org.apache.tuweni.units.bigints.BaseUInt256Value) MinerDataResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult) ImmutableUncleRewardResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableUncleRewardResult) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Supplier(java.util.function.Supplier) UncleRewardResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult.UncleRewardResult) ArrayList(java.util.ArrayList) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) List(java.util.List) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) BlockWithMetadata(org.hyperledger.besu.ethereum.api.query.BlockWithMetadata) TransactionWithMetadata(org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata) Wei(org.hyperledger.besu.datatypes.Wei) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) Suppliers(com.google.common.base.Suppliers) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) Hash(org.hyperledger.besu.datatypes.Hash) BaseUInt256Value(org.apache.tuweni.units.bigints.BaseUInt256Value) ImmutableUncleRewardResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableUncleRewardResult) UncleRewardResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.MinerDataResult.UncleRewardResult) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) ArrayList(java.util.ArrayList) Wei(org.hyperledger.besu.datatypes.Wei) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Aggregations

ProtocolSpec (org.hyperledger.besu.ethereum.mainnet.ProtocolSpec)48 Test (org.junit.Test)21 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)18 ProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule)17 Block (org.hyperledger.besu.ethereum.core.Block)16 BlockImporter (org.hyperledger.besu.ethereum.core.BlockImporter)10 Optional (java.util.Optional)8 Address (org.hyperledger.besu.datatypes.Address)8 Hash (org.hyperledger.besu.datatypes.Hash)8 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)8 List (java.util.List)7 Transaction (org.hyperledger.besu.ethereum.core.Transaction)7 BigInteger (java.math.BigInteger)6 Bytes (org.apache.tuweni.bytes.Bytes)6 Wei (org.hyperledger.besu.datatypes.Wei)6 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)5 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)5 BlockHashLookup (org.hyperledger.besu.ethereum.vm.BlockHashLookup)5 ArrayList (java.util.ArrayList)4 Bytes32 (org.apache.tuweni.bytes.Bytes32)4