github.com/decred/dcrlnd@v0.7.6/lnwire/update_fail_htlc.go (about)

     1  package lnwire
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  )
     7  
     8  // OpaqueReason is an opaque encrypted byte slice that encodes the exact
     9  // failure reason and additional some supplemental data. The contents of this
    10  // slice can only be decrypted by the sender of the original HTLC.
    11  type OpaqueReason []byte
    12  
    13  // UpdateFailHTLC is sent by Alice to Bob in order to remove a previously added
    14  // HTLC. Upon receipt of an UpdateFailHTLC the HTLC should be removed from the
    15  // next commitment transaction, with the UpdateFailHTLC propagated backwards in
    16  // the route to fully undo the HTLC.
    17  type UpdateFailHTLC struct {
    18  	// ChanIDPoint is the particular active channel that this
    19  	// UpdateFailHTLC is bound to.
    20  	ChanID ChannelID
    21  
    22  	// ID references which HTLC on the remote node's commitment transaction
    23  	// has timed out.
    24  	ID uint64
    25  
    26  	// Reason is an onion-encrypted blob that details why the HTLC was
    27  	// failed. This blob is only fully decryptable by the initiator of the
    28  	// HTLC message.
    29  	Reason OpaqueReason
    30  
    31  	// ExtraData is the set of data that was appended to this message to
    32  	// fill out the full maximum transport message size. These fields can
    33  	// be used to specify optional data such as custom TLV fields.
    34  	ExtraData ExtraOpaqueData
    35  }
    36  
    37  // A compile time check to ensure UpdateFailHTLC implements the lnwire.Message
    38  // interface.
    39  var _ Message = (*UpdateFailHTLC)(nil)
    40  
    41  // Decode deserializes a serialized UpdateFailHTLC message stored in the passed
    42  // io.Reader observing the specified protocol version.
    43  //
    44  // This is part of the lnwire.Message interface.
    45  func (c *UpdateFailHTLC) Decode(r io.Reader, pver uint32) error {
    46  	return ReadElements(r,
    47  		&c.ChanID,
    48  		&c.ID,
    49  		&c.Reason,
    50  		&c.ExtraData,
    51  	)
    52  }
    53  
    54  // Encode serializes the target UpdateFailHTLC into the passed io.Writer observing
    55  // the protocol version specified.
    56  //
    57  // This is part of the lnwire.Message interface.
    58  func (c *UpdateFailHTLC) Encode(w *bytes.Buffer, pver uint32) error {
    59  	if err := WriteChannelID(w, c.ChanID); err != nil {
    60  		return err
    61  	}
    62  
    63  	if err := WriteUint64(w, c.ID); err != nil {
    64  		return err
    65  	}
    66  
    67  	if err := WriteOpaqueReason(w, c.Reason); err != nil {
    68  		return err
    69  	}
    70  
    71  	return WriteBytes(w, c.ExtraData)
    72  }
    73  
    74  // MsgType returns the integer uniquely identifying this message type on the
    75  // wire.
    76  //
    77  // This is part of the lnwire.Message interface.
    78  func (c *UpdateFailHTLC) MsgType() MessageType {
    79  	return MsgUpdateFailHTLC
    80  }
    81  
    82  // TargetChanID returns the channel id of the link for which this message is
    83  // intended.
    84  //
    85  // NOTE: Part of peer.LinkUpdater interface.
    86  func (c *UpdateFailHTLC) TargetChanID() ChannelID {
    87  	return c.ChanID
    88  }