Skip to content

Commit

Permalink
multi: use chain.MapRPCErr instead of rpcclient.MapRPCErr
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Jul 3, 2024
1 parent e685b9d commit d1857e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions lnwallet/btcwallet/btcwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit d1857e6

Please sign in to comment.