@@ -169,9 +169,10 @@ type batchConfig struct {
169
169
// initial delay completion and publishing the batch transaction.
170
170
batchPublishDelay time.Duration
171
171
172
- // noBumping instructs sweepbatcher not to fee bump itself and rely on
173
- // external source of fee rates (FeeRateProvider).
174
- noBumping bool
172
+ // customFeeRate provides custom min fee rate per swap. The batch uses
173
+ // max of the fee rates of its swaps. In this mode confTarget is
174
+ // ignored and fee bumping by sweepbatcher is disabled.
175
+ customFeeRate FeeRateProvider
175
176
176
177
// txLabeler is a function generating a transaction label. It is called
177
178
// before publishing a batch transaction. Batch ID is passed to it.
@@ -723,6 +724,9 @@ func (b *batch) addSweeps(ctx context.Context, sweeps []*sweep) (bool, error) {
723
724
// lower that minFeeRate of other sweeps (so it is
724
725
// applied).
725
726
if b .rbfCache .FeeRate < s .minFeeRate {
727
+ b .Infof ("Increasing feerate of the batch " +
728
+ "from %v to %v" , b .rbfCache .FeeRate ,
729
+ s .minFeeRate )
726
730
b .rbfCache .FeeRate = s .minFeeRate
727
731
}
728
732
}
@@ -769,6 +773,9 @@ func (b *batch) addSweeps(ctx context.Context, sweeps []*sweep) (bool, error) {
769
773
// Update FeeRate. Max(s.minFeeRate) for all the sweeps of
770
774
// the batch is the basis for fee bumps.
771
775
if b .rbfCache .FeeRate < s .minFeeRate {
776
+ b .Infof ("Increasing feerate of the batch " +
777
+ "from %v to %v" , b .rbfCache .FeeRate ,
778
+ s .minFeeRate )
772
779
b .rbfCache .FeeRate = s .minFeeRate
773
780
b .rbfCache .SkipNextBump = true
774
781
}
@@ -968,6 +975,12 @@ func (b *batch) Run(ctx context.Context) error {
968
975
continue
969
976
}
970
977
978
+ // Update feerate of sweeps. This is normally done by
979
+ // AddSweep, but it may not be called after the sweep
980
+ // is confirmed, but fresh feerate is still needed to
981
+ // keep publishing in case of reorg.
982
+ b .updateFeeRate (ctx )
983
+
971
984
err := b .publish (ctx )
972
985
if err != nil {
973
986
return fmt .Errorf ("publish error: %w" , err )
@@ -1016,6 +1029,41 @@ func (b *batch) Run(ctx context.Context) error {
1016
1029
}
1017
1030
}
1018
1031
1032
+ // updateFeeRate gets fresh values of minFeeRate for sweeps and updates the
1033
+ // feerate of the batch if needed. This method must be called from event loop.
1034
+ func (b * batch ) updateFeeRate (ctx context.Context ) {
1035
+ for outpoint , s := range b .sweeps {
1036
+ minFeeRate , err := minimumSweepFeeRate (
1037
+ ctx , b .cfg .customFeeRate , b .wallet ,
1038
+ s .swapHash , s .outpoint , s .confTarget ,
1039
+ )
1040
+ if err != nil {
1041
+ b .Warnf ("failed to determine feerate for sweep %v of " +
1042
+ "swap %x, confTarget %d: %w" , s .outpoint ,
1043
+ s .swapHash [:6 ], s .confTarget , err )
1044
+ continue
1045
+ }
1046
+
1047
+ if minFeeRate <= s .minFeeRate {
1048
+ continue
1049
+ }
1050
+
1051
+ b .Infof ("Increasing feerate of sweep %v of swap %x from %v " +
1052
+ "to %v" , s .outpoint , s .swapHash [:6 ], s .minFeeRate ,
1053
+ minFeeRate )
1054
+ s .minFeeRate = minFeeRate
1055
+ b .sweeps [outpoint ] = s
1056
+
1057
+ if s .minFeeRate <= b .rbfCache .FeeRate {
1058
+ continue
1059
+ }
1060
+
1061
+ b .Infof ("Increasing feerate of the batch from %v to %v" ,
1062
+ b .rbfCache .FeeRate , s .minFeeRate )
1063
+ b .rbfCache .FeeRate = s .minFeeRate
1064
+ }
1065
+ }
1066
+
1019
1067
// testRunInEventLoop runs a function in the event loop blocking until
1020
1068
// the function returns. For unit tests only!
1021
1069
func (b * batch ) testRunInEventLoop (ctx context.Context , handler func ()) {
@@ -1793,7 +1841,7 @@ func (b *batch) updateRbfRate(ctx context.Context) error {
1793
1841
1794
1842
// Set the initial value for our fee rate.
1795
1843
b .rbfCache .FeeRate = rate
1796
- } else if ! b .cfg .noBumping {
1844
+ } else if noBumping := b .cfg .customFeeRate != nil ; ! noBumping {
1797
1845
if b .rbfCache .SkipNextBump {
1798
1846
// Skip fee bumping, unset the flag, to bump next time.
1799
1847
b .rbfCache .SkipNextBump = false
0 commit comments