2017-06-28 17:22:23 +02:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2021-06-17 08:17:30 +02:00
|
|
|
"bytes"
|
2017-06-28 17:22:23 +02:00
|
|
|
"crypto/sha256"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2017-09-12 17:58:42 +02:00
|
|
|
// UpdateFailMalformedHTLC is sent by either the payment forwarder or by
|
|
|
|
// payment receiver to the payment sender in order to notify it that the onion
|
|
|
|
// blob can't be parsed. For that reason we send this message instead of
|
|
|
|
// obfuscate the onion failure.
|
2017-06-28 17:22:23 +02:00
|
|
|
type UpdateFailMalformedHTLC struct {
|
|
|
|
// ChanID is the particular active channel that this
|
|
|
|
// UpdateFailMalformedHTLC is bound to.
|
|
|
|
ChanID ChannelID
|
|
|
|
|
|
|
|
// ID references which HTLC on the remote node's commitment transaction
|
|
|
|
// has timed out.
|
|
|
|
ID uint64
|
|
|
|
|
|
|
|
// ShaOnionBlob hash of the onion blob on which can't be parsed by the
|
|
|
|
// node in the payment path.
|
|
|
|
ShaOnionBlob [sha256.Size]byte
|
|
|
|
|
|
|
|
// FailureCode the exact reason why onion blob haven't been parsed.
|
|
|
|
FailureCode FailCode
|
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
|
2017-06-28 17:22:23 +02:00
|
|
|
}
|
|
|
|
|
2017-09-12 17:58:42 +02:00
|
|
|
// A compile time check to ensure UpdateFailMalformedHTLC implements the
|
|
|
|
// lnwire.Message interface.
|
2017-06-28 17:22:23 +02:00
|
|
|
var _ Message = (*UpdateFailMalformedHTLC)(nil)
|
|
|
|
|
|
|
|
// Decode deserializes a serialized UpdateFailMalformedHTLC message stored in the passed
|
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *UpdateFailMalformedHTLC) Decode(r io.Reader, pver uint32) error {
|
2018-12-10 03:27:41 +01:00
|
|
|
return ReadElements(r,
|
2017-06-28 17:22:23 +02:00
|
|
|
&c.ChanID,
|
|
|
|
&c.ID,
|
|
|
|
c.ShaOnionBlob[:],
|
|
|
|
&c.FailureCode,
|
2020-01-28 02:25:36 +01:00
|
|
|
&c.ExtraData,
|
2017-06-28 17:22:23 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-09-12 17:58:42 +02:00
|
|
|
// Encode serializes the target UpdateFailMalformedHTLC into the passed
|
|
|
|
// io.Writer observing the protocol version specified.
|
2017-06-28 17:22:23 +02:00
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2021-06-18 09:15:44 +02:00
|
|
|
func (c *UpdateFailMalformedHTLC) Encode(w *bytes.Buffer,
|
|
|
|
pver uint32) error {
|
|
|
|
|
|
|
|
if err := WriteChannelID(w, c.ChanID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteUint64(w, c.ID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(w, c.ShaOnionBlob[:]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteFailCode(w, c.FailureCode); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return WriteBytes(w, c.ExtraData)
|
2017-06-28 17:22:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *UpdateFailMalformedHTLC) MsgType() MessageType {
|
|
|
|
return MsgUpdateFailMalformedHTLC
|
|
|
|
}
|
|
|
|
|
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 *UpdateFailMalformedHTLC) TargetChanID() ChannelID {
|
|
|
|
return c.ChanID
|
|
|
|
}
|