Skip to content

Commit

Permalink
itest: sync with sweeper state to eliminate flake
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Nov 16, 2024
1 parent 85eeb57 commit 65c7d8f
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions itest/litd_custom_channels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/port"
"github.com/lightningnetwork/lnd/lntest/wait"
Expand Down Expand Up @@ -3004,13 +3005,13 @@ func testCustomChannelsHtlcSuccess(_ context.Context, net *NetworkHarness,
// With all of the HTLCs established, we'll now force close the channel with
// Alice.
t.Logf("Force close by Alice w/ HTLCs...")
daveChanPoint := &lnrpc.ChannelPoint{
aliceChanPoint := &lnrpc.ChannelPoint{
OutputIndex: uint32(assetFundResp.OutputIndex),
FundingTxid: &lnrpc.ChannelPoint_FundingTxidStr{
FundingTxidStr: assetFundResp.Txid,
},
}
_, closeTxid, err := net.CloseChannel(alice, daveChanPoint, true)
_, closeTxid, err := net.CloseChannel(alice, aliceChanPoint, true)
require.NoError(t.t, err)

t.Logf("Channel closed! Mining blocks, close_txid=%v", closeTxid)
Expand Down Expand Up @@ -3144,15 +3145,34 @@ func testCustomChannelsHtlcSuccess(_ context.Context, net *NetworkHarness,
// sweep the HTLC into her wallet.
mineBlocks(t, net, closeExpiryInfo.csvDelay, 0)

// With the way the sweeper works, we'll now need to mine an extra block to
// trigger the sweep.
mineBlocks(t, net, 1, 0)
// We'll pause here and wait until the sweeper recognizes that we've offered
// the second level sweep transaction.
err = wait.NoError(func() error {
alicePendingSweeps, err := alice.WalletKitClient.PendingSweeps(
ctxb, &walletrpc.PendingSweepsRequest{},
)
if err != nil {
return err
}

time.Sleep(time.Second * 3)
for _, sweep := range alicePendingSweeps.PendingSweeps {
if sweep.WitnessType ==
walletrpc.WitnessType_TAPROOT_HTLC_ACCEPTED_SUCCESS_SECOND_LEVEL {

return nil
}
}

t.Logf("Confirming Alice's remote HTLC success sweep")
return fmt.Errorf("failed to find second level sweep: %v",
toProtoJSON(t.t, alicePendingSweeps))
}, time.Second*5)
require.NoError(t.t, err)

// Now that we know the sweep was offered, we'll mine an extra block to
// actually trigger a sweeper broadcast.
mineBlocks(t, net, 1, 0)

// TODO(roasbef): replace w/ mine until broadcast?
t.Logf("Confirming Alice's local HTLC success sweep")

// We'll mine one final block which will confirm Alice's sweep transaction.
mineBlocks(t, net, 1, 1)
Expand Down

0 comments on commit 65c7d8f

Please sign in to comment.