PIP-0004: Bitcoin Core-Style Fee Estimation Oracle #7
andrepatta
started this conversation in
Core
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
PIP-0004: Bitcoin Core-Style Fee Estimation Oracle
Description: Replace the percentile-based gas price oracle with a confirmation-tracking fee estimator modeled after Bitcoin Core's estimatesmartfee algorithm.
Author: Parallax Protocol Team
Status: Scheduled for v1.1.2
Type: Standards Track
Category: Core
Created: 2026-04-01
Abstract
This PIP replaces the existing gas price oracle, which estimates fees by sampling a fixed number of transactions from recent blocks and returning a percentile of their gas prices, with a fee estimation algorithm modeled after Bitcoin Core's
estimatesmartfee. The new oracle tracks how long transactions at various fee levels take to confirm, groups them into exponentially-spaced fee-rate buckets, and uses exponential decay across three time horizons to recommend the lowest fee rate that historically achieved a high confirmation success rate within a requested number of blocks.Motivation
The existing gas price oracle samples 3 transactions from each of the last 20 blocks and returns the 60th percentile of their effective tips. This approach has a fundamental flaw: it does not account for block fullness. When blocks are far from full, there is little competition for block space, and even the minimum gas price should suffice for prompt confirmation. However, the percentile-based approach continues to report elevated fees as long as recent transactions happened to pay high prices, regardless of whether those high prices were necessary.
This leads to users overpaying for gas during periods of low network activity. Conversely, during sudden spikes in demand, the oracle's backward-looking percentile may underestimate the fee needed for timely confirmation.
Bitcoin Core's fee estimation algorithm solves these problems by directly measuring confirmation outcomes: it tracks what percentage of transactions at each fee level were confirmed within N blocks, and uses that empirical data to recommend fees. Since Parallax shares the same ~10-minute block target as Bitcoin, the algorithm's parameters and time horizons can be applied directly.
Specification
Fee-Rate Buckets
Transactions are grouped into
Nexponentially-spaced fee-rate buckets (default: 40 buckets with a 1.1x multiplier starting at 1 GWei). Bucketicovers gas prices in the range[MinBucketFee * BucketMultiplier^i, MinBucketFee * BucketMultiplier^(i+1)).Three Time Horizons
The oracle maintains three independent sets of tracking data, each with its own exponential decay rate:
Per-Bucket Tracking
For each fee-rate bucket and each time horizon, the oracle maintains:
confirmed[t]: The decayed count of transactions at this fee rate that were confirmed withintblocks of entering the mempool.inMempool[t]: The decayed count of transactions at this fee rate that remained unconfirmed aftertblocks.totalSeen: The decayed count of all transactions ever observed at this fee rate.Block Processing
When a new block is received:
blocksWaited = currentBlock - entryBlock + 1. For all confirmation targetst >= blocksWaited, incrementconfirmed[t]in the corresponding bucket across all horizons.tblocks, incrementinMempool[t]in the corresponding bucket.2 * MaxConfTargetblocks.Mempool Transaction Processing
When a new transaction enters the mempool:
totalSeenfor the bucket across all horizons.Fee Estimation (
eth_estimateSmartFee)Given a confirmation target
confTarget:confTargetto[1, MaxConfTarget].confTargetrange):a. Scan buckets from highest fee to lowest.
b. For each bucket with sufficient data, compute
successRate = confirmed[confTarget] / (confirmed[confTarget] + inMempool[confTarget]).c. Find the lowest bucket where
successRate >= SuccessThreshold(default: 0.95).[DefaultGasPrice, MaxPrice], whereDefaultGasPriceis the miner's minimum gas price (default: 1 GWei, configurable via--miner.gasprice).Backward-Compatible
eth_gasPriceThe existing
eth_gasPriceRPC method is implemented asEstimateSmartFee(confTarget=2), providing a "confirm in ~2 blocks" recommendation. This maintains full backward compatibility with MetaMask and other wallets that calleth_gasPrice.New RPC Method
A new RPC method
eth_estimateSmartFeeis introduced:Parameters:
confTarget(integer): The desired number of blocks within which the transaction should confirm.Returns:
{ "gasPrice": "0x...", "confTarget": 2, "successRate": 0.97 }Configuration Parameters
NumBucketsBucketMultiplierMinBucketFeeMaxConfTargetSuccessThresholdShortDecayMediumDecayLongDecayRationale
Why Bitcoin Core's Algorithm?
Bitcoin Core's fee estimation is battle-tested over a decade of production use on a network with the same ~10-minute block time as Parallax. Its key insight is that fee estimation should be based on empirical confirmation outcomes, not on sampling recent transaction prices. This naturally accounts for block fullness: when blocks are not full, even low-fee transactions confirm quickly, driving down the recommended fee. When blocks are congested, low-fee transactions fail to confirm, driving up the recommendation.
Why Three Time Horizons?
Different horizons serve different purposes:
Taking the maximum across applicable horizons ensures conservative estimates that protect against sudden fee spikes.
Why Not Include Mempool State?
Bitcoin Core's algorithm intentionally does not incorporate current mempool state into its estimates. This is a deliberate design choice: mempool state is highly volatile, node-specific (different nodes see different mempools), and can be manipulated. The history-based approach provides more stable and reliable estimates.
Minimum Gas Price Floor
The estimate is never allowed to go below the miner's configured minimum gas price (default 1 GWei). Transactions below this floor will not be picked up by miners, so recommending them would be misleading.
Backwards Compatibility
eth_gasPricecontinues to work and returns the same type of response. Its implementation changes from percentile sampling toEstimateSmartFee(confTarget=2).eth_maxPriorityFeePerGascontinues to work identically (delegates to the same path aseth_gasPrice).eth_feeHistoryis unchanged and continues to return historical block data.eth_estimateGas(gas unit estimation, not price) is unchanged.eth_gasPricewill automatically benefit from the improved estimation without any client-side changes.The new
eth_estimateSmartFeemethod is purely additive and does not affect existing functionality.Test Cases
[defaultGasPrice, maxPrice].MaxConfTargetare clamped toMaxConfTarget.Reference Implementation
The reference implementation modifies the following files:
prl/gasprice/gasprice.go— Core oracle rewrite with bucket tracking, decay, and estimationprl/prlconfig/config.go— Configuration defaultsinternal/prlapi/backend.go— Backend interface extensioninternal/prlapi/api.go— New RPC handlerprl/api_backend.go— Backend implementationprl/backend.go— Oracle initialization wiringles/api_backend.go— Light client backend implementationles/client.go— Light client oracle initializationSecurity Considerations
2 * MaxConfTargetblocks are automatically cleaned up to prevent unbounded growth.Copyright
Copyright and related rights waived via CC0.
Beta Was this translation helpful? Give feedback.
All reactions