github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/update_fail_htlc.go (about)

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