-
Notifications
You must be signed in to change notification settings - Fork 91
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
asset: Implement asset.FeeRater
for SPV wallets and minor refactor
#2356
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -905,8 +905,8 @@ var _ asset.Wallet = (*intermediaryWallet)(nil) | |
var _ asset.Accelerator = (*ExchangeWalletAccelerator)(nil) | ||
var _ asset.Accelerator = (*ExchangeWalletSPV)(nil) | ||
var _ asset.Withdrawer = (*baseWallet)(nil) | ||
var _ asset.FeeRater = (*baseWallet)(nil) | ||
var _ asset.Rescanner = (*ExchangeWalletSPV)(nil) | ||
var _ asset.FeeRater = (*ExchangeWalletFullNode)(nil) | ||
var _ asset.LogFiler = (*ExchangeWalletSPV)(nil) | ||
var _ asset.Recoverer = (*ExchangeWalletSPV)(nil) | ||
var _ asset.PeerManager = (*ExchangeWalletSPV)(nil) | ||
|
@@ -983,9 +983,8 @@ func (btc *ExchangeWalletSPV) RemovePeer(addr string) error { | |
var _ asset.FeeRater = (*ExchangeWalletFullNode)(nil) | ||
var _ asset.FeeRater = (*ExchangeWalletNoAuth)(nil) | ||
Comment on lines
983
to
984
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two assertions are a bit pointless now, but they don't hurt either. |
||
|
||
func (btc *intermediaryWallet) feeRaterHelper() uint64 { | ||
// NOTE: With baseWallet having an optional external fee rate source, we may | ||
// consider making baseWallet a FeeRater by allowing a nil local func. | ||
// FeeRate satisfies asset.FeeRater. | ||
func (btc *baseWallet) FeeRate() uint64 { | ||
rate, err := btc.feeRate(1) | ||
if err != nil { | ||
btc.log.Tracef("Failed to get fee rate: %v", err) | ||
|
@@ -994,16 +993,6 @@ func (btc *intermediaryWallet) feeRaterHelper() uint64 { | |
return rate | ||
} | ||
|
||
// FeeRate satisfies asset.FeeRater. | ||
func (btc *ExchangeWalletFullNode) FeeRate() uint64 { | ||
return btc.feeRaterHelper() | ||
} | ||
|
||
// FeeRate satisfies asset.FeeRater. | ||
func (btc *ExchangeWalletNoAuth) FeeRate() uint64 { | ||
return btc.feeRaterHelper() | ||
} | ||
|
||
// LogFilePath returns the path to the neutrino log file. | ||
func (btc *ExchangeWalletSPV) LogFilePath() string { | ||
return btc.spvNode.logFilePath() | ||
|
@@ -1295,7 +1284,7 @@ func newUnconnectedWallet(cfg *BTCCloneCFG, walletCfg *WalletConfig) (*baseWalle | |
w.cfgV.Store(baseCfg) | ||
|
||
// Default to the BTC RPC estimator (see LTC). Consumers can use | ||
// NoLocalFeeRate or a similar dummy function to power feeRate() requests | ||
// noLocalFeeRate or a similar dummy function to power feeRate() requests | ||
// with only an external fee rate source available. Otherwise, all method | ||
// calls must provide a rate or accept the configured fallback. | ||
if w.localFeeRate == nil { | ||
|
@@ -1305,10 +1294,10 @@ func newUnconnectedWallet(cfg *BTCCloneCFG, walletCfg *WalletConfig) (*baseWalle | |
return w, nil | ||
} | ||
|
||
// NoLocalFeeRate is a dummy function for BTCCloneCFG.FeeEstimator for a wallet | ||
// noLocalFeeRate is a dummy function for BTCCloneCFG.FeeEstimator for a wallet | ||
// instance that cannot support a local fee rate estimate but has an external | ||
// fee rate source. | ||
func NoLocalFeeRate(ctx context.Context, rr RawRequester, u uint64) (uint64, error) { | ||
func noLocalFeeRate(ctx context.Context, rr RawRequester, u uint64) (uint64, error) { | ||
return 0, errors.New("no local fee rate estimate possible") | ||
} | ||
|
||
|
@@ -1320,6 +1309,12 @@ func OpenSPVWallet(cfg *BTCCloneCFG, walletConstructor BTCWalletConstructor) (*E | |
return nil, err | ||
} | ||
|
||
// SPV wallets without a FeeEstimator will default to any enabled external | ||
// fee estimator. | ||
if cfg.FeeEstimator == nil { | ||
cfg.FeeEstimator = noLocalFeeRate | ||
} | ||
|
||
btc, err := newUnconnectedWallet(cfg, walletCfg) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -1639,7 +1634,8 @@ 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. TODO: Allow only external (nil local). | ||
// 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 | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch moving this under here. Looks like
LegacyBalance: cfg.Type != walletTypeSPV,
above would be best done in thiscase
as well, but it's not wrong presently, so nbd.