Repository navigation
feat: add max-priority-fee-per-gas-cap (ceiling for the oracle tip) - #34
Conversation
The gas price manager has floors (floor-max-fee-per-gas / floor-max-priority-fee-per-gas) but no ceiling, so it bids whatever eth_maxPriorityFeePerGas returns verbatim. On low-traffic chains where the bundler is the dominant tx sender, the priority-fee oracle feedback-loops on the bundler's own past tips and reports an absurd value (observed: 500 gwei on Arc mainnet, where base fee sits at the 20 gwei protocol floor and blocks are empty). With no cap, the executor pays a ~500 gwei tip for txs that need ~0/1 gwei (per Arc's docs), costing ~0.24-0.36 USDC each vs a ~0.01 USDC target -- a ~25x overpay that drains the executor wallet. Add an optional max-priority-fee-per-gas-cap (gwei, like the floors). When set, the tip is capped to it and maxFeePerGas is reduced by the same delta, so we never overpay the tip and never push maxFeePerGas below the base-fee component. Applied after the floors so the cap wins if both are configured. No behavior change when unset. Refactors bumpTheGasPrice to a single return so floors + cap compose cleanly.
There was a problem hiding this comment.
Pull request overview
Adds an optional configuration ceiling for maxPriorityFeePerGas so the bundler doesn’t blindly follow an inflated eth_maxPriorityFeePerGas value on low-traffic chains (where the oracle can feedback-loop on the bundler’s own prior tips), while keeping the base-fee component intact by reducing maxFeePerGas by the same delta.
Changes:
- Refactors
bumpTheGasPriceto compute final floor-enforced fees via a single return. - Introduces
maxPriorityFeePerGasCaplogic that caps priority fee and reducesmaxFeePerGasby the same amount. - Wires the new
max-priority-fee-per-gas-capoption through CLI option definitions and Zod config schema parsing (gwei → wei viaparseGwei).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/handlers/gasPriceManager.ts | Adds cap application for priority fee and refactors floor composition logic. |
| src/cli/config/options.ts | Exposes a new CLI/config option description for max-priority-fee-per-gas-cap. |
| src/cli/config/bundler.ts | Adds Zod schema parsing for max-priority-fee-per-gas-cap using parseGwei. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
arpan-jain
left a comment
There was a problem hiding this comment.
Important
- The cap can push the total fee bid below the base fee, so transactions are never included.
- What breaks: The cap subtracts the whole amount it trimmed from the tip out of the total fee bid. That assumes the whole trimmed amount was part of the total. In two setups it was not, so the subtraction eats into the money meant for the base fee.
- When:
- (a) Legacy chains. These run with legacy-transactions, the older transaction format that has one gas price and no separate tip. The code stores the full gas price in both the fee field and the tip field. So the cap ends up limiting the entire gas price. Example: with a 20 gwei network price and a 5 gwei cap, every bundle, wallet refill and startup cleanup is sent at 5 gwei.
- (b) A tip floor above the cap. The existing floor-max-priority-fee-per-gas setting is a minimum tip. If it is set above the cap, the bid drops too low. Example: base fee 20, floor 30, cap 5 gives a 5 gwei total bid. The PR description says "the cap wins if both are configured", which is exactly this case. Polygon has a built-in 31 gwei minimum tip that acts like a floor, so a Polygon cap below 31 gwei hits the same problem.
- Impact:
- Every bundle on that chain stalls, and users' operations sit pending.
- Resubmission bumps stop at 3×, and rotating to a fresh executor wallet starts again from the same low price. So case (a), and case (b) when the floor is far above the cap, never recover on their own.
- Wallet refills stall too, so executor wallets run dry.
- Why it doesn't block Arc: Arc uses the newer EIP-1559 transaction format (separate base fee and tip), and the planned rollout sets no tip floor. No config in this repo turns on legacy mode or a tip floor. This is a trap for the next chain where someone turns the cap on.
- Fix:
- Subtract only the part of the trimmed tip that was actually inside the total bid. That is the bumped oracle tip minus the cap.
- Skip the cap in legacy mode, or refuse that combination at startup.
- Refuse a tip floor above the cap at startup.
- Where: the subtraction is at src/handlers/gasPriceManager.ts:171-177, the legacy path at :325, and the floors at :144-157.
Minor
- A cap of "0" breaks gas price quotes when the price cache is on.
- What breaks: The gas price cache silently drops zero values. The read from the cache also treats a zero tip as "no price". So every cached read fails with "No gas price available".
- When: Two things together. The cap is set to "0", which is tempting because Arc's docs say a zero tip is accepted. And gas-price-refresh-interval is above 0, which turns on background price caching. The default is 0, which avoids the problem.
- Impact:
- pimlico_getUserOperationGasPrice fails.
- eth_sendUserOperation rejects everything, except in safe mode or API v1.
- Gas estimation fails on OP-stack, Mantle and Etherlink chains.
- Bundling itself keeps working.
- The planned Arc value is 5, so the rollout is fine. I could not check Arc's refresh interval, because its deployment config is not in this repo.
- Fix: refuse 0 in the config schema, for example .refine(v => v > 0n), or document the restriction. Locations: src/cli/config/bundler.ts:203, src/utils/minMaxQueue/createMemoryMinMaxQueue.ts:61, gasPriceManager.ts:428.
- A negative cap is accepted at startup, and then every transaction fails when it is sent.
- What breaks: The config accepts "-1" and turns it into a negative tip. The existing floor settings parse just as loosely, but a negative floor is harmless because a floor keeps the larger of two values. The cap keeps the smaller value, so the negative number wins.
- When: a typo such as "-5".
- Impact: Every bundle and refill fails with an encoding error, instead of the bundler refusing to start.
- Fix: use the same schema check as #2.
- Wallet refills never raise their fee, and a low cap makes a stuck refill more likely. This problem existed before the PR.
- What breaks: A refill transfer is sent once at the current price, and the code then waits for it. Nothing raises the fee if it sits. The first stuck refill also blocks the remaining refills in that run.
- When: the cap is set below the tip needed to win block space under real congestion. Arc's blocks are empty today, so this does not apply there now.
- Impact: Executor wallets could run down. The missing fee bump is old; the cap only makes a stuck refill more likely. Location: validateAndRefill.ts:89-162.
Note: the PR adds no tests. A small table test would have caught #1 and #2. It should cover: cap not set, legacy mode, a floor above the cap, and a cap of 0.
Reject a cap of zero or below at parse time. Refuse to start when the cap is set with legacy transactions or with a priority fee floor above it, since the cap then trims part of the base fee from maxFeePerGas.
|
Thanks, fixed in 80ceb7d:
I also added the table test you described (no cap, inflated tip, tip under the cap, legacy mode, floor above the cap, Polygon minimum, 0 and negative caps), and merged main into the branch. |
arpan-jain
left a comment
There was a problem hiding this comment.
No blocking issues. 1 small fix recommended, 3 minor. The Arc rollout as described (cap of 5 gwei, normal transactions, no floors) is not affected by any of them.
Round 1 issues are all fixed. The new commit refuses the risky settings at startup instead of changing the math:
- The cap combined with legacy transactions (the older one-price format): now refused at startup.
- A tip floor above the cap, including Polygon's built-in 31 gwei minimum: now refused at startup.
- A cap of 0 or below: now rejected when the config is read.
- Tests: 8 were added. I ran them and all 8 pass. The type check is also clean.
Recommended small fix
- The cap can push the total fee bid below the configured minimum total fee.
- What breaks: The cap lowers the total fee bid by the amount it trims from the tip. It never re-applies the operator's minimum total fee (floor-max-fee-per-gas) afterwards.
- When: That minimum and the cap are both set. Example: a 40 gwei minimum, a 5 gwei cap, a 20 gwei base fee and a 500 gwei oracle tip give a 29 gwei total bid.
- Impact: The bid still covers the base fee, so on most chains nothing breaks. Harm only comes where the operator set the minimum on purpose: on chains whose nodes reject fees below a set minimum, or as a cushion against base-fee spikes. In those cases bundles stall until retries climb back above the minimum. The bundler also starts accepting users' operations priced below it.
- Why it's low risk today: No config in the repo, past or present, sets this minimum. Arc's 20 gwei floor already shows up in the reported base fee, so Arc has no reason to set it.
- Fix: one line, and it costs nothing in fees, because the chain charges the base fee plus the tip either way. In the cap method, wrap the result as maxBigInt(..., this.config.floorMaxFeePerGas ?? 0n). Add a test that runs the full price path with this minimum set. Today's tests call the cap method directly, which is why this slipped through.
- Where: src/handlers/gasPriceManager.ts:197-205.
Minor
- The cap can't tell real congestion apart from a looping oracle. This needs documentation only.
- What breaks: Every price the bundler quotes or bids starts from the capped tip. So under genuine congestion it can't see that it needs a higher tip.
- When: Real congestion needs a tip above about 4× the cap. Retries climb to roughly 2.5–4× the cap before the wallet rotation cycle repeats. With a 5 gwei cap, a 10 gwei congestion tip still lands after about 40–50 seconds; one above about 20 gwei never does.
- Impact: Bundles wait until someone raises the cap. For users' operations that pay their own fees, the bundler covers the gap between what they signed and what it had to bid.
- Fix: add one sentence to the option's help text: "set this above the tip the chain needs under real load." The existing absolute ceiling, max-bundling-gas-price, has the same property.
- A bundle rejected for a too-low tip retries forever at the same price. This weakness existed before the PR; the cap adds a new way to trigger it.
- What breaks: The error check only recognizes "replacement transaction underpriced". A plain "transaction underpriced" rejection retries at the same price; the refuters reproduced it as 5 → 5 → 5 gwei. The operations then go back into the queue with their attempt count reset, and nothing limits how often that repeats.
- When: The cap is set below a minimum tip that a node enforces on its own. Nodes can be configured this way, but it isn't the default. The startup check only knows about the configured floor and Polygon.
- Impact: Those operations are never included and keep being re-simulated. Normal bundling intervals still apply, so it is not a tight loop.
- Where: src/executor/utils.ts:27, src/executor/executor.ts:747, src/mempool/mempool.ts:875.
- Wallet refills never raise their fee. Carried over from round 1; the code is unchanged.
- What breaks: A refill transfer is sent once and the code waits for it. A stuck refill blocks the other refills in that run.
- When: The cap is set below what congestion needs.
- Impact: Executor wallets could run down. This was confirmed 3 of 3 in round 1, as an old gap that the cap makes more likely.
Worth cutting
- The bumpTheGasPrice rewrite (gasPriceManager.ts:166-185) is leftover from the first commit and changes nothing. Restoring the original block shrinks the diff.
- Lane 5 also suggested dropping the safety check in the cap method (:203). I'd keep it. It only matters if the oracle ever quotes a total fee below its own tip, and it costs one line.
|
Thanks, fixed in fa1f652:
I kept the safety check in the cap method. The plain "transaction underpriced" retry and the refill fee bump existed before this PR. I will fix them in a follow-up PR. |
Problem
gasPriceManagerhas gas floors (floor-max-fee-per-gas,floor-max-priority-fee-per-gas) but no ceiling — it bids whatevereth_maxPriorityFeePerGasreturns, verbatim.On low-traffic chains where the bundler is the dominant tx sender, the priority-fee oracle feedback-loops on the bundler's own past tips and reports an absurd value. Observed on Arc mainnet:
eth_maxPriorityFeePerGasreturns 500 gwei, and the executor bids itThere's no config knob to cap this today (floors only raise;
gas-price-bump < 100scales a moving oracle and undershoots below base fee as the loop unwinds → stalls). So it needs a ceiling primitive.Change
Add an optional
max-priority-fee-per-gas-cap(gwei, parsed like the floors). When set:minBigIntmaxFeePerGasis reduced by the same delta, so the base-fee component is preserved (never pushes maxFee below the base fee) and we don't pay an inflated tipbumpTheGasPriceis refactored to a single return so floors + cap compose cleanly.It's also self-correcting: once the bundler bids capped tips, the oracle's percentile of recent tips drops within a few blocks and the loop unwinds.
Rollout
Set on the affected chain's config, e.g. Arc:
(5 gwei = 5× Arc's suggested tip, ~100× below the looped 500; lands at ~$0.01/tx — Arc's target. Base fee is still paid in full and can rise legitimately under real congestion.) Other low-traffic chains where the bundler dominates can set it as needed; leaving it unset preserves current behavior.