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

3D pricing metrics #107

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open

Conversation

cloudspores
Copy link
Contributor

@cloudspores cloudspores commented Oct 29, 2024

This PR exposes the following metrics

1 Node's perception on the latest extraData contents (variable cost, fixed cost, eth gas price) as gauges under the PRICING_CONF category
1 Node's perception on Profitability levels of TxPool's contents (lo, hi, avg of transaction.priorityFeePerGas / TransactionProfitabilityCalculator.profitablePriorityFeePerGas(transaction)) as histogram under the TX_POOL_PROFITABILITY categoty
1 Same metrics as above, but in context of last sealed block (this is relevant only for Sequencer) as histogram under the SEQUENCER_PROFITABILITY category

Each metric category can be enabled indipendently, using the standard metrics-category option.

For histograms, it is possible to configure the buckets using the new conf option plugin-linea-profitability-metrics-buckets, that by default is set to 0.9, 1.0, 1.2, 2, 5, 10, 100, 1000

names of the new exported metrics

# HELP linea_tx_pool_profitability_ratio_min Lowest transaction pool profitability ratio
# TYPE linea_tx_pool_profitability_ratio_min gauge
linea_tx_pool_profitability_ratio_min +Inf
# HELP linea_pricing_conf_values Profitability configuration values at runtime
# TYPE linea_pricing_conf_values gauge
linea_pricing_conf_values{field="fixed_cost_wei",} 3.0E7
linea_pricing_conf_values{field="eth_gas_price_wei",} 1.53525E8
linea_pricing_conf_values{field="variable_cost_wei",} 8.226788E9
# HELP linea_sequencer_profitability_ratio_max Highest sequencer profitability ratio
# TYPE linea_sequencer_profitability_ratio_max gauge
linea_sequencer_profitability_ratio_max{phase="pre_processing",} 16572.31055926643
linea_sequencer_profitability_ratio_max{phase="post_processing",} 0.0
# HELP linea_sequencer_profitability_ratio Sequencer profitability ratio buckets
# TYPE linea_sequencer_profitability_ratio histogram
linea_sequencer_profitability_ratio_bucket{phase="pre_processing",le="0.9",} 0.0
linea_sequencer_profitability_ratio_bucket{phase="pre_processing",le="1.0",} 0.0
linea_sequencer_profitability_ratio_bucket{phase="pre_processing",le="1.2",} 0.0
linea_sequencer_profitability_ratio_bucket{phase="pre_processing",le="2.0",} 0.0
linea_sequencer_profitability_ratio_bucket{phase="pre_processing",le="5.0",} 0.0
linea_sequencer_profitability_ratio_bucket{phase="pre_processing",le="10.0",} 0.0
linea_sequencer_profitability_ratio_bucket{phase="pre_processing",le="100.0",} 0.0
linea_sequencer_profitability_ratio_bucket{phase="pre_processing",le="1000.0",} 0.0
linea_sequencer_profitability_ratio_bucket{phase="pre_processing",le="+Inf",} 1.0
linea_sequencer_profitability_ratio_count{phase="pre_processing",} 1.0
linea_sequencer_profitability_ratio_sum{phase="pre_processing",} 16572.31055926643
# HELP linea_sequencer_profitability_ratio_min Lowest sequencer profitability ratio
# TYPE linea_sequencer_profitability_ratio_min gauge
linea_sequencer_profitability_ratio_min{phase="pre_processing",} 16572.31055926643
linea_sequencer_profitability_ratio_min{phase="post_processing",} +Inf
# HELP linea_tx_pool_profitability_ratio Transaction pool profitability ratio buckets
# TYPE linea_tx_pool_profitability_ratio histogram
linea_tx_pool_profitability_ratio_bucket{le="0.9",} 0.0
linea_tx_pool_profitability_ratio_bucket{le="1.0",} 0.0
linea_tx_pool_profitability_ratio_bucket{le="1.2",} 0.0
linea_tx_pool_profitability_ratio_bucket{le="2.0",} 0.0
linea_tx_pool_profitability_ratio_bucket{le="5.0",} 0.0
linea_tx_pool_profitability_ratio_bucket{le="10.0",} 0.0
linea_tx_pool_profitability_ratio_bucket{le="100.0",} 0.0
linea_tx_pool_profitability_ratio_bucket{le="1000.0",} 0.0
linea_tx_pool_profitability_ratio_bucket{le="+Inf",} 0.0
linea_tx_pool_profitability_ratio_count 0.0
linea_tx_pool_profitability_ratio_sum 0.0
# HELP linea_tx_pool_profitability_ratio_max Highest transaction pool profitability ratio
# TYPE linea_tx_pool_profitability_ratio_max gauge
linea_tx_pool_profitability_ratio_max 0.0
# HELP linea_sequencer_profitability_ratio_created Sequencer profitability ratio buckets
# TYPE linea_sequencer_profitability_ratio_created gauge
linea_sequencer_profitability_ratio_created{phase="pre_processing",} 1.730398405758E9
# HELP linea_tx_pool_profitability_ratio_created Transaction pool profitability ratio buckets
# TYPE linea_tx_pool_profitability_ratio_created gauge
linea_tx_pool_profitability_ratio_created 1.730398404348E9

fixes https://github.com/Consensys/protocol-misc/issues/953

fab-10 and others added 13 commits October 25, 2024 16:45
- Introduce block listener in LineaTransactionSelectorPlugin to handle transaction profitability
- Integrate transaction selector handler for processing transactions from the latest block
- Extract profitability calculation into a separate method for clarity and maintainability

Signed-off-by: Ade Lucas <[email protected]>
Signed-off-by: Ade Lucas <[email protected]>
…orPlugin

- Implement: Node's perception on Profitability levels of TxPool's contents (lo, hi, avg of TransactionProfitabilityCalculator.profitablePriorityFeePerGas(transaction) / transaction.priorityFeePerGas).

Signed-off-by: Ade Lucas <[email protected]>
…orPlugin

- Implement: Node's perception on Profitability levels of TxPool's contents (lo, hi, avg of TransactionProfitabilityCalculator.profitablePriorityFeePerGas(transaction) / transaction.priorityFeePerGas).

Signed-off-by: Ade Lucas <[email protected]>
@cloudspores cloudspores marked this pull request as ready for review October 29, 2024 07:22
@fab-10 fab-10 changed the title Sequencer 3D pricing metrics - Node's perception on Profitability levels of TxPool's contents 3D pricing metrics Nov 4, 2024
@fab-10 fab-10 force-pushed the sequencer-3d-pricing-metrics-ade branch from 644c543 to 9ac2555 Compare November 4, 2024 18:42
@fab-10 fab-10 force-pushed the sequencer-3d-pricing-metrics-ade branch from 9ac2555 to fcb4001 Compare November 4, 2024 19:20
Signed-off-by: Fabio Di Fabio <[email protected]>
Copy link
Contributor

@garyschulte garyschulte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blockion suggestions. LGTM

hidden = true,
paramLabel = "<FLOAT[]>",
description =
"List of buckets to use to create the histogram for profitability metrics (default: ${DEFAULT-VALUE})")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description could be more informative. They are buckets of what? profit for the sequencer in wei, gwei, or ? is it the tx fee revenue, or the net profit between posting to L1 vs fee on linea, etc.

I can find it in the code, but I think the option description could clear it up

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, to make it clearer

evaluationContext.getTransactionGasPrice().subtract(baseFee);
final var ratio =
effectivePriorityFee.getValue().doubleValue()
/ profitablePriorityFeePerGas.getValue().doubleValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we guaranteed that profitablePriorityFeePerGas is never zero.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be zero only the pricing conf for variable and fixed cost is zero, that seems unreasonable, and according to the Java rules that operation will result in Double.POSITIVE_INFINITY

Signed-off-by: Fabio Di Fabio <[email protected]>
@fab-10 fab-10 force-pushed the sequencer-3d-pricing-metrics-ade branch from db537b5 to 9f2708e Compare November 6, 2024 08:52
histogram.labels(labelValues).observe(value);
}

public void setMinMax(final double min, final double max, final String... labelValues) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need it as a separate method? Do you think that O(N) additional comparisons in track will impact the performance?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will review if it is possible to perform all the updates in a single method

@@ -113,6 +121,45 @@ public void start() {
l1L2BridgeSharedConfiguration(),
rejectedTxJsonRpcManager));

if (metricCategoryRegistry.isMetricCategoryEnabled(TX_POOL_PROFITABILITY)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to how it's done for ProfitableTransactionSelector maybe instead of evaluating each transaction from txpool directly, maybe it would be more efficient and less invasive if we capture txpool profitability metrics in ProfitabilityValidator?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we thought about that, but since a tx could stay in the pool for a long time, the value calculated at ProfitabilityValidator time could be different from the current value, due to the changes to the market conditions and the extra data pricing conf, so basically it will be a different metric, that represents the values at validation time, instead of the current status in the txpool.
If you think that collecting metrics in the ProfitabilityValidator is good enough, then yes it will be more efficient.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean. Let's leave it the way you did and if it causes any performance issues, we can always disable it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the txpool should have a similar content on every node, it is possible to enable this metric only on dedicated or not critical nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants