Skip to content

Commit

Permalink
multi: update RPC error import path
Browse files Browse the repository at this point in the history
These errors are now defined in `btcwallet/chain` instead of
`btcd/rpcclient`.
  • Loading branch information
yyforyongyu committed Jul 3, 2024
1 parent d1857e6 commit 39ed358
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (

"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btclog"
"github.com/btcsuite/btcwallet/chain"
"github.com/btcsuite/btcwallet/waddrmgr"
"github.com/btcsuite/btcwallet/wallet"
"github.com/btcsuite/btcwallet/walletdb"
Expand Down Expand Up @@ -1485,8 +1485,8 @@ func broadcastErrorMapper(err error) error {
switch {
// This makes sure the tx is removed from the rebroadcaster once it is
// confirmed.
case errors.Is(err, rpcclient.ErrTxAlreadyKnown),
errors.Is(err, rpcclient.ErrTxAlreadyConfirmed):
case errors.Is(err, chain.ErrTxAlreadyKnown),
errors.Is(err, chain.ErrTxAlreadyConfirmed):

returnErr = &pushtx.BroadcastError{
Code: pushtx.Confirmed,
Expand All @@ -1495,7 +1495,7 @@ func broadcastErrorMapper(err error) error {

// Transactions which are still in mempool but might fall out because
// 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{
Code: pushtx.Mempool,
Reason: err.Error(),
Expand All @@ -1506,7 +1506,7 @@ func broadcastErrorMapper(err error) error {
// Mempool conditions change over time so it makes sense to retry
// publishing the transaction. Moreover we log the detailed error so the
// 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)

returnErr = &pushtx.BroadcastError{
Expand Down
12 changes: 6 additions & 6 deletions lnwallet/btcwallet/btcwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1202,15 +1202,15 @@ func mapRpcclientError(err error) error {
switch {
// If the wallet reports a double spend, convert it to our internal
// ErrDoubleSpend and return.
case errors.Is(err, rpcclient.ErrMempoolConflict),
errors.Is(err, rpcclient.ErrMissingInputs):
case errors.Is(err, chain.ErrMempoolConflict),
errors.Is(err, chain.ErrMissingInputs):

return lnwallet.ErrDoubleSpend

// If the wallet reports that fee requirements for accepting the tx
// into mempool are not met, convert it to our internal ErrMempoolFee
// and return.
case errors.Is(err, rpcclient.ErrMempoolMinFeeNotMet):
case errors.Is(err, chain.ErrMempoolMinFeeNotMet):
return fmt.Errorf("%w: %v", lnwallet.ErrMempoolFee, err.Error())
}

Expand Down Expand Up @@ -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
// wallet. We can remove this exception once we have the above TODO
// fixed.
case errors.Is(err, rpcclient.ErrTxAlreadyInMempool),
errors.Is(err, rpcclient.ErrTxAlreadyKnown),
errors.Is(err, rpcclient.ErrTxAlreadyConfirmed):
case errors.Is(err, chain.ErrTxAlreadyInMempool),
errors.Is(err, chain.ErrTxAlreadyKnown),
errors.Is(err, chain.ErrTxAlreadyConfirmed):

err := b.wallet.PublishTransaction(tx, label)
return mapRpcclientError(err)
Expand Down
2 changes: 1 addition & 1 deletion lnwallet/btcwallet/btcwallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestCheckMempoolAcceptance(t *testing.T) {

// Now call the method under test.
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.
//
Expand Down
4 changes: 2 additions & 2 deletions lnwallet/test/test_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ func testPublishTransaction(r *rpctest.Harness,
// If RBF is enabled, we expect it to be rejected
// because it doesn't pay enough fees.
if rbf {
expectedErr = rpcclient.ErrInsufficientFee
expectedErr = chain.ErrInsufficientFee
}

// Assert the expected error.
Expand Down Expand Up @@ -1891,7 +1891,7 @@ func testPublishTransaction(r *rpctest.Harness,
// Now broadcast the transaction, we should get an error that
// the weight is too large.
err := alice.PublishTransaction(testTx, labels.External)
require.ErrorIs(t, err, rpcclient.ErrOversizeTx)
require.ErrorIs(t, err, chain.ErrOversizeTx)
})
}

Expand Down
6 changes: 3 additions & 3 deletions sweep/fee_bumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (t *TxPublisher) createRBFCompliantTx(req *BumpRequest,
fallthrough

// We are not paying enough fees so we increase it.
case errors.Is(err, rpcclient.ErrInsufficientFee):
case errors.Is(err, chain.ErrInsufficientFee):
increased := false

// Keep calling the fee function until the fee rate is
Expand Down Expand Up @@ -934,7 +934,7 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
// - 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
// means the budget is not enough.
if errors.Is(err, rpcclient.ErrInsufficientFee) ||
if errors.Is(err, chain.ErrInsufficientFee) ||
errors.Is(err, lnwallet.ErrMempoolFee) {

log.Debugf("Failed to bump tx %v: %v", oldTx.TxHash(), err)
Expand Down Expand Up @@ -989,7 +989,7 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
//
// NOTE: we may get this error if we've bypassed the mempool check,
// 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) {

log.Debugf("Failed to bump tx %v: %v", oldTx.TxHash(), err)
Expand Down
8 changes: 4 additions & 4 deletions sweep/fee_bumper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcwallet/chain"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
Expand Down Expand Up @@ -569,7 +569,7 @@ func TestCreateRBFCompliantTx(t *testing.T) {
// for the first call.
m.wallet.On("CheckMempoolAcceptance",
mock.Anything).Return(
rpcclient.ErrInsufficientFee).Once()
chain.ErrInsufficientFee).Once()

// Mock the fee function to increase feerate.
m.feeFunc.On("Increment").Return(
Expand All @@ -591,7 +591,7 @@ func TestCreateRBFCompliantTx(t *testing.T) {
// for the first call.
m.wallet.On("CheckMempoolAcceptance",
mock.Anything).Return(
rpcclient.ErrInsufficientFee).Once()
chain.ErrInsufficientFee).Once()

// Mock the fee function to NOT increase
// feerate on the first round.
Expand Down Expand Up @@ -1087,7 +1087,7 @@ func TestCreateAnPublishFail(t *testing.T) {
// Mock the testmempoolaccept to return a fee related error that should
// be ignored.
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.
resultOpt = tp.createAndPublishTx(requestID, record)
Expand Down

0 comments on commit 39ed358

Please sign in to comment.