watchtower/wtclient: integrate ClientChannelSummaries
In this commit, we utilize the more generic ClientChanSummary instead of exposing methods that only allow us to set and fetch sweep pkscripts.
This commit is contained in:
5 files changed
+57
-34
No files matched your search
@@ -150,8 +150,8 @@ type TowerClient struct {
|
||||
sessionQueue *sessionQueue
|
||||
prevTask *backupTask
|
||||
|
||||
sweepPkScriptMu sync.RWMutex
|
||||
sweepPkScripts map[lnwire.ChannelID][]byte
|
||||
summaryMu sync.RWMutex
|
||||
summaries wtdb.ChannelSummaries
|
||||
|
||||
statTicker *time.Ticker
|
||||
stats clientStats
|
||||
@@ -245,7 +245,7 @@ func New(config *Config) (*TowerClient, error) {
|
||||
|
||||
// Finally, load the sweep pkscripts that have been generated for all
|
||||
// previously registered channels.
|
||||
c.sweepPkScripts, err = c.cfg.DB.FetchChanPkScripts()
|
||||
c.summaries, err = c.cfg.DB.FetchChanSummaries()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -388,12 +388,12 @@ func (c *TowerClient) ForceQuit() {
|
||||
// within the client. This should be called during link startup to ensure that
|
||||
// the client is able to support the link during operation.
|
||||
func (c *TowerClient) RegisterChannel(chanID lnwire.ChannelID) error {
|
||||
c.sweepPkScriptMu.Lock()
|
||||
defer c.sweepPkScriptMu.Unlock()
|
||||
c.summaryMu.Lock()
|
||||
defer c.summaryMu.Unlock()
|
||||
|
||||
// If a pkscript for this channel already exists, the channel has been
|
||||
// previously registered.
|
||||
if _, ok := c.sweepPkScripts[chanID]; ok {
|
||||
if _, ok := c.summaries[chanID]; ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -406,14 +406,16 @@ func (c *TowerClient) RegisterChannel(chanID lnwire.ChannelID) error {
|
||||
|
||||
// Persist the sweep pkscript so that restarts will not introduce
|
||||
// address inflation when the channel is reregistered after a restart.
|
||||
err = c.cfg.DB.AddChanPkScript(chanID, pkScript)
|
||||
err = c.cfg.DB.RegisterChannel(chanID, pkScript)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Finally, cache the pkscript in our in-memory cache to avoid db
|
||||
// lookups for the remainder of the daemon's execution.
|
||||
c.sweepPkScripts[chanID] = pkScript
|
||||
c.summaries[chanID] = wtdb.ClientChanSummary{
|
||||
SweepPkScript: pkScript,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -429,14 +431,14 @@ func (c *TowerClient) BackupState(chanID *lnwire.ChannelID,
|
||||
breachInfo *lnwallet.BreachRetribution) error {
|
||||
|
||||
// Retrieve the cached sweep pkscript used for this channel.
|
||||
c.sweepPkScriptMu.RLock()
|
||||
sweepPkScript, ok := c.sweepPkScripts[*chanID]
|
||||
c.sweepPkScriptMu.RUnlock()
|
||||
c.summaryMu.RLock()
|
||||
summary, ok := c.summaries[*chanID]
|
||||
c.summaryMu.RUnlock()
|
||||
if !ok {
|
||||
return ErrUnregisteredChannel
|
||||
}
|
||||
|
||||
task := newBackupTask(chanID, breachInfo, sweepPkScript)
|
||||
task := newBackupTask(chanID, breachInfo, summary.SweepPkScript)
|
||||
|
||||
return c.pipeline.QueueBackupTask(task)
|
||||
}
|
||||
|
||||
@@ -605,6 +605,8 @@ func (h *testHarness) backupStates(id, from, to uint64, expErr error) {
|
||||
// backupStates instructs the channel identified by id to send a backup for
|
||||
// state i.
|
||||
func (h *testHarness) backupState(id, i uint64, expErr error) {
|
||||
h.t.Helper()
|
||||
|
||||
_, retribution := h.channel(id).getState(i)
|
||||
|
||||
chanID := chanIDFromInt(id)
|
||||
|
||||
@@ -41,14 +41,17 @@ type DB interface {
|
||||
// still be able to accept state updates.
|
||||
ListClientSessions() (map[wtdb.SessionID]*wtdb.ClientSession, error)
|
||||
|
||||
// FetchChanPkScripts returns a map of all sweep pkscripts for
|
||||
// registered channels. This is used on startup to cache the sweep
|
||||
// pkscripts of registered channels in memory.
|
||||
FetchChanPkScripts() (map[lnwire.ChannelID][]byte, error)
|
||||
// FetchChanSummaries loads a mapping from all registered channels to
|
||||
// their channel summaries.
|
||||
FetchChanSummaries() (wtdb.ChannelSummaries, error)
|
||||
|
||||
// AddChanPkScript inserts a newly generated sweep pkscript for the
|
||||
// given channel.
|
||||
AddChanPkScript(lnwire.ChannelID, []byte) error
|
||||
// RegisterChannel registers a channel for use within the client
|
||||
// database. For now, all that is stored in the channel summary is the
|
||||
// sweep pkscript that we'd like any tower sweeps to pay into. In the
|
||||
// future, this will be extended to contain more info to allow the
|
||||
// client efficiently request historical states to be backed up under
|
||||
// the client's active policy.
|
||||
RegisterChannel(lnwire.ChannelID, []byte) error
|
||||
|
||||
// MarkBackupIneligible records that the state identified by the
|
||||
// (channel id, commit height) tuple was ineligible for being backed up
|
||||
|
||||
Reference in new issue
Block a user