diff --git a/examples/wakustealthcommitments/node_spec.nim b/examples/wakustealthcommitments/node_spec.nim index dbab8a3b2..b5dafb0be 100644 --- a/examples/wakustealthcommitments/node_spec.nim +++ b/examples/wakustealthcommitments/node_spec.nim @@ -36,7 +36,6 @@ proc setup*(): Waku = conf.clusterId = twnClusterConf.clusterId conf.rlnRelayEthContractAddress = twnClusterConf.rlnRelayEthContractAddress conf.rlnRelayDynamic = twnClusterConf.rlnRelayDynamic - conf.rlnRelayBandwidthThreshold = twnClusterConf.rlnRelayBandwidthThreshold conf.discv5Discovery = twnClusterConf.discv5Discovery conf.discv5BootstrapNodes = conf.discv5BootstrapNodes & twnClusterConf.discv5BootstrapNodes diff --git a/tests/factory/test_waku_conf.nim b/tests/factory/test_waku_conf.nim index 3af911254..36e8aa9e9 100644 --- a/tests/factory/test_waku_conf.nim +++ b/tests/factory/test_waku_conf.nim @@ -56,7 +56,6 @@ suite "Waku Conf - build with cluster conf": clusterConf.rlnRelayEthContractAddress assert rlnRelayConf.dynamic == clusterConf.rlnRelayDynamic assert rlnRelayConf.chainId == clusterConf.rlnRelayChainId - assert rlnRelayConf.bandwidthThreshold == clusterConf.rlnRelayBandwidthThreshold assert rlnRelayConf.epochSizeSec == clusterConf.rlnEpochSizeSec assert rlnRelayConf.userMessageLimit == clusterConf.rlnRelayUserMessageLimit @@ -230,7 +229,6 @@ suite "Waku Conf - build with cluster conf": assert rlnRelayConf.ethContractAddress.string == contractAddress assert rlnRelayConf.dynamic == clusterConf.rlnRelayDynamic assert rlnRelayConf.chainId == clusterConf.rlnRelayChainId - assert rlnRelayConf.bandwidthThreshold == clusterConf.rlnRelayBandwidthThreshold assert rlnRelayConf.epochSizeSec == clusterConf.rlnEpochSizeSec assert rlnRelayConf.userMessageLimit == clusterConf.rlnRelayUserMessageLimit diff --git a/waku/factory/external_config.nim b/waku/factory/external_config.nim index 76d1ff821..48def0f90 100644 --- a/waku/factory/external_config.nim +++ b/waku/factory/external_config.nim @@ -315,13 +315,6 @@ hence would have reachability issues.""", name: "rln-relay-tree-path" .}: string - rlnRelayBandwidthThreshold* {. - desc: - "Message rate in bytes/sec after which verification of proofs should happen.", - defaultValue: 0, # to maintain backwards compatibility - name: "rln-relay-bandwidth-threshold" - .}: int - staticnodes* {. desc: "Peer multiaddr to directly connect with. Argument may be repeated.", name: "staticnode" diff --git a/waku/factory/networks_config.nim b/waku/factory/networks_config.nim index 0989e58af..aea96970c 100644 --- a/waku/factory/networks_config.nim +++ b/waku/factory/networks_config.nim @@ -9,7 +9,6 @@ type ClusterConf* = object rlnRelayEthContractAddress*: string rlnRelayChainId*: uint rlnRelayDynamic*: bool - rlnRelayBandwidthThreshold*: int rlnEpochSizeSec*: uint64 rlnRelayUserMessageLimit*: uint64 # TODO: should be uint16 like the `shards` parameter @@ -28,7 +27,6 @@ proc TheWakuNetworkConf*(T: type ClusterConf): ClusterConf = rlnRelayEthContractAddress: "0xfe7a9eabcE779a090FD702346Fd0bFAc02ce6Ac8", rlnRelayDynamic: true, rlnRelayChainId: 11155111, - rlnRelayBandwidthThreshold: 0, rlnEpochSizeSec: 600, rlnRelayUserMessageLimit: 100, numShardsInNetwork: 8, diff --git a/waku/factory/waku_conf.nim b/waku/factory/waku_conf.nim index cfe8932be..e4ef4332e 100644 --- a/waku/factory/waku_conf.nim +++ b/waku/factory/waku_conf.nim @@ -4,17 +4,18 @@ import libp2p/crypto/crypto, libp2p/multiaddress, secp256k1, - results + results, + waku/waku_rln_relay/rln_relay import ../common/logging +export RlnRelayConf + logScope: topics = "waku conf" type TextEnr* = distinct string - ContractAddress* = distinct string - EthRpcUrl* = distinct string NatStrategy* = distinct string DomainName* = distinct string @@ -24,14 +25,14 @@ type ProtectedShard* = object key*: secp256k1.SkPublicKey # TODO: this should come from discv5 discovery module -type Discv5Conf* = ref object +type Discv5Conf* = 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 StoreServiceConf* = ref object +type StoreServiceConf* = object legacy*: bool dbURl*: string dbVacuum*: bool @@ -40,22 +41,11 @@ type StoreServiceConf* = ref object retentionPolicy*: string resume*: bool -# TODO: this should come from RLN relay module -type RlnRelayConf* = ref object - ethContractAddress*: ContractAddress - chainId*: uint - credIndex*: Option[uint] - dynamic*: bool - bandwidthThreshold*: int - epochSizeSec*: uint64 - userMessageLimit*: uint64 - ethClientAddress*: EthRpcUrl - -type WebSocketSecureConf* = ref object +type WebSocketSecureConf* = object keyPath*: string certPath*: string -type WebSocketConf* = ref object +type WebSocketConf* = object port*: Port secureConf*: Option[WebSocketSecureConf] @@ -63,7 +53,7 @@ type WebSocketConf* = ref object ## All information needed by a waku node should be contained ## In this object. A convenient `validate` method enables doing ## sanity checks beyond type enforcement. -type WakuConf* = ref object +type WakuConf* = object nodeKey*: PrivateKey clusterId*: uint16 @@ -119,11 +109,13 @@ type WakuConf* = ref object colocationLimit*: int + # TODO: use proper type rateLimits*: seq[string] # TODO: those could be in a relay conf object maxRelayPeers*: Option[int] relayShardedPeerManagement*: bool + # TODO: use proper type relayServiceRatio*: string proc log*(conf: WakuConf) = diff --git a/waku/factory/waku_conf_builder.nim b/waku/factory/waku_conf_builder.nim index cf2539ac8..a3d434244 100644 --- a/waku/factory/waku_conf_builder.nim +++ b/waku/factory/waku_conf_builder.nim @@ -73,14 +73,13 @@ macro with(builderType: untyped, argName: untyped, argType: untyped) = ############################## type RlnRelayConfBuilder = ref object rlnRelay: Option[bool] - ethContractAddress: Option[ContractAddress] + ethContractAddress: Option[string] chainId: Option[uint] credIndex: Option[uint] dynamic: Option[bool] - bandwidthThreshold: Option[int] epochSizeSec: Option[uint64] userMessageLimit: Option[uint64] - ethClientAddress: Option[EthRpcUrl] + ethClientAddress: Option[string] proc init*(T: type RlnRelayConfBuilder): RlnRelayConfBuilder = RlnRelayConfBuilder() @@ -89,11 +88,10 @@ with(RlnRelayConfbuilder, rlnRelay, bool) with(RlnRelayConfBuilder, chainId, uint) with(RlnRelayConfBuilder, credIndex, uint) with(RlnRelayConfBuilder, dynamic, bool) -with(RlnRelayConfBuilder, bandwidthThreshold, int) with(RlnRelayConfBuilder, epochSizeSec, uint64) with(RlnRelayConfBuilder, userMessageLimit, uint64) -with(RlnRelayConfBuilder, ethContractAddress, string, ContractAddress) -with(RlnRelayConfBuilder, ethClientAddress, string, EthRpcUrl) +with(RlnRelayConfBuilder, ethContractAddress, string) +with(RlnRelayConfBuilder, ethClientAddress, string) proc build*(builder: RlnRelayConfBuilder): Result[Option[RlnRelayConf], string] = if builder.rlnRelay.isNone or not builder.rlnRelay.get(): @@ -118,12 +116,6 @@ proc build*(builder: RlnRelayConfBuilder): Result[Option[RlnRelayConf], string] else: return err("RLN Relay Dynamic was not specified") - let bandwidthThreshold = - if builder.bandwidthThreshold.isSome: - builder.bandwidthThreshold.get() - else: - return err("RLN Relay Bandwidth Threshold was not specified") - let epochSizeSec = if builder.epochSizeSec.isSome: builder.epochSizeSec.get() @@ -146,7 +138,7 @@ proc build*(builder: RlnRelayConfBuilder): Result[Option[RlnRelayConf], string] some( RlnRelayConf( chainId: chainId, - credIndex: credIndex, + credIndex: builder.credIndex, dynamic: dynamic, ethContractAddress: ethContractAddress, epochSizeSec: epochSizeSec, @@ -281,6 +273,8 @@ type WakuConfBuilder* = ref object clusterId: Option[uint16] numShardsInNetwork: Option[uint32] shards: Option[seq[uint16]] + protectedShards: Option[seq[ProtectedShard]] + contentTopics: Option[seq[string]] relay: Option[bool] filter: Option[bool] @@ -288,6 +282,8 @@ type WakuConfBuilder* = ref object peerExchange: Option[bool] storeSync: Option[bool] relayPeerExchange: Option[bool] + # TODO: move within a relayConf + rendezvous: Option[bool] discv5Only: Option[bool] clusterConf: Option[ClusterConf] @@ -339,15 +335,18 @@ proc init*(T: type WakuConfBuilder): WakuConfBuilder = with(WakuConfBuilder, clusterConf, ClusterConf) with(WakuConfBuilder, nodeKey, PrivateKey) with(WakuConfBuilder, clusterId, uint16) +with(WakuConfbuilder, shards, seq[uint16]) +with(WakuConfbuilder, protectedShards, seq[ProtectedShard]) +with(WakuConfbuilder, contentTopics, seq[string]) with(WakuConfBuilder, relay, bool) with(WakuConfBuilder, filter, bool) with(WakuConfBuilder, storeSync, bool) with(WakuConfBuilder, relayPeerExchange, bool) +with(WakuConfBuilder, rendezvous, bool) with(WakuConfBuilder, maxMessageSizeBytes, int) with(WakuConfBuilder, dnsAddrs, bool) with(WakuConfbuilder, peerPersistence, bool) with(WakuConfbuilder, maxConnections, int) -with(WakuConfbuilder, shards, seq[uint16]) with(WakuConfbuilder, dnsAddrsNameServers, seq[IpAddress]) with(WakuConfbuilder, p2pTcpPort, uint16, Port) with(WakuConfbuilder, dns4DomainName, string, DomainName) @@ -414,13 +413,6 @@ proc applyPresetConf(builder: var WakuConfBuilder) = 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: @@ -501,6 +493,13 @@ proc build*( warn "whether to mount storeSync is not specified, defaulting to not mounting" false + let rendezvous = + if builder.rendezvous.isSome: + builder.rendezvous.get() + else: + warn "whether to mount rendezvous is not specified, defaulting to not mounting" + false + let relayPeerExchange = builder.relayPeerExchange.get(false) applyPresetConf(builder) @@ -529,6 +528,10 @@ proc build*( let upperShard: uint16 = uint16(numShardsInNetwork - 1) toSeq(0.uint16 .. upperShard) + let protectedShards = builder.protectedShards.get(@[]) + + let contentTopics = builder.contentTopics.get(@[]) + let discv5Conf = builder.discv5Conf.build().valueOr: return err("Discv5 Conf building failed: " & $error) diff --git a/waku/waku_rln_relay/rln_relay.nim b/waku/waku_rln_relay/rln_relay.nim index c3f3903f9..605a21e68 100644 --- a/waku/waku_rln_relay/rln_relay.nim +++ b/waku/waku_rln_relay/rln_relay.nim @@ -32,18 +32,20 @@ import logScope: topics = "waku rln_relay" -type WakuRlnConfig* = object - rlnRelayDynamic*: bool - rlnRelayCredIndex*: Option[uint] - rlnRelayEthContractAddress*: string - rlnRelayEthClientAddress*: string - rlnRelayChainId*: uint - rlnRelayCredPath*: string - rlnRelayCredPassword*: string - rlnRelayTreePath*: string - rlnEpochSizeSec*: uint64 +type RlnRelayConf* = object of RootObj + dynamic*: bool + credIndex*: Option[uint] + ethContractAddress*: string + ethClientAddress*: string + chainId*: uint + credPath*: string + credPassword*: string + treePath*: string + epochSizeSec*: uint64 + userMessageLimit*: uint64 + +type WakuRlnConfig* = object of RlnRelayConf onFatalErrorAction*: OnFatalErrorHandler - rlnRelayUserMessageLimit*: uint64 proc createMembershipList*( rln: ptr RLN, n: int @@ -425,10 +427,10 @@ proc mount( groupManager: GroupManager wakuRlnRelay: WakuRLNRelay # create an RLN instance - let rlnInstance = createRLNInstance(tree_path = conf.rlnRelayTreePath).valueOr: + let rlnInstance = createRLNInstance(tree_path = conf.treePath).valueOr: return err("could not create RLN instance: " & $error) - if not conf.rlnRelayDynamic: + if not conf.dynamic: # static setup let parsedGroupKeys = StaticGroupKeys.toIdentityCredentials().valueOr: return err("could not parse static group keys: " & $error) @@ -436,7 +438,7 @@ proc mount( groupManager = StaticGroupManager( groupSize: StaticGroupSize, groupKeys: parsedGroupKeys, - membershipIndex: conf.rlnRelayCredIndex, + membershipIndex: conf.credIndex, rlnInstance: rlnInstance, onFatalErrorAction: conf.onFatalErrorAction, ) @@ -450,17 +452,17 @@ proc mount( some(s) let - rlnRelayCredPath = useValueOrNone(conf.rlnRelayCredPath) - rlnRelayCredPassword = useValueOrNone(conf.rlnRelayCredPassword) + rlnRelayCredPath = useValueOrNone(conf.credPath) + rlnRelayCredPassword = useValueOrNone(conf.credPassword) groupManager = OnchainGroupManager( - ethClientUrl: string(conf.rlnRelayethClientAddress), - ethContractAddress: $conf.rlnRelayEthContractAddress, - chainId: conf.rlnRelayChainId, + ethClientUrl: string(conf.ethClientAddress), + ethContractAddress: $conf.ethContractAddress, + chainId: conf.chainId, rlnInstance: rlnInstance, registrationHandler: registrationHandler, keystorePath: rlnRelayCredPath, keystorePassword: rlnRelayCredPassword, - membershipIndex: conf.rlnRelayCredIndex, + membershipIndex: conf.credIndex, onFatalErrorAction: conf.onFatalErrorAction, ) @@ -473,10 +475,9 @@ proc mount( wakuRlnRelay = WakuRLNRelay( groupManager: groupManager, - nonceManager: - NonceManager.init(conf.rlnRelayUserMessageLimit, conf.rlnEpochSizeSec.float), - rlnEpochSizeSec: conf.rlnEpochSizeSec, - rlnMaxEpochGap: max(uint64(MaxClockGapSeconds / float64(conf.rlnEpochSizeSec)), 1), + nonceManager: NonceManager.init(conf.userMessageLimit, conf.epochSizeSec.float), + rlnEpochSizeSec: conf.epochSizeSec, + rlnMaxEpochGap: max(uint64(MaxClockGapSeconds / float64(conf.epochSizeSec)), 1), onFatalErrorAction: conf.onFatalErrorAction, )