@@ -28,6 +28,7 @@ import (
2828 "github.com/lightningnetwork/lnd/fn"
2929 "github.com/lightningnetwork/lnd/lnrpc"
3030 "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
31+ "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
3132 "github.com/lightningnetwork/lnd/lntest"
3233 "github.com/lightningnetwork/lnd/lntest/port"
3334 "github.com/lightningnetwork/lnd/lntest/wait"
@@ -3004,13 +3005,13 @@ func testCustomChannelsHtlcSuccess(_ context.Context, net *NetworkHarness,
30043005 // With all of the HTLCs established, we'll now force close the channel with
30053006 // Alice.
30063007 t .Logf ("Force close by Alice w/ HTLCs..." )
3007- daveChanPoint := & lnrpc.ChannelPoint {
3008+ aliceChanPoint := & lnrpc.ChannelPoint {
30083009 OutputIndex : uint32 (assetFundResp .OutputIndex ),
30093010 FundingTxid : & lnrpc.ChannelPoint_FundingTxidStr {
30103011 FundingTxidStr : assetFundResp .Txid ,
30113012 },
30123013 }
3013- _ , closeTxid , err := net .CloseChannel (alice , daveChanPoint , true )
3014+ _ , closeTxid , err := net .CloseChannel (alice , aliceChanPoint , true )
30143015 require .NoError (t .t , err )
30153016
30163017 t .Logf ("Channel closed! Mining blocks, close_txid=%v" , closeTxid )
@@ -3144,15 +3145,34 @@ func testCustomChannelsHtlcSuccess(_ context.Context, net *NetworkHarness,
31443145 // sweep the HTLC into her wallet.
31453146 mineBlocks (t , net , closeExpiryInfo .csvDelay , 0 )
31463147
3147- // With the way the sweeper works, we'll now need to mine an extra block to
3148- // trigger the sweep.
3149- mineBlocks (t , net , 1 , 0 )
3148+ // We'll pause here and wait until the sweeper recognizes that we've offered
3149+ // the second level sweep transaction.
3150+ err = wait .NoError (func () error {
3151+ alicePendingSweeps , err := alice .WalletKitClient .PendingSweeps (
3152+ ctxb , & walletrpc.PendingSweepsRequest {},
3153+ )
3154+ if err != nil {
3155+ return err
3156+ }
31503157
3151- time .Sleep (time .Second * 3 )
3158+ for _ , sweep := range alicePendingSweeps .PendingSweeps {
3159+ if sweep .WitnessType ==
3160+ walletrpc .WitnessType_TAPROOT_HTLC_ACCEPTED_SUCCESS_SECOND_LEVEL {
3161+
3162+ return nil
3163+ }
3164+ }
31523165
3153- t .Logf ("Confirming Alice's remote HTLC success sweep" )
3166+ return fmt .Errorf ("failed to find second level sweep: %v" ,
3167+ toProtoJSON (t .t , alicePendingSweeps ))
3168+ }, time .Second * 5 )
3169+ require .NoError (t .t , err )
3170+
3171+ // Now that we know the sweep was offered, we'll mine an extra block to
3172+ // actually trigger a sweeper broadcast.
3173+ mineBlocks (t , net , 1 , 0 )
31543174
3155- // TODO(roasbef): replace w/ mine until broadcast?
3175+ t . Logf ( "Confirming Alice's local HTLC success sweep" )
31563176
31573177 // We'll mine one final block which will confirm Alice's sweep transaction.
31583178 mineBlocks (t , net , 1 , 1 )
0 commit comments