htlcswitch+refactor: add rHash and sphinx.Router to sphinxHopIterator

This will be required to construct a new hop iterator for when peeling
of dummy hops is done for route blinding.
This commit is contained in:
Elle Mouton 2024-07-10 11:20:55 +02:00
parent c1c2e1c6ce
commit 3d9c77d1fc
No known key found for this signature in database
GPG Key ID: D7D916376026F177

View File

@ -109,7 +109,7 @@ type Iterator interface {
// sphinxHopIterator is the Sphinx implementation of hop iterator which uses // sphinxHopIterator is the Sphinx implementation of hop iterator which uses
// onion routing to encode the payment route in such a way so that node might // onion routing to encode the payment route in such a way so that node might
// see only the next hop in the route.. // see only the next hop in the route.
type sphinxHopIterator struct { type sphinxHopIterator struct {
// ogPacket is the original packet from which the processed packet is // ogPacket is the original packet from which the processed packet is
// derived. // derived.
@ -123,20 +123,31 @@ type sphinxHopIterator struct {
// blindingKit contains the elements required to process hops that are // blindingKit contains the elements required to process hops that are
// part of a blinded route. // part of a blinded route.
blindingKit BlindingKit blindingKit BlindingKit
// rHash holds the payment hash for this payment. This is needed for
// when a new hop iterator is constructed.
rHash []byte
// router holds the router which can be used to decrypt onion payloads.
// This is required for peeling of dummy hops in a blinded path where
// the same node will iteratively need to unwrap the onion.
router *sphinx.Router
} }
// makeSphinxHopIterator converts a processed packet returned from a sphinx // makeSphinxHopIterator converts a processed packet returned from a sphinx
// router and converts it into an hop iterator for usage in the link. A // router and converts it into an hop iterator for usage in the link. A
// blinding kit is passed through for the link to obtain forwarding information // blinding kit is passed through for the link to obtain forwarding information
// for blinded routes. // for blinded routes.
func makeSphinxHopIterator(ogPacket *sphinx.OnionPacket, func makeSphinxHopIterator(router *sphinx.Router, ogPacket *sphinx.OnionPacket,
packet *sphinx.ProcessedPacket, packet *sphinx.ProcessedPacket, blindingKit BlindingKit,
blindingKit BlindingKit) *sphinxHopIterator { rHash []byte) *sphinxHopIterator {
return &sphinxHopIterator{ return &sphinxHopIterator{
router: router,
ogPacket: ogPacket, ogPacket: ogPacket,
processedPacket: packet, processedPacket: packet,
blindingKit: blindingKit, blindingKit: blindingKit,
rHash: rHash,
} }
} }
@ -604,12 +615,14 @@ func (p *OnionProcessor) ReconstructHopIterator(r io.Reader, rHash []byte,
return nil, err return nil, err
} }
return makeSphinxHopIterator(onionPkt, sphinxPacket, BlindingKit{ return makeSphinxHopIterator(p.router, onionPkt, sphinxPacket,
Processor: p.router, BlindingKit{
UpdateAddBlinding: blindingInfo.BlindingKey, Processor: p.router,
IncomingAmount: blindingInfo.IncomingAmt, UpdateAddBlinding: blindingInfo.BlindingKey,
IncomingCltv: blindingInfo.IncomingExpiry, IncomingAmount: blindingInfo.IncomingAmt,
}), nil IncomingCltv: blindingInfo.IncomingExpiry,
}, rHash,
), nil
} }
// DecodeHopIteratorRequest encapsulates all date necessary to process an onion // DecodeHopIteratorRequest encapsulates all date necessary to process an onion
@ -787,12 +800,12 @@ func (p *OnionProcessor) DecodeHopIterators(id []byte,
// Finally, construct a hop iterator from our processed sphinx // Finally, construct a hop iterator from our processed sphinx
// packet, simultaneously caching the original onion packet. // packet, simultaneously caching the original onion packet.
resp.HopIterator = makeSphinxHopIterator( resp.HopIterator = makeSphinxHopIterator(
&onionPkts[i], &packets[i], BlindingKit{ p.router, &onionPkts[i], &packets[i], BlindingKit{
Processor: p.router, Processor: p.router,
UpdateAddBlinding: reqs[i].BlindingPoint, UpdateAddBlinding: reqs[i].BlindingPoint,
IncomingAmount: reqs[i].IncomingAmount, IncomingAmount: reqs[i].IncomingAmount,
IncomingCltv: reqs[i].IncomingCltv, IncomingCltv: reqs[i].IncomingCltv,
}, }, reqs[i].RHash,
) )
} }