contractcourt: specify deadline and budget for commit sweep

This commit is contained in:
yyforyongyu committed 2024-04-19 21:33:33 +08:00
1 parent aa44197f88
commit 01fd4e5642
4 files changed
+101 -19

No files matched your search

+17 -11
View File
@@ -13,17 +13,12 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/sweep"
)
const (
// commitOutputConfTarget is the default confirmation target we'll use
// for sweeps of commit outputs that belong to us.
commitOutputConfTarget = 6
)
// commitSweepResolver is a resolver that will attempt to sweep the commitment
// output paying to us, in the case that the remote party broadcasts their
// version of the commitment transaction. We can sweep this output immediately,
@@ -347,12 +342,23 @@ func (c *commitSweepResolver) Resolve() (ContractResolver, error) {
// TODO(roasbeef): instead of ading ctrl block to the sign desc, make
// new input type, have sweeper set it?
// With our input constructed, we'll now offer it to the
// sweeper.
c.log.Infof("sweeping commit output")
// Calculate the budget for the sweeping this input.
budget := calculateBudget(
btcutil.Amount(inp.SignDesc().Output.Value),
c.Budget.ToLocalRatio, c.Budget.ToLocal,
)
c.log.Infof("Sweeping commit output using budget=%v", budget)
feePref := sweep.FeeEstimateInfo{ConfTarget: commitOutputConfTarget}
resultChan, err := c.Sweeper.SweepInput(inp, sweep.Params{Fee: feePref})
// With our input constructed, we'll now offer it to the sweeper.
resultChan, err := c.Sweeper.SweepInput(
inp, sweep.Params{
Budget: budget,
// Specify a nil deadline here as there's no time
// pressure.
DeadlineHeight: fn.None[int32](),
},
)
if err != nil {
c.log.Errorf("unable to sweep input: %v", err)