From 1f7d9b6425ee4a2382570e6cb16a1e75877a8974 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 5 Jul 2016 16:48:23 -0700 Subject: [PATCH] channeldb: also store their current revocation hash We now also store their current revocation hash which is given to us along with the revocation key once an initial HTLC is added to a commitment transaction. --- channeldb/channel.go | 15 ++++++++++++--- channeldb/channel_test.go | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/channeldb/channel.go b/channeldb/channel.go index 9a7cfa39..2613269c 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -134,9 +134,10 @@ type OpenChannel struct { // Current revocation for their commitment transaction. However, since // this the derived public key, we don't yet have the pre-image so we // aren't yet able to verify that it's actually in the hash chain. - TheirCurrentRevocation *btcec.PublicKey - LocalElkrem *elkrem.ElkremSender - RemoteElkrem *elkrem.ElkremReceiver + TheirCurrentRevocation *btcec.PublicKey + TheirCurrentRevocationHash [32]byte + LocalElkrem *elkrem.ElkremSender + RemoteElkrem *elkrem.ElkremReceiver // The pkScript for both sides to be used for final delivery in the case // of a cooperative close. @@ -1029,6 +1030,10 @@ func putChanEklremState(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error return err } + if _, err := b.Write(channel.TheirCurrentRevocationHash[:]); err != nil { + return err + } + // TODO(roasbeef): shouldn't be storing on disk, should re-derive as // needed senderBytes := channel.LocalElkrem.ToBytes() @@ -1074,6 +1079,10 @@ func fetchChanEklremState(nodeChanBucket *bolt.Bucket, channel *OpenChannel) err return err } + if _, err := elkremStateBytes.Read(channel.TheirCurrentRevocationHash[:]); err != nil { + return err + } + // TODO(roasbeef): should be rederiving on fly, or encrypting on disk. senderBytes, err := wire.ReadVarBytes(elkremStateBytes, 0, 1000, "") if err != nil { diff --git a/channeldb/channel_test.go b/channeldb/channel_test.go index 21507177..3d2c62e5 100644 --- a/channeldb/channel_test.go +++ b/channeldb/channel_test.go @@ -295,6 +295,9 @@ func TestOpenChannelPutGetDelete(t *testing.T) { if !newState.TheirCurrentRevocation.IsEqual(state.TheirCurrentRevocation) { t.Fatalf("revocation keys don't match") } + if !bytes.Equal(newState.TheirCurrentRevocationHash[:], state.TheirCurrentRevocationHash[:]) { + t.Fatalf("revocation hashes don't match") + } // Finally to wrap up the test, delete the state of the channel within // the database. This involves "closing" the channel which removes all