address review feedback

This commit is contained in:
frank 2024-03-01 13:43:07 +08:00
parent 3de945feaf
commit 881da9e654
4 changed files with 37 additions and 27 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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
}

View File

@ -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))