2017-05-01 19:58:08 +03:00
|
|
|
package htlcswitch
|
|
|
|
|
|
|
|
import (
|
2017-11-27 10:20:45 +03:00
|
|
|
"github.com/lightningnetwork/lnd/channeldb"
|
2017-05-01 19:58:08 +03:00
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
|
|
|
)
|
|
|
|
|
|
|
|
// htlcPacket is a wrapper around htlc lnwire update, which adds additional
|
|
|
|
// information which is needed by this package.
|
|
|
|
type htlcPacket struct {
|
2017-06-17 00:49:38 +03:00
|
|
|
// destNode is the first-hop destination of a local created HTLC add
|
|
|
|
// message.
|
|
|
|
destNode [33]byte
|
|
|
|
|
2017-10-30 21:56:51 +03:00
|
|
|
// incomingChanID is the ID of the channel that we have received an incoming
|
|
|
|
// HTLC on.
|
|
|
|
incomingChanID lnwire.ShortChannelID
|
2017-05-01 19:58:08 +03:00
|
|
|
|
2017-10-30 21:56:51 +03:00
|
|
|
// outgoingChanID is the ID of the channel that we have offered or will
|
|
|
|
// offer an outgoing HTLC on.
|
|
|
|
outgoingChanID lnwire.ShortChannelID
|
2017-05-01 19:58:08 +03:00
|
|
|
|
2017-10-30 21:56:51 +03:00
|
|
|
// incomingHTLCID is the ID of the HTLC that we have received from the peer
|
|
|
|
// on the incoming channel.
|
|
|
|
incomingHTLCID uint64
|
2017-10-24 01:50:26 +03:00
|
|
|
|
2018-02-28 09:12:19 +03:00
|
|
|
// incomingHtlcAmt is the value of the *incoming* HTLC. This will be
|
|
|
|
// set by the link when it receives an incoming HTLC to be forwarded
|
|
|
|
// through the switch. Then the outgoing link will use this once it
|
|
|
|
// creates a full circuit add. This allows us to properly populate the
|
|
|
|
// forwarding event for this circuit/packet in the case the payment
|
|
|
|
// circuit is successful.
|
|
|
|
incomingHtlcAmt lnwire.MilliSatoshi
|
|
|
|
|
2017-10-30 21:56:51 +03:00
|
|
|
// outgoingHTLCID is the ID of the HTLC that we offered to the peer on the
|
|
|
|
// outgoing channel.
|
|
|
|
outgoingHTLCID uint64
|
2017-10-24 01:50:26 +03:00
|
|
|
|
2017-11-27 10:20:45 +03:00
|
|
|
// 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
|
|
|
|
|
2017-06-17 00:49:38 +03:00
|
|
|
// amount is the value of the HTLC that is being created or modified.
|
2017-08-22 09:36:43 +03:00
|
|
|
amount lnwire.MilliSatoshi
|
2017-06-17 00:49:38 +03:00
|
|
|
|
|
|
|
// htlc lnwire message type of which depends on switch request type.
|
|
|
|
htlc lnwire.Message
|
2017-06-29 16:40:45 +03:00
|
|
|
|
2017-07-15 06:08:29 +03:00
|
|
|
// obfuscator contains the necessary state to allow the switch to wrap
|
|
|
|
// any forwarded errors in an additional layer of encryption.
|
2017-10-11 05:36:52 +03:00
|
|
|
obfuscator ErrorEncrypter
|
2017-06-29 16:40:45 +03:00
|
|
|
|
2017-12-05 04:28:16 +03:00
|
|
|
// localFailure is set to true if an HTLC fails for a local payment before
|
|
|
|
// the first hop. In this case, the failure reason is simply encoded, not
|
|
|
|
// encrypted with any shared secret.
|
|
|
|
localFailure bool
|
|
|
|
|
2017-11-27 10:20:45 +03:00
|
|
|
// 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
|
2018-01-17 07:11:01 +03:00
|
|
|
|
|
|
|
// isResolution is set to true if this packet was actually an incoming
|
|
|
|
// resolution message from an outside sub-system. We'll treat these as
|
|
|
|
// if they emanated directly from the switch. As a result, we'll
|
|
|
|
// encrypt all errors related to this packet as if we were the first
|
|
|
|
// hop.
|
|
|
|
isResolution bool
|
2017-11-27 10:20:45 +03:00
|
|
|
|
|
|
|
// 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(),
|
|
|
|
}
|
2017-05-01 19:58:08 +03:00
|
|
|
}
|