@@ -20,6 +20,7 @@ import (
2020 "github.com/lightningnetwork/lnd/lnutils"
2121 "github.com/lightningnetwork/lnd/lnwallet"
2222 "github.com/lightningnetwork/lnd/lnwallet/chainfee"
23+ "github.com/lightningnetwork/lnd/tlv"
2324)
2425
2526var (
4344 ErrThirdPartySpent = errors .New ("third party spent the output" )
4445)
4546
47+ var (
48+ // dummyChangePkScript is a dummy tapscript change script that's used
49+ // when we don't need a real address, just something that can be used
50+ // for fee estimation.
51+ dummyChangePkScript = []byte {
52+ 0x51 , 0x20 ,
53+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
54+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
55+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
56+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
57+ }
58+ )
59+
4660// Bumper defines an interface that can be used by other subsystems for fee
4761// bumping.
4862type Bumper interface {
@@ -129,12 +143,33 @@ type BumpRequest struct {
129143// compares it with the specified MaxFeeRate, and returns the smaller of the
130144// two.
131145func (r * BumpRequest ) MaxFeeRateAllowed () (chainfee.SatPerKWeight , error ) {
146+ // We'll want to know if we have any blobs, as we need to factor this
147+ // into the max fee rate for this bump request.
148+ hasBlobs := fn .Any (func (i input.Input ) bool {
149+ return fn .MapOptionZ (
150+ i .ResolutionBlob (), func (b tlv.Blob ) bool {
151+ return len (b ) > 0
152+ },
153+ )
154+ }, r .Inputs )
155+
156+ sweepAddrs := [][]byte {
157+ r .DeliveryAddress .DeliveryAddress ,
158+ }
159+
160+ // If we have blobs, then we'll add an extra sweep addr for the size
161+ // estimate below. We know that these blobs will also always be based on
162+ // p2tr addrs.
163+ if hasBlobs {
164+ // We need to pass in a real address, so we'll use a dummy
165+ // tapscript change script that's used elsewhere for tests.
166+ sweepAddrs = append (sweepAddrs , dummyChangePkScript )
167+ }
168+
132169 // Get the size of the sweep tx, which will be used to calculate the
133170 // budget fee rate.
134- //
135- // TODO(roasbeef): also wants the extra change output?
136171 size , err := calcSweepTxWeight (
137- r .Inputs , r . DeliveryAddress . DeliveryAddress ,
172+ r .Inputs , sweepAddrs ,
138173 )
139174 if err != nil {
140175 return 0 , err
@@ -163,7 +198,7 @@ func (r *BumpRequest) MaxFeeRateAllowed() (chainfee.SatPerKWeight, error) {
163198// calcSweepTxWeight calculates the weight of the sweep tx. It assumes a
164199// sweeping tx always has a single output(change).
165200func calcSweepTxWeight (inputs []input.Input ,
166- outputPkScript []byte ) (lntypes.WeightUnit , error ) {
201+ outputPkScript [][] byte ) (lntypes.WeightUnit , error ) {
167202
168203 // Use a const fee rate as we only use the weight estimator to
169204 // calculate the size.
@@ -177,7 +212,7 @@ func calcSweepTxWeight(inputs []input.Input,
177212 // TODO(yy): we should refactor the weight estimator to not require a
178213 // fee rate and max fee rate and make it a pure tx weight calculator.
179214 _ , estimator , err := getWeightEstimate (
180- inputs , nil , feeRate , 0 , [][] byte { outputPkScript } ,
215+ inputs , nil , feeRate , 0 , outputPkScript ,
181216 )
182217 if err != nil {
183218 return 0 , err
0 commit comments