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.
}
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();
}
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);
}
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);
}
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();
}
Aggregations