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

client: refactor btc FeeEstimator and added DOGE external #1967

Merged
merged 2 commits into from
Dec 2, 2022

Conversation

chappjc
Copy link
Member

@chappjc chappjc commented Nov 21, 2022

This refactors the BTC baseWallet fee rate handling to abstract the internal/external estimate calls in a feeRate method. The estimateSmartFee RPC-specific wallet method is now removed and no longer part of the btc.Wallet interface.

This replaces #1888. The commit is still authored by @vctt94, but also "co-authored" by myself and @buck54321.

Co-authored-by: Brian Stafford buck54321@gmail.com
Co-authored-by: Jonathan Chappelow chappjc@gmail.com

Comment on lines +1197 to +1225
// Default to the BTC RPC estimator (see LTC). Consumers can use
// 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 {
w.localFeeRate = rpcFeeRate
}

return w, nil
}

// 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() (uint64, error) {
return 0, errors.New("no local fee rate estimate possible")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used, but an idea to illustrate what these comments in the constructor are describing.

// override feeRate to avoid unnecessary conversions and btcjson types.
func (btc *ExchangeWalletElectrum) feeRate(_ RawRequester, confTarget uint64) (uint64, error) {
satPerKB, err := btc.ew.wallet.FeeRate(btc.ew.ctx, int64(confTarget))
func (btc *ExchangeWalletElectrum) walletFeeRate(ctx context.Context, confTarget uint64) (uint64, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes were really needed in electrum.go, but I wanted to remove the unused RawRequester junk from the ExchangeWalletElectrum method, doing the wrapping inside the ElectrumWallet constructor.

Comment on lines +188 to +189
// NOTE: btc.(*baseWallet).feeRate calls the local and external fee estimators
// in sequence, applying the limits configured in baseWallet.
Copy link
Member Author

@chappjc chappjc Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the gist of the design in this PR. A wallet choose to set these functions or not. If the local estimator is not set, the BTC RPC default is used. If the external estimator is not set, no external estimate is obtained.

I'm splitballing with the NoLocalFeeRate dummy idea for the local estimator if an instance needs to be designed that only does external estimates but there is no possibility for local estimates. We can consider this for SPV, but we may not want to implement asset.FeeRater for SPV wallets since we've established pretty well to use the fee rates from server that we have cached or fetched on-demand in Core.

Copy link
Member

@vctt94 vctt94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this makes sense. Left a suggestion but LGTM

func (btc *baseWallet) feeRate(confTarget uint64) (uint64, error) {
// Local estimate first. TODO: Allow only external (nil local).
feeRate, err := btc.localFeeRate(btc.ctx, btc.node, confTarget) // e.g. rpcFeeRate
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we also check feeRate != 0? This way if it returns 0 we can also check an external fee rate if the user wants to

@JoeGruffins
Copy link
Member

Unrelated to these changes, but confused about an error I'm getting trying this out on testnet:

[ERR] CORE: notify: |ERROR| (order) In-Flight Order Error - In-Flight order with ID 5 failed: new order request with DEX server 127.0.0.1:17273 market doge_dcr failed: rpc error: error code 53: order quantity exceeds user limit: Order quantity 100000000 too large. Current likely-taker order limit: -35000000 (you have 0 settling already and 0 in epoch taker orders) - Order: 
2022-11-29 05:23:44.460 [TRC] WEB[WS]: message of type 1 received for route acknotes

Current likely-taker order limit is negative? This is trying to sell one doge.

@chappjc
Copy link
Member Author

chappjc commented Dec 1, 2022

Expecting tests to fail. See last commit message.

vctt94 and others added 2 commits December 1, 2022 22:25
Also guard against FeeRate calls while not connected.

Co-authored-by: Brian Stafford <buck54321@gmail.com>
Co-authored-by: Jonathan Chappelow <chappjc@gmail.com>
@chappjc
Copy link
Member Author

chappjc commented Dec 2, 2022

Re-tested now that we're rebased with refactorLogin merged, also with the updateAssetWalletRefs fix.

@chappjc chappjc merged commit 5920049 into decred:master Dec 2, 2022
@chappjc chappjc deleted the client-btc-fee-refactor branch December 2, 2022 16:04
@chappjc chappjc added this to the 0.6 milestone Dec 27, 2022
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.

4 participants