From 644c5430b670ec0e0733bbc3191f26f9b7b425f2 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Thu, 31 Oct 2024 19:16:39 +0100 Subject: [PATCH] Make profitability histogram metric buckets configurable Signed-off-by: Fabio Di Fabio --- .../config/LineaProfitabilityCliOptions.java | 19 +++++++++++++++++++ .../LineaProfitabilityConfiguration.java | 2 ++ .../linea/metrics/HistogramMetrics.java | 8 ++------ .../TransactionPoolProfitabilityMetrics.java | 6 +++++- .../ProfitableTransactionSelector.java | 1 + .../ProfitableTransactionSelectorTest.java | 12 ++++++++++-- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityCliOptions.java b/sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityCliOptions.java index 037c4a90..037b63f3 100644 --- a/sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityCliOptions.java +++ b/sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityCliOptions.java @@ -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.9, 1.0, 1.2, 2, 5, 10, 100, 1000 + }; + @Positive @CommandLine.Option( names = {FIXED_GAS_COST_WEI}, @@ -135,6 +141,16 @@ 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 = "", + description = + "List of buckets to use to create the histogram for profitability metrics (default: ${DEFAULT-VALUE})") + private double[] profitabilityMetricsBuckets = DEFAULT_PROFITABILITY_METRICS_BUCKETS; + private LineaProfitabilityCliOptions() {} /** @@ -164,6 +180,7 @@ public static LineaProfitabilityCliOptions fromConfig( options.txPoolCheckP2pEnabled = config.txPoolCheckP2pEnabled(); options.extraDataPricingEnabled = config.extraDataPricingEnabled(); options.extraDataSetMinGasPriceEnabled = config.extraDataSetMinGasPriceEnabled(); + options.profitabilityMetricsBuckets = config.profitabilityMetricsBuckets(); return options; } @@ -184,6 +201,7 @@ public LineaProfitabilityConfiguration toDomainObject() { .txPoolCheckP2pEnabled(txPoolCheckP2pEnabled) .extraDataPricingEnabled(extraDataPricingEnabled) .extraDataSetMinGasPriceEnabled(extraDataSetMinGasPriceEnabled) + .profitabilityMetricsBuckets(profitabilityMetricsBuckets) .build(); } @@ -199,6 +217,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(); } } diff --git a/sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityConfiguration.java b/sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityConfiguration.java index 6aa5af24..012ad4d7 100644 --- a/sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityConfiguration.java +++ b/sequencer/src/main/java/net/consensys/linea/config/LineaProfitabilityConfiguration.java @@ -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; @@ -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 diff --git a/sequencer/src/main/java/net/consensys/linea/metrics/HistogramMetrics.java b/sequencer/src/main/java/net/consensys/linea/metrics/HistogramMetrics.java index 0bcd51f3..6dc51933 100644 --- a/sequencer/src/main/java/net/consensys/linea/metrics/HistogramMetrics.java +++ b/sequencer/src/main/java/net/consensys/linea/metrics/HistogramMetrics.java @@ -37,7 +37,6 @@ public interface LabelValue { String value(); } - private static final double[] DEFAULT_HISTOGRAM_BUCKETS = {0.9, 1.0, 1.2, 2, 5, 10, 100, 1000}; private static final String LABEL_VALUES_SEPARATOR = "\u2060"; private final LabelledMetric histogram; private final Map mins; @@ -49,6 +48,7 @@ public HistogramMetrics( final LineaMetricCategory category, final String name, final String help, + final double[] buckets, final Class... labels) { final var labelNames = getLabelNames(labels); @@ -72,11 +72,7 @@ public HistogramMetrics( this.histogram = metricsSystem.createLabelledHistogram( - category, - name, - StringUtils.capitalize(help) + " buckets", - DEFAULT_HISTOGRAM_BUCKETS, - labelNames); + category, name, StringUtils.capitalize(help) + " buckets", buckets, labelNames); } @SafeVarargs diff --git a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/metrics/TransactionPoolProfitabilityMetrics.java b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/metrics/TransactionPoolProfitabilityMetrics.java index fb4d1122..9ceaf0ee 100644 --- a/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/metrics/TransactionPoolProfitabilityMetrics.java +++ b/sequencer/src/main/java/net/consensys/linea/sequencer/txpoolvalidation/metrics/TransactionPoolProfitabilityMetrics.java @@ -60,7 +60,11 @@ public TransactionPoolProfitabilityMetrics( this.blockchainService = blockchainService; this.histogramMetrics = new HistogramMetrics( - metricsSystem, TX_POOL_PROFITABILITY, "ratio", "transaction pool profitability ratio"); + metricsSystem, + TX_POOL_PROFITABILITY, + "ratio", + "transaction pool profitability ratio", + profitabilityConf.profitabilityMetricsBuckets()); } public void update() { diff --git a/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelector.java b/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelector.java index 08ba5714..64f15010 100644 --- a/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelector.java +++ b/sequencer/src/main/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelector.java @@ -83,6 +83,7 @@ public ProfitableTransactionSelector( SEQUENCER_PROFITABILITY, "ratio", "sequencer profitability ratio", + profitabilityConf.profitabilityMetricsBuckets(), Phase.class)) : Optional.empty(); diff --git a/sequencer/src/test/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelectorTest.java b/sequencer/src/test/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelectorTest.java index 31ab5c33..8814107c 100644 --- a/sequencer/src/test/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelectorTest.java +++ b/sequencer/src/test/java/net/consensys/linea/sequencer/txselection/selectors/ProfitableTransactionSelectorTest.java @@ -41,6 +41,7 @@ import org.hyperledger.besu.plugin.data.TransactionSelectionResult; import org.hyperledger.besu.plugin.services.BlockchainService; import org.hyperledger.besu.plugin.services.MetricsSystem; +import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry; import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelector; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -65,9 +66,11 @@ public class ProfitableTransactionSelectorTest { .build(); private TestableProfitableTransactionSelector transactionSelector; private MetricsSystem metricsSystem = new NoOpMetricsSystem(); + private MetricCategoryRegistry metricCategoryRegistry; @BeforeEach public void initialize() { + metricCategoryRegistry = mock(MetricCategoryRegistry.class); transactionSelector = newSelectorForNewBlock(); transactionSelector.reset(); } @@ -76,7 +79,11 @@ private TestableProfitableTransactionSelector newSelectorForNewBlock() { final var blockchainService = mock(BlockchainService.class); when(blockchainService.getNextBlockBaseFee()).thenReturn(Optional.of(BASE_FEE)); return new TestableProfitableTransactionSelector( - blockchainService, txSelectorConf, profitabilityConf, metricsSystem); + blockchainService, + txSelectorConf, + profitabilityConf, + metricsSystem, + metricCategoryRegistry); } @Test @@ -414,7 +421,8 @@ private static class TestableProfitableTransactionSelector extends ProfitableTra final BlockchainService blockchainService, final LineaTransactionSelectorConfiguration txSelectorConf, final LineaProfitabilityConfiguration profitabilityConf, - final MetricsSystem metricsSystem) { + final MetricsSystem metricsSystem, + final MetricCategoryRegistry metricCategoryRegistry) { super( blockchainService, txSelectorConf,