Skip to content

Commit ed6a7ab

Browse files
committed
lnwallet: add noop case to retransmit test
To make sure we don't cause force-closures because of commit sig mismatches, we add a test case to verify that the retransmitted HTLC matches the original HTLC.
1 parent 68d6a80 commit ed6a7ab

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

lnwallet/channel_test.go

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,7 +3232,9 @@ func restartChannel(channelOld *LightningChannel) (*LightningChannel, error) {
32323232
// he receives Alice's CommitSig message, then Alice concludes that she needs
32333233
// to re-send the CommitDiff. After the diff has been sent, both nodes should
32343234
// 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+
32363238
// Create a test channel which will be used for the duration of this
32373239
// unittest. The channel will be funded evenly with Alice having 5 BTC,
32383240
// and Bob having 5 BTC.
@@ -3242,6 +3244,17 @@ func testChanSyncOweCommitment(t *testing.T, chanType channeldb.ChannelType) {
32423244
var fakeOnionBlob [lnwire.OnionPacketSize]byte
32433245
copy(fakeOnionBlob[:], bytes.Repeat([]byte{0x05}, lnwire.OnionPacketSize))
32443246

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[NoopAddHtlcType, 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+
32453258
// We'll start off the scenario with Bob sending 3 HTLC's to Alice in a
32463259
// single state update.
32473260
htlcAmt := lnwire.NewMSatFromSatoshis(20000)
@@ -3251,10 +3264,11 @@ func testChanSyncOweCommitment(t *testing.T, chanType channeldb.ChannelType) {
32513264
for i := 0; i < 3; i++ {
32523265
rHash := sha256.Sum256(bobPreimage[:])
32533266
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,
32583272
}
32593273

32603274
htlcIndex, err := bobChannel.AddHTLC(h, nil)
@@ -3290,15 +3304,17 @@ func testChanSyncOweCommitment(t *testing.T, chanType channeldb.ChannelType) {
32903304
t.Fatalf("unable to settle htlc: %v", err)
32913305
}
32923306
}
3307+
32933308
var alicePreimage [32]byte
32943309
copy(alicePreimage[:], bytes.Repeat([]byte{0xaa}, 32))
32953310
rHash := sha256.Sum256(alicePreimage[:])
32963311
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,
33023318
}
33033319
aliceHtlcIndex, err := aliceChannel.AddHTLC(aliceHtlc, nil)
33043320
require.NoError(t, err, "unable to add alice's htlc")
@@ -3548,6 +3564,7 @@ func TestChanSyncOweCommitment(t *testing.T) {
35483564
testCases := []struct {
35493565
name string
35503566
chanType channeldb.ChannelType
3567+
noop bool
35513568
}{
35523569
{
35533570
name: "tweakless",
@@ -3571,10 +3588,18 @@ func TestChanSyncOweCommitment(t *testing.T) {
35713588
channeldb.SimpleTaprootFeatureBit |
35723589
channeldb.TapscriptRootBit,
35733590
},
3591+
{
3592+
name: "tapscript root with noop",
3593+
chanType: channeldb.SingleFunderTweaklessBit |
3594+
channeldb.AnchorOutputsBit |
3595+
channeldb.SimpleTaprootFeatureBit |
3596+
channeldb.TapscriptRootBit,
3597+
noop: true,
3598+
},
35743599
}
35753600
for _, tc := range testCases {
35763601
t.Run(tc.name, func(t *testing.T) {
3577-
testChanSyncOweCommitment(t, tc.chanType)
3602+
testChanSyncOweCommitment(t, tc.chanType, tc.noop)
35783603
})
35793604
}
35803605
}

0 commit comments

Comments
 (0)