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:
Johan T. Halseth
2019-05-16 15:27:29 +02:00
parent f99d0c4c68
commit cd02c22977
6 changed files with 132 additions and 82 deletions

View File

@@ -795,17 +795,23 @@ func preparePayment(sendingPeer, receivingPeer lnpeer.Peer,
// Send payment and expose err channel.
return invoice, func() error {
err := sender.htlcSwitch.SendHTLC(
firstHop, pid, htlc, newMockDeobfuscator(),
firstHop, pid, htlc,
)
if err != nil {
return err
}
resultChan, err := sender.htlcSwitch.GetPaymentResult(pid)
resultChan, err := sender.htlcSwitch.GetPaymentResult(
pid, newMockDeobfuscator(),
)
if err != nil {
return err
}
result := <-resultChan
result, ok := <-resultChan
if !ok {
return fmt.Errorf("shutting down")
}
if result.Error != nil {
return result.Error
}
@@ -1275,20 +1281,26 @@ func (n *twoHopNetwork) makeHoldPayment(sendingPeer, receivingPeer lnpeer.Peer,
// Send payment and expose err channel.
go func() {
err := sender.htlcSwitch.SendHTLC(
firstHop, pid, htlc, newMockDeobfuscator(),
firstHop, pid, htlc,
)
if err != nil {
paymentErr <- err
return
}
resultChan, err := sender.htlcSwitch.GetPaymentResult(pid)
resultChan, err := sender.htlcSwitch.GetPaymentResult(
pid, newMockDeobfuscator(),
)
if err != nil {
paymentErr <- err
return
}
result := <-resultChan
result, ok := <-resultChan
if !ok {
paymentErr <- fmt.Errorf("shutting down")
}
if result.Error != nil {
paymentErr <- result.Error
return