From 364a9a8059eac016076c8038fb12facb0a8f5963 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 28 Jul 2017 16:30:02 -0700 Subject: [PATCH] lnwire: add a HtlcSigs field to the CommitSig message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new field to the CommitSig message: HtlcSigs. This new field will house signatures for each of the HTLC’s on the newly created commitment state. This addition allows us to implement the new commitment transaction structure outlined within the specification which modifies HTLC’s such that the claiming process is now a two-phase process. The first state transitions an HTLC to the delay+claim state, and the second state (after the delay has passed) allows the broadcaster of the commitment transaction to sweep the HTLC’s. Fixes #61. --- lnwire/commit_sig.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lnwire/commit_sig.go b/lnwire/commit_sig.go index 8da7833c..3c538c02 100644 --- a/lnwire/commit_sig.go +++ b/lnwire/commit_sig.go @@ -23,10 +23,19 @@ type CommitSig struct { // 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. + // If initiating a new commitment state, this signature shoud ONLY + // cover all of the sending party's pending log updates, and the log + // updates of the remote party that have been ACK'd. CommitSig *btcec.Signature - // TODO(roasbeef): add HTLC sigs after state machine is updated to - // support that + // 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 + // sender of this message), a signature for a HTLC timeout transaction + // should be signed, for each incoming HTLC the HTLC timeout + // transaction should be signed. + HtlcSigs []*btcec.Signature } // NewCommitSig creates a new empty CommitSig message. @@ -46,6 +55,7 @@ func (c *CommitSig) Decode(r io.Reader, pver uint32) error { return readElements(r, &c.ChanID, &c.CommitSig, + &c.HtlcSigs, ) } @@ -57,6 +67,7 @@ func (c *CommitSig) Encode(w io.Writer, pver uint32) error { return writeElements(w, c.ChanID, c.CommitSig, + c.HtlcSigs, ) } @@ -73,6 +84,6 @@ func (c *CommitSig) MsgType() MessageType { // // This is part of the lnwire.Message interface. func (c *CommitSig) MaxPayloadLength(uint32) uint32 { - // 32 + 64 - return 96 + // 32 + 64 + 2 + max_allowed_htlcs + return MaxMessagePayload }