Skip to content

Commit

Permalink
Remove the check that profitable priority fee must be greater than mi…
Browse files Browse the repository at this point in the history
…nGasPrice (#49)

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 committed Jul 22, 2024
1 parent 7d771f7 commit 6b5ee19
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
import org.junit.jupiter.api.Test;

public class EstimateGasCompatibilityModeTest extends EstimateGasTest {
private static final BigDecimal PRICE_MULTIPLIER = BigDecimal.valueOf(1.2);
Expand Down Expand Up @@ -63,4 +65,20 @@ protected void assertMinGasPriceLowerBound(final Wei baseFee, final Wei estimate
// the min priority fee per gas * multiplier + base fee
assertIsProfitable(null, baseFee, estimatedMaxGasPrice, 0);
}

@Test
public void lineaEstimateGasPriorityFeeMinGasPriceLowerBound() {
final Account sender = accounts.getSecondaryBenefactor();

final CallParams callParams = new CallParams(sender.getAddress(), null, "", "", "0");

final var reqLinea = new LineaEstimateGasRequest(callParams);
final var respLinea = reqLinea.execute(minerNode.nodeRequests());

final var baseFee = Wei.fromHexString(respLinea.baseFeePerGas());
final var estimatedPriorityFee = Wei.fromHexString(respLinea.priorityFeePerGas());
final var estimatedMaxGasPrice = baseFee.add(estimatedPriorityFee);

assertMinGasPriceLowerBound(baseFee, estimatedMaxGasPrice);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class EstimateGasTest extends LineaPluginTestBase {
protected static final int FIXED_GAS_COST_WEI = 0;
protected static final int VARIABLE_GAS_COST_WEI = 1_000_000_000;
protected static final double MIN_MARGIN = 1.0;
protected static final double ESTIMATE_GAS_MIN_MARGIN = 1.0;
protected static final double ESTIMATE_GAS_MIN_MARGIN = 1.1;
protected static final Wei MIN_GAS_PRICE = Wei.of(1_000_000_000);
protected static final int MAX_TRANSACTION_GAS_LIMIT = 30_000_000;
protected LineaProfitabilityConfiguration profitabilityConf;
Expand Down Expand Up @@ -154,36 +154,18 @@ protected void assertIsProfitable(

final var profitabilityCalculator = new TransactionProfitabilityCalculator(profitabilityConf);

assertThat(estimatedMaxGasPrice.greaterOrEqualThan(minGasPrice)).isTrue();

assertThat(
profitabilityCalculator.isProfitable(
"Test",
tx,
profitabilityConf.estimateGasMinMargin(),
profitabilityConf.minMargin(),
baseFee,
estimatedMaxGasPrice,
estimatedGasLimit,
minGasPrice))
.isTrue();
}

@Test
public void lineaEstimateGasPriorityFeeMinGasPriceLowerBound() {
final Account sender = accounts.getSecondaryBenefactor();

final CallParams callParams = new CallParams(sender.getAddress(), null, "", "", "0");

final var reqLinea = new LineaEstimateGasRequest(callParams);
final var respLinea = reqLinea.execute(minerNode.nodeRequests());

final var baseFee = Wei.fromHexString(respLinea.baseFeePerGas());
final var estimatedPriorityFee = Wei.fromHexString(respLinea.priorityFeePerGas());
final var estimatedMaxGasPrice = baseFee.add(estimatedPriorityFee);

assertMinGasPriceLowerBound(baseFee, estimatedMaxGasPrice);
}

@Test
public void invalidParametersLineaEstimateGasRequestReturnErrorResponse() {
final Account sender = accounts.getSecondaryBenefactor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,7 @@ private Wei getEstimatedPriorityFee(
txProfitabilityCalculator.profitablePriorityFeePerGas(
transaction, profitabilityConf.estimateGasMinMargin(), estimatedGasUsed, minGasPrice);

if (profitablePriorityFee.greaterOrEqualThan(priorityFeeLowerBound)) {
return profitablePriorityFee;
}

log.atDebug()
.setMessage(
"[{}] Estimated priority fee {} is lower that the lower bound {}, returning the latter")
.addArgument(LOG_SEQUENCE::get)
.addArgument(profitablePriorityFee::toHumanReadableString)
.addArgument(priorityFeeLowerBound::toHumanReadableString)
.log();
return priorityFeeLowerBound;
return profitablePriorityFee;
}

private Long estimateGasUsed(
Expand Down

0 comments on commit 6b5ee19

Please sign in to comment.