Fix/Benchmark Antehandler #349
Draft
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.
Description
Closes: #338
Summary
This PR fixes two benchmark-breaking sub-issues:
DefaultMinGasPrice
to 1 so the basefee can no longer decay to zero.TruncateInt()
withCeil().RoundInt()
in fee calculation, ensuring the total fee is never under-priced.Details
These issues surfaced only after commit 9fd2afe the one that introduced EIP-1559.
You can reproduce this errors by
First sub-issues : Fix for "invalid gas cap" in benchmark
During BenchmarkAnteHandler, each tx is placed into its own block. Because every block then consumes only a tiny amount of gas, the EIP-1559 algorithm repeatedly lowers the baseFee until it eventually reaches 0 atom. Here's some log for this.
Once baseFee hits zero, the back-calculated maxFeePerGas for new tx also becomes zero, whereas default
maxPriorityFeePerGas = 1
. The inequalitymaxPriorityFeePerGas (1) > maxFeePerGas (0)
violates protocol rules, and each transaction is rejected with an invalid gas cap error.Fix : in the test initializer we raise the network's floor by setting (ref)
So baseFee can never decay below 1 aatom. With this safeguard in place, maxFeePerGas is always >=1 atatom, the inequality is avoided, and the benchmark suite runs to completion without errors.
Second sub-issues : Insufficient fee caused by fee rounding error
In the test environment, a Cosmos transaction's fee is calculated like this (ref)
So the code multiplies
baseFee × gasLimit
and then usesTruncateInt()
to drop the fractional part (This is a test shortcut; in production it should bemaxFeePerGas × gasLimit
).But here's the benchmark fails.
FeeChecker later re-derives
maxFeePerGas
by dividing the total fee by gasLimit and compares it to baseFee (ref). Because the total fee was truncated, it is up to 1 aatom lower, makingmaxFeePerGas < baseFee
and triggering 'gas prices too low; insufficient fee'. Here's some log for this.Fix : Replace
TruncateInt()
withCeil().RoundInt()
(ref)So the total fee is always ≥
baseFee × gasLimit
, guaranteeingmaxFeePerGas ≥ baseFee
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
main
branchReviewers Checklist
All items are required.
Please add a note if the item is not applicable
and please add your handle next to the items reviewed
if you only reviewed selected items.
I have...
Unreleased
section inCHANGELOG.md