From 24e654ffc469fae67c2aa4eb39d721257281ff60 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 10 Aug 2021 13:33:42 +0800 Subject: [PATCH 1/3] contractcourt: more verbose logging for anchor sweeping --- contractcourt/channel_arbitrator.go | 15 ++++++++++----- lntest/itest/assertions.go | 11 ++++++----- lntest/itest/lnd_channel_force_close.go | 3 +-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index 5f4cb31d5..93710f047 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -1100,7 +1100,7 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions, // sweepWithDeadline is a helper closure that takes an anchor // resolution and sweeps it with its corresponding deadline. sweepWithDeadline := func(anchor *lnwallet.AnchorResolution, - htlcs htlcSet) error { + htlcs htlcSet, anchorPath string) error { // Find the deadline for this specific anchor. 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 "+ - "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. anchorInput := input.MakeBaseInput( @@ -1153,13 +1154,15 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions, for htlcSet, htlcs := range c.activeHTLCs { switch { case htlcSet == LocalHtlcSet && anchors.Local != nil: - err := sweepWithDeadline(anchors.Local, htlcs) + err := sweepWithDeadline(anchors.Local, htlcs, "local") if err != nil { return err } case htlcSet == RemoteHtlcSet && anchors.Remote != nil: - err := sweepWithDeadline(anchors.Remote, htlcs) + err := sweepWithDeadline( + anchors.Remote, htlcs, "remote", + ) if err != nil { return err } @@ -1167,7 +1170,9 @@ func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions, case htlcSet == RemotePendingHtlcSet && anchors.RemotePending != nil: - err := sweepWithDeadline(anchors.RemotePending, htlcs) + err := sweepWithDeadline( + anchors.RemotePending, htlcs, "remote pending", + ) if err != nil { return err } diff --git a/lntest/itest/assertions.go b/lntest/itest/assertions.go index d9bb5522f..2cc0e4986 100644 --- a/lntest/itest/assertions.go +++ b/lntest/itest/assertions.go @@ -1613,8 +1613,9 @@ func assertActiveHtlcs(nodes []*lntest.HarnessNode, payHashes ...[]byte) error { // Channel should have exactly the payHashes active. if len(payHashes) != len(htlcHashes) { - return fmt.Errorf("node %x had %v htlcs active, "+ - "expected %v", node.PubKey[:], + return fmt.Errorf("node [%s:%x] had %v "+ + "htlcs active, expected %v", + node.Cfg.Name, node.PubKey[:], len(htlcHashes), len(payHashes)) } @@ -1624,9 +1625,9 @@ func assertActiveHtlcs(nodes []*lntest.HarnessNode, payHashes ...[]byte) error { if _, ok := htlcHashes[h]; ok { continue } - return fmt.Errorf("node %x didn't have the "+ - "payHash %v active", node.PubKey[:], - h) + return fmt.Errorf("node [%s:%x] didn't have: "+ + "the payHash %v active", node.Cfg.Name, + node.PubKey[:], h) } } } diff --git a/lntest/itest/lnd_channel_force_close.go b/lntest/itest/lnd_channel_force_close.go index 7154a4102..df9ca6231 100644 --- a/lntest/itest/lnd_channel_force_close.go +++ b/lntest/itest/lnd_channel_force_close.go @@ -151,8 +151,7 @@ func testCommitmentTransactionDeadline(net *lntest.NetworkHarness, t.t, checkNumWaitingCloseChannels(pendingChanResp, 1), ) - // We should see only one sweep transaction because the anchor - // sweep is skipped. + // Check our sweep transactions can be found in mempool. sweepTxns, err := getNTxsFromMempool( net.Miner.Client, expectedSweepTxNum, minerMempoolTimeout, From fda66f6a434429bfb2d506739c1a0aa051d77b8f Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 13 Aug 2021 21:49:22 +0800 Subject: [PATCH 2/3] itest: add an extra utxo when using neutrino --- lntest/itest/lnd_channel_force_close.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lntest/itest/lnd_channel_force_close.go b/lntest/itest/lnd_channel_force_close.go index df9ca6231..0fbd4aca3 100644 --- a/lntest/itest/lnd_channel_force_close.go +++ b/lntest/itest/lnd_channel_force_close.go @@ -81,6 +81,13 @@ func testCommitmentTransactionDeadline(net *lntest.NetworkHarness, // Send some coins to the node. net.SendCoins(ctx, t.t, btcutil.SatoshiPerBitcoin, node) + + // For neutrino backend, we need one additional UTXO to create + // the sweeping tx for the remote anchor. + if net.BackendCfg.Name() == lntest.NeutrinoBackendName { + net.SendCoins(ctx, t.t, btcutil.SatoshiPerBitcoin, node) + } + return node } From ba116f7ff1ecf8502d6624ba613af3758c25f03c Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 12 Aug 2021 06:01:15 +0800 Subject: [PATCH 3/3] docs: update release note --- docs/release-notes/release-notes-0.14.0.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/release-notes/release-notes-0.14.0.md b/docs/release-notes/release-notes-0.14.0.md index 4e1b1ff74..4cf561112 100644 --- a/docs/release-notes/release-notes-0.14.0.md +++ b/docs/release-notes/release-notes-0.14.0.md @@ -114,6 +114,8 @@ you. * [Fixed context timeout when closing channels in tests](https://github.com/lightningnetwork/lnd/pull/5616). +* [Fixed transaction not found in mempool flake in commitment deadline itest](https://github.com/lightningnetwork/lnd/pull/5615). + * [Fixed a missing import and git tag in the healthcheck package](https://github.com/lightningnetwork/lnd/pull/5582). * [Fixed a data race in payment unit test](https://github.com/lightningnetwork/lnd/pull/5573).