11package sweep
22
33import (
4+ "bytes"
45 "errors"
56 "fmt"
67 "sync"
@@ -129,12 +130,29 @@ type BumpRequest struct {
129130// compares it with the specified MaxFeeRate, and returns the smaller of the
130131// two.
131132func (r * BumpRequest ) MaxFeeRateAllowed () (chainfee.SatPerKWeight , error ) {
133+ // We'll want to know if we have any blobs, as we need to factor this
134+ // into the max fee rate for this bump request.
135+ hasBlobs := fn .Any (func (i input.Input ) bool {
136+ return i .ResolutionBlob ().IsSome ()
137+ }, r .Inputs )
138+
139+ sweepAddrs := [][]byte {
140+ r .DeliveryAddress .DeliveryAddress ,
141+ }
142+
143+ // If we have blobs, then we'll add an extra sweep addr for the size
144+ // estimate below. WE know that these blobs will also always be based on
145+ // p2tr addrs.
146+ if hasBlobs {
147+ sweepAddrs = append (
148+ sweepAddrs , bytes .Repeat ([]byte {0 }, input .P2TRSize ),
149+ )
150+ }
151+
132152 // Get the size of the sweep tx, which will be used to calculate the
133153 // budget fee rate.
134- //
135- // TODO(roasbeef): also wants the extra change output?
136154 size , err := calcSweepTxWeight (
137- r .Inputs , r . DeliveryAddress . DeliveryAddress ,
155+ r .Inputs , sweepAddrs ,
138156 )
139157 if err != nil {
140158 return 0 , err
@@ -163,7 +181,7 @@ func (r *BumpRequest) MaxFeeRateAllowed() (chainfee.SatPerKWeight, error) {
163181// calcSweepTxWeight calculates the weight of the sweep tx. It assumes a
164182// sweeping tx always has a single output(change).
165183func calcSweepTxWeight (inputs []input.Input ,
166- outputPkScript []byte ) (lntypes.WeightUnit , error ) {
184+ outputPkScript [][] byte ) (lntypes.WeightUnit , error ) {
167185
168186 // Use a const fee rate as we only use the weight estimator to
169187 // calculate the size.
@@ -177,7 +195,7 @@ func calcSweepTxWeight(inputs []input.Input,
177195 // TODO(yy): we should refactor the weight estimator to not require a
178196 // fee rate and max fee rate and make it a pure tx weight calculator.
179197 _ , estimator , err := getWeightEstimate (
180- inputs , nil , feeRate , 0 , [][] byte { outputPkScript } ,
198+ inputs , nil , feeRate , 0 , outputPkScript ,
181199 )
182200 if err != nil {
183201 return 0 , err
0 commit comments