Skip to content

Commit 6640a01

Browse files
committed
htlcswitch+lnwallet: update existing tests for updated func signatures
We update existing test base to use the new function signatures. This is also important in order to verify that old behavior is maintained.
1 parent da31e7f commit 6640a01

File tree

5 files changed

+79
-50
lines changed

5 files changed

+79
-50
lines changed

htlcswitch/failure_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/btcsuite/btcd/btcec/v2"
1010
sphinx "github.com/lightningnetwork/lightning-onion"
11+
"github.com/lightningnetwork/lnd/htlcswitch/hop"
1112
"github.com/lightningnetwork/lnd/lnwire"
1213
"github.com/lightningnetwork/lnd/tlv"
1314
"github.com/stretchr/testify/require"
@@ -52,11 +53,13 @@ func TestLongFailureMessage(t *testing.T) {
5253
}
5354

5455
errorDecryptor := &SphinxErrorDecrypter{
55-
OnionErrorDecrypter: sphinx.NewOnionErrorDecrypter(circuit),
56+
decrypter: sphinx.NewOnionErrorDecrypter(
57+
circuit, hop.AttrErrorStruct,
58+
),
5659
}
5760

5861
// Assert that the failure message can still be extracted.
59-
failure, err := errorDecryptor.DecryptError(reason)
62+
failure, err := errorDecryptor.DecryptError(reason, nil)
6063
require.NoError(t, err)
6164

6265
incorrectDetails, ok := failure.msg.(*lnwire.FailIncorrectDetails)

htlcswitch/link_isolated_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (l *linkTestContext) receiveFailAliceToBob() {
254254
l.t.Fatalf("expected UpdateFailHTLC, got %T", msg)
255255
}
256256

257-
err := l.bobChannel.ReceiveFailHTLC(failMsg.ID, failMsg.Reason)
257+
err := l.bobChannel.ReceiveFailHTLC(failMsg.ID, failMsg.Reason, nil)
258258
if err != nil {
259259
l.t.Fatalf("unable to apply received fail htlc: %v", err)
260260
}

htlcswitch/link_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,7 +2678,7 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
26782678
reason := make([]byte, 292)
26792679
copy(reason, []byte("nop"))
26802680

2681-
err = harness.bobChannel.FailHTLC(bobIndex, reason, nil, nil, nil)
2681+
err = harness.bobChannel.FailHTLC(bobIndex, reason, nil, nil, nil, nil)
26822682
require.NoError(t, err, "unable to fail htlc")
26832683
failMsg := &lnwire.UpdateFailHTLC{
26842684
ID: 1,
@@ -2925,7 +2925,9 @@ func TestChannelLinkBandwidthConsistency(t *testing.T) {
29252925
if !ok {
29262926
t.Fatalf("expected UpdateFailHTLC, got %T", msg)
29272927
}
2928-
err = harness.bobChannel.ReceiveFailHTLC(failMsg.ID, []byte("fail"))
2928+
err = harness.bobChannel.ReceiveFailHTLC(
2929+
failMsg.ID, []byte("fail"), nil,
2930+
)
29292931
require.NoError(t, err, "failed receiving fail htlc")
29302932

29312933
// After failing an HTLC, the link will automatically trigger
@@ -7310,7 +7312,7 @@ func TestChannelLinkShortFailureRelay(t *testing.T) {
73107312
// Return a short htlc failure from Bob to Alice and lock in.
73117313
shortReason := make([]byte, 260)
73127314

7313-
err = harness.bobChannel.FailHTLC(0, shortReason, nil, nil, nil)
7315+
err = harness.bobChannel.FailHTLC(0, shortReason, nil, nil, nil, nil)
73147316
require.NoError(t, err)
73157317

73167318
harness.aliceLink.HandleChannelUpdate(&lnwire.UpdateFailHTLC{

htlcswitch/switch_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/btcsuite/btcd/btcutil"
1616
"github.com/davecgh/go-spew/spew"
17+
sphinx "github.com/lightningnetwork/lightning-onion"
1718
"github.com/lightningnetwork/lnd/chainntnfs"
1819
"github.com/lightningnetwork/lnd/channeldb"
1920
"github.com/lightningnetwork/lnd/contractcourt"
@@ -2744,7 +2745,7 @@ func TestSwitchSendPayment(t *testing.T) {
27442745
// back. This request should be forwarded back to alice channel link.
27452746
obfuscator := NewMockObfuscator()
27462747
failure := lnwire.NewFailIncorrectDetails(update.Amount, 100)
2747-
reason, err := obfuscator.EncryptFirstHop(failure)
2748+
reason, _, err := obfuscator.EncryptFirstHop(failure)
27482749
require.NoError(t, err, "unable obfuscate failure")
27492750

27502751
if s.IsForwardedHTLC(aliceChannelLink.ShortChanID(), update.ID) {
@@ -3235,9 +3236,9 @@ func TestInvalidFailure(t *testing.T) {
32353236
// Get payment result from switch. We expect an unreadable failure
32363237
// message error.
32373238
deobfuscator := SphinxErrorDecrypter{
3238-
OnionErrorDecrypter: &mockOnionErrorDecryptor{
3239-
err: ErrUnreadableFailureMessage,
3240-
},
3239+
decrypter: sphinx.NewOnionErrorDecrypter(
3240+
nil, hop.AttrErrorStruct,
3241+
),
32413242
}
32423243

32433244
resultChan, err := s.GetAttemptResult(
@@ -3260,10 +3261,9 @@ func TestInvalidFailure(t *testing.T) {
32603261
// Modify the decryption to simulate that decryption went alright, but
32613262
// the failure cannot be decoded.
32623263
deobfuscator = SphinxErrorDecrypter{
3263-
OnionErrorDecrypter: &mockOnionErrorDecryptor{
3264-
sourceIdx: 2,
3265-
message: []byte{200},
3266-
},
3264+
decrypter: sphinx.NewOnionErrorDecrypter(
3265+
nil, hop.AttrErrorStruct,
3266+
),
32673267
}
32683268

32693269
resultChan, err = s.GetAttemptResult(
@@ -4070,7 +4070,9 @@ func TestSwitchHoldForward(t *testing.T) {
40704070
OnionSHA256: shaOnionBlob,
40714071
}
40724072

4073-
fwdErr, err := newMockDeobfuscator().DecryptError(failPacket.Reason)
4073+
fwdErr, err := newMockDeobfuscator().DecryptError(
4074+
failPacket.Reason, nil,
4075+
)
40744076
require.NoError(t, err)
40754077
require.Equal(t, expectedFailure, fwdErr.WireMessage())
40764078

@@ -5536,7 +5538,7 @@ func testSwitchAliasInterceptFail(t *testing.T, zeroConf bool) {
55365538
require.True(t, ok)
55375539

55385540
fwdErr, err := newMockDeobfuscator().DecryptError(
5539-
failHtlc.Reason,
5541+
failHtlc.Reason, nil,
55405542
)
55415543
require.NoError(t, err)
55425544

lnwallet/channel_test.go

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,9 @@ func TestChannelZeroAddLocalHeight(t *testing.T) {
466466

467467
// Now Bob should fail the htlc back to Alice.
468468
// <----fail-----
469-
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil)
469+
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil, nil)
470470
require.NoError(t, err)
471-
err = aliceChannel.ReceiveFailHTLC(0, []byte("bad"))
471+
err = aliceChannel.ReceiveFailHTLC(0, []byte("bad"), nil)
472472
require.NoError(t, err)
473473

474474
// Bob should send a commitment signature to Alice.
@@ -2222,9 +2222,11 @@ func TestCancelHTLC(t *testing.T) {
22222222

22232223
// Now, with the HTLC committed on both sides, trigger a cancellation
22242224
// from Bob to Alice, removing the HTLC.
2225-
err = bobChannel.FailHTLC(bobHtlcIndex, []byte("failreason"), nil, nil, nil)
2225+
err = bobChannel.FailHTLC(
2226+
bobHtlcIndex, []byte("failreason"), nil, nil, nil, nil,
2227+
)
22262228
require.NoError(t, err, "unable to cancel HTLC")
2227-
err = aliceChannel.ReceiveFailHTLC(aliceHtlcIndex, []byte("bad"))
2229+
err = aliceChannel.ReceiveFailHTLC(aliceHtlcIndex, []byte("bad"), nil)
22282230
require.NoError(t, err, "unable to recv htlc cancel")
22292231

22302232
// Now trigger another state transition, the HTLC should now be removed
@@ -5481,9 +5483,9 @@ func TestChanAvailableBandwidth(t *testing.T) {
54815483
}
54825484

54835485
htlcIndex := uint64((numHtlcs * 2) - 1)
5484-
err = bobChannel.FailHTLC(htlcIndex, []byte("f"), nil, nil, nil)
5486+
err = bobChannel.FailHTLC(htlcIndex, []byte("f"), nil, nil, nil, nil)
54855487
require.NoError(t, err, "unable to cancel HTLC")
5486-
err = aliceChannel.ReceiveFailHTLC(htlcIndex, []byte("bad"))
5488+
err = aliceChannel.ReceiveFailHTLC(htlcIndex, []byte("bad"), nil)
54875489
require.NoError(t, err, "unable to recv htlc cancel")
54885490

54895491
// We must do a state transition before the balance is available
@@ -5937,9 +5939,11 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) {
59375939

59385940
// With both nodes restarted, Bob will now attempt to cancel one of
59395941
// Alice's HTLC's.
5940-
err = bobChannel.FailHTLC(htlc.ID, []byte("failreason"), nil, nil, nil)
5942+
err = bobChannel.FailHTLC(
5943+
htlc.ID, []byte("failreason"), nil, nil, nil, nil,
5944+
)
59415945
require.NoError(t, err, "unable to cancel HTLC")
5942-
err = aliceChannel.ReceiveFailHTLC(htlc.ID, []byte("bad"))
5946+
err = aliceChannel.ReceiveFailHTLC(htlc.ID, []byte("bad"), nil)
59435947
require.NoError(t, err, "unable to recv htlc cancel")
59445948

59455949
// We'll now initiate another state transition, but this time Bob will
@@ -5990,9 +5994,11 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) {
59905994

59915995
// Failing the HTLC here will cause the update to be included in Alice's
59925996
// remote log, but it should not be committed by this transition.
5993-
err = bobChannel.FailHTLC(htlc2.ID, []byte("failreason"), nil, nil, nil)
5997+
err = bobChannel.FailHTLC(
5998+
htlc2.ID, []byte("failreason"), nil, nil, nil, nil,
5999+
)
59946000
require.NoError(t, err, "unable to cancel HTLC")
5995-
err = aliceChannel.ReceiveFailHTLC(htlc2.ID, []byte("bad"))
6001+
err = aliceChannel.ReceiveFailHTLC(htlc2.ID, []byte("bad"), nil)
59966002
require.NoError(t, err, "unable to recv htlc cancel")
59976003

59986004
bobRevocation, _, finalHtlcs, err := bobChannel.
@@ -6045,9 +6051,11 @@ func TestLockedInHtlcForwardingSkipAfterRestart(t *testing.T) {
60456051

60466052
// Re-add the Fail to both Alice and Bob's channels, as the non-committed
60476053
// update will not have survived the restart.
6048-
err = bobChannel.FailHTLC(htlc2.ID, []byte("failreason"), nil, nil, nil)
6054+
err = bobChannel.FailHTLC(
6055+
htlc2.ID, []byte("failreason"), nil, nil, nil, nil,
6056+
)
60496057
require.NoError(t, err, "unable to cancel HTLC")
6050-
err = aliceChannel.ReceiveFailHTLC(htlc2.ID, []byte("bad"))
6058+
err = aliceChannel.ReceiveFailHTLC(htlc2.ID, []byte("bad"), nil)
60516059
require.NoError(t, err, "unable to recv htlc cancel")
60526060

60536061
// Have Alice initiate a state transition, which does not include the
@@ -6492,9 +6500,13 @@ func TestDesyncHTLCs(t *testing.T) {
64926500
}
64936501

64946502
// Now let Bob fail this HTLC.
6495-
err = bobChannel.FailHTLC(bobIndex, []byte("failreason"), nil, nil, nil)
6503+
err = bobChannel.FailHTLC(
6504+
bobIndex, []byte("failreason"), nil, nil, nil, nil,
6505+
)
64966506
require.NoError(t, err, "unable to cancel HTLC")
6497-
if err := aliceChannel.ReceiveFailHTLC(aliceIndex, []byte("bad")); err != nil {
6507+
if err := aliceChannel.ReceiveFailHTLC(
6508+
aliceIndex, []byte("bad"), nil,
6509+
); err != nil {
64986510
t.Fatalf("unable to recv htlc cancel: %v", err)
64996511
}
65006512

@@ -6584,10 +6596,12 @@ func TestMaxAcceptedHTLCs(t *testing.T) {
65846596

65856597
// Bob will fail the htlc specified by htlcID and then force a state
65866598
// transition.
6587-
err = bobChannel.FailHTLC(htlcID, []byte{}, nil, nil, nil)
6599+
err = bobChannel.FailHTLC(htlcID, []byte{}, nil, nil, nil, nil)
65886600
require.NoError(t, err, "unable to fail htlc")
65896601

6590-
if err := aliceChannel.ReceiveFailHTLC(htlcID, []byte{}); err != nil {
6602+
if err := aliceChannel.ReceiveFailHTLC(
6603+
htlcID, []byte{}, nil,
6604+
); err != nil {
65916605
t.Fatalf("unable to receive fail htlc: %v", err)
65926606
}
65936607

@@ -6690,10 +6704,12 @@ func TestMaxAsynchronousHtlcs(t *testing.T) {
66906704
addAndReceiveHTLC(t, aliceChannel, bobChannel, htlc, nil)
66916705

66926706
// Fail back an HTLC and sign a commitment as in steps 1 & 2.
6693-
err = bobChannel.FailHTLC(htlcID, []byte{}, nil, nil, nil)
6707+
err = bobChannel.FailHTLC(htlcID, []byte{}, nil, nil, nil, nil)
66946708
require.NoError(t, err, "unable to fail htlc")
66956709

6696-
if err := aliceChannel.ReceiveFailHTLC(htlcID, []byte{}); err != nil {
6710+
if err := aliceChannel.ReceiveFailHTLC(
6711+
htlcID, []byte{}, nil,
6712+
); err != nil {
66976713
t.Fatalf("unable to receive fail htlc: %v", err)
66986714
}
66996715

@@ -7518,10 +7534,10 @@ func TestChannelRestoreUpdateLogsFailedHTLC(t *testing.T) {
75187534
restoreAndAssert(t, aliceChannel, 1, 0, 0, 0)
75197535

75207536
// Now we make Bob fail this HTLC.
7521-
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil)
7537+
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil, nil)
75227538
require.NoError(t, err, "unable to cancel HTLC")
75237539

7524-
err = aliceChannel.ReceiveFailHTLC(0, []byte("failreason"))
7540+
err = aliceChannel.ReceiveFailHTLC(0, []byte("failreason"), nil)
75257541
require.NoError(t, err, "unable to recv htlc cancel")
75267542

75277543
// This Fail update should have been added to Alice's remote update log.
@@ -7604,19 +7620,23 @@ func TestDuplicateFailRejection(t *testing.T) {
76047620

76057621
// With the HTLC locked in, we'll now have Bob fail the HTLC back to
76067622
// Alice.
7607-
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil)
7623+
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil, nil)
76087624
require.NoError(t, err, "unable to cancel HTLC")
7609-
if err := aliceChannel.ReceiveFailHTLC(0, []byte("bad")); err != nil {
7625+
if err := aliceChannel.ReceiveFailHTLC(
7626+
0, []byte("bad"), nil,
7627+
); err != nil {
76107628
t.Fatalf("unable to recv htlc cancel: %v", err)
76117629
}
76127630

76137631
// If we attempt to fail it AGAIN, then both sides should reject this
76147632
// second failure attempt.
7615-
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil)
7633+
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil, nil)
76167634
if err == nil {
76177635
t.Fatalf("duplicate HTLC failure attempt should have failed")
76187636
}
7619-
if err := aliceChannel.ReceiveFailHTLC(0, []byte("bad")); err == nil {
7637+
if err := aliceChannel.ReceiveFailHTLC(
7638+
0, []byte("bad"), nil,
7639+
); err == nil {
76207640
t.Fatalf("duplicate HTLC failure attempt should have failed")
76217641
}
76227642

@@ -7633,14 +7653,16 @@ func TestDuplicateFailRejection(t *testing.T) {
76337653
require.NoError(t, err, "unable to restart channel")
76347654

76357655
// If we try to fail the same HTLC again, then we should get an error.
7636-
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil)
7656+
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil, nil)
76377657
if err == nil {
76387658
t.Fatalf("duplicate HTLC failure attempt should have failed")
76397659
}
76407660

76417661
// Alice on the other hand should accept the failure again, as she
76427662
// dropped all items in the logs which weren't committed.
7643-
if err := aliceChannel.ReceiveFailHTLC(0, []byte("bad")); err != nil {
7663+
if err := aliceChannel.ReceiveFailHTLC(
7664+
0, []byte("bad"), nil,
7665+
); err != nil {
76447666
t.Fatalf("unable to recv htlc cancel: %v", err)
76457667
}
76467668
}
@@ -7901,9 +7923,9 @@ func TestChannelRestoreCommitHeight(t *testing.T) {
79017923
bobChannel = restoreAndAssertCommitHeights(t, bobChannel, true, 1, 2, 2)
79027924

79037925
// Bob now fails back the htlc that was just locked in.
7904-
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil)
7926+
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil, nil)
79057927
require.NoError(t, err, "unable to cancel HTLC")
7906-
err = aliceChannel.ReceiveFailHTLC(0, []byte("bad"))
7928+
err = aliceChannel.ReceiveFailHTLC(0, []byte("bad"), nil)
79077929
require.NoError(t, err, "unable to recv htlc cancel")
79087930

79097931
// Now Bob signs for the fail update.
@@ -9224,9 +9246,9 @@ func TestChannelUnsignedAckedFailure(t *testing.T) {
92249246

92259247
// Now Bob should fail the htlc back to Alice.
92269248
// <----fail-----
9227-
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil)
9249+
err = bobChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil, nil)
92289250
require.NoError(t, err)
9229-
err = aliceChannel.ReceiveFailHTLC(0, []byte("bad"))
9251+
err = aliceChannel.ReceiveFailHTLC(0, []byte("bad"), nil)
92309252
require.NoError(t, err)
92319253

92329254
// Bob should send a commitment signature to Alice.
@@ -9328,9 +9350,9 @@ func TestChannelLocalUnsignedUpdatesFailure(t *testing.T) {
93289350

93299351
// Now Alice should fail the htlc back to Bob.
93309352
// -----fail--->
9331-
err = aliceChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil)
9353+
err = aliceChannel.FailHTLC(0, []byte("failreason"), nil, nil, nil, nil)
93329354
require.NoError(t, err)
9333-
err = bobChannel.ReceiveFailHTLC(0, []byte("bad"))
9355+
err = bobChannel.ReceiveFailHTLC(0, []byte("bad"), nil)
93349356
require.NoError(t, err)
93359357

93369358
// Alice should send a commitment signature to Bob.
@@ -10773,10 +10795,10 @@ func TestAsynchronousSendingWithFeeBuffer(t *testing.T) {
1077310795
// <----rev------- |---------------
1077410796
// <----sig------- |---------------
1077510797
// --------------- |-----rev------>
10776-
err = aliceChannel.FailHTLC(0, []byte{}, nil, nil, nil)
10798+
err = aliceChannel.FailHTLC(0, []byte{}, nil, nil, nil, nil)
1077710799
require.NoError(t, err)
1077810800

10779-
err = bobChannel.ReceiveFailHTLC(0, []byte{})
10801+
err = bobChannel.ReceiveFailHTLC(0, []byte{}, nil)
1078010802
require.NoError(t, err)
1078110803

1078210804
err = ForceStateTransition(aliceChannel, bobChannel)

0 commit comments

Comments
 (0)