mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-28 23:02:33 +02:00
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,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,
|
||||
|
Reference in New Issue
Block a user