mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-08 17:03:09 +00:00
more params
This commit is contained in:
parent
942fff1236
commit
b1c1c148b5
@ -21,6 +21,7 @@ suite "Waku Conf - build with cluster conf":
|
||||
builder.withP2pTcpPort(60000)
|
||||
builder.withMaxConnections(10)
|
||||
builder.discv5Conf.withUdpPort(9000)
|
||||
builder.withRelayServiceRatio("50:50")
|
||||
# Mount all shards in network
|
||||
let expectedShards = toSeq[0.uint16 .. 7.uint16]
|
||||
|
||||
@ -65,6 +66,7 @@ suite "Waku Conf - build with cluster conf":
|
||||
var builder = WakuConfBuilder.init()
|
||||
builder.withP2pTcpPort(60000)
|
||||
builder.withMaxConnections(10)
|
||||
builder.withRelayServiceRatio("50:50")
|
||||
builder.discv5Conf.withUdpPort(9000)
|
||||
# Mount all shards in network
|
||||
let expectedShards = toSeq[0.uint16 .. 7.uint16]
|
||||
@ -99,6 +101,7 @@ suite "Waku Conf - build with cluster conf":
|
||||
var builder = WakuConfBuilder.init()
|
||||
builder.withP2pTcpPort(60000)
|
||||
builder.withMaxConnections(10)
|
||||
builder.withRelayServiceRatio("50:50")
|
||||
builder.discv5Conf.withUdpPort(9000)
|
||||
|
||||
let # Mount all shards in network
|
||||
@ -135,6 +138,7 @@ suite "Waku Conf - build with cluster conf":
|
||||
builder.withP2pTcpPort(60000)
|
||||
builder.discv5Conf.withUdpPort(9000)
|
||||
builder.withMaxConnections(10)
|
||||
builder.withRelayServiceRatio("50:50")
|
||||
let shards = @[2.uint16, 3.uint16]
|
||||
|
||||
## Given
|
||||
@ -166,6 +170,7 @@ suite "Waku Conf - build with cluster conf":
|
||||
builder.withP2pTcpPort(60000)
|
||||
builder.discv5Conf.withUdpPort(9000)
|
||||
builder.withMaxConnections(10)
|
||||
builder.withRelayServiceRatio("50:50")
|
||||
let shards = @[2.uint16, 10.uint16]
|
||||
|
||||
## Given
|
||||
@ -189,6 +194,7 @@ suite "Waku Conf - build with cluster conf":
|
||||
builder.discv5Conf.withUdpPort(9000)
|
||||
builder.withMaxConnections(10)
|
||||
builder.rlnRelayConf.withEthClientAddress("https://my_eth_rpc_url/")
|
||||
builder.withRelayServiceRatio("50:50")
|
||||
|
||||
# Mount all shards in network
|
||||
let expectedShards = toSeq[0.uint16 .. 7.uint16]
|
||||
@ -237,6 +243,7 @@ suite "Waku Conf - node key":
|
||||
builder.withP2pTcpPort(60000)
|
||||
builder.discv5Conf.withUdpPort(9000)
|
||||
builder.withMaxConnections(10)
|
||||
builder.withRelayServiceRatio("50:50")
|
||||
|
||||
## Given
|
||||
|
||||
@ -263,6 +270,7 @@ suite "Waku Conf - node key":
|
||||
builder.withP2pTcpPort(60000)
|
||||
builder.withMaxConnections(10)
|
||||
builder.discv5Conf.withUdpPort(9000)
|
||||
builder.withRelayServiceRatio("50:50")
|
||||
|
||||
## Given
|
||||
builder.withNodeKey(nodeKey)
|
||||
@ -287,6 +295,7 @@ suite "Waku Conf - extMultiaddrs":
|
||||
builder.withP2pTcpPort(60000)
|
||||
builder.discv5Conf.withUdpPort(9000)
|
||||
builder.withMaxConnections(10)
|
||||
builder.withRelayServiceRatio("50:50")
|
||||
|
||||
## Given
|
||||
let multiaddrs =
|
||||
|
||||
@ -196,7 +196,7 @@ type WakuNodeConf* = object
|
||||
.}: seq[string]
|
||||
|
||||
extMultiAddrsOnly* {.
|
||||
desc: "Only announce external multiaddresses",
|
||||
desc: "Only announce external multiaddresses setup with --ext-multiaddr",
|
||||
defaultValue: false,
|
||||
name: "ext-multiaddr-only"
|
||||
.}: bool
|
||||
|
||||
@ -161,7 +161,7 @@ proc setupProtocols(
|
||||
## Optionally include persistent message storage.
|
||||
## No protocols are started yet.
|
||||
|
||||
if conf.discv5Only:
|
||||
if conf.discv5Conf.isSome and conf.discv5Conf.get().discv5Only:
|
||||
notice "Running node only with Discv5, not mounting additional protocols"
|
||||
return ok()
|
||||
|
||||
|
||||
@ -19,9 +19,15 @@ type
|
||||
|
||||
# TODO: this should come from discv5 discovery module
|
||||
type Discv5Conf* = ref object
|
||||
# TODO: This should probably be an option on the builder
|
||||
# But translated to everything else "false" on the config
|
||||
discv5Only*: bool
|
||||
bootstrapNodes*: seq[TextEnr]
|
||||
udpPort*: Port
|
||||
|
||||
type Storeconf* = ref object
|
||||
legacy*: bool
|
||||
|
||||
# TODO: this should come from RLN relay module
|
||||
type RlnRelayConf* = ref object
|
||||
ethContractAddress*: ContractAddress
|
||||
@ -52,7 +58,6 @@ type WakuConf* = ref object
|
||||
shards*: seq[uint16]
|
||||
|
||||
relay*: bool
|
||||
store*: bool
|
||||
filter*: bool
|
||||
lightPush*: bool
|
||||
peerExchange*: bool
|
||||
@ -62,6 +67,8 @@ type WakuConf* = ref object
|
||||
|
||||
discv5Conf*: Option[Discv5Conf]
|
||||
|
||||
storeConf*: Option[StoreConf]
|
||||
|
||||
rlnRelayConf*: Option[RlnRelayConf]
|
||||
|
||||
maxMessageSizeBytes*: int
|
||||
@ -102,7 +109,7 @@ proc log*(conf: WakuConf) =
|
||||
info "Configuration: Enabled protocols",
|
||||
relay = conf.relay,
|
||||
rlnRelay = conf.rlnRelayConf.isSome,
|
||||
store = conf.store,
|
||||
store = conf.storeConf.isSome,
|
||||
filter = conf.filter,
|
||||
lightPush = conf.lightPush,
|
||||
peerExchange = conf.peerExchange
|
||||
@ -145,6 +152,9 @@ proc validateNoEmptyStrings(wakuConf: WakuConf): Result[void, string] =
|
||||
if isEmptyOrWhiteSpace(wakuConf.dns4DomainName.get().string):
|
||||
return err("dns4DomainName is an empty string, set it to none(string) instead")
|
||||
|
||||
if isEmptyOrWhiteSpace(wakuConf.relayServiceRatio):
|
||||
return err("relayServiceRatio is an empty string")
|
||||
|
||||
return ok()
|
||||
|
||||
proc validate*(wakuConf: WakuConf): Result[void, string] =
|
||||
|
||||
@ -125,13 +125,32 @@ proc build*(builder: RlnRelayConfBuilder): Result[Option[RlnRelayConf], string]
|
||||
)
|
||||
)
|
||||
|
||||
###########################
|
||||
## Store Config Builder ##
|
||||
###########################
|
||||
type StoreConfBuilder = ref object
|
||||
store: Option[bool]
|
||||
legacy: Option[bool]
|
||||
|
||||
proc init(T: type StoreConfBuilder): StoreConfBuilder =
|
||||
StoreConfBuilder()
|
||||
|
||||
with(StoreConfBuilder, store, bool)
|
||||
with(StoreConfBuilder, legacy, bool)
|
||||
|
||||
proc build(builder: StoreConfBuilder): Result[Option[StoreConf], string] =
|
||||
if builder.store.get(false):
|
||||
return ok(none(StoreConf))
|
||||
|
||||
return ok(some(StoreConf(legacy: builder.legacy.get(true))))
|
||||
|
||||
###########################
|
||||
## Discv5 Config Builder ##
|
||||
###########################
|
||||
type Discv5ConfBuilder = ref object
|
||||
discv5*: Option[bool]
|
||||
bootstrapNodes*: Option[seq[TextEnr]]
|
||||
udpPort*: Option[Port]
|
||||
discv5: Option[bool]
|
||||
bootstrapNodes: Option[seq[TextEnr]]
|
||||
udpPort: Option[Port]
|
||||
|
||||
proc init(T: type Discv5ConfBuilder): Discv5ConfBuilder =
|
||||
Discv5ConfBuilder()
|
||||
@ -149,7 +168,7 @@ proc withBootstrapNodes(builder: var Discv5ConfBuilder, bootstrapNodes: seq[stri
|
||||
)
|
||||
|
||||
proc build(builder: Discv5ConfBuilder): Result[Option[Discv5Conf], string] =
|
||||
if builder.discv5.isNone or not builder.discv5.get():
|
||||
if not builder.discv5.get(false):
|
||||
return ok(none(Discv5Conf))
|
||||
|
||||
# TODO: Do we need to ensure there are bootstrap nodes?
|
||||
@ -233,15 +252,16 @@ type WakuConfBuilder* = ref object
|
||||
shards: Option[seq[uint16]]
|
||||
|
||||
relay: Option[bool]
|
||||
store: Option[bool]
|
||||
filter: Option[bool]
|
||||
lightPush: Option[bool]
|
||||
peerExchange: Option[bool]
|
||||
storeSync: Option[bool]
|
||||
relayPeerExchange: Option[bool]
|
||||
discv5Only: Option[bool]
|
||||
|
||||
clusterConf: Option[ClusterConf]
|
||||
|
||||
storeConf: StoreConfBuilder
|
||||
rlnRelayConf*: RlnRelayConfBuilder
|
||||
|
||||
maxMessageSizeBytes: Option[int]
|
||||
@ -262,11 +282,12 @@ type WakuConfBuilder* = ref object
|
||||
|
||||
webSocketConf*: WebSocketConfBuilder
|
||||
|
||||
dnsAddrs*: Option[bool]
|
||||
dnsAddrs: Option[bool]
|
||||
dnsAddrsNameServers: Option[seq[IpAddress]]
|
||||
peerPersistence: Option[bool]
|
||||
peerStoreCapacity: Option[int]
|
||||
maxConnections: Option[int]
|
||||
colocationLimit: Option[int]
|
||||
|
||||
agentString: Option[string]
|
||||
|
||||
@ -276,9 +297,9 @@ type WakuConfBuilder* = ref object
|
||||
relayShardedPeerManagement: Option[bool]
|
||||
relayServiceRatio: Option[string]
|
||||
|
||||
|
||||
proc init*(T: type WakuConfBuilder): WakuConfBuilder =
|
||||
WakuConfBuilder(
|
||||
storeConf: StoreConfBuilder.init(),
|
||||
rlnRelayConf: RlnRelayConfBuilder.init(),
|
||||
discv5Conf: Discv5ConfBuilder.init(),
|
||||
webSocketConf: WebSocketConfBuilder.init(),
|
||||
@ -320,6 +341,92 @@ proc nodeKey(
|
||||
return err("Failed to generate key: " & $error)
|
||||
return ok(nodeKey)
|
||||
|
||||
proc applyPresetConf(builder: var WakuConfBuilder) =
|
||||
# Apply cluster conf - values passed manually override cluster conf
|
||||
# Should be applied **first**, before individual values are pulled
|
||||
if builder.clusterConf.isNone:
|
||||
return
|
||||
var clusterConf = builder.clusterConf.get()
|
||||
|
||||
if builder.clusterId.isNone:
|
||||
builder.clusterId = some(clusterConf.clusterId)
|
||||
else:
|
||||
warn "Cluster id was manually provided alongside a cluster conf",
|
||||
used = builder.clusterId, discarded = clusterConf.clusterId
|
||||
|
||||
# Apply relay parameters
|
||||
if builder.relay.get(false) and clusterConf.rlnRelay:
|
||||
var rlnRelayConf = builder.rlnRelayConf
|
||||
|
||||
if rlnRelayConf.rlnRelay.isNone:
|
||||
rlnRelayConf.withRlnRelay(true)
|
||||
else:
|
||||
warn "RLN Relay was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.rlnRelay, discarded = clusterConf.rlnRelay
|
||||
|
||||
if rlnRelayConf.ethContractAddress.isNone:
|
||||
rlnRelayConf.withEthContractAddress(clusterConf.rlnRelayEthContractAddress)
|
||||
else:
|
||||
warn "RLN Relay ETH Contract Address was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.ethContractAddress.get().string,
|
||||
discarded = clusterConf.rlnRelayEthContractAddress.string
|
||||
|
||||
if rlnRelayConf.chainId.isNone:
|
||||
rlnRelayConf.withChainId(clusterConf.rlnRelayChainId)
|
||||
else:
|
||||
warn "RLN Relay Chain Id was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.chainId, discarded = clusterConf.rlnRelayChainId
|
||||
|
||||
if rlnRelayConf.dynamic.isNone:
|
||||
rlnRelayConf.withDynamic(clusterConf.rlnRelayDynamic)
|
||||
else:
|
||||
warn "RLN Relay Dynamic was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.dynamic, discarded = clusterConf.rlnRelayDynamic
|
||||
|
||||
if rlnRelayConf.bandwidthThreshold.isNone:
|
||||
rlnRelayConf.withBandwidthThreshold(clusterConf.rlnRelayBandwidthThreshold)
|
||||
else:
|
||||
warn "RLN Relay Bandwidth Threshold was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.bandwidthThreshold,
|
||||
discarded = clusterConf.rlnRelayBandwidthThreshold
|
||||
|
||||
if rlnRelayConf.epochSizeSec.isNone:
|
||||
rlnRelayConf.withEpochSizeSec(clusterConf.rlnEpochSizeSec)
|
||||
else:
|
||||
warn "RLN Epoch Size in Seconds was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.epochSizeSec, discarded = clusterConf.rlnEpochSizeSec
|
||||
|
||||
if rlnRelayConf.userMessageLimit.isNone:
|
||||
rlnRelayConf.withUserMessageLimit(clusterConf.rlnRelayUserMessageLimit)
|
||||
else:
|
||||
warn "RLN Relay Dynamic was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.userMessageLimit,
|
||||
discarded = clusterConf.rlnRelayUserMessageLimit
|
||||
# End Apply relay parameters
|
||||
|
||||
if builder.maxMessageSizeBytes.isNone:
|
||||
builder.maxMessageSizeBytes =
|
||||
some(int(parseCorrectMsgSize(clusterConf.maxMessageSize)))
|
||||
else:
|
||||
warn "Max Message Size was manually provided alongside a cluster conf",
|
||||
used = builder.maxMessageSizeBytes, discarded = clusterConf.maxMessageSize
|
||||
|
||||
if builder.numShardsInNetwork.isNone:
|
||||
builder.numShardsInNetwork = some(clusterConf.numShardsInNetwork)
|
||||
else:
|
||||
warn "Num Shards In Network was manually provided alongside a cluster conf",
|
||||
used = builder.numShardsInNetwork, discarded = clusterConf.numShardsInNetwork
|
||||
|
||||
if clusterConf.discv5Discovery:
|
||||
var discv5ConfBuilder = builder.discv5Conf
|
||||
|
||||
if discv5ConfBuilder.discv5.isNone:
|
||||
discv5ConfBuilder.withDiscv5(clusterConf.discv5Discovery)
|
||||
|
||||
if discv5ConfBuilder.bootstrapNodes.isNone and
|
||||
clusterConf.discv5BootstrapNodes.len > 0:
|
||||
discv5ConfBuilder.withBootstrapNodes(clusterConf.discv5BootstrapNodes)
|
||||
|
||||
proc build*(
|
||||
builder: var WakuConfBuilder, rng: ref HmacDrbgContext = crypto.newRng()
|
||||
): Result[WakuConf, string] =
|
||||
@ -335,13 +442,6 @@ proc build*(
|
||||
warn "whether to mount relay is not specified, defaulting to not mounting"
|
||||
false
|
||||
|
||||
let store =
|
||||
if builder.store.isSome:
|
||||
builder.store.get()
|
||||
else:
|
||||
warn "whether to mount store is not specified, defaulting to not mounting"
|
||||
false
|
||||
|
||||
let filter =
|
||||
if builder.filter.isSome:
|
||||
builder.filter.get()
|
||||
@ -372,88 +472,7 @@ proc build*(
|
||||
|
||||
let relayPeerExchange = builder.relayPeerExchange.get(false)
|
||||
|
||||
# Apply cluster conf - values passed manually override cluster conf
|
||||
# Should be applied **first**, before individual values are pulled
|
||||
if builder.clusterConf.isSome:
|
||||
var clusterConf = builder.clusterConf.get()
|
||||
|
||||
if builder.clusterId.isNone:
|
||||
builder.clusterId = some(clusterConf.clusterId)
|
||||
else:
|
||||
warn "Cluster id was manually provided alongside a cluster conf",
|
||||
used = builder.clusterId, discarded = clusterConf.clusterId
|
||||
|
||||
if relay and clusterConf.rlnRelay:
|
||||
var rlnRelayConf = builder.rlnRelayConf
|
||||
|
||||
if rlnRelayConf.rlnRelay.isNone:
|
||||
rlnRelayConf.withRlnRelay(true)
|
||||
else:
|
||||
warn "RLN Relay was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.rlnRelay, discarded = clusterConf.rlnRelay
|
||||
|
||||
if rlnRelayConf.ethContractAddress.isNone:
|
||||
rlnRelayConf.withEthContractAddress(clusterConf.rlnRelayEthContractAddress)
|
||||
else:
|
||||
warn "RLN Relay ETH Contract Address was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.ethContractAddress.get().string,
|
||||
discarded = clusterConf.rlnRelayEthContractAddress.string
|
||||
|
||||
if rlnRelayConf.chainId.isNone:
|
||||
rlnRelayConf.withChainId(clusterConf.rlnRelayChainId)
|
||||
else:
|
||||
warn "RLN Relay Chain Id was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.chainId, discarded = clusterConf.rlnRelayChainId
|
||||
|
||||
if rlnRelayConf.dynamic.isNone:
|
||||
rlnRelayConf.withDynamic(clusterConf.rlnRelayDynamic)
|
||||
else:
|
||||
warn "RLN Relay Dynamic was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.dynamic, discarded = clusterConf.rlnRelayDynamic
|
||||
|
||||
if rlnRelayConf.bandwidthThreshold.isNone:
|
||||
rlnRelayConf.withBandwidthThreshold(clusterConf.rlnRelayBandwidthThreshold)
|
||||
else:
|
||||
warn "RLN Relay Bandwidth Threshold was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.bandwidthThreshold,
|
||||
discarded = clusterConf.rlnRelayBandwidthThreshold
|
||||
|
||||
if rlnRelayConf.epochSizeSec.isNone:
|
||||
rlnRelayConf.withEpochSizeSec(clusterConf.rlnEpochSizeSec)
|
||||
else:
|
||||
warn "RLN Epoch Size in Seconds was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.epochSizeSec, discarded = clusterConf.rlnEpochSizeSec
|
||||
|
||||
if rlnRelayConf.userMessageLimit.isNone:
|
||||
rlnRelayConf.withUserMessageLimit(clusterConf.rlnRelayUserMessageLimit)
|
||||
else:
|
||||
warn "RLN Relay Dynamic was manually provided alongside a cluster conf",
|
||||
used = rlnRelayConf.userMessageLimit,
|
||||
discarded = clusterConf.rlnRelayUserMessageLimit
|
||||
|
||||
if builder.maxMessageSizeBytes.isNone:
|
||||
builder.maxMessageSizeBytes =
|
||||
some(int(parseCorrectMsgSize(clusterConf.maxMessageSize)))
|
||||
else:
|
||||
warn "Max Message Size was manually provided alongside a cluster conf",
|
||||
used = builder.maxMessageSizeBytes, discarded = clusterConf.maxMessageSize
|
||||
|
||||
if builder.numShardsInNetwork.isNone:
|
||||
builder.numShardsInNetwork = some(clusterConf.numShardsInNetwork)
|
||||
else:
|
||||
warn "Num Shards In Network was manually provided alongside a cluster conf",
|
||||
used = builder.numShardsInNetwork, discarded = clusterConf.numShardsInNetwork
|
||||
|
||||
if clusterConf.discv5Discovery:
|
||||
var discv5ConfBuilder = builder.discv5Conf
|
||||
|
||||
if discv5ConfBuilder.discv5.isNone:
|
||||
discv5ConfBuilder.withDiscv5(clusterConf.discv5Discovery)
|
||||
|
||||
if discv5ConfBuilder.bootstrapNodes.isNone and
|
||||
clusterConf.discv5BootstrapNodes.len > 0:
|
||||
discv5ConfBuilder.withBootstrapNodes(clusterConf.discv5BootstrapNodes)
|
||||
# Apply preset - end
|
||||
applyPresetConf(builder)
|
||||
|
||||
let nodeKey = ?nodeKey(builder, rng)
|
||||
|
||||
@ -482,6 +501,9 @@ proc build*(
|
||||
let discv5Conf = builder.discv5Conf.build().valueOr:
|
||||
return err("Discv5 Conf building failed: " & $error)
|
||||
|
||||
let storeConf = builder.storeConf.build().valueOr:
|
||||
return err("Store Conf building failed: " & $error)
|
||||
|
||||
let rlnRelayConf = builder.rlnRelayConf.build().valueOr:
|
||||
return err("RLN Relay Conf building failed: " & $error)
|
||||
|
||||
@ -610,10 +632,10 @@ proc build*(
|
||||
numShardsInNetwork: numShardsInNetwork,
|
||||
shards: shards,
|
||||
relay: relay,
|
||||
store: store,
|
||||
filter: filter,
|
||||
lightPush: lightPush,
|
||||
peerExchange: peerExchange,
|
||||
storeConf: storeConf,
|
||||
relayPeerExchange: relayPeerExchange,
|
||||
discv5Conf: discv5Conf,
|
||||
rlnRelayConf: rlnRelayConf,
|
||||
@ -636,7 +658,7 @@ proc build*(
|
||||
agentString: agentString,
|
||||
colocationLimit: colocationLimit,
|
||||
maxRelayPeers: builder.maxRelayPeers,
|
||||
relayServiceRatio: relayServiceRatio
|
||||
rateLimits: rateLimits
|
||||
relayServiceRatio: relayServiceRatio,
|
||||
rateLimits: rateLimits,
|
||||
)
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user