fix: setup shards (#1256)

This commit is contained in:
richΛrd 2024-11-22 09:36:02 -04:00 committed by GitHub
parent dd82c24e00
commit 96702e278b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 12 deletions

View File

@ -309,11 +309,6 @@ func Execute(options NodeOptions) error {
nodeOpts = append(nodeOpts, discv5Opts) nodeOpts = append(nodeOpts, discv5Opts)
} }
wakuNode, err := node.New(nodeOpts...)
if err != nil {
return fmt.Errorf("could not instantiate waku: %w", err)
}
//Process pubSub and contentTopics specified and arrive at all corresponding pubSubTopics //Process pubSub and contentTopics specified and arrive at all corresponding pubSubTopics
pubSubTopicMap, err := processTopics(options) pubSubTopicMap, err := processTopics(options)
if err != nil { if err != nil {
@ -325,6 +320,22 @@ func Execute(options NodeOptions) error {
pubSubTopicMapKeys = append(pubSubTopicMapKeys, k) pubSubTopicMapKeys = append(pubSubTopicMapKeys, k)
} }
rs, err := wprotocol.TopicsToRelayShards(pubSubTopicMapKeys...)
if err == nil {
if len(rs) == 1 {
nodeOpts = append(nodeOpts, node.WithShards(rs[0].ShardIDs))
} else {
logger.Warn("could not set ENR shard info", zap.String("error", "invalid number of clusters found"), zap.Int("numClusters", len(rs)))
}
} else {
logger.Warn("could not obtain list of shards", zap.Error(err))
}
wakuNode, err := node.New(nodeOpts...)
if err != nil {
return fmt.Errorf("could not instantiate waku: %w", err)
}
if err = wakuNode.Start(ctx); err != nil { if err = wakuNode.Start(ctx); err != nil {
return nonRecoverError(err) return nonRecoverError(err)
} }

View File

@ -464,13 +464,17 @@ func (w *WakuNode) Start(ctx context.Context) error {
if err != nil { if err != nil {
return err return err
} }
//TODO: setting this up temporarily to improve connectivity success for lightNode in status. }
//This will have to be removed or changed with community sharding will be implemented.
if w.opts.shards != nil { //TODO: setting this up temporarily to improve connectivity success for lightNode
err = w.SetRelayShards(*w.opts.shards) // in status. Also, when executing go-waku service-node as a lightclient
if err != nil { // (using --pubsub-topic and --relay=false)
return err // This will have to be removed or changed with community sharding will be
} // implemented.
if w.opts.shards != nil {
err = w.SetRelayShards(*w.opts.shards)
if err != nil {
return err
} }
} }