github.com/decred/dcrlnd@v0.7.6/lnwire/commit_sig.go (about) 1 package lnwire 2 3 import ( 4 "bytes" 5 "io" 6 ) 7 8 // CommitSig is sent by either side to stage any pending HTLC's in the 9 // receiver's pending set into a new commitment state. Implicitly, the new 10 // commitment transaction constructed which has been signed by CommitSig 11 // includes all HTLC's in the remote node's pending set. A CommitSig message 12 // may be sent after a series of UpdateAddHTLC/UpdateFulfillHTLC messages in 13 // order to batch add several HTLC's with a single signature covering all 14 // implicitly accepted HTLC's. 15 type CommitSig struct { 16 // ChanID uniquely identifies to which currently active channel this 17 // CommitSig applies to. 18 ChanID ChannelID 19 20 // CommitSig is Alice's signature for Bob's new commitment transaction. 21 // Alice is able to send this signature without requesting any 22 // additional data due to the piggybacking of Bob's next revocation 23 // hash in his prior RevokeAndAck message, as well as the canonical 24 // ordering used for all inputs/outputs within commitment transactions. 25 // If initiating a new commitment state, this signature should ONLY 26 // cover all of the sending party's pending log updates, and the log 27 // updates of the remote party that have been ACK'd. 28 CommitSig Sig 29 30 // HtlcSigs is a signature for each relevant HTLC output within the 31 // created commitment. The order of the signatures is expected to be 32 // identical to the placement of the HTLC's within the BIP 69 sorted 33 // commitment transaction. For each outgoing HTLC (from the PoV of the 34 // sender of this message), a signature for an HTLC timeout transaction 35 // should be signed, for each incoming HTLC the HTLC timeout 36 // transaction should be signed. 37 HtlcSigs []Sig 38 39 // ExtraData is the set of data that was appended to this message to 40 // fill out the full maximum transport message size. These fields can 41 // be used to specify optional data such as custom TLV fields. 42 ExtraData ExtraOpaqueData 43 } 44 45 // NewCommitSig creates a new empty CommitSig message. 46 func NewCommitSig() *CommitSig { 47 return &CommitSig{ 48 ExtraData: make([]byte, 0), 49 } 50 } 51 52 // A compile time check to ensure CommitSig implements the lnwire.Message 53 // interface. 54 var _ Message = (*CommitSig)(nil) 55 56 // Decode deserializes a serialized CommitSig message stored in the 57 // passed io.Reader observing the specified protocol version. 58 // 59 // This is part of the lnwire.Message interface. 60 func (c *CommitSig) Decode(r io.Reader, pver uint32) error { 61 return ReadElements(r, 62 &c.ChanID, 63 &c.CommitSig, 64 &c.HtlcSigs, 65 &c.ExtraData, 66 ) 67 } 68 69 // Encode serializes the target CommitSig into the passed io.Writer 70 // observing the protocol version specified. 71 // 72 // This is part of the lnwire.Message interface. 73 func (c *CommitSig) Encode(w *bytes.Buffer, pver uint32) error { 74 if err := WriteChannelID(w, c.ChanID); err != nil { 75 return err 76 } 77 78 if err := WriteSig(w, c.CommitSig); err != nil { 79 return err 80 } 81 82 if err := WriteSigs(w, c.HtlcSigs); err != nil { 83 return err 84 } 85 86 return WriteBytes(w, c.ExtraData) 87 } 88 89 // MsgType returns the integer uniquely identifying this message type on the 90 // wire. 91 // 92 // This is part of the lnwire.Message interface. 93 func (c *CommitSig) MsgType() MessageType { 94 return MsgCommitSig 95 } 96 97 // TargetChanID returns the channel id of the link for which this message is 98 // intended. 99 // 100 // NOTE: Part of peer.LinkUpdater interface. 101 func (c *CommitSig) TargetChanID() ChannelID { 102 return c.ChanID 103 }