From 7c7ed5e638d971e1eabad4ab534cdf9a5819362a Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 30 Jun 2016 11:55:12 -0700 Subject: [PATCH] lnwire: add a `LogIndex` field to CommitSignature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates the CommitSignature message to match the latest version of the state-machine protocol. The log index specifies up to which index in the receiver’s HTLC log the sender’s signature covers. --- lnwire/commit_signature.go | 21 ++++++++++++++++++--- lnwire/commit_signature_test.go | 3 +-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lnwire/commit_signature.go b/lnwire/commit_signature.go index cf37d57d8..a491b95bd 100644 --- a/lnwire/commit_signature.go +++ b/lnwire/commit_signature.go @@ -21,6 +21,12 @@ type CommitSignature struct { // CommitSignature applies to. ChannelPoint *wire.OutPoint + // LogIndex is the index into the reciever's HTLC log to which this + // commitment signature covers. In order to properly verify this + // signature, the receiver should include all the HTLC's within their + // log with an index less-than-or-equal to the listed log-index. + LogIndex uint64 + // Fee represents the total miner's fee that was used when constructing // the new commitment transaction. // TODO(roasbeef): is the above comment correct? @@ -49,10 +55,12 @@ var _ Message = (*CommitSignature)(nil) // This is part of the lnwire.Message interface. func (c *CommitSignature) Decode(r io.Reader, pver uint32) error { // ChannelPoint(8) + // LogIndex(8) // Fee(8) // RequesterCommitSig(73max+2) err := readElements(r, &c.ChannelPoint, + &c.LogIndex, &c.Fee, &c.CommitSig, ) @@ -68,9 +76,16 @@ func (c *CommitSignature) Decode(r io.Reader, pver uint32) error { // // This is part of the lnwire.Message interface. func (c *CommitSignature) Encode(w io.Writer, pver uint32) error { - // TODO(roasbeef): make similar modificaiton to all other encode/decode - // messags - return writeElements(w, c.ChannelPoint, c.Fee, c.CommitSig) + err := writeElements(w, + c.ChannelPoint, + c.LogIndex, + c.Fee, + c.CommitSig, + ) + if err != nil { + return err + } + return nil } // Command returns the integer uniquely identifying this message type on the diff --git a/lnwire/commit_signature_test.go b/lnwire/commit_signature_test.go index 8bc0616f6..a1ef67836 100644 --- a/lnwire/commit_signature_test.go +++ b/lnwire/commit_signature_test.go @@ -9,11 +9,10 @@ import ( ) func TestCommitSignatureEncodeDecode(t *testing.T) { - copy(revocationHash[:], revocationHashBytes) - commitSignature := &CommitSignature{ ChannelPoint: outpoint1, Fee: btcutil.Amount(10000), + LogIndex: 5, CommitSig: commitSig, }