multi: extract path ID and total amt from received payment
We've covered all the logic for building a blinded path to ourselves and putting that into an invoice - so now we start preparing to actually be able to recognise the incoming payment as one from a blinded path we created. The incoming update_add_htlc will have an `encrypted_recipient_data` blob for us that we would have put in the original invoice. From this we extract the PathID which we wrote. We consider this the payment address and we use this to derive the associated invoice location. Blinded path payments will not include MPP records, so the payment address and total payment amount must be gleaned from the pathID and new totalAmtMsat onion field respectively. This commit only covers the final hop payload of a hop in a blinded path. Dummy hops will be handled in the following commit.
This commit is contained in:
8 files changed
+94
-18
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package hop
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
@@ -27,4 +28,9 @@ type ForwardingInfo struct {
|
||||
// node in UpdateAddHtlc. This field is set if the htlc is part of a
|
||||
// blinded route.
|
||||
NextBlinding lnwire.BlindingPointRecord
|
||||
|
||||
// PathID is a secret identifier that the creator of a blinded path
|
||||
// sets for itself to ensure that the blinded path has been used in the
|
||||
// correct context.
|
||||
PathID *chainhash.Hash
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
@@ -230,11 +231,11 @@ func parseAndValidateRecipientData(r *sphinxHopIterator, payload *Payload,
|
||||
return nil, routeRole, err
|
||||
}
|
||||
|
||||
// Exit early if this onion is for the exit hop of the route since
|
||||
// route blinding receives are not yet supported.
|
||||
// This is the final node in the blinded route.
|
||||
if isFinal {
|
||||
return nil, routeRole, fmt.Errorf("being the final hop in a " +
|
||||
"blinded path is not yet supported")
|
||||
return deriveBlindedRouteFinalHopForwardingInfo(
|
||||
routeData, payload, routeRole,
|
||||
)
|
||||
}
|
||||
|
||||
// Else, we are a forwarding node in this blinded path.
|
||||
@@ -243,6 +244,32 @@ func parseAndValidateRecipientData(r *sphinxHopIterator, payload *Payload,
|
||||
)
|
||||
}
|
||||
|
||||
// deriveBlindedRouteFinalHopForwardingInfo extracts the PathID from the
|
||||
// routeData and constructs the ForwardingInfo accordingly.
|
||||
func deriveBlindedRouteFinalHopForwardingInfo(
|
||||
routeData *record.BlindedRouteData, payload *Payload,
|
||||
routeRole RouteRole) (*Payload, RouteRole, error) {
|
||||
|
||||
var pathID *chainhash.Hash
|
||||
routeData.PathID.WhenSome(func(r tlv.RecordT[tlv.TlvType6, []byte]) {
|
||||
var id chainhash.Hash
|
||||
copy(id[:], r.Val)
|
||||
pathID = &id
|
||||
})
|
||||
if pathID == nil {
|
||||
return nil, routeRole, ErrInvalidPayload{
|
||||
Type: tlv.Type(6),
|
||||
Violation: InsufficientViolation,
|
||||
}
|
||||
}
|
||||
|
||||
payload.FwdInfo = ForwardingInfo{
|
||||
PathID: pathID,
|
||||
}
|
||||
|
||||
return payload, routeRole, nil
|
||||
}
|
||||
|
||||
// deriveBlindedRouteForwardingInfo uses the parsed BlindedRouteData from the
|
||||
// recipient to derive the ForwardingInfo for the payment.
|
||||
func deriveBlindedRouteForwardingInfo(r *sphinxHopIterator,
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/record"
|
||||
@@ -408,6 +409,12 @@ func (h *Payload) BlindingPoint() *btcec.PublicKey {
|
||||
return h.blindingPoint
|
||||
}
|
||||
|
||||
// PathID returns the path ID that was encoded in the final hop payload of a
|
||||
// blinded payment.
|
||||
func (h *Payload) PathID() *chainhash.Hash {
|
||||
return h.FwdInfo.PathID
|
||||
}
|
||||
|
||||
// Metadata returns the additional data that is sent along with the
|
||||
// payment to the payee.
|
||||
func (h *Payload) Metadata() []byte {
|
||||
@@ -460,10 +467,6 @@ func getMinRequiredViolation(set tlv.TypeMap) *tlv.Type {
|
||||
// the route "expires" and a malicious party does not have endless opportunity
|
||||
// to probe the blinded route and compare it to updated channel policies in
|
||||
// the network.
|
||||
//
|
||||
// Note that this function only validates blinded route data for forwarding
|
||||
// nodes, as LND does not yet support receiving via a blinded route (which has
|
||||
// different validation rules).
|
||||
func ValidateBlindedRouteData(blindedData *record.BlindedRouteData,
|
||||
incomingAmount lnwire.MilliSatoshi, incomingTimelock uint32) error {
|
||||
|
||||
|
||||
@@ -3774,9 +3774,6 @@ func (l *channelLink) sendHTLCError(pd *lnwallet.PaymentDescriptor,
|
||||
// that we're not part of a blinded route and an error encrypter that'll be
|
||||
// used if we are the introduction node and need to present an error as if
|
||||
// we're the failing party.
|
||||
//
|
||||
// Note: this function does not yet handle special error cases for receiving
|
||||
// nodes in blinded paths, as LND does not support blinded receives.
|
||||
func (l *channelLink) sendIncomingHTLCFailureMsg(htlcIndex uint64,
|
||||
e hop.ErrorEncrypter,
|
||||
originalFailure lnwire.OpaqueReason) error {
|
||||
|
||||
Reference in new issue
Block a user