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

@ -318,14 +318,12 @@ func (b *StatusNode) wakuV2Service(nodeConfig *params.NodeConfig, telemetryServe
KeepAliveInterval: nodeConfig.WakuV2Config.KeepAliveInterval, KeepAliveInterval: nodeConfig.WakuV2Config.KeepAliveInterval,
Rendezvous: nodeConfig.Rendezvous, Rendezvous: nodeConfig.Rendezvous,
WakuNodes: nodeConfig.ClusterConfig.WakuNodes, WakuNodes: nodeConfig.ClusterConfig.WakuNodes,
EnablePeerExchangeServer: nodeConfig.WakuV2Config.PeerExchange,
EnableStore: nodeConfig.WakuV2Config.EnableStore, EnableStore: nodeConfig.WakuV2Config.EnableStore,
StoreCapacity: nodeConfig.WakuV2Config.StoreCapacity, StoreCapacity: nodeConfig.WakuV2Config.StoreCapacity,
StoreSeconds: nodeConfig.WakuV2Config.StoreSeconds, StoreSeconds: nodeConfig.WakuV2Config.StoreSeconds,
DiscoveryLimit: nodeConfig.WakuV2Config.DiscoveryLimit, DiscoveryLimit: nodeConfig.WakuV2Config.DiscoveryLimit,
DiscV5BootstrapNodes: nodeConfig.ClusterConfig.DiscV5BootstrapNodes, DiscV5BootstrapNodes: nodeConfig.ClusterConfig.DiscV5BootstrapNodes,
Nameserver: nodeConfig.WakuV2Config.Nameserver, Nameserver: nodeConfig.WakuV2Config.Nameserver,
EnableDiscV5: nodeConfig.WakuV2Config.EnableDiscV5,
UDPPort: nodeConfig.WakuV2Config.UDPPort, UDPPort: nodeConfig.WakuV2Config.UDPPort,
AutoUpdate: nodeConfig.WakuV2Config.AutoUpdate, AutoUpdate: nodeConfig.WakuV2Config.AutoUpdate,
DefaultShardPubsubTopic: shard.DefaultShardPubsubTopic(), DefaultShardPubsubTopic: shard.DefaultShardPubsubTopic(),
@ -334,13 +332,15 @@ func (b *StatusNode) wakuV2Service(nodeConfig *params.NodeConfig, telemetryServe
ClusterID: nodeConfig.ClusterConfig.ClusterID, ClusterID: nodeConfig.ClusterConfig.ClusterID,
} }
// apply peer exchange settings // Configure peer exchange and discv5 settings based on node type
if cfg.LightClient { if cfg.LightClient {
cfg.EnablePeerExchangeServer = false cfg.EnablePeerExchangeServer = false
cfg.EnablePeerExchangeClient = true cfg.EnablePeerExchangeClient = true
cfg.EnableDiscV5 = false
} else { } else {
cfg.EnablePeerExchangeServer = true cfg.EnablePeerExchangeServer = true
cfg.EnablePeerExchangeClient = false cfg.EnablePeerExchangeClient = false
cfg.EnableDiscV5 = true
} }
if nodeConfig.WakuV2Config.MaxMessageSize > 0 { if nodeConfig.WakuV2Config.MaxMessageSize > 0 {

View File

@ -196,6 +196,7 @@ type WakuV2Config struct {
Nameserver string Nameserver string
// EnableDiscV5 indicates if DiscoveryV5 is enabled or not // EnableDiscV5 indicates if DiscoveryV5 is enabled or not
// Deprecated: will be calculated based on LightClient
EnableDiscV5 bool EnableDiscV5 bool
// UDPPort number to start discovery v5 // UDPPort number to start discovery v5

View File

@ -21,6 +21,8 @@ package wakuv2
import ( import (
"errors" "errors"
"go.uber.org/zap"
"github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/waku-org/go-waku/waku/v2/protocol/relay"
"github.com/status-im/status-go/protocol/common/shard" "github.com/status-im/status-go/protocol/common/shard"
@ -30,6 +32,11 @@ import (
"github.com/status-im/status-go/wakuv2/common" "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. // Config represents the configuration state of a waku node.
type Config struct { type Config struct {
MaxMessageSize uint32 `toml:",omitempty"` // Maximal message length allowed by the waku node 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 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) { 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) { 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 return nil
} }

View File

@ -170,8 +170,8 @@ func New(nodeKey string, fleet string, cfg *Config, logger *zap.Logger, appDB *s
} }
cfg = setDefaults(cfg) cfg = setDefaults(cfg)
if err = cfg.Validate(); err != nil { if err = cfg.Validate(logger); err != nil {
logger.Warn("bad wakuv2 configuration", zap.Error(err)) return nil, err
} }
logger.Info("starting wakuv2 with config", zap.Any("config", cfg)) logger.Info("starting wakuv2 with config", zap.Any("config", cfg))