From d840761cc4a1c75678d29007f6e1ae8f5ad7b93c Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 26 Oct 2022 10:31:39 +0200 Subject: [PATCH] watchtower: dont load closed channel details In this commit, the FetchChanSummaries method is adapted to skip loading any channel summaries if the channel has been marked as closed. --- watchtower/wtclient/interface.go | 3 ++- watchtower/wtdb/client_db.go | 10 +++++++++- watchtower/wtmock/client_db.go | 8 +++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/watchtower/wtclient/interface.go b/watchtower/wtclient/interface.go index 4dd9176ae..4eebef4e5 100644 --- a/watchtower/wtclient/interface.go +++ b/watchtower/wtclient/interface.go @@ -83,7 +83,8 @@ type DB interface { NumAckedUpdates(id *wtdb.SessionID) (uint64, error) // FetchChanSummaries loads a mapping from all registered channels to - // their channel summaries. + // their channel summaries. Only the channels that have not yet been + // marked as closed will be loaded. FetchChanSummaries() (wtdb.ChannelSummaries, error) // MarkChannelClosed will mark a registered channel as closed by setting diff --git a/watchtower/wtdb/client_db.go b/watchtower/wtdb/client_db.go index c3e5447d6..53c643b6f 100644 --- a/watchtower/wtdb/client_db.go +++ b/watchtower/wtdb/client_db.go @@ -1284,7 +1284,8 @@ func (c *ClientDB) NumAckedUpdates(id *SessionID) (uint64, error) { } // FetchChanSummaries loads a mapping from all registered channels to their -// channel summaries. +// channel summaries. Only the channels that have not yet been marked as closed +// will be loaded. func (c *ClientDB) FetchChanSummaries() (ChannelSummaries, error) { var summaries map[lnwire.ChannelID]ClientChanSummary @@ -1300,6 +1301,13 @@ func (c *ClientDB) FetchChanSummaries() (ChannelSummaries, error) { return ErrCorruptChanDetails } + // If this channel has already been marked as closed, + // then its summary does not need to be loaded. + closedHeight := chanDetails.Get(cChanClosedHeight) + if len(closedHeight) > 0 { + return nil + } + var chanID lnwire.ChannelID copy(chanID[:], k) diff --git a/watchtower/wtmock/client_db.go b/watchtower/wtmock/client_db.go index 7213f17b6..e004fcdaf 100644 --- a/watchtower/wtmock/client_db.go +++ b/watchtower/wtmock/client_db.go @@ -566,13 +566,19 @@ func (m *ClientDB) ListClosableSessions() (map[wtdb.SessionID]uint32, error) { } // FetchChanSummaries loads a mapping from all registered channels to their -// channel summaries. +// channel summaries. Only the channels that have not yet been marked as closed +// will be loaded. func (m *ClientDB) FetchChanSummaries() (wtdb.ChannelSummaries, error) { m.mu.Lock() defer m.mu.Unlock() summaries := make(map[lnwire.ChannelID]wtdb.ClientChanSummary) for chanID, channel := range m.channels { + // Don't load the channel if it has been marked as closed. + if channel.closedHeight > 0 { + continue + } + summaries[chanID] = wtdb.ClientChanSummary{ SweepPkScript: cloneBytes( channel.summary.SweepPkScript,