From 48667bdcbe202ebcb736c5f030d96b7887336477 Mon Sep 17 00:00:00 2001 From: Joseph Poon Date: Thu, 17 Mar 2016 16:51:30 -0700 Subject: [PATCH] Updated Commit Revocation --- lnwire/commit_revocation.go | 19 +++++++------------ lnwire/commit_revocation_test.go | 11 ++++++----- lnwire/commit_signature_test.go | 4 ++-- lnwire/message.go | 14 -------------- 4 files changed, 15 insertions(+), 33 deletions(-) diff --git a/lnwire/commit_revocation.go b/lnwire/commit_revocation.go index 8050a9d6..bb79d5fd 100644 --- a/lnwire/commit_revocation.go +++ b/lnwire/commit_revocation.go @@ -11,16 +11,11 @@ type CommitRevocation 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. - CommitmentHeight uint64 - // Revocation to use RevocationProof [20]byte + + //Next revocation to use + NextRevocationHash [20]byte } func (c *CommitRevocation) Decode(r io.Reader, pver uint32) error { @@ -29,8 +24,8 @@ func (c *CommitRevocation) Decode(r io.Reader, pver uint32) error { // RevocationProof(20) err := readElements(r, &c.ChannelID, - &c.CommitmentHeight, &c.RevocationProof, + &c.NextRevocationHash, ) if err != nil { return err @@ -49,8 +44,8 @@ func NewCommitRevocation() *CommitRevocation { func (c *CommitRevocation) Encode(w io.Writer, pver uint32) error { err := writeElements(w, c.ChannelID, - c.CommitmentHeight, c.RevocationProof, + c.NextRevocationHash, ) if err != nil { return err @@ -64,7 +59,7 @@ func (c *CommitRevocation) Command() uint32 { } func (c *CommitRevocation) MaxPayloadLength(uint32) uint32 { - return 36 + return 48 } // Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts) @@ -76,7 +71,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("CommitmentHeight:\t%d\n", c.CommitmentHeight) + fmt.Sprintf("RevocationProof:\t%x\n", c.RevocationProof) + + fmt.Sprintf("NextRevocationHash:\t%x\n", c.NextRevocationHash) + fmt.Sprintf("--- End CommitRevocation ---\n") } diff --git a/lnwire/commit_revocation_test.go b/lnwire/commit_revocation_test.go index c654d5b4..8340ce73 100644 --- a/lnwire/commit_revocation_test.go +++ b/lnwire/commit_revocation_test.go @@ -7,14 +7,15 @@ import ( var ( // Need to to do this here _ = copy(revocationHash[:], revocationHashBytes) + _ = copy(nextHop[:], nextHopBytes) commitRevocation = &CommitRevocation{ - ChannelID: uint64(12345678), - CommitmentHeight: uint64(12345), - RevocationProof: revocationHash, // technically it's not a hash... fix later + ChannelID: uint64(12345678), + RevocationProof: revocationHash, // technically it's not a hash... fix later + NextRevocationHash: nextHop, // technically it's not a hash... fix later } - commitRevocationSerializedString = "0000000000bc614e00000000000030394132b6b48371f7b022a16eacb9b2b0ebee134d41" - commitRevocationSerializedMessage = "0709110b000007da000000240000000000bc614e00000000000030394132b6b48371f7b022a16eacb9b2b0ebee134d41" + commitRevocationSerializedString = "0000000000bc614e4132b6b48371f7b022a16eacb9b2b0ebee134d4194a9ded5a30fc5944cb1e2cbcd980f30616a1440" + commitRevocationSerializedMessage = "0709110b000007da000000300000000000bc614e4132b6b48371f7b022a16eacb9b2b0ebee134d4194a9ded5a30fc5944cb1e2cbcd980f30616a1440" ) func TestCommitRevocationEncodeDecode(t *testing.T) { diff --git a/lnwire/commit_signature_test.go b/lnwire/commit_signature_test.go index 95af1a51..2979186e 100644 --- a/lnwire/commit_signature_test.go +++ b/lnwire/commit_signature_test.go @@ -12,8 +12,8 @@ var ( commitSignature = &CommitSignature{ ChannelID: uint64(12345678), CommitmentHeight: uint64(12345), - LastCommittedKeyAlice: uint64(12345), - LastCommittedKeyBob: uint64(54321), + LastCommittedKeyAlice: HTLCKey(12345), + LastCommittedKeyBob: HTLCKey(54321), RevocationHash: revocationHash, Fee: btcutil.Amount(10000), CommitSig: commitSig, diff --git a/lnwire/message.go b/lnwire/message.go index 48ebdf9e..c5be1344 100644 --- a/lnwire/message.go +++ b/lnwire/message.go @@ -9,20 +9,6 @@ import ( "github.com/btcsuite/btcd/wire" ) -// message type identifyer bytes -const ( - MSGID_FUNDREQUEST = 0x30 - MSGID_FUNDRESPONSE = 0x31 - - MSGID_CLOSEREQUEST = 0x40 - MSGID_CLOSERESPONSE = 0x41 - - MSGID_TEXTCHAT = 0x70 - - MSGID_FWDMSG = 0x20 - MSGID_FWDAUTHREQ = 0x21 -) - // 4-byte network + 4-byte message id + payload-length 4-byte const MessageHeaderSize = 12