@@ -13,6 +13,7 @@ import (
13
13
"github.com/btcsuite/btcwallet/chain"
14
14
"github.com/davecgh/go-spew/spew"
15
15
"github.com/lightningnetwork/lnd/chainntnfs"
16
+ "github.com/lightningnetwork/lnd/fn"
16
17
"github.com/lightningnetwork/lnd/input"
17
18
"github.com/lightningnetwork/lnd/labels"
18
19
"github.com/lightningnetwork/lnd/lnutils"
@@ -815,22 +816,20 @@ func (t *TxPublisher) handleFeeBumpTx(requestID uint64, r *monitorRecord,
815
816
816
817
// The fee function now has a new fee rate, we will use it to bump the
817
818
// fee of the tx.
818
- result , err := t .createAndPublishTx (requestID , r )
819
- if err != nil {
820
- log .Errorf ("Failed to bump tx %v: %v" , oldTxid , err )
821
-
822
- return
823
- }
819
+ resultOpt := t .createAndPublishTx (requestID , r )
824
820
825
- // Notify the new result.
826
- t .handleResult (result )
821
+ // If there's a result, we will notify the caller about the result.
822
+ resultOpt .WhenSome (func (result BumpResult ) {
823
+ // Notify the new result.
824
+ t .handleResult (& result )
825
+ })
827
826
}
828
827
829
828
// createAndPublishTx creates a new tx with a higher fee rate and publishes it
830
829
// to the network. It will update the record with the new tx and fee rate if
831
830
// successfully created, and return the result when published successfully.
832
831
func (t * TxPublisher ) createAndPublishTx (requestID uint64 ,
833
- r * monitorRecord ) ( * BumpResult , error ) {
832
+ r * monitorRecord ) fn. Option [ BumpResult ] {
834
833
835
834
// Fetch the old tx.
836
835
oldTx := r .tx
@@ -842,21 +841,8 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
842
841
// directly here.
843
842
tx , fee , err := t .createAndCheckTx (r .req , r .feeFunction )
844
843
845
- // If the tx doesn't not have enought budget, we will return a result
846
- // so the sweeper can handle it by re-clustering the utxos.
847
- if errors .Is (err , ErrNotEnoughBudget ) {
848
- log .Warnf ("Fail to fee bump tx %v: %v" , oldTx .TxHash (), err )
849
-
850
- return & BumpResult {
851
- Event : TxFailed ,
852
- Tx : oldTx ,
853
- Err : err ,
854
- requestID : requestID ,
855
- }, nil
856
- }
857
-
858
- // If the error is not budget related, we will return an error and let
859
- // the fee bumper retry it at next block.
844
+ // If the error is fee related, we will return an error and let the fee
845
+ // bumper retry it at next block.
860
846
//
861
847
// NOTE: we can check the RBF error here and ask the fee function to
862
848
// recalculate the fee rate. However, this would defeat the purpose of
@@ -865,12 +851,40 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
865
851
// - if the deadline is close, we expect the fee function to give us a
866
852
// higher fee rate. If the fee rate cannot satisfy the RBF rules, it
867
853
// means the budget is not enough.
854
+ if errors .Is (err , rpcclient .ErrInsufficientFee ) ||
855
+ errors .Is (err , lnwallet .ErrMempoolFee ) {
856
+
857
+ log .Debugf ("Failed to bump tx %v: %v" , oldTx .TxHash (), err )
858
+ return fn .None [BumpResult ]()
859
+ }
860
+
861
+ // If the error is not fee related, we will return a `TxFailed` event
862
+ // so this input can be retried.
868
863
if err != nil {
869
- log .Infof ("Failed to bump tx %v: %v" , oldTx .TxHash (), err )
870
- return nil , err
864
+ // If the tx doesn't not have enought budget, we will return a
865
+ // result so the sweeper can handle it by re-clustering the
866
+ // utxos.
867
+ if errors .Is (err , ErrNotEnoughBudget ) {
868
+ log .Warnf ("Fail to fee bump tx %v: %v" , oldTx .TxHash (),
869
+ err )
870
+ } else {
871
+ // Otherwise, an unexpected error occurred, we will
872
+ // fail the tx and let the sweeper retry the whole
873
+ // process.
874
+ log .Errorf ("Failed to bump tx %v: %v" , oldTx .TxHash (),
875
+ err )
876
+ }
877
+
878
+ return fn .Some (BumpResult {
879
+ Event : TxFailed ,
880
+ Tx : oldTx ,
881
+ Err : err ,
882
+ requestID : requestID ,
883
+ })
871
884
}
872
885
873
- // Register a new record by overwriting the same requestID.
886
+ // The tx has been created without any errors, we now register a new
887
+ // record by overwriting the same requestID.
874
888
t .records .Store (requestID , & monitorRecord {
875
889
tx : tx ,
876
890
req : r .req ,
@@ -881,7 +895,10 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
881
895
// Attempt to broadcast this new tx.
882
896
result , err := t .broadcast (requestID )
883
897
if err != nil {
884
- return nil , err
898
+ log .Infof ("Failed to broadcast replacement tx %v: %v" ,
899
+ tx .TxHash (), err )
900
+
901
+ return fn .None [BumpResult ]()
885
902
}
886
903
887
904
// A successful replacement tx is created, attach the old tx.
@@ -890,15 +907,15 @@ func (t *TxPublisher) createAndPublishTx(requestID uint64,
890
907
// If the new tx failed to be published, we will return the result so
891
908
// the caller can handle it.
892
909
if result .Event == TxFailed {
893
- return result , nil
910
+ return fn . Some ( * result )
894
911
}
895
912
896
913
log .Infof ("Replaced tx=%v with new tx=%v" , oldTx .TxHash (), tx .TxHash ())
897
914
898
915
// Otherwise, it's a successful RBF, set the event and return.
899
916
result .Event = TxReplaced
900
917
901
- return result , nil
918
+ return fn . Some ( * result )
902
919
}
903
920
904
921
// isConfirmed checks the btcwallet to see whether the tx is confirmed.
0 commit comments