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
This commit is contained in:
Olaoluwa Osuntokun 2016-09-05 16:58:14 -07:00
parent c1b98da530
commit e83a6a0f6c
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 5 additions and 41 deletions

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

@ -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")
}