fix(electrum): gate low-fee estimate fallback to non-mainnet networks#4019
Open
lrsaturnino wants to merge 1 commit into
Open
fix(electrum): gate low-fee estimate fallback to non-mainnet networks#4019lrsaturnino wants to merge 1 commit into
lrsaturnino wants to merge 1 commit into
Conversation
When the Electrum fee oracle returns no estimate for any confirmation target, EstimateSatPerVByteFee returned a hardcoded 2 sat/vByte for every network. On mainnet this turns a fail-safe (error, no broadcast) into a fail-broadcast: the tBTC sweep and redemption fee paths build and broadcast transactions at a feerate that can be left unconfirmable or evicted under congestion, stalling sweeps and redemptions. Gate the fallback to test networks (testnet, testnet4, regtest) via a new Electrum Config.Network field resolved from the client configuration. On mainnet, and on any unset or unknown network, the oracle failure is surfaced as an error so callers do not broadcast at a guessed feerate. The field is tagged mapstructure:"-" and set after config unmarshal, so a config key cannot re-enable the fallback on mainnet. Add a unit test covering the fallback decision per network and propagate the resolved network into the Electrum integration test configs.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
piotr-roslaniec
approved these changes
Jun 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
PR #4002 added an Electrum fee-estimate fallback: when
blockchain.estimatefeereturns no estimate for any confirmation target (common on quiet testnet4 mempools, which answer-32603for every target),EstimateSatPerVByteFeereturns a hardcoded2sat/vByte instead of an error.That fallback is network-blind. Before, an oracle failure returned an error and no transaction was broadcast on a guessed feerate (fail-safe). After, the same failure yields a fixed
2sat/vByte that flows into the production tBTC proposal fee paths (tbtcpg/deposit_sweep.go,redemptions.go,moving_funds.go,moved_funds_sweep.go) on mainnet as well, with no minimum-feerate floor inTransactionFeeEstimator.EstimateFee. On mainnet a2sat/vByte transaction can be left unconfirmable under congestion, or evicted if the dynamic mempool minimum feerate rises above it — stalling sweeps and redemptions (delayed mints / undelivered BTC). The funds are not lost, but operations can get stuck.Solution
Gate the fallback to networks where an underpriced transaction is economically harmless —
testnet,testnet4,regtest. Onmainnet, and on any unset or unknown network, the oracle failure is surfaced as an error so callers do not broadcast at a guessed feerate (fail-closed default).electrum.Config.Networkfield carries the resolved Bitcoin network into the connection. It is set from the client configuration inconfig.resolveElectrum, taggedmapstructure:"-", and assigned after config unmarshal — so a config-file key cannot re-enable the fallback on mainnet.feeFallbackResultandlowFeeFallbackAllowed) so it can be tested deterministically without a live Electrum client.Tests
TestFeeFallbackResultcovers the decision per network: mainnet and unknown fail safe with an error; testnet/testnet4/regtest use the fallback; transport-level failures always error.config.TestResolveElectrumnow asserts the resolved network is propagated into the Electrum config.Unknown.gofmt -l,go vet,go build ./...,go test(changed packages),go vet -tags=integration(compile), Staticcheck 2025.1.1, and gosec (0 issues).Notes
This is a follow-up to the review of #4002 and is based on its head branch (
stack/testnet4-04-go-testnet4-runtime), so the diff is scoped to this fix.