2016-09-23 04:51:43 +03:00
|
|
|
package lnwire
|
|
|
|
|
2017-06-08 20:55:41 +03:00
|
|
|
import "io"
|
2017-01-06 08:43:25 +03:00
|
|
|
|
2017-02-21 09:02:42 +03:00
|
|
|
// OpaqueReason is an opaque encrypted byte slice that encodes the exact
|
|
|
|
// failure reason and additional some supplemental data. The contents of this
|
|
|
|
// slice can only be decrypted by the sender of the original HTLC.
|
|
|
|
type OpaqueReason []byte
|
|
|
|
|
2017-02-16 15:25:36 +03:00
|
|
|
// UpdateFailHTLC is sent by Alice to Bob in order to remove a previously added
|
|
|
|
// HTLC. Upon receipt of an UpdateFailHTLC the HTLC should be removed from the
|
|
|
|
// next commitment transaction, with the UpdateFailHTLC propagated backwards in
|
|
|
|
// the route to fully undo the HTLC.
|
|
|
|
type UpdateFailHTLC struct {
|
2017-06-08 20:55:41 +03:00
|
|
|
// ChanIDPoint is the particular active channel that this UpdateFailHTLC
|
|
|
|
// is bound to.
|
2017-04-17 01:22:20 +03:00
|
|
|
ChanID ChannelID
|
2016-09-23 04:51:43 +03:00
|
|
|
|
2017-02-16 15:25:36 +03:00
|
|
|
// ID references which HTLC on the remote node's commitment transaction
|
|
|
|
// has timed out.
|
|
|
|
ID uint64
|
2017-01-06 08:43:25 +03:00
|
|
|
|
2017-02-16 15:25:36 +03:00
|
|
|
// Reason is an onion-encrypted blob that details why the HTLC was
|
|
|
|
// failed. This blob is only fully decryptable by the initiator of the
|
|
|
|
// HTLC message.
|
2017-02-21 09:02:42 +03:00
|
|
|
Reason OpaqueReason
|
2016-09-23 04:51:43 +03:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:25:36 +03:00
|
|
|
// A compile time check to ensure UpdateFailHTLC implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*UpdateFailHTLC)(nil)
|
|
|
|
|
|
|
|
// Decode deserializes a serialized UpdateFailHTLC message stored in the passed
|
2016-09-23 04:51:43 +03:00
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-02-16 15:25:36 +03:00
|
|
|
func (c *UpdateFailHTLC) Decode(r io.Reader, pver uint32) error {
|
2017-02-23 21:59:50 +03:00
|
|
|
return readElements(r,
|
2017-04-17 01:22:20 +03:00
|
|
|
&c.ChanID,
|
2017-02-16 15:25:36 +03:00
|
|
|
&c.ID,
|
2017-02-21 09:02:42 +03:00
|
|
|
&c.Reason,
|
2016-09-23 04:51:43 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-02-16 15:25:36 +03:00
|
|
|
// Encode serializes the target UpdateFailHTLC into the passed io.Writer observing
|
2016-09-23 04:51:43 +03:00
|
|
|
// the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-02-16 15:25:36 +03:00
|
|
|
func (c *UpdateFailHTLC) Encode(w io.Writer, pver uint32) error {
|
2017-02-23 21:59:50 +03:00
|
|
|
return writeElements(w,
|
2017-04-17 01:22:20 +03:00
|
|
|
c.ChanID,
|
2017-02-16 15:25:36 +03:00
|
|
|
c.ID,
|
2017-02-21 09:02:42 +03:00
|
|
|
c.Reason,
|
2016-09-23 04:51:43 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-04-20 01:57:43 +03:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2016-09-23 04:51:43 +03:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 01:57:43 +03:00
|
|
|
func (c *UpdateFailHTLC) MsgType() MessageType {
|
|
|
|
return MsgUpdateFailHTLC
|
2016-09-23 04:51:43 +03:00
|
|
|
}
|
|
|
|
|
2017-02-16 15:25:36 +03:00
|
|
|
// MaxPayloadLength returns the maximum allowed payload size for a UpdateFailHTLC
|
2016-09-23 04:51:43 +03:00
|
|
|
// complete message observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-02-16 15:25:36 +03:00
|
|
|
func (c *UpdateFailHTLC) MaxPayloadLength(uint32) uint32 {
|
2017-06-08 20:55:41 +03:00
|
|
|
var length uint32
|
|
|
|
|
|
|
|
// Length of the ChanID
|
|
|
|
length += 32
|
|
|
|
|
|
|
|
// Length of the ID
|
|
|
|
length += 8
|
|
|
|
|
|
|
|
// Length of the length opaque reason
|
|
|
|
length += 2
|
|
|
|
|
|
|
|
// Length of the Reason
|
|
|
|
length += 166
|
|
|
|
|
|
|
|
return length
|
2016-09-23 04:51:43 +03:00
|
|
|
}
|