htlcswitch/packet: adds serialization to htlcPacket

This commit is contained in:
Conner Fromknecht 2017-11-26 23:20:45 -08:00
parent 3048dfd4be
commit e4fb420665
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF
1 changed files with 47 additions and 4 deletions

View File

@ -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(),
}
}