wtclient+lnrpc: move Policy to Manager

This commit is contained in:
Elle Mouton committed 2023-11-28 09:54:03 +02:00
1 parent 4e51bf3a3f
commit ab2f781b4a
3 files changed
+31 -11

No files matched your search

+9 -4
View File
@@ -16,9 +16,9 @@ import (
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/watchtower" "github.com/lightningnetwork/lnd/watchtower"
"github.com/lightningnetwork/lnd/watchtower/blob"
"github.com/lightningnetwork/lnd/watchtower/wtclient" "github.com/lightningnetwork/lnd/watchtower/wtclient"
"github.com/lightningnetwork/lnd/watchtower/wtdb" "github.com/lightningnetwork/lnd/watchtower/wtdb"
"github.com/lightningnetwork/lnd/watchtower/wtpolicy"
"google.golang.org/grpc" "google.golang.org/grpc"
"gopkg.in/macaroon-bakery.v2/bakery" "gopkg.in/macaroon-bakery.v2/bakery"
) )
@@ -437,17 +437,22 @@ func (c *WatchtowerClient) Policy(ctx context.Context,
return nil, err return nil, err
} }
var policy wtpolicy.Policy var blobType blob.Type
switch req.PolicyType { switch req.PolicyType {
case PolicyType_LEGACY: case PolicyType_LEGACY:
policy = c.cfg.Client.Policy() blobType = blob.TypeAltruistCommit
case PolicyType_ANCHOR: case PolicyType_ANCHOR:
policy = c.cfg.AnchorClient.Policy() blobType = blob.TypeAltruistAnchorCommit
default: default:
return nil, fmt.Errorf("unknown policy type: %v", return nil, fmt.Errorf("unknown policy type: %v",
req.PolicyType) req.PolicyType)
} }
policy, err := c.cfg.ClientMgr.Policy(blobType)
if err != nil {
return nil, err
}
return &PolicyResponse{ return &PolicyResponse{
MaxUpdates: uint32(policy.MaxUpdates), MaxUpdates: uint32(policy.MaxUpdates),
SweepSatPerVbyte: uint32(policy.SweepFeeRate.FeePerVByte()), SweepSatPerVbyte: uint32(policy.SweepFeeRate.FeePerVByte()),
+2 -5
View File
@@ -95,9 +95,6 @@ type RegisteredTower struct {
// Client is the primary interface used by the daemon to control a client's // Client is the primary interface used by the daemon to control a client's
// lifecycle and backup revoked states. // lifecycle and backup revoked states.
type Client interface { type Client interface {
// Policy returns the active client policy configuration.
Policy() wtpolicy.Policy
// RegisterChannel persistently initializes any channel-dependent // RegisterChannel persistently initializes any channel-dependent
// parameters within the client. This should be called during link // parameters within the client. This should be called during link
// startup to ensure that the client is able to support the link during // 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() return c.stats.getStatsCopy()
} }
// Policy returns the active client policy configuration. // policy returns the active client policy configuration.
func (c *TowerClient) Policy() wtpolicy.Policy { func (c *TowerClient) policy() wtpolicy.Policy {
return c.cfg.Policy return c.cfg.Policy
} }
+20 -2
View File
@@ -38,6 +38,9 @@ type TowerClientManager interface {
// Stats returns the in-memory statistics of the client since startup. // Stats returns the in-memory statistics of the client since startup.
Stats() ClientStats Stats() ClientStats
// Policy returns the active client policy configuration.
Policy(blob.Type) (wtpolicy.Policy, error)
// RegisteredTowers retrieves the list of watchtowers registered with // RegisteredTowers retrieves the list of watchtowers registered with
// the client. It returns a set of registered towers per client policy // the client. It returns a set of registered towers per client policy
// type. // type.
@@ -353,7 +356,7 @@ func (m *Manager) RegisteredTowers(opts ...wtdb.ClientSessionListOption) (
return nil, err return nil, err
} }
resp[client.Policy().BlobType] = towers resp[client.policy().BlobType] = towers
} }
return resp, nil return resp, nil
@@ -379,8 +382,23 @@ func (m *Manager) LookupTower(key *btcec.PublicKey,
return nil, err return nil, err
} }
resp[client.Policy().BlobType] = tower resp[client.policy().BlobType] = tower
} }
return resp, nil 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
}