Skip to content

Commit f959242

Browse files
committed
temp: contractcourt+lnrpc: supply budget when sweeping inputs
Need more work here to determine the proper budget.
1 parent 7fede49 commit f959242

7 files changed

+90
-3
lines changed

contractcourt/anchor_resolver.go

+7
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ func (c *anchorResolver) Resolve() (ContractResolver, error) {
118118
Fee: sweep.FeeEstimateInfo{
119119
FeeRate: relayFeeRate,
120120
},
121+
// For normal anchor sweeping ,the budget is 330 sats.
122+
Budget: btcutil.Amount(
123+
anchorInput.SignDesc().Output.Value,
124+
),
125+
126+
// TODO(yy): specify a no deadline here.
127+
// DeadlineHeight: ,
121128
},
122129
)
123130
if err != nil {

contractcourt/channel_arbitrator.go

+10
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,16 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions,
13641364
},
13651365
Force: force,
13661366
ExclusiveGroup: &exclusiveGroup,
1367+
1368+
// TODO(yy): we need to figure out what the
1369+
// budget is here based on the context - for
1370+
// CPFP purpose, the budget is the total value
1371+
// under protection.
1372+
Budget: anchor.CommitFee,
1373+
1374+
// For CPFP purpose anchors, the deadline is
1375+
// defined above.
1376+
DeadlineHeight: int32(deadline + heightHint),
13671377
},
13681378
)
13691379
if err != nil {

contractcourt/commit_sweep_resolver.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,19 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
352352
c.log.Infof("sweeping commit output")
353353

354354
feePref := sweep.FeeEstimateInfo{ConfTarget: commitOutputConfTarget}
355-
resultChan, err := c.Sweeper.SweepInput(inp, sweep.Params{Fee: feePref})
355+
resultChan, err := c.Sweeper.SweepInput(
356+
inp, sweep.Params{
357+
Fee: feePref,
358+
359+
// TODO(yy): make this configurable as the budget can
360+
// be large here.
361+
Budget: btcutil.Amount(inp.SignDesc().Output.Value),
362+
363+
// TODO(yy): specify a default deadline here as there's
364+
// no time pressure.
365+
// DeadlineHeight: ,
366+
},
367+
)
356368
if err != nil {
357369
c.log.Errorf("unable to sweep input: %v", err)
358370

contractcourt/htlc_success_resolver.go

+17
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ func (h *htlcSuccessResolver) broadcastReSignedSuccessTx() (
266266
Fee: sweep.FeeEstimateInfo{
267267
ConfTarget: secondLevelConfTarget,
268268
},
269+
270+
// TODO(yy): make this a user-config option.
271+
Budget: btcutil.Amount(
272+
secondLevelInput.SignDesc().Output.Value,
273+
),
274+
275+
// TODO(yy): find the deadline - for first
276+
// level success tx, it needs to be confirmed
277+
// before the to remote CLTV.
278+
// DeadlineHeight:
269279
},
270280
)
271281
if err != nil {
@@ -378,6 +388,13 @@ func (h *htlcSuccessResolver) broadcastReSignedSuccessTx() (
378388
Fee: sweep.FeeEstimateInfo{
379389
ConfTarget: sweepConfTarget,
380390
},
391+
392+
// TODO(yy): make this a user-config option.
393+
Budget: btcutil.Amount(inp.SignDesc().Output.Value),
394+
395+
// TODO(yy): find the deadline here - for second level
396+
// success tx, there's no rush to get it confirmed.
397+
// DeadlineHeight:
381398
},
382399
)
383400
if err != nil {

contractcourt/htlc_timeout_resolver.go

+33
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,20 @@ func (h *htlcTimeoutResolver) sweepSecondLevelTx() error {
483483
h.broadcastHeight,
484484
))
485485
}
486+
486487
_, err := h.Sweeper.SweepInput(
487488
inp,
488489
sweep.Params{
489490
Fee: sweep.FeeEstimateInfo{
490491
ConfTarget: secondLevelConfTarget,
491492
},
492493
Force: true,
494+
495+
// TODO(yy): make this a user-config option.
496+
Budget: btcutil.Amount(inp.SignDesc().Output.Value),
497+
498+
// TODO(yy): specify a no-deadline here.
499+
// DeadlineHeight:
493500
},
494501
)
495502
if err != nil {
@@ -699,12 +706,38 @@ func (h *htlcTimeoutResolver) handleCommitSpend(
699706
h.htlcResolution.CsvDelay, h.broadcastHeight,
700707
h.htlc.RHash,
701708
)
709+
// Get the tx-level nLocktime for this HTLC.
710+
nLocktime, required := inp.RequiredLockTime()
711+
if !required {
712+
log.Errorf("%T(%x): second level tx not timelocked", h,
713+
h.htlc.RHash[:])
714+
}
715+
702716
_, err = h.Sweeper.SweepInput(
703717
inp,
704718
sweep.Params{
705719
Fee: sweep.FeeEstimateInfo{
706720
ConfTarget: sweepConfTarget,
707721
},
722+
723+
// TODO(yy): make this a user-config option.
724+
Budget: btcutil.Amount(
725+
inp.SignDesc().Output.Value,
726+
),
727+
728+
// For first level timeout tx, we'll use the
729+
// nLocktime as the deadline, tho the actual
730+
// deadline should be the CTLV inside this
731+
// HTLC's corresponding incoming HTLC. It's ok
732+
// if the tx is not cofnirmed by nLocktime, as
733+
// if the remote decides to go with the
734+
// preimage path, we will notice the preimage
735+
// and settled the incoming HTLC anyway. We
736+
// still need to set a deadline here, as it's
737+
// required that when grouping
738+
// SINGLE|ANYONECANPAY txes, the nLocktime of
739+
// all inputs must be the same.
740+
DeadlineHeight: int32(nLocktime),
708741
},
709742
)
710743
if err != nil {

contractcourt/utxonursery.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,14 @@ func (u *UtxoNursery) sweepMatureOutputs(classHeight uint32,
830830
local := output
831831

832832
resultChan, err := u.cfg.SweepInput(&local, sweep.Params{
833-
Fee: feePref,
834-
Force: true,
833+
Fee: feePref,
834+
Force: true,
835+
Budget: local.Amount(),
836+
// TODO(yy): specify a default deadline here as there's
837+
// no time pressure.
838+
//
839+
// TODO(yy): unify UtxoSweeper and UtxoNursery.
840+
// DeadlineHeight: ,
835841
})
836842
if err != nil {
837843
return err

lnrpc/walletrpc/walletkit_server.go

+2
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,8 @@ func UnmarshallOutPoint(op *lnrpc.OutPoint) (*wire.OutPoint, error) {
938938
// the output should be swept on-chain within. If a fee preference is not
939939
// explicitly specified, then an error is returned. The status of the input
940940
// sweep can be checked through the PendingSweeps RPC.
941+
//
942+
// TODO(yy): redefine this method to provide a guaranteed fee bumping.
941943
func (w *WalletKit) BumpFee(ctx context.Context,
942944
in *BumpFeeRequest) (*BumpFeeResponse, error) {
943945

0 commit comments

Comments
 (0)