|
|
@ -105,6 +105,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
.number(1) |
|
|
|
.number(1) |
|
|
|
.gasLimit(gasLimit) |
|
|
|
.gasLimit(gasLimit) |
|
|
|
.timestamp(Instant.now().toEpochMilli()) |
|
|
|
.timestamp(Instant.now().toEpochMilli()) |
|
|
|
|
|
|
|
.baseFee(1L) |
|
|
|
.buildProcessableBlockHeader(); |
|
|
|
.buildProcessableBlockHeader(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -133,15 +134,14 @@ public class BlockTransactionSelectorTest { |
|
|
|
this::isCancelled, |
|
|
|
this::isCancelled, |
|
|
|
miningBeneficiary, |
|
|
|
miningBeneficiary, |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier()); |
|
|
|
Optional.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final BlockTransactionSelector.TransactionSelectionResults results = |
|
|
|
final BlockTransactionSelector.TransactionSelectionResults results = |
|
|
|
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit()); |
|
|
|
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit()); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(results.getTransactions().size()).isEqualTo(0); |
|
|
|
assertThat(results.getTransactions().size()).isEqualTo(0); |
|
|
|
assertThat(results.getReceipts().size()).isEqualTo(0); |
|
|
|
assertThat(results.getReceipts().size()).isEqualTo(0); |
|
|
|
assertThat(results.getFrontierCumulativeGasUsed()).isEqualTo(0); |
|
|
|
assertThat(results.getCumulativeGasUsed()).isEqualTo(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -172,8 +172,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
this::isCancelled, |
|
|
|
this::isCancelled, |
|
|
|
miningBeneficiary, |
|
|
|
miningBeneficiary, |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier()); |
|
|
|
Optional.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final BlockTransactionSelector.TransactionSelectionResults results = |
|
|
|
final BlockTransactionSelector.TransactionSelectionResults results = |
|
|
|
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit()); |
|
|
|
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit()); |
|
|
@ -181,7 +180,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
assertThat(results.getTransactions().size()).isEqualTo(1); |
|
|
|
assertThat(results.getTransactions().size()).isEqualTo(1); |
|
|
|
Assertions.assertThat(results.getTransactions()).contains(transaction); |
|
|
|
Assertions.assertThat(results.getTransactions()).contains(transaction); |
|
|
|
assertThat(results.getReceipts().size()).isEqualTo(1); |
|
|
|
assertThat(results.getReceipts().size()).isEqualTo(1); |
|
|
|
assertThat(results.getFrontierCumulativeGasUsed()).isEqualTo(95L); |
|
|
|
assertThat(results.getCumulativeGasUsed()).isEqualTo(95L); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -229,8 +228,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
this::isCancelled, |
|
|
|
this::isCancelled, |
|
|
|
miningBeneficiary, |
|
|
|
miningBeneficiary, |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier()); |
|
|
|
Optional.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final BlockTransactionSelector.TransactionSelectionResults results = |
|
|
|
final BlockTransactionSelector.TransactionSelectionResults results = |
|
|
|
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit()); |
|
|
|
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit()); |
|
|
@ -238,7 +236,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
assertThat(results.getTransactions().size()).isEqualTo(4); |
|
|
|
assertThat(results.getTransactions().size()).isEqualTo(4); |
|
|
|
assertThat(results.getTransactions().contains(transactionsToInject.get(1))).isFalse(); |
|
|
|
assertThat(results.getTransactions().contains(transactionsToInject.get(1))).isFalse(); |
|
|
|
assertThat(results.getReceipts().size()).isEqualTo(4); |
|
|
|
assertThat(results.getReceipts().size()).isEqualTo(4); |
|
|
|
assertThat(results.getFrontierCumulativeGasUsed()).isEqualTo(400); |
|
|
|
assertThat(results.getCumulativeGasUsed()).isEqualTo(400); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -274,8 +272,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
this::isCancelled, |
|
|
|
this::isCancelled, |
|
|
|
miningBeneficiary, |
|
|
|
miningBeneficiary, |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier()); |
|
|
|
Optional.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final BlockTransactionSelector.TransactionSelectionResults results = |
|
|
|
final BlockTransactionSelector.TransactionSelectionResults results = |
|
|
|
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit()); |
|
|
|
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit()); |
|
|
@ -284,7 +281,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
|
|
|
|
|
|
|
|
assertThat(results.getTransactions().containsAll(transactionsToInject.subList(0, 3))).isTrue(); |
|
|
|
assertThat(results.getTransactions().containsAll(transactionsToInject.subList(0, 3))).isTrue(); |
|
|
|
assertThat(results.getReceipts().size()).isEqualTo(3); |
|
|
|
assertThat(results.getReceipts().size()).isEqualTo(3); |
|
|
|
assertThat(results.getFrontierCumulativeGasUsed()).isEqualTo(300); |
|
|
|
assertThat(results.getCumulativeGasUsed()).isEqualTo(300); |
|
|
|
|
|
|
|
|
|
|
|
// Ensure receipts have the correct cumulative gas
|
|
|
|
// Ensure receipts have the correct cumulative gas
|
|
|
|
Assertions.assertThat(results.getReceipts().get(0).getCumulativeGasUsed()).isEqualTo(100); |
|
|
|
Assertions.assertThat(results.getReceipts().get(0).getCumulativeGasUsed()).isEqualTo(100); |
|
|
@ -310,8 +307,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
this::isCancelled, |
|
|
|
this::isCancelled, |
|
|
|
miningBeneficiary, |
|
|
|
miningBeneficiary, |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier()); |
|
|
|
Optional.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Transaction tx = createTransaction(1); |
|
|
|
final Transaction tx = createTransaction(1); |
|
|
|
pendingTransactions.addRemoteTransaction(tx); |
|
|
|
pendingTransactions.addRemoteTransaction(tx); |
|
|
@ -323,6 +319,68 @@ public class BlockTransactionSelectorTest { |
|
|
|
assertThat(pendingTransactions.size()).isEqualTo(0); |
|
|
|
assertThat(pendingTransactions.size()).isEqualTo(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void useSingleGasSpaceForAllTransactions() { |
|
|
|
|
|
|
|
final ProcessableBlockHeader blockHeader = createBlockWithGasLimit(300); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Address miningBeneficiary = AddressHelpers.ofValue(1); |
|
|
|
|
|
|
|
final BlockTransactionSelector selector = |
|
|
|
|
|
|
|
new BlockTransactionSelector( |
|
|
|
|
|
|
|
transactionProcessor, |
|
|
|
|
|
|
|
blockchain, |
|
|
|
|
|
|
|
worldState, |
|
|
|
|
|
|
|
pendingTransactions, |
|
|
|
|
|
|
|
blockHeader, |
|
|
|
|
|
|
|
this::createReceipt, |
|
|
|
|
|
|
|
Wei.of(6), |
|
|
|
|
|
|
|
0.8, |
|
|
|
|
|
|
|
this::isCancelled, |
|
|
|
|
|
|
|
miningBeneficiary, |
|
|
|
|
|
|
|
TransactionPriceCalculator.eip1559(), |
|
|
|
|
|
|
|
TransactionGasBudgetCalculator.frontier()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pendingTransactions.addRemoteTransaction(fillingLegacyTx); |
|
|
|
|
|
|
|
pendingTransactions.addRemoteTransaction(extraEIP1559Tx); |
|
|
|
|
|
|
|
final BlockTransactionSelector.TransactionSelectionResults results = |
|
|
|
|
|
|
|
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(results.getTransactions().size()).isEqualTo(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void transactionTooLargeForBlockDoesNotPreventMoreBeingAddedIfBlockOccupancyNotReached() { |
|
|
|
public void transactionTooLargeForBlockDoesNotPreventMoreBeingAddedIfBlockOccupancyNotReached() { |
|
|
|
final ProcessableBlockHeader blockHeader = createBlockWithGasLimit(300); |
|
|
|
final ProcessableBlockHeader blockHeader = createBlockWithGasLimit(300); |
|
|
@ -347,8 +405,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
this::isCancelled, |
|
|
|
this::isCancelled, |
|
|
|
miningBeneficiary, |
|
|
|
miningBeneficiary, |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier()); |
|
|
|
Optional.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final TransactionTestFixture txTestFixture = new TransactionTestFixture(); |
|
|
|
final TransactionTestFixture txTestFixture = new TransactionTestFixture(); |
|
|
|
// Add 3 transactions to the Pending Transactions, 79% of block, 100% of block and 10% of block
|
|
|
|
// Add 3 transactions to the Pending Transactions, 79% of block, 100% of block and 10% of block
|
|
|
@ -405,8 +462,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
this::isCancelled, |
|
|
|
this::isCancelled, |
|
|
|
miningBeneficiary, |
|
|
|
miningBeneficiary, |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier()); |
|
|
|
Optional.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final TransactionTestFixture txTestFixture = new TransactionTestFixture(); |
|
|
|
final TransactionTestFixture txTestFixture = new TransactionTestFixture(); |
|
|
|
// Add 4 transactions to the Pending Transactions 15% (ok), 79% (ok), 25% (too large), 10%
|
|
|
|
// Add 4 transactions to the Pending Transactions 15% (ok), 79% (ok), 25% (too large), 10%
|
|
|
@ -467,8 +523,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
this::isCancelled, |
|
|
|
this::isCancelled, |
|
|
|
miningBeneficiary, |
|
|
|
miningBeneficiary, |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier()); |
|
|
|
Optional.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final TransactionTestFixture txTestFixture = new TransactionTestFixture(); |
|
|
|
final TransactionTestFixture txTestFixture = new TransactionTestFixture(); |
|
|
|
final Transaction validTransaction = |
|
|
|
final Transaction validTransaction = |
|
|
@ -549,8 +604,7 @@ public class BlockTransactionSelectorTest { |
|
|
|
this::isCancelled, |
|
|
|
this::isCancelled, |
|
|
|
miningBeneficiary, |
|
|
|
miningBeneficiary, |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionPriceCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier(), |
|
|
|
TransactionGasBudgetCalculator.frontier()); |
|
|
|
Optional.empty()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final BlockTransactionSelector.TransactionSelectionResults results = |
|
|
|
final BlockTransactionSelector.TransactionSelectionResults results = |
|
|
|
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit()); |
|
|
|
selector.buildTransactionListForBlock(blockHeader.getNumber(), blockHeader.getGasLimit()); |
|
|
|