From 25fc464a6e91a3d7a0c263206fe7c076065558f8 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 23 May 2019 20:48:36 -0700 Subject: [PATCH] watchtower/wtdb/client_chan_summary: add ClientChanSummary A ClientChanSummary will be inserted for each channel registered with the client, which for now will just track the sweep pkscript to use. In the future, this will be extended with additional information to enable the client to efficiently compute which historical states need to be backed up under a given policy. --- watchtower/wtdb/client_chan_summary.go | 32 ++++++++++++++++++++++++++ watchtower/wtdb/codec_test.go | 8 +++++++ 2 files changed, 40 insertions(+) create mode 100644 watchtower/wtdb/client_chan_summary.go diff --git a/watchtower/wtdb/client_chan_summary.go b/watchtower/wtdb/client_chan_summary.go new file mode 100644 index 000000000..d4b3c3c38 --- /dev/null +++ b/watchtower/wtdb/client_chan_summary.go @@ -0,0 +1,32 @@ +package wtdb + +import ( + "io" + + "github.com/lightningnetwork/lnd/lnwire" +) + +// ChannelSummaries is a map for a given channel id to it's ClientChanSummary. +type ChannelSummaries map[lnwire.ChannelID]ClientChanSummary + +// ClientChanSummary tracks channel-specific information. A new +// ClientChanSummary is inserted in the database the first time the client +// encounters a particular channel. +type ClientChanSummary struct { + // SweepPkScript is the pkscript to which all justice transactions will + // deposit recovered funds for this particular channel. + SweepPkScript []byte + + // TODO(conner): later extend with info about initial commit height, + // ineligible states, etc. +} + +// Encode writes the ClientChanSummary to the passed io.Writer. +func (s *ClientChanSummary) Encode(w io.Writer) error { + return WriteElement(w, s.SweepPkScript) +} + +// Decode reads a ClientChanSummary form the passed io.Reader. +func (s *ClientChanSummary) Decode(r io.Reader) error { + return ReadElement(r, &s.SweepPkScript) +} diff --git a/watchtower/wtdb/codec_test.go b/watchtower/wtdb/codec_test.go index 21e11c6fd..69c7b0594 100644 --- a/watchtower/wtdb/codec_test.go +++ b/watchtower/wtdb/codec_test.go @@ -153,6 +153,8 @@ func TestCodec(tt *testing.T) { obj2 = &wtdb.BackupID{} case *wtdb.Tower: obj2 = &wtdb.Tower{} + case *wtdb.ClientChanSummary: + obj2 = &wtdb.ClientChanSummary{} default: t.Fatalf("unknown type: %T", obj) return false @@ -238,6 +240,12 @@ func TestCodec(tt *testing.T) { return mainScenario(&obj) }, }, + { + name: "ClientChanSummary", + scenario: func(obj wtdb.ClientChanSummary) bool { + return mainScenario(&obj) + }, + }, } for _, test := range tests {