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.
This commit is contained in:
parent
440ae7818a
commit
25fc464a6e
32
watchtower/wtdb/client_chan_summary.go
Normal file
32
watchtower/wtdb/client_chan_summary.go
Normal file
@ -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)
|
||||
}
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user