wtclient: add anchor-aware session negotiation and filtering
This commit is contained in:
parent
eb00e496bf
commit
781c6e5bea
@ -41,13 +41,14 @@ const (
|
|||||||
DefaultForceQuitDelay = 10 * time.Second
|
DefaultForceQuitDelay = 10 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// genActiveSessionFilter generates a filter that selects active sessions that
|
||||||
// activeSessionFilter is a filter that ignored any sessions which are
|
// also match the desired channel type, either legacy or anchor.
|
||||||
// not active.
|
func genActiveSessionFilter(anchor bool) func(*wtdb.ClientSession) bool {
|
||||||
activeSessionFilter = func(s *wtdb.ClientSession) bool {
|
return func(s *wtdb.ClientSession) bool {
|
||||||
return s.Status == wtdb.CSessionActive
|
return s.Status == wtdb.CSessionActive &&
|
||||||
|
anchor == s.Policy.IsAnchorChannel()
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
|
|
||||||
// RegisteredTower encompasses information about a registered watchtower with
|
// RegisteredTower encompasses information about a registered watchtower with
|
||||||
// the client.
|
// the client.
|
||||||
@ -280,6 +281,8 @@ func New(config *Config) (*TowerClient, error) {
|
|||||||
// the client. We will use any of these session if their policies match
|
// the client. We will use any of these session if their policies match
|
||||||
// the current policy of the client, otherwise they will be ignored and
|
// the current policy of the client, otherwise they will be ignored and
|
||||||
// new sessions will be requested.
|
// new sessions will be requested.
|
||||||
|
isAnchorClient := cfg.Policy.IsAnchorChannel()
|
||||||
|
activeSessionFilter := genActiveSessionFilter(isAnchorClient)
|
||||||
candidateSessions, err := getClientSessions(
|
candidateSessions, err := getClientSessions(
|
||||||
cfg.DB, cfg.SecretKeyRing, nil, activeSessionFilter,
|
cfg.DB, cfg.SecretKeyRing, nil, activeSessionFilter,
|
||||||
)
|
)
|
||||||
@ -1068,6 +1071,8 @@ func (c *TowerClient) handleNewTower(msg *newTowerMsg) error {
|
|||||||
c.candidateTowers.AddCandidate(tower)
|
c.candidateTowers.AddCandidate(tower)
|
||||||
|
|
||||||
// Include all of its corresponding sessions to our set of candidates.
|
// Include all of its corresponding sessions to our set of candidates.
|
||||||
|
isAnchorClient := c.cfg.Policy.IsAnchorChannel()
|
||||||
|
activeSessionFilter := genActiveSessionFilter(isAnchorClient)
|
||||||
sessions, err := getClientSessions(
|
sessions, err := getClientSessions(
|
||||||
c.cfg.DB, c.cfg.SecretKeyRing, &tower.ID, activeSessionFilter,
|
c.cfg.DB, c.cfg.SecretKeyRing, &tower.ID, activeSessionFilter,
|
||||||
)
|
)
|
||||||
|
@ -112,8 +112,19 @@ var _ SessionNegotiator = (*sessionNegotiator)(nil)
|
|||||||
|
|
||||||
// newSessionNegotiator initializes a fresh sessionNegotiator instance.
|
// newSessionNegotiator initializes a fresh sessionNegotiator instance.
|
||||||
func newSessionNegotiator(cfg *NegotiatorConfig) *sessionNegotiator {
|
func newSessionNegotiator(cfg *NegotiatorConfig) *sessionNegotiator {
|
||||||
|
// Generate the set of features the negitator will present to the tower
|
||||||
|
// upon connection. For anchor channels, we'll conditionally signal that
|
||||||
|
// we require support for anchor channels depdening on the requested
|
||||||
|
// policy.
|
||||||
|
features := []lnwire.FeatureBit{
|
||||||
|
wtwire.AltruistSessionsRequired,
|
||||||
|
}
|
||||||
|
if cfg.Policy.IsAnchorChannel() {
|
||||||
|
features = append(features, wtwire.AnchorCommitRequired)
|
||||||
|
}
|
||||||
|
|
||||||
localInit := wtwire.NewInitMessage(
|
localInit := wtwire.NewInitMessage(
|
||||||
lnwire.NewRawFeatureVector(wtwire.AltruistSessionsRequired),
|
lnwire.NewRawFeatureVector(features...),
|
||||||
cfg.ChainHash,
|
cfg.ChainHash,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user