Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tx effective gas price when comparing with min mineable gas price… #6958

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ protected boolean promotionFilter(final PendingTransaction pendingTransaction) {

// priority txs are promoted even if they pay less
if (!pendingTransaction.hasPriority()) {
// check if max fee per gas is higher than the min gas price
// check if effective gas price is higher than the min gas price
if (pendingTransaction
.getTransaction()
.getMaxGasPrice()
.getEffectiveGasPrice(nextBlockBaseFee)
.lessThan(miningParameters.getMinTransactionGasPrice())) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class PendingTransactionEstimatedMemorySizeTest extends BaseTransactionPo
@Test
public void toSize() {
TransactionTestFixture preparedTx =
prepareTransaction(TransactionType.ACCESS_LIST, 10, Wei.of(500), 10, 0);
prepareTransaction(TransactionType.ACCESS_LIST, 10, Wei.of(500), Wei.ZERO, 10, 0);
Transaction txTo =
preparedTx.to(Optional.of(Address.extract(Bytes32.random()))).createTransaction(KEYS1);
BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
Expand Down Expand Up @@ -115,7 +115,7 @@ public void toSize() {
public void payloadSize() {

TransactionTestFixture preparedTx =
prepareTransaction(TransactionType.ACCESS_LIST, 10, Wei.of(500), 10, 0);
prepareTransaction(TransactionType.ACCESS_LIST, 10, Wei.of(500), Wei.ZERO, 10, 0);
Transaction txPayload = preparedTx.createTransaction(KEYS1);
BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
txPayload.writeTo(rlpOut);
Expand Down Expand Up @@ -207,7 +207,7 @@ private void blobsWithCommitmentsFieldSize(
final long containerSize,
final long itemSize) {
TransactionTestFixture preparedTx =
prepareTransaction(TransactionType.BLOB, 10, Wei.of(500), 10, 1);
prepareTransaction(TransactionType.BLOB, 10, Wei.of(500), Wei.of(50), 10, 1);
Transaction txBlob = preparedTx.createTransaction(KEYS1);
BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
TransactionEncoder.encodeRLP(txBlob, rlpOut, EncodingContext.POOLED_TRANSACTION);
Expand Down Expand Up @@ -239,7 +239,7 @@ private void blobsWithCommitmentsFieldSize(
@Test
public void blobsWithCommitmentsSize() {
TransactionTestFixture preparedTx =
prepareTransaction(TransactionType.BLOB, 10, Wei.of(500), 10, 1);
prepareTransaction(TransactionType.BLOB, 10, Wei.of(500), Wei.of(50), 10, 1);
Transaction txBlob = preparedTx.createTransaction(KEYS1);
BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
TransactionEncoder.encodeRLP(txBlob, rlpOut, EncodingContext.POOLED_TRANSACTION);
Expand Down Expand Up @@ -268,7 +268,7 @@ public void blobsWithCommitmentsSize() {
public void pendingTransactionSize() {

TransactionTestFixture preparedTx =
prepareTransaction(TransactionType.ACCESS_LIST, 10, Wei.of(500), 10, 0);
prepareTransaction(TransactionType.ACCESS_LIST, 10, Wei.of(500), Wei.ZERO, 10, 0);
Transaction txPayload = preparedTx.createTransaction(KEYS1);
BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
txPayload.writeTo(rlpOut);
Expand Down Expand Up @@ -300,7 +300,7 @@ public void accessListSize() {
final List<AccessListEntry> ales = List.of(ale1);

TransactionTestFixture preparedTx =
prepareTransaction(TransactionType.ACCESS_LIST, 0, Wei.of(500), 0, 0);
prepareTransaction(TransactionType.ACCESS_LIST, 0, Wei.of(500), Wei.ZERO, 0, 0);
Transaction txAccessList = preparedTx.accessList(ales).createTransaction(KEYS1);
BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
txAccessList.writeTo(rlpOut);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

public class BaseFeePrioritizedTransactionsTest extends AbstractPrioritizedTransactionsTestBase {
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();

@Override
Expand All @@ -72,7 +74,7 @@ AbstractPrioritizedTransactions getSorter(

@Override
protected BlockHeader mockBlockHeader() {
return mockBlockHeader(Wei.ONE);
return mockBlockHeader(DEFAULT_BASE_FEE);
}

private BlockHeader mockBlockHeader(final Wei baseFee) {
Expand Down Expand Up @@ -112,19 +114,9 @@ protected Transaction createTransactionReplacement(
keys);
}

@Test
public void shouldPrioritizePriorityFeeThenTimeAddedToPoolOnlyEIP1559Txs() {
shouldPrioritizePriorityFeeThenTimeAddedToPoolSameTypeTxs(EIP1559);
}

@Test
public void shouldPrioritizeGasPriceThenTimeAddedToPoolOnlyFrontierTxs() {
shouldPrioritizePriorityFeeThenTimeAddedToPoolSameTypeTxs(FRONTIER);
}

@Test
public void shouldPrioritizeEffectivePriorityFeeThenTimeAddedToPoolOnMixedTypes() {
final var nextBlockBaseFee = Optional.of(Wei.ONE);
final var nextBlockBaseFee = Optional.of(DEFAULT_MIN_GAS_PRICE.subtract(1));

final PendingTransaction highGasPriceTransaction =
createRemotePendingTransaction(
Expand Down Expand Up @@ -167,7 +159,6 @@ public void shouldPrioritizeEffectivePriorityFeeThenTimeAddedToPoolOnMixedTypes(

@Test
public void txBelowCurrentMineableMinPriorityFeeIsNotPrioritized() {
setBaseFee(DEFAULT_MIN_GAS_PRICE.subtract(2));
miningParameters.setMinPriorityFeePerGas(Wei.of(5));
final PendingTransaction lowPriorityFeeTx =
createRemotePendingTransaction(
Expand All @@ -179,7 +170,6 @@ public void txBelowCurrentMineableMinPriorityFeeIsNotPrioritized() {

@Test
public void txWithPriorityBelowCurrentMineableMinPriorityFeeIsPrioritized() {
setBaseFee(DEFAULT_MIN_GAS_PRICE.subtract(2));
miningParameters.setMinPriorityFeePerGas(Wei.of(5));
final PendingTransaction lowGasPriceTx =
createRemotePendingTransaction(
Expand All @@ -188,11 +178,29 @@ public void txWithPriorityBelowCurrentMineableMinPriorityFeeIsPrioritized() {
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 PendingTransaction highGasPriceTransaction =
createRemotePendingTransaction(
createTransaction(0, DEFAULT_MIN_GAS_PRICE.multiply(20), KEYS1));
createTransaction(0, DEFAULT_MIN_GAS_PRICE.multiply(200), KEYS1));

final var lowValueTxs =
IntStream.range(0, MAX_TRANSACTIONS)
Expand All @@ -202,16 +210,12 @@ private void shouldPrioritizePriorityFeeThenTimeAddedToPoolSameTypeTxs(
createTransaction(
transactionType,
0,
DEFAULT_MIN_GAS_PRICE.add(1),
DEFAULT_MIN_GAS_PRICE.add(1).multiply(20),
0,
SIGNATURE_ALGORITHM.get().generateKeyPair())))
.collect(Collectors.toUnmodifiableList());

shouldPrioritizeValueThenTimeAddedToPool(
lowValueTxs.iterator(), highGasPriceTransaction, lowValueTxs.get(0));
}

private void setBaseFee(final Wei baseFee) {
transactions.blockAdded(EIP1559_FEE_MARKET, mockBlockHeader(baseFee), Map.of());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ protected Transaction createEIP1559Transaction(
protected Transaction createEIP4844Transaction(
final long nonce, final KeyPair keys, final int gasFeeMultiplier, final int blobCount) {
return createTransaction(
TransactionType.BLOB, nonce, Wei.of(5000L).multiply(gasFeeMultiplier), 0, blobCount, keys);
TransactionType.BLOB,
nonce,
Wei.of(5000L).multiply(gasFeeMultiplier),
Wei.of(5000L).multiply(gasFeeMultiplier).divide(10),
0,
blobCount,
keys);
}

protected Transaction createTransaction(
Expand All @@ -112,24 +118,28 @@ protected Transaction createTransaction(
final Wei maxGasPrice,
final int payloadSize,
final KeyPair keys) {
return createTransaction(type, nonce, maxGasPrice, payloadSize, 0, keys);
return createTransaction(
type, nonce, maxGasPrice, maxGasPrice.divide(10), payloadSize, 0, keys);
}

protected Transaction createTransaction(
final TransactionType type,
final long nonce,
final Wei maxGasPrice,
final Wei maxPriorityFeePerGas,
final int payloadSize,
final int blobCount,
final KeyPair keys) {
return prepareTransaction(type, nonce, maxGasPrice, payloadSize, blobCount)
return prepareTransaction(
type, nonce, maxGasPrice, maxPriorityFeePerGas, payloadSize, blobCount)
.createTransaction(keys);
}

protected TransactionTestFixture prepareTransaction(
final TransactionType type,
final long nonce,
final Wei maxGasPrice,
final Wei maxPriorityFeePerGas,
final int payloadSize,
final int blobCount) {

Expand All @@ -145,7 +155,7 @@ protected TransactionTestFixture prepareTransaction(
}
if (type.supports1559FeeMarket()) {
tx.maxFeePerGas(Optional.of(maxGasPrice))
.maxPriorityFeePerGas(Optional.of(maxGasPrice.divide(10)));
.maxPriorityFeePerGas(Optional.of(maxPriorityFeePerGas));
if (type.supportsBlob() && blobCount > 0) {
final var versionHashes =
IntStream.range(0, blobCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
public class LayersTest extends BaseTransactionPoolTest {
private static final int MAX_PRIO_TRANSACTIONS = 3;
private static final int MAX_FUTURE_FOR_SENDER = 10;
private static final Wei BASE_FEE = Wei.ONE;
private static final Wei MIN_GAS_PRICE = BASE_FEE;

private final TransactionPoolConfiguration poolConfig =
ImmutableTransactionPoolConfiguration.builder()
Expand Down Expand Up @@ -96,7 +98,7 @@ public class LayersTest extends BaseTransactionPoolTest {
this::transactionReplacementTester,
FeeMarket.london(0L),
new BlobCache(),
MiningParameters.newDefault());
MiningParameters.newDefault().setMinTransactionGasPrice(MIN_GAS_PRICE));

private final LayeredPendingTransactions pendingTransactions =
new LayeredPendingTransactions(poolConfig, prioritizedTransactions);
Expand Down Expand Up @@ -1180,7 +1182,7 @@ static Stream<Arguments> providerPrioritySenders() {

private static BlockHeader mockBlockHeader() {
final BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getBaseFee()).thenReturn(Optional.of(Wei.ONE));
when(blockHeader.getBaseFee()).thenReturn(Optional.of(BASE_FEE));
return blockHeader;
}

Expand Down
Loading