Skip to content

Commit 2db0807

Browse files
committed
feat(metering): add base_meteredPriorityFeePerGas RPC endpoint
Add priority fee estimation based on single-block resource consumption: - Add core estimation algorithm (compute_estimate) that determines the minimum priority fee needed for inclusion based on resource demand vs capacity - Add ResourceKind, ResourceLimits, ResourceDemand types for multi-resource estimation - Add base_meteredPriorityFeePerGas RPC endpoint - Document the RPC response format in README.md
1 parent fa14653 commit 2db0807

File tree

9 files changed

+1016
-14
lines changed

9 files changed

+1016
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/client/metering/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ alloy-eips.workspace = true
4949
# rpc
5050
jsonrpsee.workspace = true
5151

52+
# DA calculation
53+
op-alloy-flz.workspace = true
54+
5255
# misc
5356
tracing.workspace = true
5457
eyre.workspace = true

crates/client/metering/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,53 @@ Re-executes a block by number and returns timing metrics.
3333

3434
**Returns:**
3535
- `MeterBlockResponse`: Contains timing breakdown for signer recovery, EVM execution, and state root calculation
36+
37+
### `base_meteredPriorityFeePerGas`
38+
39+
Meters a bundle and returns a recommended priority fee based on recent block congestion.
40+
41+
**Parameters:**
42+
- `bundle`: Bundle object containing transactions to simulate
43+
44+
**Returns:**
45+
- `MeteredPriorityFeeResponse`: Contains metering results plus priority fee recommendation
46+
47+
**Response:**
48+
```json
49+
{
50+
"bundleGasPrice": "0x...",
51+
"bundleHash": "0x...",
52+
"results": [...],
53+
"totalGasUsed": 21000,
54+
"totalExecutionTimeUs": 1234,
55+
"priorityFee": "0x5f5e100",
56+
"blocksSampled": 1,
57+
"resourceEstimates": [
58+
{
59+
"resource": "gasUsed",
60+
"thresholdPriorityFee": "0x3b9aca00",
61+
"recommendedPriorityFee": "0x5f5e100",
62+
"cumulativeUsage": "0x1e8480",
63+
"thresholdTxCount": 5,
64+
"totalTransactions": 10
65+
},
66+
{
67+
"resource": "executionTime",
68+
...
69+
},
70+
{
71+
"resource": "dataAvailability",
72+
...
73+
}
74+
]
75+
}
76+
```
77+
78+
**Algorithm:**
79+
1. Meter the bundle to get resource consumption (gas, execution time, DA bytes)
80+
2. Meter the latest block to get historical transaction data
81+
3. For each resource type, run the estimation algorithm:
82+
- Walk from highest-paying transactions, subtracting usage from remaining capacity
83+
- Stop when adding another tx would leave less room than the bundle needs
84+
- The last included tx's fee is the threshold
85+
4. Return the maximum fee across all resources as `priorityFee`

0 commit comments

Comments
 (0)