foundry
foundry copied to clipboard
Support suggested priority fee sampling
Component
Anvil
Describe the feature you would like
Currently the maxPriorityFeePerGas returns a simple constant, ideally this should do fee sampling across the recent blockrange.
ref https://github.com/foundry-rs/foundry/issues/7070
The endpoint should look at all the previous transactions in a certain range and do some sampling
ref: https://github.com/paradigmxyz/reth/blob/3c3c7b36adeb0a0491518854a2b13f9f85fc0aff/crates/rpc/rpc/src/eth/gas_oracle.rs#L127-L127
https://github.com/ethereum/go-ethereum/blob/fc380f52ef9778e988266f776b9593ce719cf79d/eth/gasprice/gasprice.go#L144-L150
Additional context
No response
This is interesting, would love to take this on! Quickly forking mainnet and running a simple Python script gets me this:
- `eth_gasPrice`: 22766662410
- `maxPriorityFeePerGas`: 44533324820
- Difference: 21766662410
So I sent the same request to Goerli, and the difference was a +7. This isn't ideal, and I understand this is the part that needs to be fixed.
- Retrieves latest block header.
- Returns cached price if for current block.
- Sets limit to twice
max_block_history
or total blocks if less. - Iterates over past blocks, fetching or using cached transaction tips.
- Fills results with last price for empty transactions.
- Sorts fees, selects fee at configured percentile.
- Constrains price by maximum if set.
- Updates cache with new price and block hash, returns suggested gas price.
So had a few questions
- Did I get this right?
- Do we have an equivalent for the
max_block_history
- The function I have to work on is max_priority_fee_per_gas (pasted below), right?
pub fn suggested_priority_fee(&self) -> U256 {
U256::from(1e9 as u64)
}
- Did I get this right?
this sums it up
- Do we have an equivalent for the max_block_history
we don't, I'd recommend to move this impl to the Backend
struct instead because this has direct access to all the mined blocks.
for forking mode, this should only take into account locally mined blocks.
the logic we need is basically the reth gas oracle
https://github.com/paradigmxyz/reth/blob/3c3c7b36adeb0a0491518854a2b13f9f85fc0aff/crates/rpc/rpc/src/eth/gas_oracle.rs#L216
we calculate this for a configured block range and then sort it and return the configured percentile.
3The function I have to work on is max_priority_fee_per_gas (pasted below), right?
yes this is only used by the rpc endpoint
Gotcha, starting some work on this!
probably closed by #7984.