From 5218dca5b65b543c4803bfd3d4ee84aa860f2483 Mon Sep 17 00:00:00 2001 From: Joseph Poon Date: Mon, 11 Apr 2016 00:55:48 -0700 Subject: [PATCH] Simplified the commitment messages --- lnwire/commit_revocation.go | 21 ++++++--------------- lnwire/commit_signature.go | 36 ++++-------------------------------- 2 files changed, 10 insertions(+), 47 deletions(-) diff --git a/lnwire/commit_revocation.go b/lnwire/commit_revocation.go index bb79d5fdc..69f55c925 100644 --- a/lnwire/commit_revocation.go +++ b/lnwire/commit_revocation.go @@ -8,24 +8,17 @@ import ( // Multiple Clearing Requests are possible by putting this inside an array of // clearing requests type CommitRevocation struct { - // We can use a different data type for this if necessary... - ChannelID uint64 - - // Revocation to use - RevocationProof [20]byte - //Next revocation to use NextRevocationHash [20]byte + Revocation [20]byte } func (c *CommitRevocation) Decode(r io.Reader, pver uint32) error { - // ChannelID(8) - // CommitmentHeight(8) - // RevocationProof(20) + // NextRevocationHash(20) + // Revocation(20) err := readElements(r, - &c.ChannelID, - &c.RevocationProof, &c.NextRevocationHash, + &c.Revocation, ) if err != nil { return err @@ -43,9 +36,8 @@ func NewCommitRevocation() *CommitRevocation { // Writes the data to w func (c *CommitRevocation) Encode(w io.Writer, pver uint32) error { err := writeElements(w, - c.ChannelID, - c.RevocationProof, c.NextRevocationHash, + c.Revocation, ) if err != nil { return err @@ -70,8 +62,7 @@ func (c *CommitRevocation) Validate() error { func (c *CommitRevocation) String() string { return fmt.Sprintf("\n--- Begin CommitRevocation ---\n") + - fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) + - fmt.Sprintf("RevocationProof:\t%x\n", c.RevocationProof) + fmt.Sprintf("NextRevocationHash:\t%x\n", c.NextRevocationHash) + + fmt.Sprintf("Revocation:\t%x\n", c.Revocation) + fmt.Sprintf("--- End CommitRevocation ---\n") } diff --git a/lnwire/commit_signature.go b/lnwire/commit_signature.go index 09114a522..14540c166 100644 --- a/lnwire/commit_signature.go +++ b/lnwire/commit_signature.go @@ -10,25 +10,9 @@ import ( // Multiple Clearing Requests are possible by putting this inside an array of // clearing requests type CommitSignature struct { - // We can use a different data type for this if necessary... - ChannelID uint64 - - // Height of the commitment - // You should have the most recent commitment height stored locally - // This should be validated! - // 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 - LastCommittedKeyAlice HTLCKey - LastCommittedKeyBob HTLCKey - - // Hash of the revocation to use - RevocationHash [20]byte + HighestPosition uint64 // Total miners' fee that was used Fee btcutil.Amount @@ -44,11 +28,7 @@ func (c *CommitSignature) Decode(r io.Reader, pver uint32) error { // Fee(8) // RequesterCommitSig(73max+2) err := readElements(r, - &c.ChannelID, - &c.CommitmentHeight, - &c.LastCommittedKeyAlice, - &c.LastCommittedKeyBob, - &c.RevocationHash, + &c.HighestPosition, &c.Fee, &c.CommitSig, ) @@ -68,11 +48,7 @@ func NewCommitSignature() *CommitSignature { // Writes the data to w func (c *CommitSignature) Encode(w io.Writer, pver uint32) error { err := writeElements(w, - c.ChannelID, - c.CommitmentHeight, - c.LastCommittedKeyAlice, - c.LastCommittedKeyBob, - c.RevocationHash, + c.HighestPosition, c.Fee, c.CommitSig, ) @@ -115,11 +91,7 @@ func (c *CommitSignature) String() string { } 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("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("HighestPosition:\t%d\n", c.HighestPosition) + fmt.Sprintf("Fee:\t\t\t%s\n", c.Fee.String()) + fmt.Sprintf("CommitSig:\t\t%x\n", serializedSig) + fmt.Sprintf("--- End CommitSignature ---\n")