From d1857e63ad0bec2fbd3c644853f5b16abc97f5a1 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 3 Jul 2024 23:43:11 +0800 Subject: [PATCH] multi: use `chain.MapRPCErr` instead of `rpcclient.MapRPCErr` --- config_builder.go | 22 ++++++++++++---------- lnwallet/btcwallet/btcwallet.go | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/config_builder.go b/config_builder.go index 49a0b6c507b..3df81519077 100644 --- a/config_builder.go +++ b/config_builder.go @@ -708,9 +708,9 @@ func (d *DefaultWalletImpl) BuildChainControl( // The broadcast is already always active for neutrino nodes, so we // don't want to create a rebroadcast loop. if partialChainControl.Cfg.NeutrinoCS == nil { + cs := partialChainControl.ChainSource broadcastCfg := pushtx.Config{ Broadcast: func(tx *wire.MsgTx) error { - cs := partialChainControl.ChainSource _, err := cs.SendRawTransaction( tx, true, ) @@ -724,7 +724,10 @@ func (d *DefaultWalletImpl) BuildChainControl( // In case the backend is different from neutrino we // make sure that broadcast backend errors are mapped // to the neutrino broadcastErr. - MapCustomBroadcastError: broadcastErrorMapper, + MapCustomBroadcastError: func(err error) error { + rpcErr := cs.MapRPCErr(err) + return broadcastErrorMapper(rpcErr) + }, } lnWalletConfig.Rebroadcaster = newWalletReBroadcaster( @@ -1475,27 +1478,27 @@ func parseHeaderStateAssertion(state string) (*headerfs.FilterHeader, error) { // the neutrino BroadcastError which allows the Rebroadcaster which currently // resides in the neutrino package to use all of its functionalities. func broadcastErrorMapper(err error) error { - returnErr := rpcclient.MapRPCErr(err) + var returnErr error // We only filter for specific backend errors which are relevant for the // Rebroadcaster. switch { // This makes sure the tx is removed from the rebroadcaster once it is // confirmed. - case errors.Is(returnErr, rpcclient.ErrTxAlreadyKnown), + case errors.Is(err, rpcclient.ErrTxAlreadyKnown), errors.Is(err, rpcclient.ErrTxAlreadyConfirmed): returnErr = &pushtx.BroadcastError{ Code: pushtx.Confirmed, - Reason: returnErr.Error(), + Reason: err.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(returnErr, rpcclient.ErrTxAlreadyInMempool): + case errors.Is(err, rpcclient.ErrTxAlreadyInMempool): returnErr = &pushtx.BroadcastError{ Code: pushtx.Mempool, - Reason: returnErr.Error(), + Reason: err.Error(), } // Transactions which are not accepted into mempool because of low fees @@ -1504,12 +1507,11 @@ func broadcastErrorMapper(err error) error { // 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): - ltndLog.Warnf("Error while broadcasting transaction: %v", - returnErr) + ltndLog.Warnf("Error while broadcasting transaction: %v", err) returnErr = &pushtx.BroadcastError{ Code: pushtx.Mempool, - Reason: returnErr.Error(), + Reason: err.Error(), } } diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index ebca031c541..2b4d29fbca4 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -1277,7 +1277,7 @@ func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx, label string) error { // We need to use the string to create an error type and map it to a // btcwallet error. - err = rpcclient.MapRPCErr(errors.New(result.RejectReason)) + err = b.chain.MapRPCErr(errors.New(result.RejectReason)) //nolint:lll // These two errors are ignored inside `PublishTransaction`: @@ -1922,7 +1922,7 @@ func (b *BtcWallet) CheckMempoolAcceptance(tx *wire.MsgTx) error { // Mempool check failed, we now map the reject reason to a proper RPC // error and return it. if !result.Allowed { - err := rpcclient.MapRPCErr(errors.New(result.RejectReason)) + err := b.chain.MapRPCErr(errors.New(result.RejectReason)) return fmt.Errorf("mempool rejection: %w", err) }