contractcourt: more verbose logging for anchor sweeping

This commit is contained in:
yyforyongyu
2021-08-10 13:33:42 +08:00
parent 52767a7567
commit 24e654ffc4
3 changed files with 17 additions and 12 deletions

View File

@@ -1100,7 +1100,7 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions,
// sweepWithDeadline is a helper closure that takes an anchor // sweepWithDeadline is a helper closure that takes an anchor
// resolution and sweeps it with its corresponding deadline. // resolution and sweeps it with its corresponding deadline.
sweepWithDeadline := func(anchor *lnwallet.AnchorResolution, sweepWithDeadline := func(anchor *lnwallet.AnchorResolution,
htlcs htlcSet) error { htlcs htlcSet, anchorPath string) error {
// Find the deadline for this specific anchor. // Find the deadline for this specific anchor.
deadline, err := c.findCommitmentDeadline(heightHint, htlcs) deadline, err := c.findCommitmentDeadline(heightHint, htlcs)
@@ -1109,7 +1109,8 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions,
} }
log.Debugf("ChannelArbitrator(%v): pre-confirmation sweep of "+ log.Debugf("ChannelArbitrator(%v): pre-confirmation sweep of "+
"anchor of tx %v", c.cfg.ChanPoint, anchor.CommitAnchor) "anchor of %s commit tx %v", c.cfg.ChanPoint,
anchorPath, anchor.CommitAnchor)
// Prepare anchor output for sweeping. // Prepare anchor output for sweeping.
anchorInput := input.MakeBaseInput( anchorInput := input.MakeBaseInput(
@@ -1153,13 +1154,15 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions,
for htlcSet, htlcs := range c.activeHTLCs { for htlcSet, htlcs := range c.activeHTLCs {
switch { switch {
case htlcSet == LocalHtlcSet && anchors.Local != nil: case htlcSet == LocalHtlcSet && anchors.Local != nil:
err := sweepWithDeadline(anchors.Local, htlcs) err := sweepWithDeadline(anchors.Local, htlcs, "local")
if err != nil { if err != nil {
return err return err
} }
case htlcSet == RemoteHtlcSet && anchors.Remote != nil: case htlcSet == RemoteHtlcSet && anchors.Remote != nil:
err := sweepWithDeadline(anchors.Remote, htlcs) err := sweepWithDeadline(
anchors.Remote, htlcs, "remote",
)
if err != nil { if err != nil {
return err return err
} }
@@ -1167,7 +1170,9 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions,
case htlcSet == RemotePendingHtlcSet && case htlcSet == RemotePendingHtlcSet &&
anchors.RemotePending != nil: anchors.RemotePending != nil:
err := sweepWithDeadline(anchors.RemotePending, htlcs) err := sweepWithDeadline(
anchors.RemotePending, htlcs, "remote pending",
)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -1613,8 +1613,9 @@ func assertActiveHtlcs(nodes []*lntest.HarnessNode, payHashes ...[]byte) error {
// Channel should have exactly the payHashes active. // Channel should have exactly the payHashes active.
if len(payHashes) != len(htlcHashes) { if len(payHashes) != len(htlcHashes) {
return fmt.Errorf("node %x had %v htlcs active, "+ return fmt.Errorf("node [%s:%x] had %v "+
"expected %v", node.PubKey[:], "htlcs active, expected %v",
node.Cfg.Name, node.PubKey[:],
len(htlcHashes), len(payHashes)) len(htlcHashes), len(payHashes))
} }
@@ -1624,9 +1625,9 @@ func assertActiveHtlcs(nodes []*lntest.HarnessNode, payHashes ...[]byte) error {
if _, ok := htlcHashes[h]; ok { if _, ok := htlcHashes[h]; ok {
continue continue
} }
return fmt.Errorf("node %x didn't have the "+ return fmt.Errorf("node [%s:%x] didn't have: "+
"payHash %v active", node.PubKey[:], "the payHash %v active", node.Cfg.Name,
h) node.PubKey[:], h)
} }
} }
} }

View File

@@ -151,8 +151,7 @@ func testCommitmentTransactionDeadline(net *lntest.NetworkHarness,
t.t, checkNumWaitingCloseChannels(pendingChanResp, 1), t.t, checkNumWaitingCloseChannels(pendingChanResp, 1),
) )
// We should see only one sweep transaction because the anchor // Check our sweep transactions can be found in mempool.
// sweep is skipped.
sweepTxns, err := getNTxsFromMempool( sweepTxns, err := getNTxsFromMempool(
net.Miner.Client, net.Miner.Client,
expectedSweepTxNum, minerMempoolTimeout, expectedSweepTxNum, minerMempoolTimeout,