2017-02-16 15:08:34 +03:00
|
|
|
package lnwire
|
|
|
|
|
2019-09-25 22:00:59 +03:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
2017-02-16 15:08:34 +03:00
|
|
|
|
|
|
|
// OnionPacketSize is the size of the serialized Sphinx onion packet included
|
2017-06-11 04:15:03 +03:00
|
|
|
// in each UpdateAddHTLC message. The breakdown of the onion packet is as
|
|
|
|
// follows: 1-byte version, 33-byte ephemeral public key (for ECDH), 1300-bytes
|
|
|
|
// of per-hop data, and a 32-byte HMAC over the entire packet.
|
|
|
|
const OnionPacketSize = 1366
|
2017-02-16 15:08:34 +03:00
|
|
|
|
|
|
|
// UpdateAddHTLC is the message sent by Alice to Bob when she wishes to add an
|
|
|
|
// HTLC to his remote commitment transaction. In addition to information
|
|
|
|
// detailing the value, the ID, expiry, and the onion blob is also included
|
|
|
|
// which allows Bob to derive the next hop in the route. The HTLC added by this
|
|
|
|
// message is to be added to the remote node's "pending" HTLC's. A subsequent
|
|
|
|
// CommitSig message will move the pending HTLC to the newly created commitment
|
|
|
|
// transaction, marking them as "staged".
|
|
|
|
type UpdateAddHTLC struct {
|
2017-06-11 04:15:03 +03:00
|
|
|
// ChanID is the particular active channel that this UpdateAddHTLC is
|
|
|
|
// bound to.
|
2017-04-17 01:22:20 +03:00
|
|
|
ChanID ChannelID
|
2017-02-16 15:08:34 +03:00
|
|
|
|
|
|
|
// ID is the identification server for this HTLC. This value is
|
|
|
|
// explicitly included as it allows nodes to survive single-sided
|
|
|
|
// restarts. The ID value for this sides starts at zero, and increases
|
|
|
|
// with each offered HTLC.
|
|
|
|
ID uint64
|
|
|
|
|
2017-08-22 08:33:20 +03:00
|
|
|
// Amount is the amount of millisatoshis this HTLC is worth.
|
|
|
|
Amount MilliSatoshi
|
2017-02-16 15:08:34 +03:00
|
|
|
|
|
|
|
// PaymentHash is the payment hash to be included in the HTLC this
|
2017-12-18 05:40:05 +03:00
|
|
|
// request creates. The pre-image to this HTLC must be revealed by the
|
2017-02-16 15:08:34 +03:00
|
|
|
// upstream peer in order to fully settle the HTLC.
|
|
|
|
PaymentHash [32]byte
|
|
|
|
|
2017-09-12 18:58:42 +03:00
|
|
|
// Expiry is the number of blocks after which this HTLC should expire.
|
|
|
|
// It is the receiver's duty to ensure that the outgoing HTLC has a
|
|
|
|
// sufficient expiry value to allow her to redeem the incoming HTLC.
|
|
|
|
Expiry uint32
|
|
|
|
|
2017-02-16 15:08:34 +03:00
|
|
|
// OnionBlob is the raw serialized mix header used to route an HTLC in
|
|
|
|
// a privacy-preserving manner. The mix header is defined currently to
|
|
|
|
// be parsed as a 4-tuple: (groupElement, routingInfo, headerMAC,
|
|
|
|
// body). First the receiving node should use the groupElement, and
|
|
|
|
// its current onion key to derive a shared secret with the source.
|
|
|
|
// Once the shared secret has been derived, the headerMAC should be
|
|
|
|
// checked FIRST. Note that the MAC only covers the routingInfo field.
|
|
|
|
// If the MAC matches, and the shared secret is fresh, then the node
|
|
|
|
// should strip off a layer of encryption, exposing the next hop to be
|
|
|
|
// used in the subsequent UpdateAddHTLC message.
|
|
|
|
OnionBlob [OnionPacketSize]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewUpdateAddHTLC returns a new empty UpdateAddHTLC message.
|
|
|
|
func NewUpdateAddHTLC() *UpdateAddHTLC {
|
|
|
|
return &UpdateAddHTLC{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure UpdateAddHTLC implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*UpdateAddHTLC)(nil)
|
|
|
|
|
|
|
|
// Decode deserializes a serialized UpdateAddHTLC message stored in the passed
|
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error {
|
2018-12-10 05:27:41 +03:00
|
|
|
return ReadElements(r,
|
2017-04-17 01:22:20 +03:00
|
|
|
&c.ChanID,
|
2017-02-16 15:08:34 +03:00
|
|
|
&c.ID,
|
|
|
|
&c.Amount,
|
|
|
|
c.PaymentHash[:],
|
2017-09-12 18:58:42 +03:00
|
|
|
&c.Expiry,
|
2017-02-16 15:08:34 +03:00
|
|
|
c.OnionBlob[:],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target UpdateAddHTLC into the passed io.Writer observing
|
|
|
|
// the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *UpdateAddHTLC) Encode(w io.Writer, pver uint32) error {
|
2018-12-10 05:27:41 +03:00
|
|
|
return WriteElements(w,
|
2017-04-17 01:22:20 +03:00
|
|
|
c.ChanID,
|
2017-02-16 15:08:34 +03:00
|
|
|
c.ID,
|
|
|
|
c.Amount,
|
|
|
|
c.PaymentHash[:],
|
2017-09-12 18:58:42 +03:00
|
|
|
c.Expiry,
|
2017-02-16 15:08:34 +03:00
|
|
|
c.OnionBlob[:],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-04-20 01:57:43 +03:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2017-02-16 15:08:34 +03:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 01:57:43 +03:00
|
|
|
func (c *UpdateAddHTLC) MsgType() MessageType {
|
|
|
|
return MsgUpdateAddHTLC
|
2017-02-16 15:08:34 +03:00
|
|
|
}
|
|
|
|
|
2018-04-18 05:02:04 +03:00
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for an UpdateAddHTLC
|
2017-02-16 15:08:34 +03:00
|
|
|
// complete message observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *UpdateAddHTLC) MaxPayloadLength(uint32) uint32 {
|
2017-06-11 04:15:03 +03:00
|
|
|
// 1450
|
|
|
|
return 32 + 8 + 4 + 8 + 32 + 1366
|
2017-02-16 15:08:34 +03:00
|
|
|
}
|
2019-09-25 22:00:59 +03:00
|
|
|
|
|
|
|
// TargetChanID returns the channel id of the link for which this message is
|
|
|
|
// intended.
|
|
|
|
//
|
|
|
|
// NOTE: Part of lnd.LinkUpdater interface.
|
|
|
|
func (c *UpdateAddHTLC) TargetChanID() ChannelID {
|
|
|
|
return c.ChanID
|
|
|
|
}
|