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:
Johan T. Halseth 2019-05-16 15:27:28 +02:00
parent bbbe3a37f5
commit cff4d3547d
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 3 additions and 28 deletions

@ -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
// 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,
htlc *lnwire.UpdateAddHTLC,
deobfuscator ErrorDecrypter) ([sha256.Size]byte, error) {

@ -1748,16 +1748,6 @@ func TestSwitchSendPayment(t *testing.T) {
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 {
case packet := <-aliceChannelLink.packets:
if err := aliceChannelLink.completeCircuit(packet); err != nil {
@ -1765,29 +1755,13 @@ func TestSwitchSendPayment(t *testing.T) {
}
case err := <-errChan:
if err != ErrPaymentInFlight {
if err != nil {
t.Fatalf("unable to send payment: %v", err)
}
case <-time.After(time.Second):
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 {
t.Fatal("wrong amount of circuits")
}