@@ -3232,7 +3232,9 @@ func restartChannel(channelOld *LightningChannel) (*LightningChannel, error) {
3232
3232
// he receives Alice's CommitSig message, then Alice concludes that she needs
3233
3233
// to re-send the CommitDiff. After the diff has been sent, both nodes should
3234
3234
// resynchronize and be able to complete the dangling commit.
3235
- func testChanSyncOweCommitment (t * testing.T , chanType channeldb.ChannelType ) {
3235
+ func testChanSyncOweCommitment (t * testing.T ,
3236
+ chanType channeldb.ChannelType , noop bool ) {
3237
+
3236
3238
// Create a test channel which will be used for the duration of this
3237
3239
// unittest. The channel will be funded evenly with Alice having 5 BTC,
3238
3240
// and Bob having 5 BTC.
@@ -3242,6 +3244,17 @@ func testChanSyncOweCommitment(t *testing.T, chanType channeldb.ChannelType) {
3242
3244
var fakeOnionBlob [lnwire .OnionPacketSize ]byte
3243
3245
copy (fakeOnionBlob [:], bytes .Repeat ([]byte {0x05 }, lnwire .OnionPacketSize ))
3244
3246
3247
+ // Let's create the noop add TLV record. This will only be
3248
+ // effective for channels that have a tapscript root.
3249
+ noopRecord := tlv.NewPrimitiveRecord [NoOpHtlcTLVType , bool ](true )
3250
+ records , err := tlv .RecordsToMap ([]tlv.Record {noopRecord .Record ()})
3251
+ require .NoError (t , err )
3252
+
3253
+ // If the noop flag is not set for this test, nullify the records.
3254
+ if ! noop {
3255
+ records = nil
3256
+ }
3257
+
3245
3258
// We'll start off the scenario with Bob sending 3 HTLC's to Alice in a
3246
3259
// single state update.
3247
3260
htlcAmt := lnwire .NewMSatFromSatoshis (20000 )
@@ -3251,10 +3264,11 @@ func testChanSyncOweCommitment(t *testing.T, chanType channeldb.ChannelType) {
3251
3264
for i := 0 ; i < 3 ; i ++ {
3252
3265
rHash := sha256 .Sum256 (bobPreimage [:])
3253
3266
h := & lnwire.UpdateAddHTLC {
3254
- PaymentHash : rHash ,
3255
- Amount : htlcAmt ,
3256
- Expiry : uint32 (10 ),
3257
- OnionBlob : fakeOnionBlob ,
3267
+ PaymentHash : rHash ,
3268
+ Amount : htlcAmt ,
3269
+ Expiry : uint32 (10 ),
3270
+ OnionBlob : fakeOnionBlob ,
3271
+ CustomRecords : records ,
3258
3272
}
3259
3273
3260
3274
htlcIndex , err := bobChannel .AddHTLC (h , nil )
@@ -3290,15 +3304,17 @@ func testChanSyncOweCommitment(t *testing.T, chanType channeldb.ChannelType) {
3290
3304
t .Fatalf ("unable to settle htlc: %v" , err )
3291
3305
}
3292
3306
}
3307
+
3293
3308
var alicePreimage [32 ]byte
3294
3309
copy (alicePreimage [:], bytes .Repeat ([]byte {0xaa }, 32 ))
3295
3310
rHash := sha256 .Sum256 (alicePreimage [:])
3296
3311
aliceHtlc := & lnwire.UpdateAddHTLC {
3297
- ChanID : chanID ,
3298
- PaymentHash : rHash ,
3299
- Amount : htlcAmt ,
3300
- Expiry : uint32 (10 ),
3301
- OnionBlob : fakeOnionBlob ,
3312
+ ChanID : chanID ,
3313
+ PaymentHash : rHash ,
3314
+ Amount : htlcAmt ,
3315
+ Expiry : uint32 (10 ),
3316
+ OnionBlob : fakeOnionBlob ,
3317
+ CustomRecords : records ,
3302
3318
}
3303
3319
aliceHtlcIndex , err := aliceChannel .AddHTLC (aliceHtlc , nil )
3304
3320
require .NoError (t , err , "unable to add alice's htlc" )
@@ -3519,22 +3535,25 @@ func testChanSyncOweCommitment(t *testing.T, chanType channeldb.ChannelType) {
3519
3535
3520
3536
// At this point, the final balances of both parties should properly
3521
3537
// reflect the amount of HTLC's sent.
3522
- bobMsatSent := numBobHtlcs * htlcAmt
3523
- if aliceChannel .channelState .TotalMSatSent != htlcAmt {
3524
- t .Fatalf ("wrong value for msat sent: expected %v, got %v" ,
3525
- htlcAmt , aliceChannel .channelState .TotalMSatSent )
3526
- }
3527
- if aliceChannel .channelState .TotalMSatReceived != bobMsatSent {
3528
- t .Fatalf ("wrong value for msat recv: expected %v, got %v" ,
3529
- bobMsatSent , aliceChannel .channelState .TotalMSatReceived )
3530
- }
3531
- if bobChannel .channelState .TotalMSatSent != bobMsatSent {
3532
- t .Fatalf ("wrong value for msat sent: expected %v, got %v" ,
3533
- bobMsatSent , bobChannel .channelState .TotalMSatSent )
3534
- }
3535
- if bobChannel .channelState .TotalMSatReceived != htlcAmt {
3536
- t .Fatalf ("wrong value for msat recv: expected %v, got %v" ,
3537
- htlcAmt , bobChannel .channelState .TotalMSatReceived )
3538
+ if noop {
3539
+ // If this test-case includes noop HTLCs, then we don't expect
3540
+ // any balance changes.
3541
+ require .Zero (t , aliceChannel .channelState .TotalMSatSent )
3542
+ require .Zero (t , aliceChannel .channelState .TotalMSatReceived )
3543
+ require .Zero (t , bobChannel .channelState .TotalMSatSent )
3544
+ require .Zero (t , bobChannel .channelState .TotalMSatReceived )
3545
+ } else {
3546
+ // Otherwise, calculate the expected changes and assert them.
3547
+ bobMsatSent := numBobHtlcs * htlcAmt
3548
+
3549
+ aliceChan := aliceChannel .channelState
3550
+ bobChan := bobChannel .channelState
3551
+
3552
+ require .Equal (t , aliceChan .TotalMSatSent , htlcAmt )
3553
+ require .Equal (t , aliceChan .TotalMSatReceived , bobMsatSent )
3554
+
3555
+ require .Equal (t , bobChan .TotalMSatSent , bobMsatSent )
3556
+ require .Equal (t , bobChan .TotalMSatReceived , htlcAmt )
3538
3557
}
3539
3558
}
3540
3559
@@ -3548,6 +3567,7 @@ func TestChanSyncOweCommitment(t *testing.T) {
3548
3567
testCases := []struct {
3549
3568
name string
3550
3569
chanType channeldb.ChannelType
3570
+ noop bool
3551
3571
}{
3552
3572
{
3553
3573
name : "tweakless" ,
@@ -3571,10 +3591,18 @@ func TestChanSyncOweCommitment(t *testing.T) {
3571
3591
channeldb .SimpleTaprootFeatureBit |
3572
3592
channeldb .TapscriptRootBit ,
3573
3593
},
3594
+ {
3595
+ name : "tapscript root with noop" ,
3596
+ chanType : channeldb .SingleFunderTweaklessBit |
3597
+ channeldb .AnchorOutputsBit |
3598
+ channeldb .SimpleTaprootFeatureBit |
3599
+ channeldb .TapscriptRootBit ,
3600
+ noop : true ,
3601
+ },
3574
3602
}
3575
3603
for _ , tc := range testCases {
3576
3604
t .Run (tc .name , func (t * testing.T ) {
3577
- testChanSyncOweCommitment (t , tc .chanType )
3605
+ testChanSyncOweCommitment (t , tc .chanType , tc . noop )
3578
3606
})
3579
3607
}
3580
3608
}
0 commit comments