htlcswitch/switch: clarify paymentID uniqueness
With the following commits, it'll become important to not resuse paymentIDs, since there is no way to tell whether the HTLC in question has already been forwarded and settled/failed. We clarify this in the SendHTLC comments, and alter the tests to not attempt to resend an HTLC with a duplicate payment ID.
This commit is contained in:
parent
bbbe3a37f5
commit
cff4d3547d
@ -348,7 +348,8 @@ func (s *Switch) ProcessContractResolution(msg contractcourt.ResolutionMsg) erro
|
|||||||
|
|
||||||
// SendHTLC is used by other subsystems which aren't belong to htlc switch
|
// SendHTLC is used by other subsystems which aren't belong to htlc switch
|
||||||
// package in order to send the htlc update. The paymentID used MUST be unique
|
// package in order to send the htlc update. The paymentID used MUST be unique
|
||||||
// for this HTLC, otherwise the switch might reject it.
|
// for this HTLC, and MUST be used only once, otherwise the switch might reject
|
||||||
|
// it.
|
||||||
func (s *Switch) SendHTLC(firstHop lnwire.ShortChannelID, paymentID uint64,
|
func (s *Switch) SendHTLC(firstHop lnwire.ShortChannelID, paymentID uint64,
|
||||||
htlc *lnwire.UpdateAddHTLC,
|
htlc *lnwire.UpdateAddHTLC,
|
||||||
deobfuscator ErrorDecrypter) ([sha256.Size]byte, error) {
|
deobfuscator ErrorDecrypter) ([sha256.Size]byte, error) {
|
||||||
|
@ -1748,16 +1748,6 @@ func TestSwitchSendPayment(t *testing.T) {
|
|||||||
errChan <- err
|
errChan <- err
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
|
||||||
// Send the payment with the same payment hash and same
|
|
||||||
// amount and check that it will be propagated successfully
|
|
||||||
_, err := s.SendHTLC(
|
|
||||||
aliceChannelLink.ShortChanID(), 0, update,
|
|
||||||
newMockDeobfuscator(),
|
|
||||||
)
|
|
||||||
errChan <- err
|
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case packet := <-aliceChannelLink.packets:
|
case packet := <-aliceChannelLink.packets:
|
||||||
if err := aliceChannelLink.completeCircuit(packet); err != nil {
|
if err := aliceChannelLink.completeCircuit(packet); err != nil {
|
||||||
@ -1765,29 +1755,13 @@ func TestSwitchSendPayment(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case err := <-errChan:
|
case err := <-errChan:
|
||||||
if err != ErrPaymentInFlight {
|
if err != nil {
|
||||||
t.Fatalf("unable to send payment: %v", err)
|
t.Fatalf("unable to send payment: %v", err)
|
||||||
}
|
}
|
||||||
case <-time.After(time.Second):
|
case <-time.After(time.Second):
|
||||||
t.Fatal("request was not propagated to destination")
|
t.Fatal("request was not propagated to destination")
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
|
||||||
case packet := <-aliceChannelLink.packets:
|
|
||||||
if err := aliceChannelLink.completeCircuit(packet); err != nil {
|
|
||||||
t.Fatalf("unable to complete payment circuit: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
case err := <-errChan:
|
|
||||||
t.Fatalf("unable to send payment: %v", err)
|
|
||||||
case <-time.After(time.Second):
|
|
||||||
t.Fatal("request was not propagated to destination")
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.numPendingPayments() != 1 {
|
|
||||||
t.Fatal("wrong amount of pending payments")
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.circuits.NumOpen() != 1 {
|
if s.circuits.NumOpen() != 1 {
|
||||||
t.Fatal("wrong amount of circuits")
|
t.Fatal("wrong amount of circuits")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user