multi: update node announcement features in feature manager first

Move merge of our features into the feature manager, rather than
updating our node announcement then retrospectively setting the
feature manger's set to the new vector. This allows us to use the
feature vector as our single source of truth for announcements.
This commit is contained in:
Carla Kirk-Cohen committed 2023-05-04 10:35:46 -04:00
1 parent 019127c4f4
commit e41c65785f
6 files changed
+90 -40

No files matched your search

+6 -3
View File
@@ -23,7 +23,10 @@ type Config struct {
// ParseAddr parses an address from its string format to a net.Addr.
ParseAddr func(addr string) (net.Addr, error)
// UpdateNodeAnnouncement updates our node announcement applying the
// given NodeAnnModifiers and broadcasts the new version to the network.
UpdateNodeAnnouncement func(...netann.NodeAnnModifier) error
// UpdateNodeAnnouncement updates and broadcasts our node announcement,
// setting the feature vector provided and applying the
// NodeAnnModifiers. If no feature updates are required, a nil feature
// vector should be provided.
UpdateNodeAnnouncement func(features *lnwire.RawFeatureVector,
mods ...netann.NodeAnnModifier) error
}
+14 -11
View File
@@ -315,20 +315,21 @@ func (s *Server) UpdateNodeAnnouncement(_ context.Context,
currentNodeAnn := s.cfg.GetNodeAnnouncement()
if len(req.FeatureUpdates) > 0 {
features, ops, err := s.updateFeatures(
currentNodeAnn.Features,
req.FeatureUpdates,
nodeAnnFeatures := currentNodeAnn.Features
featureUpdates := len(req.FeatureUpdates) > 0
if featureUpdates {
var (
ops *lnrpc.Op
err error
)
nodeAnnFeatures, ops, err = s.updateFeatures(
nodeAnnFeatures, req.FeatureUpdates,
)
if err != nil {
return nil, fmt.Errorf("error trying to update node "+
"features: %w", err)
}
resp.Ops = append(resp.Ops, ops)
nodeModifiers = append(
nodeModifiers,
netann.NodeAnnSetFeatures(features),
)
}
if req.Color != "" {
@@ -386,12 +387,14 @@ func (s *Server) UpdateNodeAnnouncement(_ context.Context,
)
}
if len(nodeModifiers) == 0 {
return nil, fmt.Errorf("unable detect any new values to " +
if len(nodeModifiers) == 0 && !featureUpdates {
return nil, fmt.Errorf("unable to detect any new values to " +
"update the node announcement")
}
if err := s.cfg.UpdateNodeAnnouncement(nodeModifiers...); err != nil {
if err := s.cfg.UpdateNodeAnnouncement(
nodeAnnFeatures, nodeModifiers...,
); err != nil {
return nil, err
}