From e83a6a0f6c7430ab832e24bb7bbcbd2dcf5aad09 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 5 Sep 2016 16:58:14 -0700 Subject: [PATCH] channeldb: remove revocation keys from channel deltas This commit removes the revocation hash/keys from the channel deltas. In the case of an uncooperative closure, we can efficiently re-generate the proper elkrem pre-image so this storage was completely unnecessary --- channeldb/channel.go | 29 +---------------------------- channeldb/channel_test.go | 17 ++++------------- 2 files changed, 5 insertions(+), 41 deletions(-) diff --git a/channeldb/channel.go b/channeldb/channel.go index b2f2f70f..b3230550 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -255,19 +255,12 @@ type HTLC struct { // ChannelDelta is a snapshot of the commitment state at a particular point in // the commitment chain. With each state transition, a snapshot of the current // state along with all non-settled HTLC's are recorded. -// TODO(roasbeef): should only need the key instead of hash after refactor -// within state machine. -// * won't actually be needed if it's a past state? type ChannelDelta struct { - RevocationHash [32]byte - RevocationKey *btcec.PublicKey - LocalBalance btcutil.Amount RemoteBalance btcutil.Amount + UpdateNum uint32 Htlcs []*HTLC - - UpdateNum uint32 } // RecordChannelDelta records the new state transition within an on-disk @@ -1340,14 +1333,6 @@ func deserializeHTLC(r io.Reader) (*HTLC, error) { } func serializeChannelDelta(w io.Writer, delta *ChannelDelta) error { - if _, err := w.Write(delta.RevocationHash[:]); err != nil { - return err - } - serializeKey := delta.RevocationKey.SerializeCompressed() - if _, err := w.Write(serializeKey); err != nil { - return err - } - // TODO(roasbeef): could use compression here to reduce on-disk space. var scratch [8]byte byteOrder.PutUint64(scratch[:], uint64(delta.LocalBalance)) @@ -1381,21 +1366,9 @@ func deserializeChannelDelta(r io.Reader) (*ChannelDelta, error) { var ( err error scratch [8]byte - key [33]byte ) delta := &ChannelDelta{} - if _, err = r.Read(delta.RevocationHash[:]); err != nil { - return nil, err - } - - if _, err = r.Read(key[:]); err != nil { - return nil, err - } - delta.RevocationKey, err = btcec.ParsePubKey(key[:], btcec.S256()) - if err != nil { - return nil, err - } if _, err := r.Read(scratch[:]); err != nil { return nil, err diff --git a/channeldb/channel_test.go b/channeldb/channel_test.go index a4ea1639..5f5e09f3 100644 --- a/channeldb/channel_test.go +++ b/channeldb/channel_test.go @@ -367,12 +367,10 @@ func TestChannelStateUpdateLog(t *testing.T) { newTx := channel.OurCommitTx.Copy() newTx.TxIn[0].Sequence = newSequence delta := &ChannelDelta{ - RevocationHash: key, - RevocationKey: pubKey, - LocalBalance: btcutil.Amount(1e8), - RemoteBalance: btcutil.Amount(1e8), - Htlcs: htlcs, - UpdateNum: 1, + LocalBalance: btcutil.Amount(1e8), + RemoteBalance: btcutil.Amount(1e8), + Htlcs: htlcs, + UpdateNum: 1, } if err := channel.RecordChannelDelta(newTx, newSig, delta); err != nil { t.Fatalf("unable to record channel delta: %v", err) @@ -416,13 +414,6 @@ func TestChannelStateUpdateLog(t *testing.T) { // The two deltas (the original vs the on-disk version) should // identical, and all HTLC data should properly be retained. - if !bytes.Equal(delta.RevocationHash[:], diskDelta.RevocationHash[:]) { - t.Fatalf("revocation hashes don't match") - } - if !bytes.Equal(delta.RevocationKey.SerializeCompressed(), - diskDelta.RevocationKey.SerializeCompressed()) { - t.Fatalf("revocation keys don't match") - } if delta.LocalBalance != diskDelta.LocalBalance { t.Fatalf("local balances don't match") }