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

     1  package lnwire
     2  
     3  import (
     4  	"crypto/sha256"
     5  	"io"
     6  )
     7  
     8  // UpdateFailMalformedHTLC is sent by either the payment forwarder or by
     9  // payment receiver to the payment sender in order to notify it that the onion
    10  // blob can't be parsed. For that reason we send this message instead of
    11  // obfuscate the onion failure.
    12  type UpdateFailMalformedHTLC struct {
    13  	// ChanID is the particular active channel that this
    14  	// UpdateFailMalformedHTLC is bound to.
    15  	ChanID ChannelID
    16  
    17  	// ID references which HTLC on the remote node's commitment transaction
    18  	// has timed out.
    19  	ID uint64
    20  
    21  	// ShaOnionBlob hash of the onion blob on which can't be parsed by the
    22  	// node in the payment path.
    23  	ShaOnionBlob [sha256.Size]byte
    24  
    25  	// FailureCode the exact reason why onion blob haven't been parsed.
    26  	FailureCode FailCode
    27  }
    28  
    29  // A compile time check to ensure UpdateFailMalformedHTLC implements the
    30  // lnwire.Message interface.
    31  var _ Message = (*UpdateFailMalformedHTLC)(nil)
    32  
    33  // Decode deserializes a serialized UpdateFailMalformedHTLC message stored in the passed
    34  // io.Reader observing the specified protocol version.
    35  //
    36  // This is part of the lnwire.Message interface.
    37  func (c *UpdateFailMalformedHTLC) Decode(r io.Reader, pver uint32) error {
    38  	return ReadElements(r,
    39  		&c.ChanID,
    40  		&c.ID,
    41  		c.ShaOnionBlob[:],
    42  		&c.FailureCode,
    43  	)
    44  }
    45  
    46  // Encode serializes the target UpdateFailMalformedHTLC into the passed
    47  // io.Writer observing the protocol version specified.
    48  //
    49  // This is part of the lnwire.Message interface.
    50  func (c *UpdateFailMalformedHTLC) Encode(w io.Writer, pver uint32) error {
    51  	return WriteElements(w,
    52  		c.ChanID,
    53  		c.ID,
    54  		c.ShaOnionBlob[:],
    55  		c.FailureCode,
    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 *UpdateFailMalformedHTLC) MsgType() MessageType {
    64  	return MsgUpdateFailMalformedHTLC
    65  }
    66  
    67  // MaxPayloadLength returns the maximum allowed payload size for a
    68  // UpdateFailMalformedHTLC complete message observing the specified protocol
    69  // version.
    70  //
    71  // This is part of the lnwire.Message interface.
    72  func (c *UpdateFailMalformedHTLC) MaxPayloadLength(uint32) uint32 {
    73  	// 32 +  8 + 32 + 2
    74  	return 74
    75  }
    76  
    77  // TargetChanID returns the channel id of the link for which this message is
    78  // intended.
    79  //
    80  // NOTE: Part of peer.LinkUpdater interface.
    81  func (c *UpdateFailMalformedHTLC) TargetChanID() ChannelID {
    82  	return c.ChanID
    83  }