Search in sources :

Example 1 with ProtocolScheduleBuilder

use of org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder in project besu by hyperledger.

the class BaseBftProtocolSchedule method createProtocolSchedule.

public ProtocolSchedule createProtocolSchedule(final GenesisConfigOptions config, final ForksSchedule<? extends BftConfigOptions> forksSchedule, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final BftExtraDataCodec bftExtraDataCodec, final EvmConfiguration evmConfiguration) {
    final Map<Long, Function<ProtocolSpecBuilder, ProtocolSpecBuilder>> specMap = new HashMap<>();
    forksSchedule.getForks().forEach(forkSpec -> specMap.put(forkSpec.getBlock(), builder -> applyBftChanges(builder, forkSpec.getValue(), config.isQuorum(), bftExtraDataCodec)));
    final ProtocolSpecAdapters specAdapters = new ProtocolSpecAdapters(specMap);
    return new ProtocolScheduleBuilder(config, DEFAULT_CHAIN_ID, specAdapters, privacyParameters, isRevertReasonEnabled, config.isQuorum(), evmConfiguration).createProtocolSchedule();
}
Also used : MainnetProtocolSpecs(org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSpecs) ProtocolSpecBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder) ProtocolSpecAdapters(org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters) ProtocolScheduleBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder) FeeMarket(org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket) HashMap(java.util.HashMap) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) EvmConfiguration(org.hyperledger.besu.evm.internal.EvmConfiguration) Function(java.util.function.Function) ProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule) BftConfigOptions(org.hyperledger.besu.config.BftConfigOptions) MainnetBlockBodyValidator(org.hyperledger.besu.ethereum.mainnet.MainnetBlockBodyValidator) MainnetBlockImporter(org.hyperledger.besu.ethereum.mainnet.MainnetBlockImporter) ForksSchedule(org.hyperledger.besu.consensus.common.ForksSchedule) BlockHeaderValidator(org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator) Map(java.util.Map) Wei(org.hyperledger.besu.datatypes.Wei) BigInteger(java.math.BigInteger) PrivacyParameters(org.hyperledger.besu.ethereum.core.PrivacyParameters) Function(java.util.function.Function) HashMap(java.util.HashMap) ProtocolSpecAdapters(org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters) ProtocolScheduleBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder)

Example 2 with ProtocolScheduleBuilder

use of org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder in project besu by hyperledger.

the class PoWBlockCreatorTest method createMainnetBlock1_fixedDifficulty1.

@Test
public void createMainnetBlock1_fixedDifficulty1() {
    final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}").getConfigOptions();
    final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(new ProtocolScheduleBuilder(genesisConfigOptions, BigInteger.valueOf(42), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, genesisConfigOptions.isQuorum(), EvmConfiguration.DEFAULT).createProtocolSchedule()).build();
    final PoWSolver solver = new PoWSolver(Lists.newArrayList(BLOCK_1_NONCE), PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
    final BaseFeePendingTransactionsSorter pendingTransactions = new BaseFeePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
    final PoWBlockCreator blockCreator = new PoWBlockCreator(BLOCK_1_COINBASE, () -> Optional.empty(), parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, executionContextTestFixture.getProtocolContext(), executionContextTestFixture.getProtocolSchedule(), solver, Wei.ZERO, 0.8, executionContextTestFixture.getBlockchain().getChainHeadHeader());
    blockCreator.createBlock(BLOCK_1_TIMESTAMP);
// If we weren't setting difficulty to 2^256-1 a difficulty of 1 would have caused a
// IllegalArgumentException at the previous line, as 2^256 is 33 bytes.
}
Also used : EpochCalculator(org.hyperledger.besu.ethereum.mainnet.EpochCalculator) BaseFeePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter) ExecutionContextTestFixture(org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolScheduleBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder) PoWSolver(org.hyperledger.besu.ethereum.mainnet.PoWSolver) Test(org.junit.Test)

Example 3 with ProtocolScheduleBuilder

use of org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder in project besu by hyperledger.

the class PoWBlockCreatorTest method rewardBeneficiary_zeroReward_skipZeroRewardsTrue.

@Test
public void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() {
    final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}").getConfigOptions();
    final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(new ProtocolScheduleBuilder(genesisConfigOptions, BigInteger.valueOf(42), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, genesisConfigOptions.isQuorum(), EvmConfiguration.DEFAULT).createProtocolSchedule()).build();
    final PoWSolver solver = new PoWSolver(Lists.newArrayList(BLOCK_1_NONCE), PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
    final BaseFeePendingTransactionsSorter pendingTransactions = new BaseFeePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
    final PoWBlockCreator blockCreator = new PoWBlockCreator(BLOCK_1_COINBASE, () -> Optional.of(10_000_000L), parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, executionContextTestFixture.getProtocolContext(), executionContextTestFixture.getProtocolSchedule(), solver, Wei.ZERO, 0.8, executionContextTestFixture.getBlockchain().getChainHeadHeader());
    final MutableWorldState mutableWorldState = executionContextTestFixture.getStateArchive().getMutable();
    assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNull();
    final ProcessableBlockHeader header = BlockHeaderBuilder.create().parentHash(Hash.ZERO).coinbase(BLOCK_1_COINBASE).difficulty(Difficulty.ONE).number(1).gasLimit(1).timestamp(1).buildProcessableBlockHeader();
    blockCreator.rewardBeneficiary(mutableWorldState, header, Collections.emptyList(), BLOCK_1_COINBASE, Wei.ZERO, true);
    assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNull();
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) EpochCalculator(org.hyperledger.besu.ethereum.mainnet.EpochCalculator) BaseFeePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) ExecutionContextTestFixture(org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolScheduleBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder) PoWSolver(org.hyperledger.besu.ethereum.mainnet.PoWSolver) Test(org.junit.Test)

Example 4 with ProtocolScheduleBuilder

use of org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder in project besu by hyperledger.

the class PoWBlockCreatorTest method rewardBeneficiary_zeroReward_skipZeroRewardsFalse.

@Test
public void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() {
    final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.fromConfig("{\"config\": {\"ethash\": {\"fixeddifficulty\":1}}}").getConfigOptions();
    final ExecutionContextTestFixture executionContextTestFixture = ExecutionContextTestFixture.builder().protocolSchedule(new ProtocolScheduleBuilder(genesisConfigOptions, BigInteger.valueOf(42), ProtocolSpecAdapters.create(0, Function.identity()), PrivacyParameters.DEFAULT, false, genesisConfigOptions.isQuorum(), EvmConfiguration.DEFAULT).createProtocolSchedule()).build();
    final PoWSolver solver = new PoWSolver(Lists.newArrayList(BLOCK_1_NONCE), PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator(), 1000, 8);
    final BaseFeePendingTransactionsSorter pendingTransactions = new BaseFeePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 1, TestClock.fixed(), metricsSystem, executionContextTestFixture.getProtocolContext().getBlockchain()::getChainHeadHeader, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
    final PoWBlockCreator blockCreator = new PoWBlockCreator(BLOCK_1_COINBASE, () -> Optional.of(10_000_000L), parent -> BLOCK_1_EXTRA_DATA, pendingTransactions, executionContextTestFixture.getProtocolContext(), executionContextTestFixture.getProtocolSchedule(), solver, Wei.ZERO, 0.8, executionContextTestFixture.getBlockchain().getChainHeadHeader());
    final MutableWorldState mutableWorldState = executionContextTestFixture.getStateArchive().getMutable();
    assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNull();
    final ProcessableBlockHeader header = BlockHeaderBuilder.create().parentHash(Hash.ZERO).coinbase(BLOCK_1_COINBASE).difficulty(Difficulty.ONE).number(1).gasLimit(1).timestamp(1).buildProcessableBlockHeader();
    blockCreator.rewardBeneficiary(mutableWorldState, header, Collections.emptyList(), BLOCK_1_COINBASE, Wei.ZERO, false);
    assertThat(mutableWorldState.get(BLOCK_1_COINBASE)).isNotNull();
    assertThat(mutableWorldState.get(BLOCK_1_COINBASE).getBalance()).isEqualTo(Wei.ZERO);
}
Also used : MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) EpochCalculator(org.hyperledger.besu.ethereum.mainnet.EpochCalculator) BaseFeePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) ExecutionContextTestFixture(org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolScheduleBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder) PoWSolver(org.hyperledger.besu.ethereum.mainnet.PoWSolver) Test(org.junit.Test)

Example 5 with ProtocolScheduleBuilder

use of org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder in project besu by hyperledger.

the class IbftProtocolSchedule method create.

public static ProtocolSchedule create(final GenesisConfigOptions config, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, final EvmConfiguration evmConfiguration) {
    final IbftLegacyConfigOptions ibftConfig = config.getIbftLegacyConfigOptions();
    final long blockPeriod = ibftConfig.getBlockPeriodSeconds();
    return new ProtocolScheduleBuilder(config, DEFAULT_CHAIN_ID, ProtocolSpecAdapters.create(0, builder -> applyIbftChanges(blockPeriod, builder, config.isQuorum(), ibftConfig.getCeil2Nby3Block())), privacyParameters, isRevertReasonEnabled, config.isQuorum(), evmConfiguration).createProtocolSchedule();
}
Also used : IbftLegacyConfigOptions(org.hyperledger.besu.config.IbftLegacyConfigOptions) ProtocolScheduleBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder)

Aggregations

ProtocolScheduleBuilder (org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder)7 GenesisConfigOptions (org.hyperledger.besu.config.GenesisConfigOptions)5 ExecutionContextTestFixture (org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture)4 BaseFeePendingTransactionsSorter (org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter)4 EpochCalculator (org.hyperledger.besu.ethereum.mainnet.EpochCalculator)4 PoWSolver (org.hyperledger.besu.ethereum.mainnet.PoWSolver)4 Test (org.junit.Test)4 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)2 ProcessableBlockHeader (org.hyperledger.besu.ethereum.core.ProcessableBlockHeader)2 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Function (java.util.function.Function)1 BftConfigOptions (org.hyperledger.besu.config.BftConfigOptions)1 CliqueConfigOptions (org.hyperledger.besu.config.CliqueConfigOptions)1 IbftLegacyConfigOptions (org.hyperledger.besu.config.IbftLegacyConfigOptions)1 EpochManager (org.hyperledger.besu.consensus.common.EpochManager)1 ForksSchedule (org.hyperledger.besu.consensus.common.ForksSchedule)1 Address (org.hyperledger.besu.datatypes.Address)1 Wei (org.hyperledger.besu.datatypes.Wei)1