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.
This commit is contained in:
Olaoluwa Osuntokun 2016-07-05 16:48:23 -07:00
parent 06af4b130f
commit 1f7d9b6425
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 15 additions and 3 deletions

@ -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 {

@ -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