Skip to content

Conversation

@niran
Copy link
Contributor

@niran niran commented Jan 12, 2026

Summary

Add a new RPC endpoint base_meteredPriorityFeePerGas that meters a bundle and returns a recommended priority fee based on resource consumption.

This PR introduces the core estimation algorithm that answers: "What priority fee would my bundle need to pay to displace enough lower-paying transactions to free up the resources I need?"

Changes

  • Add base_meteredPriorityFeePerGas RPC endpoint that meters a bundle and estimates priority fees
  • Add core estimation types: ResourceKind, ResourceLimits, ResourceDemand, ResourceEstimate
  • Add compute_estimate algorithm implementing top-down fee estimation
  • Add estimate_from_transactions for single-block estimation from a list of transactions
  • Add configuration options: resource limits, percentile, uncongested fee, cache size
  • Document the RPC response format in README

Algorithm

The estimation algorithm walks transactions from highest to lowest priority fee, accumulating resource usage until adding another transaction would leave insufficient capacity for the bundle. The last included transaction's fee becomes the threshold.

Response Format

{
  "bundleGasPrice": "0x...",
  "bundleHash": "0x...",
  "results": [...],
  "totalGasUsed": 21000,
  "totalExecutionTimeUs": 1234,
  "priorityFee": "0x5f5e100",
  "blocksSampled": 1,
  "resourceEstimates": [
    { "resource": "gasUsed", "thresholdPriorityFee": "0x...", ... },
    { "resource": "executionTime", ... },
    { "resource": "dataAvailability", ... }
  ]
}

Test Plan

  • Unit tests for compute_estimate covering congested, uncongested, and edge cases
  • Unit tests for estimate_from_transactions
  • Manual testing with sample bundles

@niran niran force-pushed the niran/priority-fee-1a-single-block branch from aa07e74 to 2db0807 Compare January 12, 2026 01:07
- Add MeteringTestContext for unit tests that don't need a full node
- Move meter.rs tests inline using MeteringTestContext (sync tests)
- Move block.rs tests inline using MeteringTestContext (sync tests)
- Move rpc.rs tests inline using TestHarness with MeteringExtension
- Delete tests/ directory (all tests now inline)
- Update lib.rs to expose test_utils with #[cfg(any(test, feature = "test-utils"))]
@niran niran force-pushed the niran/metering-test-harness branch from fa14653 to 64ae567 Compare January 12, 2026 17:38
@danyalprout danyalprout added this to the v0.4.0 milestone Jan 12, 2026
Address PR review feedback:
- Delete test_utils.rs and remove test-utils feature to avoid duplication
- Use TestHarness from base-client-node for all tests
- Remove envelope_from_signed helper - use direct conversion
- Remove unused imports
@niran niran force-pushed the niran/priority-fee-1a-single-block branch from 2db0807 to 7f4a2e1 Compare January 12, 2026 18:55
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
@niran niran force-pushed the niran/priority-fee-1a-single-block branch from 7f4a2e1 to 07e3ad4 Compare January 12, 2026 19:18
Base automatically changed from niran/metering-test-harness to main January 12, 2026 19:35
@cb-heimdall
Copy link
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

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