Skip to content

Commit

Permalink
linea_estimateGas compatibility mode multiplier
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 committed Mar 13, 2024
1 parent cdbe27b commit 602d618
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,36 @@

package net.consensys.linea.config;

import java.math.BigDecimal;

import com.google.common.base.MoreObjects;
import picocli.CommandLine;

/** The Linea RPC CLI options. */
public class LineaRpcCliOptions {
private static final String ESTIMATE_GAS_COMPATIBILITY_MODE_ENABLED =
"--plugin-linea-estimate-gas-compatibility-mode-enabled";
private static final boolean DEFAULT_ESTIMATE_GAS_COMPATIBILITY_MODE_ENABLED = false;
private static final String ESTIMATE_GAS_COMPATIBILITY_MODE_MULTIPLIER =
"--plugin-linea-estimate-gas-compatibility-mode-multiplier";
private static final BigDecimal DEFAULT_ESTIMATE_GAS_COMPATIBILITY_MODE_MULTIPLIER =
BigDecimal.valueOf(1.2);

@CommandLine.Option(
names = {ESTIMATE_GAS_COMPATIBILITY_MODE_ENABLED},
paramLabel = "<BOOLEAN>",
description =
"Set to true to return the min mineable gas price, instead of the profitable price (default: ${DEFAULT-VALUE})")
private boolean estimateGasCompatibilityModeEnabled = false;
"Set to true to return the min mineable gas price * multiplier, instead of the profitable price (default: ${DEFAULT-VALUE})")
private boolean estimateGasCompatibilityModeEnabled =
DEFAULT_ESTIMATE_GAS_COMPATIBILITY_MODE_ENABLED;

@CommandLine.Option(
names = {ESTIMATE_GAS_COMPATIBILITY_MODE_MULTIPLIER},
paramLabel = "<FLOAT>",
description =
"Set to multiplier to apply to the min mineable gas price when the compatibility mode is enabled (default: ${DEFAULT-VALUE})")
private BigDecimal estimateGasCompatibilityMultiplier =
DEFAULT_ESTIMATE_GAS_COMPATIBILITY_MODE_MULTIPLIER;

private LineaRpcCliOptions() {}

Expand All @@ -50,6 +66,7 @@ public static LineaRpcCliOptions create() {
public static LineaRpcCliOptions fromConfig(final LineaRpcConfiguration config) {
final LineaRpcCliOptions options = create();
options.estimateGasCompatibilityModeEnabled = config.estimateGasCompatibilityModeEnabled();
options.estimateGasCompatibilityMultiplier = config.estimateGasCompatibilityMultiplier();
return options;
}

Expand All @@ -61,13 +78,15 @@ public static LineaRpcCliOptions fromConfig(final LineaRpcConfiguration config)
public LineaRpcConfiguration toDomainObject() {
return LineaRpcConfiguration.builder()
.estimateGasCompatibilityModeEnabled(estimateGasCompatibilityModeEnabled)
.estimateGasCompatibilityMultiplier(estimateGasCompatibilityMultiplier)
.build();
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add(ESTIMATE_GAS_COMPATIBILITY_MODE_ENABLED, estimateGasCompatibilityModeEnabled)
.add(ESTIMATE_GAS_COMPATIBILITY_MODE_MULTIPLIER, estimateGasCompatibilityMultiplier)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@

package net.consensys.linea.config;

import java.math.BigDecimal;

import lombok.Builder;

/** The Linea RPC configuration. */
@Builder(toBuilder = true)
public record LineaRpcConfiguration(boolean estimateGasCompatibilityModeEnabled) {}
public record LineaRpcConfiguration(
boolean estimateGasCompatibilityModeEnabled, BigDecimal estimateGasCompatibilityMultiplier) {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity.create;

import java.math.BigDecimal;
import java.math.BigInteger;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -136,7 +137,11 @@ private Wei getEstimatedPriorityFee(
final Wei priorityFeeLowerBound = minGasPrice.subtract(baseFee);

if (rpcConfiguration.estimateGasCompatibilityModeEnabled()) {
return priorityFeeLowerBound;
return Wei.of(
rpcConfiguration
.estimateGasCompatibilityMultiplier()
.multiply(new BigDecimal(priorityFeeLowerBound.getAsBigInteger()))
.toBigInteger());
}

if (profitablePriorityFee.greaterOrEqualThan(priorityFeeLowerBound)) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependency-management.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ dependencyManagement {

dependency 'com.splunk.logging:splunk-library-javalogging:1.11.5'

dependency 'io.vertx:vertx-core:4.3.8'
dependency 'io.vertx:vertx-core:4.5.4'

dependency 'com.slack.api:slack-api-client:1.32.1'

Expand Down

0 comments on commit 602d618

Please sign in to comment.