mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-08 05:08:13 +02:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user