Skip to content

Commit

Permalink
Merge branch 'main' into release-v0.1.4-testX
Browse files Browse the repository at this point in the history
# Conflicts:
#	acceptance-tests/src/test/resources/moduleLimits_sendRawTx.toml
#	acceptance-tests/src/test/resources/txOverflowModuleLimits.toml
#	gradle.properties
#	sequencer/src/main/java/net/consensys/linea/AbstractLineaSharedPrivateOptionsPlugin.java
#	sequencer/src/main/java/net/consensys/linea/sequencer/txselection/LineaTransactionSelectorFactory.java
#	sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/LineaTransactionSelector.java
  • Loading branch information
fab-10 committed Nov 29, 2024
2 parents ef1c6a7 + ab849c5 commit f7aa6e6
Show file tree
Hide file tree
Showing 39 changed files with 725 additions and 278 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Next release
* feat: Report rejected transactions only due to trace limit overflows to an external service.
* feat: Report rejected transactions to an external service for validators used by LineaTransactionPoolValidatorPlugin [#85](https://github.com/Consensys/linea-sequencer/pull/85)
* feat: Report rejected transactions to an external service for LineaTransactionSelector used by LineaTransactionSelectorPlugin [#69](https://github.com/Consensys/linea-sequencer/pull/69)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

package linea.plugin.acc.test;

import static net.consensys.linea.metrics.LineaMetricCategory.PRICING_CONF;
import static net.consensys.linea.metrics.LineaMetricCategory.SEQUENCER_PROFITABILITY;
import static net.consensys.linea.metrics.LineaMetricCategory.TX_POOL_PROFITABILITY;
import static org.assertj.core.api.Assertions.*;

import java.io.IOException;
Expand All @@ -40,7 +43,6 @@
import linea.plugin.acc.test.tests.web3j.generated.RevertExample;
import linea.plugin.acc.test.tests.web3j.generated.SimpleStorage;
import lombok.extern.slf4j.Slf4j;
import net.consensys.linea.metrics.LineaMetricCategory;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
Expand Down Expand Up @@ -136,7 +138,8 @@ private BesuNode createCliqueNodeWithExtraCliOptionsAndRpcApis(
.metricsConfiguration(
MetricsConfiguration.builder()
.enabled(true)
.metricCategories(Set.of(LineaMetricCategory.PROFITABILITY))
.metricCategories(
Set.of(PRICING_CONF, SEQUENCER_PROFITABILITY, TX_POOL_PROFITABILITY))
.build())
.requestedPlugins(
List.of(
Expand Down Expand Up @@ -352,7 +355,7 @@ protected double getMetricValue(
+ metricName
+ labelValues.stream()
.map(lv -> lv.getKey() + "=\"" + lv.getValue() + "\"")
.collect(Collectors.joining(",", "{", ",}"));
.collect(Collectors.joining(",", "{", "}"));

final var foundMetric =
respLines.body().filter(line -> line.startsWith(searchString)).findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package linea.plugin.acc.test.extradata;

import static java.util.Map.entry;
import static net.consensys.linea.metrics.LineaMetricCategory.PRICING_CONF;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
Expand All @@ -23,7 +24,6 @@

import linea.plugin.acc.test.LineaPluginTestBase;
import linea.plugin.acc.test.TestCommandLineOptionsBuilder;
import net.consensys.linea.metrics.LineaMetricCategory;
import org.apache.tuweni.bytes.Bytes32;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
Expand Down Expand Up @@ -125,24 +125,17 @@ public void updateProfitabilityParamsViaExtraData() throws IOException, Interrup
assertThat(getTxPoolContent()).isEmpty();

final var fixedCostMetric =
getMetricValue(
LineaMetricCategory.PROFITABILITY, "conf", List.of(entry("field", "fixed_cost_wei")));
getMetricValue(PRICING_CONF, "values", List.of(entry("field", "fixed_cost_wei")));

assertThat(fixedCostMetric).isEqualTo(MIN_GAS_PRICE.multiply(2).getValue().doubleValue());

final var variableCostMetric =
getMetricValue(
LineaMetricCategory.PROFITABILITY,
"conf",
List.of(entry("field", "variable_cost_wei")));
getMetricValue(PRICING_CONF, "values", List.of(entry("field", "variable_cost_wei")));

assertThat(variableCostMetric).isEqualTo(MIN_GAS_PRICE.getValue().doubleValue());

final var ethGasPriceMetric =
getMetricValue(
LineaMetricCategory.PROFITABILITY,
"conf",
List.of(entry("field", "eth_gas_price_wei")));
getMetricValue(PRICING_CONF, "values", List.of(entry("field", "eth_gas_price_wei")));

assertThat(ethGasPriceMetric).isEqualTo(MIN_GAS_PRICE.getValue().doubleValue());
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
releaseVersion=0.1.4-test35
besuVersion=24.11-delivery38
releaseVersion=0.1.4-test36
besuVersion=24.11-delivery39
besuArtifactGroup=io.consensys.linea-besu
distributionIdentifier=besu-sequencer-plugins
distributionBaseUrl=https://artifacts.consensys.net/public/linea-besu/raw/names/linea-besu.tar.gz/versions/
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.util.Map;

import lombok.extern.slf4j.Slf4j;
import org.hyperledger.besu.plugin.BesuContext;
import org.hyperledger.besu.plugin.BesuPlugin;
import org.hyperledger.besu.plugin.ServiceManager;
import org.hyperledger.besu.plugin.services.PicoCLIOptions;

/**
Expand All @@ -41,14 +41,14 @@ protected LineaOptionsPluginConfiguration getConfigurationByKey(final String key
}

@Override
public synchronized void register(final BesuContext context) {
public synchronized void register(final ServiceManager serviceManager) {
final PicoCLIOptions cmdlineOptions =
context
serviceManager
.getService(PicoCLIOptions.class)
.orElseThrow(
() ->
new IllegalStateException(
"Failed to obtain PicoCLI options from the BesuContext"));
"Failed to obtain PicoCLI options from the ServiceManager"));

getLineaPluginConfigMap()
.forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package net.consensys.linea;

import lombok.extern.slf4j.Slf4j;
import org.hyperledger.besu.plugin.BesuContext;
import org.hyperledger.besu.plugin.BesuPlugin;
import org.hyperledger.besu.plugin.ServiceManager;

@Slf4j
public abstract class AbstractLineaRequiredPlugin extends AbstractLineaSharedPrivateOptionsPlugin {
Expand All @@ -28,15 +28,15 @@ public abstract class AbstractLineaRequiredPlugin extends AbstractLineaSharedPri
*
* <p>If that's NOT desired, the plugin should implement {@link BesuPlugin} directly.
*
* @param context the BesuContext to be used.
* @param serviceManager the ServiceManager to be used.
*/
@Override
public void register(final BesuContext context) {
super.register(context);
public void register(final ServiceManager serviceManager) {
super.register(serviceManager);
try {
log.info("Registering Linea plugin {}", this.getClass().getName());

doRegister(context);
doRegister(serviceManager);

} catch (Exception e) {
log.error("Halting Besu startup: exception in plugin registration: ", e);
Expand All @@ -49,7 +49,7 @@ public void register(final BesuContext context) {
/**
* Linea plugins need to implement this method. Called by {@link BesuPlugin} register method
*
* @param context the BesuContext to be used.
* @param serviceManager the ServiceManager to be used.
*/
public abstract void doRegister(final BesuContext context);
public abstract void doRegister(final ServiceManager serviceManager);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
import net.consensys.linea.config.LineaTransactionPoolValidatorConfiguration;
import net.consensys.linea.config.LineaTransactionSelectorCliOptions;
import net.consensys.linea.config.LineaTransactionSelectorConfiguration;
import net.consensys.linea.metrics.LineaMetricCategory;
import org.hyperledger.besu.plugin.BesuContext;
import org.hyperledger.besu.plugin.ServiceManager;
import org.hyperledger.besu.plugin.services.BlockchainService;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry;
Expand All @@ -57,11 +56,12 @@ public abstract class AbstractLineaSharedPrivateOptionsPlugin
extends AbstractLineaSharedOptionsPlugin {
protected static BlockchainService blockchainService;
protected static MetricsSystem metricsSystem;
protected static MetricCategoryRegistry metricCategoryRegistry;

private static final AtomicBoolean sharedRegisterTasksDone = new AtomicBoolean(false);
private static final AtomicBoolean sharedStartTasksDone = new AtomicBoolean(false);

private BesuContext besuContext;
private ServiceManager serviceManager;

static {
// force the initialization of the gnark compress native library to fail fast in case of issues
Expand Down Expand Up @@ -122,44 +122,44 @@ public LineaRejectedTxReportingConfiguration rejectedTxReportingConfiguration()
}

@Override
public synchronized void register(final BesuContext context) {
super.register(context);
public synchronized void register(final ServiceManager serviceManager) {
super.register(serviceManager);

besuContext = context;
this.serviceManager = serviceManager;

if (sharedRegisterTasksDone.compareAndSet(false, true)) {
performSharedRegisterTasksOnce(context);
performSharedRegisterTasksOnce(serviceManager);
}
}

protected static void performSharedRegisterTasksOnce(final BesuContext context) {
protected static void performSharedRegisterTasksOnce(final ServiceManager serviceManager) {
blockchainService =
context
serviceManager
.getService(BlockchainService.class)
.orElseThrow(
() ->
new RuntimeException(
"Failed to obtain BlockchainService from the BesuContext."));

context
.getService(MetricCategoryRegistry.class)
.orElseThrow(
() ->
new RuntimeException(
"Failed to obtain MetricCategoryRegistry from the BesuContext."))
.addMetricCategory(LineaMetricCategory.PROFITABILITY);
"Failed to obtain BlockchainService from the ServiceManager."));

metricCategoryRegistry =
serviceManager
.getService(MetricCategoryRegistry.class)
.orElseThrow(
() ->
new RuntimeException(
"Failed to obtain MetricCategoryRegistry from the ServiceManager."));
}

@Override
public void start() {
super.start();

if (sharedStartTasksDone.compareAndSet(false, true)) {
performSharedStartTasksOnce(besuContext);
performSharedStartTasksOnce(serviceManager);
}
}

private static void performSharedStartTasksOnce(final BesuContext context) {
private static void performSharedStartTasksOnce(final ServiceManager serviceManager) {
blockchainService
.getChainId()
.ifPresentOrElse(
Expand All @@ -173,10 +173,11 @@ private static void performSharedStartTasksOnce(final BesuContext context) {
});

metricsSystem =
context
serviceManager
.getService(MetricsSystem.class)
.orElseThrow(
() -> new RuntimeException("Failed to obtain MetricSystem from the BesuContext."));
() ->
new RuntimeException("Failed to obtain MetricSystem from the ServiceManager."));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,28 @@ public boolean isProfitable(

final Wei profitablePriorityFee =
profitablePriorityFeePerGas(transaction, minMargin, gas, minGasPriceWei);

return isProfitable(
context,
profitablePriorityFee,
transaction,
minMargin,
baseFee,
payingGasPrice,
gas,
minGasPriceWei);
}

public boolean isProfitable(
final String context,
final Wei profitablePriorityFee,
final Transaction transaction,
final double minMargin,
final Wei baseFee,
final Wei payingGasPrice,
final long gas,
final Wei minGasPriceWei) {

final Wei profitableGasPrice = baseFee.add(profitablePriorityFee);

if (payingGasPrice.lessThan(profitableGasPrice)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public class LineaProfitabilityCliOptions implements LineaCliOptions {
"--plugin-linea-extra-data-set-min-gas-price-enabled";
public static final boolean DEFAULT_EXTRA_DATA_SET_MIN_GAS_PRICE_ENABLED = true;

public static final String PROFITABILITY_METRICS_BUCKETS =
"--plugin-linea-profitability-metrics-buckets";
public static final double[] DEFAULT_PROFITABILITY_METRICS_BUCKETS = {
0.1, 0.3, 0.5, 0.7, 0.9, 1.0, 1.1, 1.2, 1.5, 2.0, 5.0, 10.0
};

@Positive
@CommandLine.Option(
names = {FIXED_GAS_COST_WEI},
Expand Down Expand Up @@ -135,6 +141,17 @@ public class LineaProfitabilityCliOptions implements LineaCliOptions {
"Enable setting min gas price runtime value via extra data field (default: ${DEFAULT-VALUE})")
private boolean extraDataSetMinGasPriceEnabled = DEFAULT_EXTRA_DATA_SET_MIN_GAS_PRICE_ENABLED;

@CommandLine.Option(
names = {PROFITABILITY_METRICS_BUCKETS},
arity = "1..*",
split = ",",
hidden = true,
paramLabel = "<FLOAT[]>",
description =
"List of buckets to use to create the histogram for ratio between the effective priority fee "
+ "and the calculate profitable priority of the tx (default: ${DEFAULT-VALUE})")
private double[] profitabilityMetricsBuckets = DEFAULT_PROFITABILITY_METRICS_BUCKETS;

private LineaProfitabilityCliOptions() {}

/**
Expand Down Expand Up @@ -164,6 +181,7 @@ public static LineaProfitabilityCliOptions fromConfig(
options.txPoolCheckP2pEnabled = config.txPoolCheckP2pEnabled();
options.extraDataPricingEnabled = config.extraDataPricingEnabled();
options.extraDataSetMinGasPriceEnabled = config.extraDataSetMinGasPriceEnabled();
options.profitabilityMetricsBuckets = config.profitabilityMetricsBuckets();
return options;
}

Expand All @@ -184,6 +202,7 @@ public LineaProfitabilityConfiguration toDomainObject() {
.txPoolCheckP2pEnabled(txPoolCheckP2pEnabled)
.extraDataPricingEnabled(extraDataPricingEnabled)
.extraDataSetMinGasPriceEnabled(extraDataSetMinGasPriceEnabled)
.profitabilityMetricsBuckets(profitabilityMetricsBuckets)
.build();
}

Expand All @@ -199,6 +218,7 @@ public String toString() {
.add(TX_POOL_ENABLE_CHECK_P2P, txPoolCheckP2pEnabled)
.add(EXTRA_DATA_PRICING_ENABLED, extraDataPricingEnabled)
.add(EXTRA_DATA_SET_MIN_GAS_PRICE_ENABLED, extraDataSetMinGasPriceEnabled)
.add(PROFITABILITY_METRICS_BUCKETS, profitabilityMetricsBuckets)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class LineaProfitabilityConfiguration implements LineaOptionsConfiguratio
/** It is safe to keep this as long, since it will store value <= max_int * 1000 */
private long variableCostWei;

/** It is safe to keep this as long, since it will store value <= max_int * 1000 */
private long ethGasPriceWei;

private double minMargin;
Expand All @@ -42,6 +43,7 @@ public class LineaProfitabilityConfiguration implements LineaOptionsConfiguratio
private boolean txPoolCheckP2pEnabled;
private boolean extraDataPricingEnabled;
private boolean extraDataSetMinGasPriceEnabled;
private double[] profitabilityMetricsBuckets;

/**
* These 2 parameters must be atomically updated
Expand Down
Loading

0 comments on commit f7aa6e6

Please sign in to comment.