router+switch: rename paymentID->attemptID

To distinguish the attempt's unique ID from the overall payment
identifier, we name it attemptID everywhere, and note that the
paymentHash argument won't be the actual payment hash for AMP payments.
This commit is contained in:
Johan T. Halseth 2021-04-07 15:03:54 +02:00
parent 7795353e9f
commit a9f19b100b
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 43 additions and 36 deletions

@ -363,12 +363,15 @@ func (s *Switch) ProcessContractResolution(msg contractcourt.ResolutionMsg) erro
} }
// GetPaymentResult returns the the result of the payment attempt with the // GetPaymentResult returns the the result of the payment attempt with the
// given paymentID. The method returns a channel where the payment result will // given attemptID. The paymentHash should be set to the payment's overall
// be sent when available, or an error is encountered during forwarding. When a // hash, or in case of AMP payments the payment's unique identifier.
// result is received on the channel, the HTLC is guaranteed to no longer be in //
// flight. The switch shutting down is signaled by closing the channel. If the // The method returns a channel where the payment result will be sent when
// paymentID is unknown, ErrPaymentIDNotFound will be returned. // available, or an error is encountered during forwarding. When a result is
func (s *Switch) GetPaymentResult(paymentID uint64, paymentHash lntypes.Hash, // received on the channel, the HTLC is guaranteed to no longer be in flight.
// The switch shutting down is signaled by closing the channel. If the
// attemptID is unknown, ErrPaymentIDNotFound will be returned.
func (s *Switch) GetPaymentResult(attemptID uint64, paymentHash lntypes.Hash,
deobfuscator ErrorDecrypter) (<-chan *PaymentResult, error) { deobfuscator ErrorDecrypter) (<-chan *PaymentResult, error) {
var ( var (
@ -376,7 +379,7 @@ func (s *Switch) GetPaymentResult(paymentID uint64, paymentHash lntypes.Hash,
err error err error
outKey = CircuitKey{ outKey = CircuitKey{
ChanID: hop.Source, ChanID: hop.Source,
HtlcID: paymentID, HtlcID: attemptID,
} }
) )
@ -384,7 +387,7 @@ func (s *Switch) GetPaymentResult(paymentID uint64, paymentHash lntypes.Hash,
// result is already available. // result is already available.
// Assumption: no one will add this payment ID other than the caller. // Assumption: no one will add this payment ID other than the caller.
if s.circuits.LookupCircuit(outKey) == nil { if s.circuits.LookupCircuit(outKey) == nil {
res, err := s.networkResults.getResult(paymentID) res, err := s.networkResults.getResult(attemptID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -394,7 +397,7 @@ func (s *Switch) GetPaymentResult(paymentID uint64, paymentHash lntypes.Hash,
} else { } else {
// The payment was committed to the circuits, subscribe for a // The payment was committed to the circuits, subscribe for a
// result. // result.
nChan, err = s.networkResults.subscribeResult(paymentID) nChan, err = s.networkResults.subscribeResult(attemptID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -420,12 +423,12 @@ func (s *Switch) GetPaymentResult(paymentID uint64, paymentHash lntypes.Hash,
return return
} }
log.Debugf("Received network result %T for paymentID=%v", n.msg, log.Debugf("Received network result %T for attemptID=%v", n.msg,
paymentID) attemptID)
// Extract the result and pass it to the result channel. // Extract the result and pass it to the result channel.
result, err := s.extractResult( result, err := s.extractResult(
deobfuscator, n, paymentID, paymentHash, deobfuscator, n, attemptID, paymentHash,
) )
if err != nil { if err != nil {
e := fmt.Errorf("unable to extract result: %v", err) e := fmt.Errorf("unable to extract result: %v", err)
@ -450,10 +453,10 @@ func (s *Switch) CleanStore(keepPids map[uint64]struct{}) error {
} }
// 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 attemptID used MUST be unique
// for this HTLC, and MUST be used only once, otherwise the switch might reject // for this HTLC, and MUST be used only once, otherwise the switch might reject
// it. // it.
func (s *Switch) SendHTLC(firstHop lnwire.ShortChannelID, paymentID uint64, func (s *Switch) SendHTLC(firstHop lnwire.ShortChannelID, attemptID uint64,
htlc *lnwire.UpdateAddHTLC) error { htlc *lnwire.UpdateAddHTLC) error {
// Generate and send new update packet, if error will be received on // Generate and send new update packet, if error will be received on
@ -461,7 +464,7 @@ func (s *Switch) SendHTLC(firstHop lnwire.ShortChannelID, paymentID uint64,
// system and something wrong happened. // system and something wrong happened.
packet := &htlcPacket{ packet := &htlcPacket{
incomingChanID: hop.Source, incomingChanID: hop.Source,
incomingHTLCID: paymentID, incomingHTLCID: attemptID,
outgoingChanID: firstHop, outgoingChanID: firstHop,
htlc: htlc, htlc: htlc,
} }
@ -794,7 +797,7 @@ func (s *Switch) getLocalLink(pkt *htlcPacket, htlc *lnwire.UpdateAddHTLC) (
func (s *Switch) handleLocalResponse(pkt *htlcPacket) { func (s *Switch) handleLocalResponse(pkt *htlcPacket) {
defer s.wg.Done() defer s.wg.Done()
paymentID := pkt.incomingHTLCID attemptID := pkt.incomingHTLCID
// The error reason will be unencypted in case this a local // The error reason will be unencypted in case this a local
// failure or a converted error. // failure or a converted error.
@ -807,9 +810,9 @@ func (s *Switch) handleLocalResponse(pkt *htlcPacket) {
// Store the result to the db. This will also notify subscribers about // Store the result to the db. This will also notify subscribers about
// the result. // the result.
if err := s.networkResults.storeResult(paymentID, n); err != nil { if err := s.networkResults.storeResult(attemptID, n); err != nil {
log.Errorf("Unable to complete payment for pid=%v: %v", log.Errorf("Unable to complete payment for pid=%v: %v",
paymentID, err) attemptID, err)
return return
} }
@ -857,7 +860,7 @@ func (s *Switch) handleLocalResponse(pkt *htlcPacket) {
// extractResult uses the given deobfuscator to extract the payment result from // extractResult uses the given deobfuscator to extract the payment result from
// the given network message. // the given network message.
func (s *Switch) extractResult(deobfuscator ErrorDecrypter, n *networkResult, func (s *Switch) extractResult(deobfuscator ErrorDecrypter, n *networkResult,
paymentID uint64, paymentHash lntypes.Hash) (*PaymentResult, error) { attemptID uint64, paymentHash lntypes.Hash) (*PaymentResult, error) {
switch htlc := n.msg.(type) { switch htlc := n.msg.(type) {
@ -872,7 +875,7 @@ func (s *Switch) extractResult(deobfuscator ErrorDecrypter, n *networkResult,
// user payment and return fail response. // user payment and return fail response.
case *lnwire.UpdateFailHTLC: case *lnwire.UpdateFailHTLC:
paymentErr := s.parseFailedPayment( paymentErr := s.parseFailedPayment(
deobfuscator, paymentID, paymentHash, n.unencrypted, deobfuscator, attemptID, paymentHash, n.unencrypted,
n.isResolution, htlc, n.isResolution, htlc,
) )
@ -894,7 +897,7 @@ func (s *Switch) extractResult(deobfuscator ErrorDecrypter, n *networkResult,
// 3) A failure from the remote party, which will need to be decrypted using // 3) A failure from the remote party, which will need to be decrypted using
// the payment deobfuscator. // the payment deobfuscator.
func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter, func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
paymentID uint64, paymentHash lntypes.Hash, unencrypted, attemptID uint64, paymentHash lntypes.Hash, unencrypted,
isResolution bool, htlc *lnwire.UpdateFailHTLC) error { isResolution bool, htlc *lnwire.UpdateFailHTLC) error {
switch { switch {
@ -918,7 +921,7 @@ func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
log.Errorf("%v: (hash=%v, pid=%d): %v", log.Errorf("%v: (hash=%v, pid=%d): %v",
linkError.FailureDetail.FailureString(), linkError.FailureDetail.FailureString(),
paymentHash, paymentID, err) paymentHash, attemptID, err)
return linkError return linkError
} }
@ -938,7 +941,7 @@ func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
log.Infof("%v: hash=%v, pid=%d", log.Infof("%v: hash=%v, pid=%d",
linkError.FailureDetail.FailureString(), linkError.FailureDetail.FailureString(),
paymentHash, paymentID) paymentHash, attemptID)
return linkError return linkError
@ -951,7 +954,7 @@ func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
if err != nil { if err != nil {
log.Errorf("unable to de-obfuscate onion failure "+ log.Errorf("unable to de-obfuscate onion failure "+
"(hash=%v, pid=%d): %v", "(hash=%v, pid=%d): %v",
paymentHash, paymentID, err) paymentHash, attemptID, err)
return ErrUnreadableFailureMessage return ErrUnreadableFailureMessage
} }

@ -165,17 +165,21 @@ type PaymentAttemptDispatcher interface {
// denoted by its public key. A non-nil error is to be returned if the // denoted by its public key. A non-nil error is to be returned if the
// payment was unsuccessful. // payment was unsuccessful.
SendHTLC(firstHop lnwire.ShortChannelID, SendHTLC(firstHop lnwire.ShortChannelID,
paymentID uint64, attemptID uint64,
htlcAdd *lnwire.UpdateAddHTLC) error htlcAdd *lnwire.UpdateAddHTLC) error
// GetPaymentResult returns the the result of the payment attempt with // GetPaymentResult returns the the result of the payment attempt with
// the given paymentID. The method returns a channel where the payment // the given attemptID. The paymentHash should be set to the payment's
// result will be sent when available, or an error is encountered // overall hash, or in case of AMP payments the payment's unique
// during forwarding. When a result is received on the channel, the // identifier.
// HTLC is guaranteed to no longer be in flight. The switch shutting //
// down is signaled by closing the channel. If the paymentID is // The method returns a channel where the payment result will be sent
// unknown, ErrPaymentIDNotFound will be returned. // when available, or an error is encountered during forwarding. When a
GetPaymentResult(paymentID uint64, paymentHash lntypes.Hash, // result is received on the channel, the HTLC is guaranteed to no
// longer be in flight. The switch shutting down is signaled by
// closing the channel. If the attemptID is unknown,
// ErrPaymentIDNotFound will be returned.
GetPaymentResult(attemptID uint64, paymentHash lntypes.Hash,
deobfuscator htlcswitch.ErrorDecrypter) ( deobfuscator htlcswitch.ErrorDecrypter) (
<-chan *htlcswitch.PaymentResult, error) <-chan *htlcswitch.PaymentResult, error)
@ -211,13 +215,13 @@ type MissionController interface {
// input for future probability estimates. It returns a bool indicating // input for future probability estimates. It returns a bool indicating
// whether this error is a final error and no further payment attempts // whether this error is a final error and no further payment attempts
// need to be made. // need to be made.
ReportPaymentFail(paymentID uint64, rt *route.Route, ReportPaymentFail(attemptID uint64, rt *route.Route,
failureSourceIdx *int, failure lnwire.FailureMessage) ( failureSourceIdx *int, failure lnwire.FailureMessage) (
*channeldb.FailureReason, error) *channeldb.FailureReason, error)
// ReportPaymentSuccess reports a successful payment to mission control as input // ReportPaymentSuccess reports a successful payment to mission control as input
// for future probability estimates. // for future probability estimates.
ReportPaymentSuccess(paymentID uint64, rt *route.Route) error ReportPaymentSuccess(attemptID uint64, rt *route.Route) error
// GetProbability is expected to return the success probability of a // GetProbability is expected to return the success probability of a
// payment from fromNode along edge. // payment from fromNode along edge.
@ -2081,7 +2085,7 @@ func (r *ChannelRouter) tryApplyChannelUpdate(rt *route.Route,
// error type, this error is either the final outcome of the payment or we need // error type, this error is either the final outcome of the payment or we need
// to continue with an alternative route. A final outcome is indicated by a // to continue with an alternative route. A final outcome is indicated by a
// non-nil return value. // non-nil return value.
func (r *ChannelRouter) processSendError(paymentID uint64, rt *route.Route, func (r *ChannelRouter) processSendError(attemptID uint64, rt *route.Route,
sendErr error) *channeldb.FailureReason { sendErr error) *channeldb.FailureReason {
internalErrorReason := channeldb.FailureReasonError internalErrorReason := channeldb.FailureReasonError
@ -2091,7 +2095,7 @@ func (r *ChannelRouter) processSendError(paymentID uint64, rt *route.Route,
// Report outcome to mission control. // Report outcome to mission control.
reason, err := r.cfg.MissionControl.ReportPaymentFail( reason, err := r.cfg.MissionControl.ReportPaymentFail(
paymentID, rt, srcIdx, msg, attemptID, rt, srcIdx, msg,
) )
if err != nil { if err != nil {
log.Errorf("Error reporting payment result to mc: %v", log.Errorf("Error reporting payment result to mc: %v",