|
|
@ -37,7 +37,6 @@ import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Random; |
|
|
|
import java.util.Random; |
|
|
|
import java.util.function.BiFunction; |
|
|
|
import java.util.function.BiFunction; |
|
|
@ -45,9 +44,12 @@ import java.util.stream.Collectors; |
|
|
|
import java.util.stream.IntStream; |
|
|
|
import java.util.stream.IntStream; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest; |
|
|
|
|
|
|
|
import org.junit.jupiter.params.provider.EnumSource; |
|
|
|
|
|
|
|
|
|
|
|
public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTransactionsTestBase { |
|
|
|
public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTransactionsTestBase { |
|
|
|
private static final FeeMarket EIP1559_FEE_MARKET = FeeMarket.london(0L); |
|
|
|
private static final FeeMarket EIP1559_FEE_MARKET = FeeMarket.london(0L); |
|
|
|
|
|
|
|
private static final Wei DEFAULT_BASE_FEE = DEFAULT_MIN_GAS_PRICE.subtract(2); |
|
|
|
private static final Random randomizeTxType = new Random(); |
|
|
|
private static final Random randomizeTxType = new Random(); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -72,7 +74,7 @@ public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTrans |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected BlockHeader mockBlockHeader() { |
|
|
|
protected BlockHeader mockBlockHeader() { |
|
|
|
return mockBlockHeader(Wei.ONE); |
|
|
|
return mockBlockHeader(DEFAULT_BASE_FEE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private BlockHeader mockBlockHeader(final Wei baseFee) { |
|
|
|
private BlockHeader mockBlockHeader(final Wei baseFee) { |
|
|
@ -112,19 +114,9 @@ public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTrans |
|
|
|
keys); |
|
|
|
keys); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void shouldPrioritizePriorityFeeThenTimeAddedToPoolOnlyEIP1559Txs() { |
|
|
|
|
|
|
|
shouldPrioritizePriorityFeeThenTimeAddedToPoolSameTypeTxs(EIP1559); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void shouldPrioritizeGasPriceThenTimeAddedToPoolOnlyFrontierTxs() { |
|
|
|
|
|
|
|
shouldPrioritizePriorityFeeThenTimeAddedToPoolSameTypeTxs(FRONTIER); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void shouldPrioritizeEffectivePriorityFeeThenTimeAddedToPoolOnMixedTypes() { |
|
|
|
public void shouldPrioritizeEffectivePriorityFeeThenTimeAddedToPoolOnMixedTypes() { |
|
|
|
final var nextBlockBaseFee = Optional.of(Wei.ONE); |
|
|
|
final var nextBlockBaseFee = Optional.of(DEFAULT_MIN_GAS_PRICE.subtract(1)); |
|
|
|
|
|
|
|
|
|
|
|
final PendingTransaction highGasPriceTransaction = |
|
|
|
final PendingTransaction highGasPriceTransaction = |
|
|
|
createRemotePendingTransaction( |
|
|
|
createRemotePendingTransaction( |
|
|
@ -167,7 +159,6 @@ public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTrans |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void txBelowCurrentMineableMinPriorityFeeIsNotPrioritized() { |
|
|
|
public void txBelowCurrentMineableMinPriorityFeeIsNotPrioritized() { |
|
|
|
setBaseFee(DEFAULT_MIN_GAS_PRICE.subtract(2)); |
|
|
|
|
|
|
|
miningParameters.setMinPriorityFeePerGas(Wei.of(5)); |
|
|
|
miningParameters.setMinPriorityFeePerGas(Wei.of(5)); |
|
|
|
final PendingTransaction lowPriorityFeeTx = |
|
|
|
final PendingTransaction lowPriorityFeeTx = |
|
|
|
createRemotePendingTransaction( |
|
|
|
createRemotePendingTransaction( |
|
|
@ -179,7 +170,6 @@ public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTrans |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void txWithPriorityBelowCurrentMineableMinPriorityFeeIsPrioritized() { |
|
|
|
public void txWithPriorityBelowCurrentMineableMinPriorityFeeIsPrioritized() { |
|
|
|
setBaseFee(DEFAULT_MIN_GAS_PRICE.subtract(2)); |
|
|
|
|
|
|
|
miningParameters.setMinPriorityFeePerGas(Wei.of(5)); |
|
|
|
miningParameters.setMinPriorityFeePerGas(Wei.of(5)); |
|
|
|
final PendingTransaction lowGasPriceTx = |
|
|
|
final PendingTransaction lowGasPriceTx = |
|
|
|
createRemotePendingTransaction( |
|
|
|
createRemotePendingTransaction( |
|
|
@ -188,11 +178,29 @@ public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTrans |
|
|
|
assertTransactionPrioritized(lowGasPriceTx); |
|
|
|
assertTransactionPrioritized(lowGasPriceTx); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void shouldPrioritizePriorityFeeThenTimeAddedToPoolSameTypeTxs( |
|
|
|
@ParameterizedTest |
|
|
|
|
|
|
|
@EnumSource( |
|
|
|
|
|
|
|
value = TransactionType.class, |
|
|
|
|
|
|
|
names = {"EIP1559", "BLOB"}) |
|
|
|
|
|
|
|
public void txWithEffectiveGasPriceBelowCurrentMineableMinGasPriceIsNotPrioritized( |
|
|
|
|
|
|
|
final TransactionType type) { |
|
|
|
|
|
|
|
final PendingTransaction lowGasPriceTx = |
|
|
|
|
|
|
|
createRemotePendingTransaction( |
|
|
|
|
|
|
|
createTransaction(type, 0, DEFAULT_MIN_GAS_PRICE, Wei.ONE, 0, 1, KEYS1)); |
|
|
|
|
|
|
|
assertThat(prioritizeTransaction(lowGasPriceTx)).isEqualTo(DROPPED); |
|
|
|
|
|
|
|
assertEvicted(lowGasPriceTx); |
|
|
|
|
|
|
|
assertTransactionNotPrioritized(lowGasPriceTx); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedTest |
|
|
|
|
|
|
|
@EnumSource( |
|
|
|
|
|
|
|
value = TransactionType.class, |
|
|
|
|
|
|
|
names = {"EIP1559", "FRONTIER"}) |
|
|
|
|
|
|
|
public void shouldPrioritizePriorityFeeThenTimeAddedToPoolSameTypeTxs( |
|
|
|
final TransactionType transactionType) { |
|
|
|
final TransactionType transactionType) { |
|
|
|
final PendingTransaction highGasPriceTransaction = |
|
|
|
final PendingTransaction highGasPriceTransaction = |
|
|
|
createRemotePendingTransaction( |
|
|
|
createRemotePendingTransaction( |
|
|
|
createTransaction(0, DEFAULT_MIN_GAS_PRICE.multiply(20), KEYS1)); |
|
|
|
createTransaction(0, DEFAULT_MIN_GAS_PRICE.multiply(200), KEYS1)); |
|
|
|
|
|
|
|
|
|
|
|
final var lowValueTxs = |
|
|
|
final var lowValueTxs = |
|
|
|
IntStream.range(0, MAX_TRANSACTIONS) |
|
|
|
IntStream.range(0, MAX_TRANSACTIONS) |
|
|
@ -202,7 +210,7 @@ public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTrans |
|
|
|
createTransaction( |
|
|
|
createTransaction( |
|
|
|
transactionType, |
|
|
|
transactionType, |
|
|
|
0, |
|
|
|
0, |
|
|
|
DEFAULT_MIN_GAS_PRICE.add(1), |
|
|
|
DEFAULT_MIN_GAS_PRICE.add(1).multiply(20), |
|
|
|
0, |
|
|
|
0, |
|
|
|
SIGNATURE_ALGORITHM.get().generateKeyPair()))) |
|
|
|
SIGNATURE_ALGORITHM.get().generateKeyPair()))) |
|
|
|
.collect(Collectors.toUnmodifiableList()); |
|
|
|
.collect(Collectors.toUnmodifiableList()); |
|
|
@ -210,8 +218,4 @@ public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTrans |
|
|
|
shouldPrioritizeValueThenTimeAddedToPool( |
|
|
|
shouldPrioritizeValueThenTimeAddedToPool( |
|
|
|
lowValueTxs.iterator(), highGasPriceTransaction, lowValueTxs.get(0)); |
|
|
|
lowValueTxs.iterator(), highGasPriceTransaction, lowValueTxs.get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setBaseFee(final Wei baseFee) { |
|
|
|
|
|
|
|
transactions.blockAdded(EIP1559_FEE_MARKET, mockBlockHeader(baseFee), Map.of()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|