Merge pull request #5615 from yyforyongyu/itest-fix-commitment-deadline

itest: fix commit deadline for neutrino backend
This commit is contained in:
Oliver Gugger 2021-08-19 16:40:14 +02:00 committed by GitHub
commit 9e8b9ccd4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 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

@ -114,6 +114,8 @@ you.
* [Fixed context timeout when closing channels in tests](https://github.com/lightningnetwork/lnd/pull/5616). * [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 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). * [Fixed a data race in payment unit test](https://github.com/lightningnetwork/lnd/pull/5573).

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

@ -81,6 +81,13 @@ func testCommitmentTransactionDeadline(net *lntest.NetworkHarness,
// Send some coins to the node. // Send some coins to the node.
net.SendCoins(ctx, t.t, btcutil.SatoshiPerBitcoin, 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 return node
} }
@ -151,8 +158,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,