@@ -3,6 +3,7 @@ package itest
3
3
import (
4
4
"bytes"
5
5
"context"
6
+ "encoding/hex"
6
7
"fmt"
7
8
"math"
8
9
"math/big"
@@ -12,6 +13,7 @@ import (
12
13
"github.com/btcsuite/btcd/btcec/v2/schnorr"
13
14
"github.com/btcsuite/btcd/btcutil"
14
15
"github.com/btcsuite/btcd/chaincfg/chainhash"
16
+ "github.com/btcsuite/btcd/wire"
15
17
"github.com/lightninglabs/taproot-assets/asset"
16
18
"github.com/lightninglabs/taproot-assets/itest"
17
19
"github.com/lightninglabs/taproot-assets/proof"
@@ -3261,8 +3263,8 @@ func runCustomChannelsHtlcForceClose(ctx context.Context, t *harnessTest,
3261
3263
// At this point, both sides should have 4 (or +4 with MPP) HTLCs
3262
3264
// active.
3263
3265
numHtlcs := 4
3266
+ numAdditionalShards := assetInvoiceAmt / assetsPerMPPShard
3264
3267
if mpp {
3265
- numAdditionalShards := assetInvoiceAmt / assetsPerMPPShard
3266
3268
numHtlcs += numAdditionalShards * 2
3267
3269
}
3268
3270
t .Logf ("Asserting both Alice and Bob have %d HTLCs..." , numHtlcs )
@@ -3521,6 +3523,10 @@ func runCustomChannelsHtlcForceClose(ctx context.Context, t *harnessTest,
3521
3523
3522
3524
// We'll wait for both Alice and Bob to present their respective sweeps
3523
3525
// to the sweeper.
3526
+ numTimeoutHTLCs := 1
3527
+ if mpp {
3528
+ numTimeoutHTLCs += numAdditionalShards
3529
+ }
3524
3530
assertSweepExists (
3525
3531
t .t , alice ,
3526
3532
walletrpc .WitnessType_TAPROOT_HTLC_LOCAL_OFFERED_TIMEOUT ,
@@ -3542,6 +3548,59 @@ func runCustomChannelsHtlcForceClose(ctx context.Context, t *harnessTest,
3542
3548
// Finally, we'll mine a single block to confirm them.
3543
3549
mineBlocks (t , net , 1 , 2 )
3544
3550
3551
+ // Make sure Bob swept all his HTLCs.
3552
+ bobSweeps , err := bob .WalletKitClient .ListSweeps (
3553
+ ctx , & walletrpc.ListSweepsRequest {
3554
+ Verbose : true ,
3555
+ },
3556
+ )
3557
+ require .NoError (t .t , err )
3558
+
3559
+ var bobSweepTx * wire.MsgTx
3560
+ for _ , sweep := range bobSweeps .GetTransactionDetails ().Transactions {
3561
+ for _ , tx := range timeoutSweeps {
3562
+ if sweep .TxHash == tx .String () {
3563
+
3564
+ txBytes , err := hex .DecodeString (sweep .RawTxHex )
3565
+ require .NoError (t .t , err )
3566
+
3567
+ bobSweepTx = & wire.MsgTx {}
3568
+ err = bobSweepTx .Deserialize (
3569
+ bytes .NewReader (txBytes ),
3570
+ )
3571
+ require .NoError (t .t , err )
3572
+ }
3573
+ }
3574
+ }
3575
+ require .NotNil (t .t , bobSweepTx , "Bob's sweep transaction not found" )
3576
+
3577
+ // There's always an extra input that pays for the fees. So we can only
3578
+ // count the remainder as HTLC inputs.
3579
+ numSweptHTLCs := len (bobSweepTx .TxIn ) - 1
3580
+
3581
+ // If we didn't yet sweep all HTLCs, then we need to wait for another
3582
+ // sweep.
3583
+ if numSweptHTLCs < numTimeoutHTLCs {
3584
+ assertSweepExists (
3585
+ t .t , bob ,
3586
+ // nolint: lll
3587
+ walletrpc .WitnessType_TAPROOT_HTLC_OFFERED_REMOTE_TIMEOUT ,
3588
+ )
3589
+
3590
+ t .Logf ("Confirming additional HTLC timeout sweep txns" )
3591
+
3592
+ additionalTimeoutSweeps , err := waitForNTxsInMempool (
3593
+ net .Miner .Client , 1 , shortTimeout ,
3594
+ )
3595
+ require .NoError (t .t , err )
3596
+
3597
+ t .Logf ("Asserting balance on additional timeout sweeps: %v" ,
3598
+ additionalTimeoutSweeps )
3599
+
3600
+ // Finally, we'll mine a single block to confirm them.
3601
+ mineBlocks (t , net , 1 , 1 )
3602
+ }
3603
+
3545
3604
// At this point, Bob's balance should be incremented by an additional
3546
3605
// HTLC value.
3547
3606
bobExpectedBalance += uint64 (assetInvoiceAmt - 1 )
0 commit comments