From 54bacec4223ef160aeee8566ffca02e6007b7b59 Mon Sep 17 00:00:00 2001 From: ziggie Date: Sat, 3 Jun 2023 13:58:31 +0200 Subject: [PATCH] lnwallet: add new ErrMempoolFee error. --- lnwallet/btcwallet/btcwallet.go | 12 ++++++++++-- lnwallet/interface.go | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 3050be03a..1535d434b 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -1192,8 +1192,9 @@ func (b *BtcWallet) ListUnspentWitness(minConfs, maxConfs int32, // PublishTransaction performs cursory validation (dust checks, etc), then // finally broadcasts the passed transaction to the Bitcoin network. If // publishing the transaction fails, an error describing the reason is returned -// (currently ErrDoubleSpend). If the transaction is already published to the -// network (either in the mempool or chain) no error will be returned. +// and mapped to the wallet's internal error types. If the transaction is +// already published to the network (either in the mempool or chain) no error +// will be returned. func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx, label string) error { if err := b.wallet.PublishTransaction(tx, label); err != nil { // If we failed to publish the transaction, check whether we @@ -1210,6 +1211,13 @@ func (b *BtcWallet) PublishTransaction(tx *wire.MsgTx, label string) error { case *base.ErrReplacement: 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 *base.ErrMempoolFee: + return fmt.Errorf("%w: %v", lnwallet.ErrMempoolFee, + err.Error()) + default: return err } diff --git a/lnwallet/interface.go b/lnwallet/interface.go index f27e6345d..d8dc9d5b8 100644 --- a/lnwallet/interface.go +++ b/lnwallet/interface.go @@ -69,6 +69,12 @@ var ( // ErrNotMine is an error denoting that a WalletController instance is // unable to spend a specified output. ErrNotMine = errors.New("the passed output doesn't belong to the wallet") + + // ErrMempoolFee is returned from PublishTransaction in case the tx + // being published is not accepted into mempool because the fee + // requirements of the mempool backend are not met. + ErrMempoolFee = errors.New("transaction rejected by the mempool " + + "because of low fees") ) // ErrNoOutputs is returned if we try to create a transaction with no outputs