Search in sources :

Example 1 with BaseFeePendingTransactionsSorter

use of org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter 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 2 with BaseFeePendingTransactionsSorter

use of org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter 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 3 with BaseFeePendingTransactionsSorter

use of org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter 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 4 with BaseFeePendingTransactionsSorter

use of org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter in project besu by hyperledger.

the class BlockTransactionSelectorTest method useSingleGasSpaceForAllTransactions.

@Test
public void useSingleGasSpaceForAllTransactions() {
    final ProcessableBlockHeader blockHeader = createBlockWithGasLimit(300);
    final Address miningBeneficiary = AddressHelpers.ofValue(1);
    final BaseFeePendingTransactionsSorter pendingTransactions1559 = new BaseFeePendingTransactionsSorter(TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS, 5, TestClock.fixed(), metricsSystem, () -> {
        final BlockHeader mockBlockHeader = mock(BlockHeader.class);
        when(mockBlockHeader.getBaseFee()).thenReturn(Optional.of(Wei.ONE));
        return mockBlockHeader;
    }, TransactionPoolConfiguration.DEFAULT_PRICE_BUMP);
    final BlockTransactionSelector selector = new BlockTransactionSelector(transactionProcessor, blockchain, worldState, pendingTransactions1559, blockHeader, this::createReceipt, Wei.of(6), 0.8, this::isCancelled, miningBeneficiary, FeeMarket.london(0L));
    // this should fill up all the block space
    final Transaction fillingLegacyTx = Transaction.builder().type(TransactionType.FRONTIER).gasLimit(300).gasPrice(Wei.of(10)).nonce(1).payload(Bytes.EMPTY).to(Address.ID).value(Wei.ZERO).sender(Address.ID).chainId(BigInteger.ONE).signAndBuild(keyPair);
    // so we shouldn't include this
    final Transaction extraEIP1559Tx = Transaction.builder().type(TransactionType.EIP1559).nonce(0).maxPriorityFeePerGas(Wei.of(10)).maxFeePerGas(Wei.of(10)).gasLimit(50).to(Address.ID).value(Wei.of(0)).payload(Bytes.EMPTY).chainId(BigInteger.ONE).signAndBuild(keyPair);
    when(transactionProcessor.processTransaction(any(), any(), any(), any(), any(), any(), anyBoolean(), any())).thenReturn(TransactionProcessingResult.successful(new ArrayList<>(), 0, 0, Bytes.EMPTY, ValidationResult.valid()));
    pendingTransactions1559.addRemoteTransaction(fillingLegacyTx);
    pendingTransactions1559.addRemoteTransaction(extraEIP1559Tx);
    final BlockTransactionSelector.TransactionSelectionResults results = selector.buildTransactionListForBlock();
    assertThat(results.getTransactions().size()).isEqualTo(1);
}
Also used : Address(org.hyperledger.besu.datatypes.Address) Transaction(org.hyperledger.besu.ethereum.core.Transaction) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) BaseFeePendingTransactionsSorter(org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter) ArrayList(java.util.ArrayList) ProcessableBlockHeader(org.hyperledger.besu.ethereum.core.ProcessableBlockHeader) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Test(org.junit.Test)

Example 5 with BaseFeePendingTransactionsSorter

use of org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter in project besu by hyperledger.

the class PoWBlockCreatorTest method createMainnetBlock1.

@Test
public void createMainnetBlock1() throws IOException {
    final GenesisConfigOptions genesisConfigOptions = GenesisConfigFile.DEFAULT.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());
    // A Hashrate should not exist in the block creator prior to creating a block
    assertThat(blockCreator.getHashesPerSecond().isPresent()).isFalse();
    final Block actualBlock = blockCreator.createBlock(BLOCK_1_TIMESTAMP);
    final Block expectedBlock = ValidationTestUtils.readBlock(1);
    assertThat(actualBlock).isEqualTo(expectedBlock);
    assertThat(blockCreator.getHashesPerSecond().isPresent()).isTrue();
}
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) Block(org.hyperledger.besu.ethereum.core.Block) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ProtocolScheduleBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder) PoWSolver(org.hyperledger.besu.ethereum.mainnet.PoWSolver) Test(org.junit.Test)

Aggregations

BaseFeePendingTransactionsSorter (org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter)9 Test (org.junit.Test)8 ExecutionContextTestFixture (org.hyperledger.besu.ethereum.core.ExecutionContextTestFixture)5 GenesisConfigOptions (org.hyperledger.besu.config.GenesisConfigOptions)4 EpochCalculator (org.hyperledger.besu.ethereum.mainnet.EpochCalculator)4 PoWSolver (org.hyperledger.besu.ethereum.mainnet.PoWSolver)4 ProtocolScheduleBuilder (org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder)4 ProcessableBlockHeader (org.hyperledger.besu.ethereum.core.ProcessableBlockHeader)3 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)2 ArrayList (java.util.ArrayList)1 Address (org.hyperledger.besu.datatypes.Address)1 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)1 FilterManagerBuilder (org.hyperledger.besu.ethereum.api.jsonrpc.internal.filter.FilterManagerBuilder)1 EthGetFilterChanges (org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.EthGetFilterChanges)1 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)1 Block (org.hyperledger.besu.ethereum.core.Block)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 Transaction (org.hyperledger.besu.ethereum.core.Transaction)1 EthContext (org.hyperledger.besu.ethereum.eth.manager.EthContext)1 EthPeers (org.hyperledger.besu.ethereum.eth.manager.EthPeers)1