diff --git a/lnrpc/wtclientrpc/wtclient.go b/lnrpc/wtclientrpc/wtclient.go index 756eec2bf..a6b1fa0c0 100644 --- a/lnrpc/wtclientrpc/wtclient.go +++ b/lnrpc/wtclientrpc/wtclient.go @@ -420,19 +420,7 @@ func (c *WatchtowerClient) Stats(_ context.Context, return nil, err } - clientStats := []wtclient.ClientStats{ - c.cfg.Client.Stats(), - c.cfg.AnchorClient.Stats(), - } - - var stats wtclient.ClientStats - for _, stat := range clientStats { - stats.NumTasksAccepted += stat.NumTasksAccepted - stats.NumTasksIneligible += stat.NumTasksIneligible - stats.NumTasksPending += stat.NumTasksPending - stats.NumSessionsAcquired += stat.NumSessionsAcquired - stats.NumSessionsExhausted += stat.NumSessionsExhausted - } + stats := c.cfg.ClientMgr.Stats() return &StatsResponse{ NumBackups: uint32(stats.NumTasksAccepted), diff --git a/watchtower/wtclient/client.go b/watchtower/wtclient/client.go index 5714c382c..d7d3ef900 100644 --- a/watchtower/wtclient/client.go +++ b/watchtower/wtclient/client.go @@ -104,9 +104,6 @@ type Client interface { LookupTower(*btcec.PublicKey, ...wtdb.ClientSessionListOption) (*RegisteredTower, error) - // Stats returns the in-memory statistics of the client since startup. - Stats() ClientStats - // Policy returns the active client policy configuration. Policy() wtpolicy.Policy @@ -1635,8 +1632,8 @@ func (c *TowerClient) LookupTower(pubKey *btcec.PublicKey, }, nil } -// Stats returns the in-memory statistics of the client since startup. -func (c *TowerClient) Stats() ClientStats { +// getStats returns the in-memory statistics of the client since startup. +func (c *TowerClient) getStats() ClientStats { return c.stats.getStatsCopy() } diff --git a/watchtower/wtclient/manager.go b/watchtower/wtclient/manager.go index b28268f62..ac28cd21b 100644 --- a/watchtower/wtclient/manager.go +++ b/watchtower/wtclient/manager.go @@ -33,6 +33,9 @@ type TowerClientManager interface { // only serves as a way of removing the address from the watchtower // instead. RemoveTower(*btcec.PublicKey, net.Addr) error + + // Stats returns the in-memory statistics of the client since startup. + Stats() ClientStats } // Config provides the TowerClient with access to the resources it requires to @@ -299,3 +302,22 @@ func (m *Manager) RemoveTower(key *btcec.PublicKey, addr net.Addr) error { return nil } + +// Stats returns the in-memory statistics of the clients managed by the Manager +// since startup. +func (m *Manager) Stats() ClientStats { + m.clientsMu.Lock() + defer m.clientsMu.Unlock() + + var resp ClientStats + for _, client := range m.clients { + stats := client.getStats() + resp.NumTasksAccepted += stats.NumTasksAccepted + resp.NumTasksIneligible += stats.NumTasksIneligible + resp.NumTasksPending += stats.NumTasksPending + resp.NumSessionsAcquired += stats.NumSessionsAcquired + resp.NumSessionsExhausted += stats.NumSessionsExhausted + } + + return resp +}