Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btc: disable estimatesmartfee for bitcoin #3046

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ var (
Tab: "External",
Description: "Connect to bitcoind",
DefaultConfigPath: dexbtc.SystemConfigPath("bitcoin"),
ConfigOpts: append(RPCConfigOpts("Bitcoin", "8332"), CommonConfigOpts("BTC", true)...),
ConfigOpts: append(RPCConfigOpts("Bitcoin", "8332"), CommonConfigOpts("BTC", false)...),
MultiFundingOpts: MultiFundingOpts,
}
spvWalletDefinition = &asset.WalletDefinition{
Expand All @@ -201,7 +201,7 @@ var (
Tab: "Electrum (external)",
Description: "Use an external Electrum Wallet",
// json: DefaultConfigPath: filepath.Join(btcutil.AppDataDir("electrum", false), "config"), // e.g. ~/.electrum/config
ConfigOpts: append(append(ElectrumConfigOpts, CommonConfigOpts("BTC", false)...), apiFallbackOpt(false)),
ConfigOpts: append(ElectrumConfigOpts, CommonConfigOpts("BTC", false)...),
MultiFundingOpts: MultiFundingOpts,
}

Expand Down Expand Up @@ -508,6 +508,12 @@ func parseRPCWalletConfig(settings map[string]string, symbol string, net dex.Net
return nil, nil, err
}

// For BTC, external fee rates are the default because of the instability
// of estimatesmartfee.
if symbol == "btc" {
cfg.ApiFeeFallback = true
}

cl, err := newRPCConnection(cfg, singularWallet)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -1849,17 +1855,19 @@ func (btc *baseWallet) legacyBalance() (*asset.Balance, error) {

// feeRate returns the current optimal fee rate in sat / byte using the
// estimatesmartfee RPC or an external API if configured and enabled.
func (btc *baseWallet) feeRate(confTarget uint64) (uint64, error) {
// Local estimate first. localFeeRate might be a dummy function for spv
// wallets.
feeRate, err := btc.localFeeRate(btc.ctx, btc.node, confTarget) // e.g. rpcFeeRate
if err == nil {
return feeRate, nil
func (btc *baseWallet) feeRate(confTarget uint64) (feeRate uint64, err error) {
allowExternalFeeRate := btc.apiFeeFallback()
// Because of the problems Bitcoin's unstable estimatesmartfee has caused,
// we won't use it.
if btc.symbol != "btc" || !allowExternalFeeRate {
feeRate, err := btc.localFeeRate(btc.ctx, btc.node, confTarget) // e.g. rpcFeeRate
if err == nil {
return feeRate, nil
} else if !allowExternalFeeRate {
return 0, fmt.Errorf("error getting local rate and external rates are disabled: %w", err)
}
}

if !btc.apiFeeFallback() {
return 0, err
}
if btc.feeCache == nil {
return 0, fmt.Errorf("external fee rate fetcher not configured")
}
Expand Down
Loading