Skip to content

client/asset/eth: handle swap fee rates below the network base fee#3615

Open
peterzen wants to merge 4 commits into
decred:masterfrom
peterzen:evm-swap-basefee-check
Open

client/asset/eth: handle swap fee rates below the network base fee#3615
peterzen wants to merge 4 commits into
decred:masterfrom
peterzen:evm-swap-basefee-check

Conversation

@peterzen

@peterzen peterzen commented Jul 6, 2026

Copy link
Copy Markdown
Member

Prevents stuck EVM swap settlements when the network base fee exceeds the server-assigned fee rate (the tx's gas fee cap).

Two commits: the first refuses to broadcast an unminable swap tx, leaving the nonce unspent so core can retry. The second improves on refusal: raise the fee cap to 2*baseFee funds permitting (the same rescue Redeem already uses; a higher cap is protocol-legal since ValidateFeeRate only enforces a floor), refusing only when balance cannot cover a minable cap. Applies to all EVM-family wallets (eth, polygon).

This is also the client-side prerequisite for live server fee-rate assignment (#3616).

Related issue #3608

peterzen and others added 4 commits July 3, 2026 10:01
The server-assigned swap fee rate becomes the transaction's gas fee cap
verbatim. If the network's base fee exceeds it at broadcast time, the tx
cannot be mined until the base fee recedes, and meanwhile occupies the nonce,
blocking every subsequent transaction from the wallet until it is mined or
replaced.

Check the assigned rate against the current base fee before initiation and
error instead of broadcasting, leaving the nonce unspent. Core retries the
swap, which proceeds if the base fee recedes within the broadcast timeout.
The already-initiated recovery path is unaffected. Redeem already handles
this condition by raising its fee cap, funds permitting.

Co-Authored-By: Claude Fable 5 <[email protected]>
Rather than refusing outright when the server-assigned swap fee rate is
below the network's current base fee, attempt to raise the tx's gas fee cap
to 2*baseFee, funds permitting, mirroring the existing rescue in Redeem.
Under EIP-1559 the fee cap is not the fee paid, and the server's
ValidateFeeRate only requires the cap to be at least the assigned rate, so
a higher cap is protocol-legal. Refusal remains as a last resort when
available balance cannot cover a minable cap.

This also prepares for live (non-maximal) server fee rate assignment, where
a fee spike between match time and broadcast time would otherwise strand
honest traders.

Co-Authored-By: Claude Fable 5 <[email protected]>
Address review: the base fee is provider-reported, so compute the rescue
budget in big.Int to keep absurd values from overflowing the decision, and
guard the gasLimit division.

Co-Authored-By: Claude Fable 5 <[email protected]>
The initial maxFeeRate value derived from swaps.FeeRate was never read now
that the rescue result determines the fee cap; declare it at the point of
use instead. Fixes the ineffassign CI failure.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants