htlcswitch+router: move deobfuscator creation to GetPaymentResult call
In this commit we move handing the deobfuscator from the router to the switch from when the payment is initiated, to when the result is queried. We do this because only the router can recreate the deobfuscator after a restart, and we are preparing for being able to handle results across restarts. Since the deobfuscator cannot be nil anymore, we can also get rid of that special case.
This commit is contained in:
6 files changed
+132
-82
No files matched your search
+16
-7
@@ -1112,21 +1112,26 @@ func TestChannelLinkMultiHopUnknownPaymentHash(t *testing.T) {
|
||||
// Send payment and expose err channel.
|
||||
err = n.aliceServer.htlcSwitch.SendHTLC(
|
||||
n.firstBobChannelLink.ShortChanID(), pid, htlc,
|
||||
newMockDeobfuscator(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get send payment: %v", err)
|
||||
}
|
||||
|
||||
resultChan, err := n.aliceServer.htlcSwitch.GetPaymentResult(pid)
|
||||
resultChan, err := n.aliceServer.htlcSwitch.GetPaymentResult(
|
||||
pid, newMockDeobfuscator(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get payment result: %v", err)
|
||||
}
|
||||
|
||||
var result *PaymentResult
|
||||
var ok bool
|
||||
select {
|
||||
|
||||
case result = <-resultChan:
|
||||
case result, ok = <-resultChan:
|
||||
if !ok {
|
||||
t.Fatalf("unexpected shutdown")
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatalf("no result arrive")
|
||||
}
|
||||
@@ -3888,19 +3893,24 @@ func TestChannelLinkAcceptDuplicatePayment(t *testing.T) {
|
||||
// properly.
|
||||
err = n.aliceServer.htlcSwitch.SendHTLC(
|
||||
n.firstBobChannelLink.ShortChanID(), pid, htlc,
|
||||
newMockDeobfuscator(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to send payment to carol: %v", err)
|
||||
}
|
||||
|
||||
resultChan, err := n.aliceServer.htlcSwitch.GetPaymentResult(pid)
|
||||
resultChan, err := n.aliceServer.htlcSwitch.GetPaymentResult(
|
||||
pid, newMockDeobfuscator(),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to get payment result: %v", err)
|
||||
}
|
||||
|
||||
select {
|
||||
case result := <-resultChan:
|
||||
case result, ok := <-resultChan:
|
||||
if !ok {
|
||||
t.Fatalf("unexpected shutdown")
|
||||
}
|
||||
|
||||
if result.Error != nil {
|
||||
t.Fatalf("payment failed: %v", result.Error)
|
||||
}
|
||||
@@ -3912,7 +3922,6 @@ func TestChannelLinkAcceptDuplicatePayment(t *testing.T) {
|
||||
// as it's a duplicate request.
|
||||
err = n.aliceServer.htlcSwitch.SendHTLC(
|
||||
n.firstBobChannelLink.ShortChanID(), pid, htlc,
|
||||
newMockDeobfuscator(),
|
||||
)
|
||||
if err != ErrAlreadyPaid {
|
||||
t.Fatalf("ErrAlreadyPaid should have been received got: %v", err)
|
||||
|
||||
Reference in new issue
Block a user