diff --git a/node/status_node_services.go b/node/status_node_services.go index 39f171488..3e91b7c33 100644 --- a/node/status_node_services.go +++ b/node/status_node_services.go @@ -311,36 +311,36 @@ func (b *StatusNode) wakuService(wakuCfg *params.WakuConfig, clusterCfg *params. func (b *StatusNode) wakuV2Service(nodeConfig *params.NodeConfig, telemetryServerURL string) (*wakuv2.Waku, error) { if b.wakuV2Srvc == nil { cfg := &wakuv2.Config{ - MaxMessageSize: wakucommon.DefaultMaxMessageSize, - Host: nodeConfig.WakuV2Config.Host, - Port: nodeConfig.WakuV2Config.Port, - LightClient: nodeConfig.WakuV2Config.LightClient, - KeepAliveInterval: nodeConfig.WakuV2Config.KeepAliveInterval, - Rendezvous: nodeConfig.Rendezvous, - WakuNodes: nodeConfig.ClusterConfig.WakuNodes, - EnablePeerExchangeServer: nodeConfig.WakuV2Config.PeerExchange, - EnableStore: nodeConfig.WakuV2Config.EnableStore, - StoreCapacity: nodeConfig.WakuV2Config.StoreCapacity, - StoreSeconds: nodeConfig.WakuV2Config.StoreSeconds, - DiscoveryLimit: nodeConfig.WakuV2Config.DiscoveryLimit, - DiscV5BootstrapNodes: nodeConfig.ClusterConfig.DiscV5BootstrapNodes, - Nameserver: nodeConfig.WakuV2Config.Nameserver, - EnableDiscV5: nodeConfig.WakuV2Config.EnableDiscV5, - UDPPort: nodeConfig.WakuV2Config.UDPPort, - AutoUpdate: nodeConfig.WakuV2Config.AutoUpdate, - DefaultShardPubsubTopic: shard.DefaultShardPubsubTopic(), - UseShardAsDefaultTopic: nodeConfig.WakuV2Config.UseShardAsDefaultTopic, - TelemetryServerURL: telemetryServerURL, - ClusterID: nodeConfig.ClusterConfig.ClusterID, + MaxMessageSize: wakucommon.DefaultMaxMessageSize, + Host: nodeConfig.WakuV2Config.Host, + Port: nodeConfig.WakuV2Config.Port, + LightClient: nodeConfig.WakuV2Config.LightClient, + KeepAliveInterval: nodeConfig.WakuV2Config.KeepAliveInterval, + Rendezvous: nodeConfig.Rendezvous, + WakuNodes: nodeConfig.ClusterConfig.WakuNodes, + EnableStore: nodeConfig.WakuV2Config.EnableStore, + StoreCapacity: nodeConfig.WakuV2Config.StoreCapacity, + StoreSeconds: nodeConfig.WakuV2Config.StoreSeconds, + DiscoveryLimit: nodeConfig.WakuV2Config.DiscoveryLimit, + DiscV5BootstrapNodes: nodeConfig.ClusterConfig.DiscV5BootstrapNodes, + Nameserver: nodeConfig.WakuV2Config.Nameserver, + UDPPort: nodeConfig.WakuV2Config.UDPPort, + AutoUpdate: nodeConfig.WakuV2Config.AutoUpdate, + DefaultShardPubsubTopic: shard.DefaultShardPubsubTopic(), + UseShardAsDefaultTopic: nodeConfig.WakuV2Config.UseShardAsDefaultTopic, + TelemetryServerURL: telemetryServerURL, + ClusterID: nodeConfig.ClusterConfig.ClusterID, } - // apply peer exchange settings + // Configure peer exchange and discv5 settings based on node type if cfg.LightClient { cfg.EnablePeerExchangeServer = false cfg.EnablePeerExchangeClient = true + cfg.EnableDiscV5 = false } else { cfg.EnablePeerExchangeServer = true cfg.EnablePeerExchangeClient = false + cfg.EnableDiscV5 = true } if nodeConfig.WakuV2Config.MaxMessageSize > 0 { diff --git a/params/config.go b/params/config.go index 8f1a5909e..6e298f438 100644 --- a/params/config.go +++ b/params/config.go @@ -196,6 +196,7 @@ type WakuV2Config struct { Nameserver string // EnableDiscV5 indicates if DiscoveryV5 is enabled or not + // Deprecated: will be calculated based on LightClient EnableDiscV5 bool // UDPPort number to start discovery v5 diff --git a/wakuv2/config.go b/wakuv2/config.go index 966c4c232..dd838bdb9 100644 --- a/wakuv2/config.go +++ b/wakuv2/config.go @@ -21,6 +21,8 @@ package wakuv2 import ( "errors" + "go.uber.org/zap" + "github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/status-im/status-go/protocol/common/shard" @@ -30,6 +32,11 @@ import ( "github.com/status-im/status-go/wakuv2/common" ) +var ( + ErrBadLightClientConfig = errors.New("either peer exchange server or discv5 must be disabled, and the peer exchange client must be enabled") + ErrBadFullNodeConfig = errors.New("peer exchange server and discv5 must be enabled, and the peer exchange client must be disabled") +) + // Config represents the configuration state of a waku node. type Config struct { MaxMessageSize uint32 `toml:",omitempty"` // Maximal message length allowed by the waku node @@ -61,12 +68,14 @@ type Config struct { SkipPublishToTopic bool `toml:",omitempty"` // Used in testing } -func (c *Config) Validate() error { +func (c *Config) Validate(logger *zap.Logger) error { if c.LightClient && (c.EnablePeerExchangeServer || c.EnableDiscV5 || !c.EnablePeerExchangeClient) { - return errors.New("bad configuration for a light client: either peer exchange server or discv5 must be disabled, and the peer exchange client must be enabled") + logger.Warn("bad configuration for a light client", zap.Error(ErrBadLightClientConfig)) + return nil } if !c.LightClient && (!c.EnablePeerExchangeServer || !c.EnableDiscV5 || c.EnablePeerExchangeClient) { - return errors.New("bad configuration for a full node: peer exchange server and discv5 must be enabled, and the peer exchange client must be disabled") + logger.Warn("bad configuration for a full node", zap.Error(ErrBadFullNodeConfig)) + return nil } return nil } diff --git a/wakuv2/waku.go b/wakuv2/waku.go index 77dbad789..776bdd99d 100644 --- a/wakuv2/waku.go +++ b/wakuv2/waku.go @@ -170,8 +170,8 @@ func New(nodeKey string, fleet string, cfg *Config, logger *zap.Logger, appDB *s } cfg = setDefaults(cfg) - if err = cfg.Validate(); err != nil { - logger.Warn("bad wakuv2 configuration", zap.Error(err)) + if err = cfg.Validate(logger); err != nil { + return nil, err } logger.Info("starting wakuv2 with config", zap.Any("config", cfg))