multi: update RPC error import path

These errors are now defined in `btcwallet/chain` instead of
`btcd/rpcclient`.
This commit is contained in:
yyforyongyu 2024-07-03 23:04:58 +08:00
parent e0a506ab26
commit ddf46f435c
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
6 changed files with 24 additions and 21 deletions

View file

@ -17,9 +17,9 @@ import (
"github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btclog" "github.com/btcsuite/btclog"
"github.com/btcsuite/btcwallet/chain"
"github.com/btcsuite/btcwallet/waddrmgr" "github.com/btcsuite/btcwallet/waddrmgr"
"github.com/btcsuite/btcwallet/wallet" "github.com/btcsuite/btcwallet/wallet"
"github.com/btcsuite/btcwallet/walletdb" "github.com/btcsuite/btcwallet/walletdb"
@ -1485,8 +1485,8 @@ func broadcastErrorMapper(err error) error {
switch { switch {
// This makes sure the tx is removed from the rebroadcaster once it is // This makes sure the tx is removed from the rebroadcaster once it is
// confirmed. // confirmed.
case errors.Is(err, rpcclient.ErrTxAlreadyKnown), case errors.Is(err, chain.ErrTxAlreadyKnown),
errors.Is(err, rpcclient.ErrTxAlreadyConfirmed): errors.Is(err, chain.ErrTxAlreadyConfirmed):
returnErr = &pushtx.BroadcastError{ returnErr = &pushtx.BroadcastError{
Code: pushtx.Confirmed, Code: pushtx.Confirmed,
@ -1495,7 +1495,7 @@ func broadcastErrorMapper(err error) error {
// Transactions which are still in mempool but might fall out because // Transactions which are still in mempool but might fall out because
// of low fees are rebroadcasted despite of their backend error. // of low fees are rebroadcasted despite of their backend error.
case errors.Is(err, rpcclient.ErrTxAlreadyInMempool): case errors.Is(err, chain.ErrTxAlreadyInMempool):
returnErr = &pushtx.BroadcastError{ returnErr = &pushtx.BroadcastError{
Code: pushtx.Mempool, Code: pushtx.Mempool,
Reason: err.Error(), Reason: err.Error(),
@ -1506,7 +1506,7 @@ func broadcastErrorMapper(err error) error {
// Mempool conditions change over time so it makes sense to retry // Mempool conditions change over time so it makes sense to retry
// publishing the transaction. Moreover we log the detailed error so the // publishing the transaction. Moreover we log the detailed error so the
// user can intervene and increase the size of his mempool. // user can intervene and increase the size of his mempool.
case errors.Is(err, rpcclient.ErrMempoolMinFeeNotMet): case errors.Is(err, chain.ErrMempoolMinFeeNotMet):
ltndLog.Warnf("Error while broadcasting transaction: %v", err) ltndLog.Warnf("Error while broadcasting transaction: %v", err)
returnErr = &pushtx.BroadcastError{ returnErr = &pushtx.BroadcastError{

View file

@ -1202,15 +1202,15 @@ func mapRpcclientError(err error) error {
switch { switch {
// If the wallet reports a double spend, convert it to our internal // If the wallet reports a double spend, convert it to our internal
// ErrDoubleSpend and return. // ErrDoubleSpend and return.
case errors.Is(err, rpcclient.ErrMempoolConflict), case errors.Is(err, chain.ErrMempoolConflict),
errors.Is(err, rpcclient.ErrMissingInputs): errors.Is(err, chain.ErrMissingInputs):
return lnwallet.ErrDoubleSpend return lnwallet.ErrDoubleSpend
// If the wallet reports that fee requirements for accepting the tx // If the wallet reports that fee requirements for accepting the tx
// into mempool are not met, convert it to our internal ErrMempoolFee // into mempool are not met, convert it to our internal ErrMempoolFee
// and return. // and return.
case errors.Is(err, rpcclient.ErrMempoolMinFeeNotMet): case errors.Is(err, chain.ErrMempoolMinFeeNotMet):
return fmt.Errorf("%w: %v", lnwallet.ErrMempoolFee, err.Error()) return fmt.Errorf("%w: %v", lnwallet.ErrMempoolFee, err.Error())
} }
@ -1295,9 +1295,9 @@ func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx, label string) error {
// `PublishTransaction` again because we need to mark the label in the // `PublishTransaction` again because we need to mark the label in the
// wallet. We can remove this exception once we have the above TODO // wallet. We can remove this exception once we have the above TODO
// fixed. // fixed.
case errors.Is(err, rpcclient.ErrTxAlreadyInMempool), case errors.Is(err, chain.ErrTxAlreadyInMempool),
errors.Is(err, rpcclient.ErrTxAlreadyKnown), errors.Is(err, chain.ErrTxAlreadyKnown),
errors.Is(err, rpcclient.ErrTxAlreadyConfirmed): errors.Is(err, chain.ErrTxAlreadyConfirmed):
err := b.wallet.PublishTransaction(tx, label) err := b.wallet.PublishTransaction(tx, label)
return mapRpcclientError(err) return mapRpcclientError(err)

View file

@ -10,6 +10,7 @@ import (
"github.com/btcsuite/btcwallet/wallet" "github.com/btcsuite/btcwallet/wallet"
"github.com/lightningnetwork/lnd/lnmock" "github.com/lightningnetwork/lnd/lnmock"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -204,10 +205,12 @@ func TestCheckMempoolAcceptance(t *testing.T) {
}} }}
mockChain.On("TestMempoolAccept", []*wire.MsgTx{tx}, maxFeeRate).Return( mockChain.On("TestMempoolAccept", []*wire.MsgTx{tx}, maxFeeRate).Return(
results, nil).Once() results, nil).Once()
mockChain.On("MapRPCErr", mock.Anything).Return(
chain.ErrInsufficientFee).Once()
// Now call the method under test. // Now call the method under test.
err = wallet.CheckMempoolAcceptance(tx) err = wallet.CheckMempoolAcceptance(tx)
rt.ErrorIs(err, rpcclient.ErrInsufficientFee) rt.ErrorIs(err, chain.ErrInsufficientFee)
// Assert that when the tx is accepted, no error is returned. // Assert that when the tx is accepted, no error is returned.
// //

View file

@ -1808,7 +1808,7 @@ func testPublishTransaction(r *rpctest.Harness,
// If RBF is enabled, we expect it to be rejected // If RBF is enabled, we expect it to be rejected
// because it doesn't pay enough fees. // because it doesn't pay enough fees.
if rbf { if rbf {
expectedErr = rpcclient.ErrInsufficientFee expectedErr = chain.ErrInsufficientFee
} }
// Assert the expected error. // Assert the expected error.
@ -1891,7 +1891,7 @@ func testPublishTransaction(r *rpctest.Harness,
// Now broadcast the transaction, we should get an error that // Now broadcast the transaction, we should get an error that
// the weight is too large. // the weight is too large.
err := alice.PublishTransaction(testTx, labels.External) err := alice.PublishTransaction(testTx, labels.External)
require.ErrorIs(t, err, rpcclient.ErrOversizeTx) require.ErrorIs(t, err, chain.ErrOversizeTx)
}) })
} }

View file

@ -427,7 +427,7 @@ func (t *TxPublisher) createRBFCompliantTx(req *BumpRequest,
fallthrough fallthrough
// We are not paying enough fees so we increase it. // We are not paying enough fees so we increase it.
case errors.Is(err, rpcclient.ErrInsufficientFee): case errors.Is(err, chain.ErrInsufficientFee):
increased := false increased := false
// Keep calling the fee function until the fee rate is // Keep calling the fee function until the fee rate is
@ -934,7 +934,7 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
// - if the deadline is close, we expect the fee function to give us a // - if the deadline is close, we expect the fee function to give us a
// higher fee rate. If the fee rate cannot satisfy the RBF rules, it // higher fee rate. If the fee rate cannot satisfy the RBF rules, it
// means the budget is not enough. // means the budget is not enough.
if errors.Is(err, rpcclient.ErrInsufficientFee) || if errors.Is(err, chain.ErrInsufficientFee) ||
errors.Is(err, lnwallet.ErrMempoolFee) { errors.Is(err, lnwallet.ErrMempoolFee) {
log.Debugf("Failed to bump tx %v: %v", oldTx.TxHash(), err) log.Debugf("Failed to bump tx %v: %v", oldTx.TxHash(), err)
@ -989,7 +989,7 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
// //
// NOTE: we may get this error if we've bypassed the mempool check, // NOTE: we may get this error if we've bypassed the mempool check,
// which means we are suing neutrino backend. // which means we are suing neutrino backend.
if errors.Is(result.Err, rpcclient.ErrInsufficientFee) || if errors.Is(result.Err, chain.ErrInsufficientFee) ||
errors.Is(result.Err, lnwallet.ErrMempoolFee) { errors.Is(result.Err, lnwallet.ErrMempoolFee) {
log.Debugf("Failed to bump tx %v: %v", oldTx.TxHash(), err) log.Debugf("Failed to bump tx %v: %v", oldTx.TxHash(), err)

View file

@ -8,8 +8,8 @@ import (
"github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcwallet/chain"
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/keychain"
@ -569,7 +569,7 @@ func TestCreateRBFCompliantTx(t *testing.T) {
// for the first call. // for the first call.
m.wallet.On("CheckMempoolAcceptance", m.wallet.On("CheckMempoolAcceptance",
mock.Anything).Return( mock.Anything).Return(
rpcclient.ErrInsufficientFee).Once() chain.ErrInsufficientFee).Once()
// Mock the fee function to increase feerate. // Mock the fee function to increase feerate.
m.feeFunc.On("Increment").Return( m.feeFunc.On("Increment").Return(
@ -591,7 +591,7 @@ func TestCreateRBFCompliantTx(t *testing.T) {
// for the first call. // for the first call.
m.wallet.On("CheckMempoolAcceptance", m.wallet.On("CheckMempoolAcceptance",
mock.Anything).Return( mock.Anything).Return(
rpcclient.ErrInsufficientFee).Once() chain.ErrInsufficientFee).Once()
// Mock the fee function to NOT increase // Mock the fee function to NOT increase
// feerate on the first round. // feerate on the first round.
@ -1087,7 +1087,7 @@ func TestCreateAnPublishFail(t *testing.T) {
// Mock the testmempoolaccept to return a fee related error that should // Mock the testmempoolaccept to return a fee related error that should
// be ignored. // be ignored.
m.wallet.On("CheckMempoolAcceptance", m.wallet.On("CheckMempoolAcceptance",
mock.Anything).Return(rpcclient.ErrInsufficientFee).Once() mock.Anything).Return(chain.ErrInsufficientFee).Once()
// Call the createAndPublish method and expect a none option. // Call the createAndPublish method and expect a none option.
resultOpt = tp.createAndPublishTx(requestID, record) resultOpt = tp.createAndPublishTx(requestID, record)