fix(fortuna): fix too high fees #2532
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Reject setting the fees too high
Rationale
We estimate priority fees similar to how ethers.rs library does it. This is the general algo:
1- Get the priority fees of the last 10 blocks
2- Sort them
3- Get the median OR if there is any sudden increase, take the median from that index forward (https://github.com/gakonst/ethers-rs/blob/master/ethers-core/src/utils/mod.rs#L590)
Now the way priority fees are calculated for a block is just the average of priority fees for the transactions in that block. So if a block (https://berascan.com/block/2933426) only includes a single tx with very high priority fee, that would be overall priority fee for that block. So what happened for fortuna is we took that priority fee (because of that sudden increase heuristic) and set our fees according to that and that led to a super high fee.
This is what happens once in a while in berachain. When there is not a lot of activity on-chain, it's pretty easy to skew the priority fees.
I think adjusting the algo is a bit futile, I just set some hard caps. Also, in case we exceed that hardcap, we don't even attempt to set it but just try to wait a minute and recalculate again.