diff --git a/config_builder.go b/config_builder.go index 3df815190..bf6274cdf 100644 --- a/config_builder.go +++ b/config_builder.go @@ -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" @@ -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, @@ -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(), @@ -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{ diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 28b029b8a..196bd3c09 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -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()) } @@ -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) diff --git a/lnwallet/btcwallet/btcwallet_test.go b/lnwallet/btcwallet/btcwallet_test.go index 892ec25fd..c5bd8905a 100644 --- a/lnwallet/btcwallet/btcwallet_test.go +++ b/lnwallet/btcwallet/btcwallet_test.go @@ -10,6 +10,7 @@ import ( "github.com/btcsuite/btcwallet/wallet" "github.com/lightningnetwork/lnd/lnmock" "github.com/lightningnetwork/lnd/lnwallet" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -204,10 +205,12 @@ func TestCheckMempoolAcceptance(t *testing.T) { }} mockChain.On("TestMempoolAccept", []*wire.MsgTx{tx}, maxFeeRate).Return( results, nil).Once() + mockChain.On("MapRPCErr", mock.Anything).Return( + chain.ErrInsufficientFee).Once() // 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. // diff --git a/lnwallet/test/test_interface.go b/lnwallet/test/test_interface.go index dd1db5f20..c3d26f6cf 100644 --- a/lnwallet/test/test_interface.go +++ b/lnwallet/test/test_interface.go @@ -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. @@ -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) }) } diff --git a/sweep/fee_bumper.go b/sweep/fee_bumper.go index b4d429894..e79280166 100644 --- a/sweep/fee_bumper.go +++ b/sweep/fee_bumper.go @@ -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 @@ -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) @@ -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) diff --git a/sweep/fee_bumper_test.go b/sweep/fee_bumper_test.go index 63a828654..4c4a9519f 100644 --- a/sweep/fee_bumper_test.go +++ b/sweep/fee_bumper_test.go @@ -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" @@ -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( @@ -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. @@ -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)