2017-02-16 15:04:58 +03:00
|
|
|
package lnwire
|
|
|
|
|
2019-09-25 22:00:59 +03:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
2017-02-16 15:04:58 +03:00
|
|
|
|
|
|
|
// CommitSig is sent by either side to stage any pending HTLC's in the
|
2020-11-26 00:12:29 +03:00
|
|
|
// receiver's pending set into a new commitment state. Implicitly, the new
|
2017-02-16 15:04:58 +03:00
|
|
|
// commitment transaction constructed which has been signed by CommitSig
|
|
|
|
// includes all HTLC's in the remote node's pending set. A CommitSig message
|
2018-02-07 06:11:11 +03:00
|
|
|
// may be sent after a series of UpdateAddHTLC/UpdateFulfillHTLC messages in
|
2017-02-16 15:04:58 +03:00
|
|
|
// order to batch add several HTLC's with a single signature covering all
|
|
|
|
// implicitly accepted HTLC's.
|
|
|
|
type CommitSig struct {
|
2017-04-17 01:22:20 +03:00
|
|
|
// ChanID uniquely identifies to which currently active channel this
|
|
|
|
// CommitSig applies to.
|
|
|
|
ChanID ChannelID
|
2017-02-16 15:04:58 +03:00
|
|
|
|
|
|
|
// CommitSig is Alice's signature for Bob's new commitment transaction.
|
|
|
|
// Alice is able to send this signature without requesting any
|
|
|
|
// additional data due to the piggybacking of Bob's next revocation
|
|
|
|
// hash in his prior RevokeAndAck message, as well as the canonical
|
|
|
|
// ordering used for all inputs/outputs within commitment transactions.
|
2017-12-18 05:40:05 +03:00
|
|
|
// If initiating a new commitment state, this signature should ONLY
|
2017-07-29 02:30:02 +03:00
|
|
|
// cover all of the sending party's pending log updates, and the log
|
|
|
|
// updates of the remote party that have been ACK'd.
|
2018-01-31 06:41:52 +03:00
|
|
|
CommitSig Sig
|
2017-02-16 15:04:58 +03:00
|
|
|
|
2017-07-29 02:30:02 +03:00
|
|
|
// HtlcSigs is a signature for each relevant HTLC output within the
|
|
|
|
// created commitment. The order of the signatures is expected to be
|
|
|
|
// identical to the placement of the HTLC's within the BIP 69 sorted
|
|
|
|
// commitment transaction. For each outgoing HTLC (from the PoV of the
|
2018-04-18 05:02:04 +03:00
|
|
|
// sender of this message), a signature for an HTLC timeout transaction
|
2017-07-29 02:30:02 +03:00
|
|
|
// should be signed, for each incoming HTLC the HTLC timeout
|
|
|
|
// transaction should be signed.
|
2018-01-31 06:41:52 +03:00
|
|
|
HtlcSigs []Sig
|
2020-01-28 04:25:36 +03: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-02-16 15:04:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewCommitSig creates a new empty CommitSig message.
|
|
|
|
func NewCommitSig() *CommitSig {
|
2020-01-28 04:25:36 +03:00
|
|
|
return &CommitSig{
|
|
|
|
ExtraData: make([]byte, 0),
|
|
|
|
}
|
2017-02-16 15:04:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure CommitSig implements the lnwire.Message
|
|
|
|
// interface.
|
|
|
|
var _ Message = (*CommitSig)(nil)
|
|
|
|
|
|
|
|
// Decode deserializes a serialized CommitSig message stored in the
|
|
|
|
// passed io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *CommitSig) Decode(r io.Reader, pver uint32) error {
|
2018-12-10 05:27:41 +03:00
|
|
|
return ReadElements(r,
|
2017-04-17 01:22:20 +03:00
|
|
|
&c.ChanID,
|
2017-02-16 15:04:58 +03:00
|
|
|
&c.CommitSig,
|
2017-07-29 02:30:02 +03:00
|
|
|
&c.HtlcSigs,
|
2020-01-28 04:25:36 +03:00
|
|
|
&c.ExtraData,
|
2017-02-16 15:04:58 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target CommitSig into the passed io.Writer
|
|
|
|
// observing the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (c *CommitSig) Encode(w io.Writer, pver uint32) error {
|
2018-12-10 05:27:41 +03:00
|
|
|
return WriteElements(w,
|
2017-04-17 01:22:20 +03:00
|
|
|
c.ChanID,
|
2017-02-16 15:04:58 +03:00
|
|
|
c.CommitSig,
|
2017-07-29 02:30:02 +03:00
|
|
|
c.HtlcSigs,
|
2020-01-28 04:25:36 +03:00
|
|
|
c.ExtraData,
|
2017-02-16 15:04:58 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-04-20 01:57:43 +03:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2017-02-16 15:04:58 +03:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 01:57:43 +03:00
|
|
|
func (c *CommitSig) MsgType() MessageType {
|
|
|
|
return MsgCommitSig
|
2017-02-16 15:04:58 +03:00
|
|
|
}
|
|
|
|
|
2019-09-25 22:00:59 +03:00
|
|
|
// TargetChanID returns the channel id of the link for which this message is
|
|
|
|
// intended.
|
|
|
|
//
|
2020-07-03 00:46:06 +03:00
|
|
|
// NOTE: Part of peer.LinkUpdater interface.
|
2019-09-25 22:00:59 +03:00
|
|
|
func (c *CommitSig) TargetChanID() ChannelID {
|
|
|
|
return c.ChanID
|
|
|
|
}
|