wtclient+lnrpc: move Policy to Manager

This commit is contained in:
Elle Mouton 2023-05-16 14:15:09 +02:00
parent 4e51bf3a3f
commit ab2f781b4a
No known key found for this signature in database
GPG Key ID: D7D916376026F177
3 changed files with 31 additions and 11 deletions

View File

@ -16,9 +16,9 @@ import (
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/watchtower"
"github.com/lightningnetwork/lnd/watchtower/blob"
"github.com/lightningnetwork/lnd/watchtower/wtclient"
"github.com/lightningnetwork/lnd/watchtower/wtdb"
"github.com/lightningnetwork/lnd/watchtower/wtpolicy"
"google.golang.org/grpc"
"gopkg.in/macaroon-bakery.v2/bakery"
)
@ -437,17 +437,22 @@ func (c *WatchtowerClient) Policy(ctx context.Context,
return nil, err
}
var policy wtpolicy.Policy
var blobType blob.Type
switch req.PolicyType {
case PolicyType_LEGACY:
policy = c.cfg.Client.Policy()
blobType = blob.TypeAltruistCommit
case PolicyType_ANCHOR:
policy = c.cfg.AnchorClient.Policy()
blobType = blob.TypeAltruistAnchorCommit
default:
return nil, fmt.Errorf("unknown policy type: %v",
req.PolicyType)
}
policy, err := c.cfg.ClientMgr.Policy(blobType)
if err != nil {
return nil, err
}
return &PolicyResponse{
MaxUpdates: uint32(policy.MaxUpdates),
SweepSatPerVbyte: uint32(policy.SweepFeeRate.FeePerVByte()),

View File

@ -95,9 +95,6 @@ type RegisteredTower struct {
// Client is the primary interface used by the daemon to control a client's
// lifecycle and backup revoked states.
type Client interface {
// Policy returns the active client policy configuration.
Policy() wtpolicy.Policy
// RegisterChannel persistently initializes any channel-dependent
// parameters within the client. This should be called during link
// startup to ensure that the client is able to support the link during
@ -1620,8 +1617,8 @@ func (c *TowerClient) getStats() ClientStats {
return c.stats.getStatsCopy()
}
// Policy returns the active client policy configuration.
func (c *TowerClient) Policy() wtpolicy.Policy {
// policy returns the active client policy configuration.
func (c *TowerClient) policy() wtpolicy.Policy {
return c.cfg.Policy
}

View File

@ -38,6 +38,9 @@ type TowerClientManager interface {
// Stats returns the in-memory statistics of the client since startup.
Stats() ClientStats
// Policy returns the active client policy configuration.
Policy(blob.Type) (wtpolicy.Policy, error)
// RegisteredTowers retrieves the list of watchtowers registered with
// the client. It returns a set of registered towers per client policy
// type.
@ -353,7 +356,7 @@ func (m *Manager) RegisteredTowers(opts ...wtdb.ClientSessionListOption) (
return nil, err
}
resp[client.Policy().BlobType] = towers
resp[client.policy().BlobType] = towers
}
return resp, nil
@ -379,8 +382,23 @@ func (m *Manager) LookupTower(key *btcec.PublicKey,
return nil, err
}
resp[client.Policy().BlobType] = tower
resp[client.policy().BlobType] = tower
}
return resp, nil
}
// Policy returns the active client policy configuration for the client using
// the given blob type.
func (m *Manager) Policy(blobType blob.Type) (wtpolicy.Policy, error) {
m.clientsMu.Lock()
defer m.clientsMu.Unlock()
var policy wtpolicy.Policy
client, ok := m.clients[blobType]
if !ok {
return policy, fmt.Errorf("no client for the given blob type")
}
return client.policy(), nil
}