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

     1  package lnwire
     2  
     3  import (
     4  	"io"
     5  )
     6  
     7  // CommitSig is sent by either side to stage any pending HTLC's in the
     8  // receiver's pending set into a new commitment state. Implicitly, the new
     9  // commitment transaction constructed which has been signed by CommitSig
    10  // includes all HTLC's in the remote node's pending set. A CommitSig message
    11  // may be sent after a series of UpdateAddHTLC/UpdateFulfillHTLC messages in
    12  // order to batch add several HTLC's with a single signature covering all
    13  // implicitly accepted HTLC's.
    14  type CommitSig struct {
    15  	// ChanID uniquely identifies to which currently active channel this
    16  	// CommitSig applies to.
    17  	ChanID ChannelID
    18  
    19  	// CommitSig is Alice's signature for Bob's new commitment transaction.
    20  	// Alice is able to send this signature without requesting any
    21  	// additional data due to the piggybacking of Bob's next revocation
    22  	// hash in his prior RevokeAndAck message, as well as the canonical
    23  	// ordering used for all inputs/outputs within commitment transactions.
    24  	// If initiating a new commitment state, this signature should ONLY
    25  	// cover all of the sending party's pending log updates, and the log
    26  	// updates of the remote party that have been ACK'd.
    27  	CommitSig Sig
    28  
    29  	// HtlcSigs is a signature for each relevant HTLC output within the
    30  	// created commitment. The order of the signatures is expected to be
    31  	// identical to the placement of the HTLC's within the BIP 69 sorted
    32  	// commitment transaction. For each outgoing HTLC (from the PoV of the
    33  	// sender of this message), a signature for an HTLC timeout transaction
    34  	// should be signed, for each incoming HTLC the HTLC timeout
    35  	// transaction should be signed.
    36  	HtlcSigs []Sig
    37  }
    38  
    39  // NewCommitSig creates a new empty CommitSig message.
    40  func NewCommitSig() *CommitSig {
    41  	return &CommitSig{}
    42  }
    43  
    44  // A compile time check to ensure CommitSig implements the lnwire.Message
    45  // interface.
    46  var _ Message = (*CommitSig)(nil)
    47  
    48  // Decode deserializes a serialized CommitSig message stored in the
    49  // passed io.Reader observing the specified protocol version.
    50  //
    51  // This is part of the lnwire.Message interface.
    52  func (c *CommitSig) Decode(r io.Reader, pver uint32) error {
    53  	return ReadElements(r,
    54  		&c.ChanID,
    55  		&c.CommitSig,
    56  		&c.HtlcSigs,
    57  	)
    58  }
    59  
    60  // Encode serializes the target CommitSig into the passed io.Writer
    61  // observing the protocol version specified.
    62  //
    63  // This is part of the lnwire.Message interface.
    64  func (c *CommitSig) Encode(w io.Writer, pver uint32) error {
    65  	return WriteElements(w,
    66  		c.ChanID,
    67  		c.CommitSig,
    68  		c.HtlcSigs,
    69  	)
    70  }
    71  
    72  // MsgType returns the integer uniquely identifying this message type on the
    73  // wire.
    74  //
    75  // This is part of the lnwire.Message interface.
    76  func (c *CommitSig) MsgType() MessageType {
    77  	return MsgCommitSig
    78  }
    79  
    80  // MaxPayloadLength returns the maximum allowed payload size for a
    81  // CommitSig complete message observing the specified protocol version.
    82  //
    83  // This is part of the lnwire.Message interface.
    84  func (c *CommitSig) MaxPayloadLength(uint32) uint32 {
    85  	// 32 + 64 + 2 + max_allowed_htlcs
    86  	return MaxMessagePayload
    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 *CommitSig) TargetChanID() ChannelID {
    94  	return c.ChanID
    95  }