@@ -20,6 +20,7 @@ import (
20
20
"github.com/lightningnetwork/lnd/keychain"
21
21
"github.com/lightningnetwork/lnd/lnrpc"
22
22
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
23
+ "github.com/lightningnetwork/lnd/lnrpc/verrpc"
23
24
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
24
25
"github.com/lightningnetwork/lnd/lnwallet"
25
26
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
@@ -134,7 +135,8 @@ type WalletKitClient interface {
134
135
// child-pays-for-parent (CPFP) scenario. If the given output has been
135
136
// used in a previous BumpFee call, then a transaction replacing the
136
137
// previous is broadcast, resulting in a replace-by-fee (RBF) scenario.
137
- BumpFee (context.Context , wire.OutPoint , chainfee.SatPerKWeight ) error
138
+ BumpFee (context.Context , wire.OutPoint , chainfee.SatPerKWeight ,
139
+ ... BumpFeeOption ) error
138
140
139
141
// ListAccounts retrieves all accounts belonging to the wallet by default.
140
142
// Optional name and addressType can be provided to filter through all the
@@ -218,6 +220,7 @@ type walletKitClient struct {
218
220
walletKitMac serializedMacaroon
219
221
timeout time.Duration
220
222
params * chaincfg.Params
223
+ version * verrpc.Version
221
224
}
222
225
223
226
// A compile time check to ensure that walletKitClient implements the
@@ -226,13 +229,15 @@ var _ WalletKitClient = (*walletKitClient)(nil)
226
229
227
230
func newWalletKitClient (conn grpc.ClientConnInterface ,
228
231
walletKitMac serializedMacaroon , timeout time.Duration ,
229
- chainParams * chaincfg.Params ) * walletKitClient {
232
+ chainParams * chaincfg.Params ,
233
+ version * verrpc.Version ) * walletKitClient {
230
234
231
235
return & walletKitClient {
232
236
client : walletrpc .NewWalletKitClient (conn ),
233
237
walletKitMac : walletKitMac ,
234
238
timeout : timeout ,
235
239
params : chainParams ,
240
+ version : version ,
236
241
}
237
242
}
238
243
@@ -737,28 +742,92 @@ func (m *walletKitClient) ListSweepsVerbose(ctx context.Context,
737
742
return result , nil
738
743
}
739
744
745
+ // BumpFeeOption customizes a BumpFee call.
746
+ type BumpFeeOption func (* walletrpc.BumpFeeRequest )
747
+
748
+ // WithImmediate is an option for enabling the immediate mode of BumpFee. The
749
+ // sweeper will sweep this input without waiting for the next block.
750
+ func WithImmediate () BumpFeeOption {
751
+ return func (r * walletrpc.BumpFeeRequest ) {
752
+ r .Immediate = true
753
+ }
754
+ }
755
+
756
+ // WithTargetConf is an option for setting the target_conf of BumpFee. If set,
757
+ // the underlying fee estimator will use the target_conf to estimate the
758
+ // starting fee rate for the fee function. Pass feeRate=0 to BumpFee if you
759
+ // add this option.
760
+ func WithTargetConf (targetConf uint32 ) BumpFeeOption {
761
+ return func (r * walletrpc.BumpFeeRequest ) {
762
+ r .TargetConf = targetConf
763
+ }
764
+ }
765
+
766
+ // WithBudget is an option for setting the budget of BumpFee. It is the max
767
+ // amount in sats that can be used as the fees. Setting this value greater than
768
+ // the input's value may result in CPFP - one or more wallet utxos will be used
769
+ // to pay the fees specified by the budget. If not set, for new inputs, by
770
+ // default 50% of the input's value will be treated as the budget for fee
771
+ // bumping; for existing inputs, their current budgets will be retained.
772
+ func WithBudget (budget btcutil.Amount ) BumpFeeOption {
773
+ return func (r * walletrpc.BumpFeeRequest ) {
774
+ r .Budget = uint64 (budget )
775
+ }
776
+ }
777
+
778
+ // targetConfFixed is the minimum version in which bug #9470 is merged and new
779
+ // meaning of TargetConf is enabled. In versions prior to this version the field
780
+ // had a different meaning.
781
+ var targetConfFixed = & verrpc.Version {
782
+ AppMajor : 0 ,
783
+ AppMinor : 18 ,
784
+ AppPatch : 5 ,
785
+ }
786
+
740
787
// BumpFee attempts to bump the fee of a transaction by spending one of its
741
788
// outputs at the given fee rate. This essentially results in a
742
789
// child-pays-for-parent (CPFP) scenario. If the given output has been used in a
743
790
// previous BumpFee call, then a transaction replacing the previous is
744
791
// broadcast, resulting in a replace-by-fee (RBF) scenario.
745
792
func (m * walletKitClient ) BumpFee (ctx context.Context , op wire.OutPoint ,
746
- feeRate chainfee.SatPerKWeight ) error {
793
+ feeRate chainfee.SatPerKWeight , opts ... BumpFeeOption ) error {
747
794
748
795
rpcCtx , cancel := context .WithTimeout (ctx , m .timeout )
749
796
defer cancel ()
750
797
751
- _ , err := m .client .BumpFee (
752
- m .walletKitMac .WithMacaroonAuth (rpcCtx ),
753
- & walletrpc.BumpFeeRequest {
754
- Outpoint : & lnrpc.OutPoint {
755
- TxidBytes : op .Hash [:],
756
- OutputIndex : op .Index ,
757
- },
758
- SatPerByte : uint32 (feeRate .FeePerKVByte () / 1000 ),
759
- Force : false ,
798
+ req := & walletrpc.BumpFeeRequest {
799
+ Outpoint : & lnrpc.OutPoint {
800
+ TxidBytes : op .Hash [:],
801
+ OutputIndex : op .Index ,
760
802
},
761
- )
803
+ SatPerVbyte : uint64 (feeRate .FeePerVByte ()),
804
+ Immediate : false ,
805
+ }
806
+
807
+ for _ , opt := range opts {
808
+ opt (req )
809
+ }
810
+
811
+ // Make sure that feeRate and WithTargetConf are not used together.
812
+ if feeRate != 0 && req .TargetConf != 0 {
813
+ return fmt .Errorf ("can't use target_conf if feeRate != 0" )
814
+ }
815
+
816
+ // Make sure that the version of LND is at least targetConfFixed,
817
+ // because before it the meaning of TargetConf was different. See
818
+ // https://github.com/lightningnetwork/lnd/pull/9470
819
+ // TODO(Boris): remove this check when minimalCompatibleVersion
820
+ // is bumped to targetConfFixed.
821
+ if req .TargetConf != 0 {
822
+ err := AssertVersionCompatible (m .version , targetConfFixed )
823
+ if err != nil {
824
+ return fmt .Errorf ("can't use target_conf before " +
825
+ "version 0.18.5, see #9470" )
826
+ }
827
+ }
828
+
829
+ _ , err := m .client .BumpFee (m .walletKitMac .WithMacaroonAuth (rpcCtx ), req )
830
+
762
831
return err
763
832
}
764
833
0 commit comments