mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 22:25:24 +01:00
wtclient: don't unnecessarily load exhausted sessions
In this commit, a new `ExhaustedSessionFilter` function is added and used as a PostEvalFilterFn used when loading sessions from the DB. It allows us to not unnecessarily load exhausted sessions into memory for areas of the code where they will not be needed.
This commit is contained in:
parent
49cd23725a
commit
8623e6107d
1 changed files with 10 additions and 0 deletions
|
@ -74,6 +74,14 @@ func (c *TowerClient) genSessionFilter(
|
|||
}
|
||||
}
|
||||
|
||||
// ExhaustedSessionFilter constructs a wtdb.ClientSessionFilterFn filter
|
||||
// function that will filter out any sessions that have been exhausted.
|
||||
func ExhaustedSessionFilter() wtdb.ClientSessionFilterFn {
|
||||
return func(session *wtdb.ClientSession) bool {
|
||||
return session.SeqNum < session.Policy.MaxUpdates
|
||||
}
|
||||
}
|
||||
|
||||
// RegisteredTower encompasses information about a registered watchtower with
|
||||
// the client.
|
||||
type RegisteredTower struct {
|
||||
|
@ -414,6 +422,7 @@ func New(config *Config) (*TowerClient, error) {
|
|||
wtdb.WithPreEvalFilterFn(c.genSessionFilter(true)),
|
||||
wtdb.WithPerMaxHeight(perMaxHeight),
|
||||
wtdb.WithPerCommittedUpdate(perCommittedUpdate),
|
||||
wtdb.WithPostEvalFilterFn(ExhaustedSessionFilter()),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1627,6 +1636,7 @@ func (c *TowerClient) handleNewTower(msg *newTowerMsg) error {
|
|||
sessions, err := getClientSessions(
|
||||
c.cfg.DB, c.cfg.SecretKeyRing, &tower.ID,
|
||||
wtdb.WithPreEvalFilterFn(c.genSessionFilter(true)),
|
||||
wtdb.WithPostEvalFilterFn(ExhaustedSessionFilter()),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to determine sessions for tower %x: "+
|
||||
|
|
Loading…
Add table
Reference in a new issue