@@ -3,6 +3,7 @@ package itest
33import (
44 "bytes"
55 "context"
6+ "encoding/hex"
67 "fmt"
78 "math"
89 "math/big"
@@ -12,6 +13,7 @@ import (
1213 "github.com/btcsuite/btcd/btcec/v2/schnorr"
1314 "github.com/btcsuite/btcd/btcutil"
1415 "github.com/btcsuite/btcd/chaincfg/chainhash"
16+ "github.com/btcsuite/btcd/wire"
1517 "github.com/lightninglabs/taproot-assets/asset"
1618 "github.com/lightninglabs/taproot-assets/itest"
1719 "github.com/lightninglabs/taproot-assets/proof"
@@ -3261,8 +3263,8 @@ func runCustomChannelsHtlcForceClose(ctx context.Context, t *harnessTest,
32613263 // At this point, both sides should have 4 (or +4 with MPP) HTLCs
32623264 // active.
32633265 numHtlcs := 4
3266+ numAdditionalShards := assetInvoiceAmt / assetsPerMPPShard
32643267 if mpp {
3265- numAdditionalShards := assetInvoiceAmt / assetsPerMPPShard
32663268 numHtlcs += numAdditionalShards * 2
32673269 }
32683270 t .Logf ("Asserting both Alice and Bob have %d HTLCs..." , numHtlcs )
@@ -3521,6 +3523,10 @@ func runCustomChannelsHtlcForceClose(ctx context.Context, t *harnessTest,
35213523
35223524 // We'll wait for both Alice and Bob to present their respective sweeps
35233525 // to the sweeper.
3526+ numTimeoutHTLCs := 1
3527+ if mpp {
3528+ numTimeoutHTLCs += numAdditionalShards
3529+ }
35243530 assertSweepExists (
35253531 t .t , alice ,
35263532 walletrpc .WitnessType_TAPROOT_HTLC_LOCAL_OFFERED_TIMEOUT ,
@@ -3542,6 +3548,58 @@ func runCustomChannelsHtlcForceClose(ctx context.Context, t *harnessTest,
35423548 // Finally, we'll mine a single block to confirm them.
35433549 mineBlocks (t , net , 1 , 2 )
35443550
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+ txBytes , err := hex .DecodeString (sweep .RawTxHex )
3564+ require .NoError (t .t , err )
3565+
3566+ bobSweepTx = & wire.MsgTx {}
3567+ err = bobSweepTx .Deserialize (
3568+ bytes .NewReader (txBytes ),
3569+ )
3570+ require .NoError (t .t , err )
3571+ }
3572+ }
3573+ }
3574+ require .NotNil (t .t , bobSweepTx , "Bob's sweep transaction not found" )
3575+
3576+ // There's always an extra input that pays for the fees. So we can only
3577+ // count the remainder as HTLC inputs.
3578+ numSweptHTLCs := len (bobSweepTx .TxIn ) - 1
3579+
3580+ // If we didn't yet sweep all HTLCs, then we need to wait for another
3581+ // sweep.
3582+ if numSweptHTLCs < numTimeoutHTLCs {
3583+ assertSweepExists (
3584+ t .t , bob ,
3585+ // nolint: lll
3586+ walletrpc .WitnessType_TAPROOT_HTLC_OFFERED_REMOTE_TIMEOUT ,
3587+ )
3588+
3589+ t .Logf ("Confirming additional HTLC timeout sweep txns" )
3590+
3591+ additionalTimeoutSweeps , err := waitForNTxsInMempool (
3592+ net .Miner .Client , 1 , shortTimeout ,
3593+ )
3594+ require .NoError (t .t , err )
3595+
3596+ t .Logf ("Asserting balance on additional timeout sweeps: %v" ,
3597+ additionalTimeoutSweeps )
3598+
3599+ // Finally, we'll mine a single block to confirm them.
3600+ mineBlocks (t , net , 1 , 1 )
3601+ }
3602+
35453603 // At this point, Bob's balance should be incremented by an additional
35463604 // HTLC value.
35473605 bobExpectedBalance += uint64 (assetInvoiceAmt - 1 )
0 commit comments