mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 14:40:30 +01:00
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:
parent
c1b98da530
commit
e83a6a0f6c
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
|
// 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
|
// the commitment chain. With each state transition, a snapshot of the current
|
||||||
// state along with all non-settled HTLC's are recorded.
|
// 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 {
|
type ChannelDelta struct {
|
||||||
RevocationHash [32]byte
|
|
||||||
RevocationKey *btcec.PublicKey
|
|
||||||
|
|
||||||
LocalBalance btcutil.Amount
|
LocalBalance btcutil.Amount
|
||||||
RemoteBalance btcutil.Amount
|
RemoteBalance btcutil.Amount
|
||||||
|
UpdateNum uint32
|
||||||
|
|
||||||
Htlcs []*HTLC
|
Htlcs []*HTLC
|
||||||
|
|
||||||
UpdateNum uint32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RecordChannelDelta records the new state transition within an on-disk
|
// 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 {
|
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.
|
// TODO(roasbeef): could use compression here to reduce on-disk space.
|
||||||
var scratch [8]byte
|
var scratch [8]byte
|
||||||
byteOrder.PutUint64(scratch[:], uint64(delta.LocalBalance))
|
byteOrder.PutUint64(scratch[:], uint64(delta.LocalBalance))
|
||||||
|
@ -1381,21 +1366,9 @@ func deserializeChannelDelta(r io.Reader) (*ChannelDelta, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
scratch [8]byte
|
scratch [8]byte
|
||||||
key [33]byte
|
|
||||||
)
|
)
|
||||||
|
|
||||||
delta := &ChannelDelta{}
|
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 {
|
if _, err := r.Read(scratch[:]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -367,12 +367,10 @@ func TestChannelStateUpdateLog(t *testing.T) {
|
||||||
newTx := channel.OurCommitTx.Copy()
|
newTx := channel.OurCommitTx.Copy()
|
||||||
newTx.TxIn[0].Sequence = newSequence
|
newTx.TxIn[0].Sequence = newSequence
|
||||||
delta := &ChannelDelta{
|
delta := &ChannelDelta{
|
||||||
RevocationHash: key,
|
LocalBalance: btcutil.Amount(1e8),
|
||||||
RevocationKey: pubKey,
|
RemoteBalance: btcutil.Amount(1e8),
|
||||||
LocalBalance: btcutil.Amount(1e8),
|
Htlcs: htlcs,
|
||||||
RemoteBalance: btcutil.Amount(1e8),
|
UpdateNum: 1,
|
||||||
Htlcs: htlcs,
|
|
||||||
UpdateNum: 1,
|
|
||||||
}
|
}
|
||||||
if err := channel.RecordChannelDelta(newTx, newSig, delta); err != nil {
|
if err := channel.RecordChannelDelta(newTx, newSig, delta); err != nil {
|
||||||
t.Fatalf("unable to record channel delta: %v", err)
|
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
|
// The two deltas (the original vs the on-disk version) should
|
||||||
// identical, and all HTLC data should properly be retained.
|
// 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 {
|
if delta.LocalBalance != diskDelta.LocalBalance {
|
||||||
t.Fatalf("local balances don't match")
|
t.Fatalf("local balances don't match")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue