diff --git a/htlcswitch/packet.go b/htlcswitch/packet.go index cdaccedb..01e50d27 100644 --- a/htlcswitch/packet.go +++ b/htlcswitch/packet.go @@ -1,6 +1,7 @@ package htlcswitch import ( + "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/lnwire" ) @@ -35,6 +36,20 @@ type htlcPacket struct { // outgoing channel. outgoingHTLCID uint64 + // sourceRef is used by forwarded htlcPackets to locate incoming Add + // entry in a fwdpkg owned by the incoming link. This value can be nil + // if there is no such entry, e.g. switch initiated payments. + sourceRef *channeldb.AddRef + + // destRef is used to locate a settle/fail entry in the outgoing link's + // fwdpkg. If sourceRef is non-nil, this reference should be to a + // settle/fail in response to the sourceRef. + destRef *channeldb.SettleFailRef + + // incomingAmount is the value in milli-satoshis that arrived on an + // incoming link. + incomingAmount lnwire.MilliSatoshi + // amount is the value of the HTLC that is being created or modified. amount lnwire.MilliSatoshi @@ -50,10 +65,10 @@ type htlcPacket struct { // encrypted with any shared secret. localFailure bool - // isRouted is set to true if the incomingChanID and incomingHTLCID fields - // of a forwarded fail packet are already set and do not need to be looked - // up in the circuit map. - isRouted bool + // hasSource is set to true if the incomingChanID and incomingHTLCID + // fields of a forwarded fail packet are already set and do not need to + // be looked up in the circuit map. + hasSource bool // isResolution is set to true if this packet was actually an incoming // resolution message from an outside sub-system. We'll treat these as @@ -61,4 +76,32 @@ type htlcPacket struct { // encrypt all errors related to this packet as if we were the first // hop. isResolution bool + + // circuit holds a reference to an Add's circuit which is persisted in + // the switch during successful forwarding. + circuit *PaymentCircuit +} + +// inKey returns the circuit key used to identify the incoming htlc. +func (p *htlcPacket) inKey() CircuitKey { + return CircuitKey{ + ChanID: p.incomingChanID, + HtlcID: p.incomingHTLCID, + } +} + +// outKey returns the circuit key used to identify the outgoing, forwarded htlc. +func (p *htlcPacket) outKey() CircuitKey { + return CircuitKey{ + ChanID: p.outgoingChanID, + HtlcID: p.outgoingHTLCID, + } +} + +// keystone returns a tuple containing the incoming and outgoing circuit keys. +func (p *htlcPacket) keystone() Keystone { + return Keystone{ + InKey: p.inKey(), + OutKey: p.outKey(), + } }