From 4b8a8f410a7782fe12bc37056d38219115c456f7 Mon Sep 17 00:00:00 2001 From: Joseph Poon Date: Tue, 15 Mar 2016 16:22:41 -0700 Subject: [PATCH] Commit message update Doesn't need to use a list, only needs to show each party's most recent state. --- lnwire/commit_signature.go | 21 +++++++++++---------- lnwire/commit_signature_test.go | 18 +++++++++--------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lnwire/commit_signature.go b/lnwire/commit_signature.go index 062db8d5..09114a52 100644 --- a/lnwire/commit_signature.go +++ b/lnwire/commit_signature.go @@ -19,10 +19,13 @@ type CommitSignature struct { // This is used for shachain. // Each party increments their own CommitmentHeight, they can differ for // each part of the Commitment. + //FIXME This might be superfluous CommitmentHeight uint64 // List of HTLC Keys which are updated from all parties - UpdatedHTLCKeys []uint64 + //UpdatedHTLCKeys []uint64 + LastCommittedKeyAlice HTLCKey + LastCommittedKeyBob HTLCKey // Hash of the revocation to use RevocationHash [20]byte @@ -37,14 +40,14 @@ type CommitSignature struct { func (c *CommitSignature) Decode(r io.Reader, pver uint32) error { // ChannelID(8) // CommitmentHeight(8) - // c.UpdatedHTLCKeys(8*1000max) // RevocationHash(20) // Fee(8) // RequesterCommitSig(73max+2) err := readElements(r, &c.ChannelID, &c.CommitmentHeight, - &c.UpdatedHTLCKeys, + &c.LastCommittedKeyAlice, + &c.LastCommittedKeyBob, &c.RevocationHash, &c.Fee, &c.CommitSig, @@ -67,7 +70,8 @@ func (c *CommitSignature) Encode(w io.Writer, pver uint32) error { err := writeElements(w, c.ChannelID, c.CommitmentHeight, - c.UpdatedHTLCKeys, + c.LastCommittedKeyAlice, + c.LastCommittedKeyBob, c.RevocationHash, c.Fee, c.CommitSig, @@ -106,18 +110,15 @@ func (c *CommitSignature) String() string { // c.Fee, // c.CommitSig, var serializedSig []byte - if &c.CommitSig != nil && c.CommitSig.R != nil { + if c.CommitSig != nil && c.CommitSig.R != nil { serializedSig = c.CommitSig.Serialize() } - var items string - for i := 0; i < len(c.UpdatedHTLCKeys); i++ { - items += fmt.Sprintf("%d ", c.UpdatedHTLCKeys[i]) - } return fmt.Sprintf("\n--- Begin CommitSignature ---\n") + fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) + fmt.Sprintf("CommitmentHeight:\t%d\n", c.CommitmentHeight) + - fmt.Sprintf("UpdatedHTLCKeys:\t%s\n", items) + + fmt.Sprintf("LastCommittedKeyAlice:\t%d\n", c.LastCommittedKeyAlice) + + fmt.Sprintf("LastCommittedKeyBob:\t%d\n", c.LastCommittedKeyBob) + fmt.Sprintf("RevocationHash:\t\t%x\n", c.RevocationHash) + fmt.Sprintf("Fee:\t\t\t%s\n", c.Fee.String()) + fmt.Sprintf("CommitSig:\t\t%x\n", serializedSig) + diff --git a/lnwire/commit_signature_test.go b/lnwire/commit_signature_test.go index 3ec086b2..95af1a51 100644 --- a/lnwire/commit_signature_test.go +++ b/lnwire/commit_signature_test.go @@ -10,16 +10,16 @@ var ( _ = copy(revocationHash[:], revocationHashBytes) commitSignature = &CommitSignature{ - ChannelID: uint64(12345678), - CommitmentHeight: uint64(12345), - // CommitterLastStaging: uint64(12345678), - UpdatedHTLCKeys: []uint64{1, 2, 3, 4, 5}, - RevocationHash: revocationHash, - Fee: btcutil.Amount(10000), - CommitSig: commitSig, + ChannelID: uint64(12345678), + CommitmentHeight: uint64(12345), + LastCommittedKeyAlice: uint64(12345), + LastCommittedKeyBob: uint64(54321), + RevocationHash: revocationHash, + Fee: btcutil.Amount(10000), + CommitSig: commitSig, } - commitSignatureSerializedString = "0000000000bc614e00000000000030390005000000000000000100000000000000020000000000000003000000000000000400000000000000054132b6b48371f7b022a16eacb9b2b0ebee134d4100000000000027104630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df" - commitSignatureSerializedMessage = "0709110b000007d00000009d0000000000bc614e00000000000030390005000000000000000100000000000000020000000000000003000000000000000400000000000000054132b6b48371f7b022a16eacb9b2b0ebee134d4100000000000027104630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df" + commitSignatureSerializedString = "0000000000bc614e00000000000030390000000000003039000000000000d4314132b6b48371f7b022a16eacb9b2b0ebee134d4100000000000027104630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df" + commitSignatureSerializedMessage = "0709110b000007d0000000830000000000bc614e00000000000030390000000000003039000000000000d4314132b6b48371f7b022a16eacb9b2b0ebee134d4100000000000027104630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df" ) func TestCommitSignatureEncodeDecode(t *testing.T) {