mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-25 18:51:20 +02:00
routing: use Identifier in place of PaymentHash
Since we want to support AMP payment using a different unique payment identifier (AMP payments don't go to one specific hash), we change the nomenclature to be Identifier instead of PaymentHash.
This commit is contained in:
@@ -698,7 +698,11 @@ func (r *RouterBackend) extractIntentFromSendRequest(
|
||||
payIntent.MaxParts = 1
|
||||
}
|
||||
|
||||
copy(payIntent.PaymentHash[:], payReq.PaymentHash[:])
|
||||
err = payIntent.SetPaymentHash(*payReq.PaymentHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
destKey := payReq.Destination.SerializeCompressed()
|
||||
copy(payIntent.Target[:], destKey)
|
||||
|
||||
@@ -737,7 +741,15 @@ func (r *RouterBackend) extractIntentFromSendRequest(
|
||||
payIntent.Amount = reqAmt
|
||||
|
||||
// Payment hash.
|
||||
copy(payIntent.PaymentHash[:], rpcPayReq.PaymentHash)
|
||||
paymentHash, err := lntypes.MakeHash(rpcPayReq.PaymentHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = payIntent.SetPaymentHash(paymentHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Parse destination feature bits.
|
||||
features, err := UnmarshalFeatures(rpcPayReq.DestFeatures)
|
||||
@@ -1217,7 +1229,7 @@ func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
|
||||
htlcs = append(htlcs, htlc)
|
||||
}
|
||||
|
||||
paymentHash := payment.Info.PaymentHash
|
||||
paymentID := payment.Info.PaymentIdentifier
|
||||
creationTimeNS := MarshalTimeNano(payment.Info.CreationTime)
|
||||
|
||||
failureReason, err := marshallPaymentFailureReason(
|
||||
@@ -1228,7 +1240,8 @@ func (r *RouterBackend) MarshallPayment(payment *channeldb.MPPayment) (
|
||||
}
|
||||
|
||||
return &lnrpc.Payment{
|
||||
PaymentHash: hex.EncodeToString(paymentHash[:]),
|
||||
// TODO: set this to setID for AMP-payments?
|
||||
PaymentHash: hex.EncodeToString(paymentID[:]),
|
||||
Value: satValue,
|
||||
ValueMsat: msatValue,
|
||||
ValueSat: satValue,
|
||||
|
@@ -316,21 +316,21 @@ func (s *Server) SendPaymentV2(req *SendPaymentRequest,
|
||||
if err == channeldb.ErrPaymentInFlight ||
|
||||
err == channeldb.ErrAlreadyPaid {
|
||||
|
||||
log.Debugf("SendPayment async result for hash %x: %v",
|
||||
payment.PaymentHash, err)
|
||||
log.Debugf("SendPayment async result for payment %x: %v",
|
||||
payment.Identifier(), err)
|
||||
|
||||
return status.Error(
|
||||
codes.AlreadyExists, err.Error(),
|
||||
)
|
||||
}
|
||||
|
||||
log.Errorf("SendPayment async error for hash %x: %v",
|
||||
payment.PaymentHash, err)
|
||||
log.Errorf("SendPayment async error for payment %x: %v",
|
||||
payment.Identifier(), err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return s.trackPayment(payment.PaymentHash, stream, req.NoInflightUpdates)
|
||||
return s.trackPayment(payment.Identifier(), stream, req.NoInflightUpdates)
|
||||
}
|
||||
|
||||
// EstimateRouteFee allows callers to obtain a lower bound w.r.t how much it
|
||||
@@ -719,14 +719,14 @@ func (s *Server) TrackPaymentV2(request *TrackPaymentRequest,
|
||||
}
|
||||
|
||||
// trackPayment writes payment status updates to the provided stream.
|
||||
func (s *Server) trackPayment(paymentHash lntypes.Hash,
|
||||
func (s *Server) trackPayment(identifier lntypes.Hash,
|
||||
stream Router_TrackPaymentV2Server, noInflightUpdates bool) error {
|
||||
|
||||
router := s.cfg.RouterBackend
|
||||
|
||||
// Subscribe to the outcome of this payment.
|
||||
subscription, err := router.Tower.SubscribePayment(
|
||||
paymentHash,
|
||||
identifier,
|
||||
)
|
||||
switch {
|
||||
case err == channeldb.ErrPaymentNotInitiated:
|
||||
@@ -769,7 +769,7 @@ func (s *Server) trackPayment(paymentHash lntypes.Hash,
|
||||
return errServerShuttingDown
|
||||
|
||||
case <-stream.Context().Done():
|
||||
log.Debugf("Payment status stream %v canceled", paymentHash)
|
||||
log.Debugf("Payment status stream %v canceled", identifier)
|
||||
return stream.Context().Err()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user