2016-09-23 03:51:43 +02:00
|
|
|
package lnwire
|
|
|
|
|
2019-09-25 21:00:59 +02:00
|
|
|
import (
|
2021-06-17 08:17:30 +02:00
|
|
|
"bytes"
|
2019-09-25 21:00:59 +02:00
|
|
|
"io"
|
|
|
|
)
|
2017-01-06 06:43:25 +01:00
|
|
|
|
2017-02-21 07:02:42 +01: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 13:25:36 +01: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 {
|
2022-04-17 00:53:32 +02:00
|
|
|
// ChanID is the particular active channel that this
|
2017-08-22 07:38:48 +02:00
|
|
|
// UpdateFailHTLC is bound to.
|
2017-04-17 00:22:20 +02:00
|
|
|
ChanID ChannelID
|
2016-09-23 03:51:43 +02:00
|
|
|
|
2017-02-16 13:25:36 +01:00
|
|
|
// ID references which HTLC on the remote node's commitment transaction
|
|
|
|
// has timed out.
|
|
|
|
ID uint64
|
2017-01-06 06:43:25 +01:00
|
|
|
|
2017-02-16 13:25:36 +01: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 07:02:42 +01:00
|
|
|
Reason OpaqueReason
|
2020-01-28 02:25:36 +01:00
|
|
|
|
|
|
|
// ExtraData is the set of data that was appended to this message to
|
|
|
|
// fill out the full maximum transport message size. These fields can
|
|
|
|
// be used to specify optional data such as custom TLV fields.
|
|
|
|
ExtraData ExtraOpaqueData
|
2016-09-23 03:51:43 +02:00
|
|
|
}
|
|
|
|
|
2017-02-16 13:25:36 +01: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 03:51:43 +02:00
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-02-16 13:25:36 +01:00
|
|
|
func (c *UpdateFailHTLC) Decode(r io.Reader, pver uint32) error {
|
2018-12-10 03:27:41 +01:00
|
|
|
return ReadElements(r,
|
2017-04-17 00:22:20 +02:00
|
|
|
&c.ChanID,
|
2017-02-16 13:25:36 +01:00
|
|
|
&c.ID,
|
2017-02-21 07:02:42 +01:00
|
|
|
&c.Reason,
|
2020-01-28 02:25:36 +01:00
|
|
|
&c.ExtraData,
|
2016-09-23 03:51:43 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-02-16 13:25:36 +01:00
|
|
|
// Encode serializes the target UpdateFailHTLC into the passed io.Writer observing
|
2016-09-23 03:51:43 +02:00
|
|
|
// the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2021-06-17 08:17:30 +02:00
|
|
|
func (c *UpdateFailHTLC) Encode(w *bytes.Buffer, pver uint32) error {
|
2021-06-18 09:15:44 +02:00
|
|
|
if err := WriteChannelID(w, c.ChanID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteUint64(w, c.ID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteOpaqueReason(w, c.Reason); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return WriteBytes(w, c.ExtraData)
|
2016-09-23 03:51:43 +02:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:57:43 +02:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2016-09-23 03:51:43 +02:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 00:57:43 +02:00
|
|
|
func (c *UpdateFailHTLC) MsgType() MessageType {
|
|
|
|
return MsgUpdateFailHTLC
|
2016-09-23 03:51:43 +02:00
|
|
|
}
|
|
|
|
|
2019-09-25 21:00:59 +02:00
|
|
|
// TargetChanID returns the channel id of the link for which this message is
|
|
|
|
// intended.
|
|
|
|
//
|
2020-07-02 23:46:06 +02:00
|
|
|
// NOTE: Part of peer.LinkUpdater interface.
|
2019-09-25 21:00:59 +02:00
|
|
|
func (c *UpdateFailHTLC) TargetChanID() ChannelID {
|
|
|
|
return c.ChanID
|
|
|
|
}
|