From 9d080d0d64643f97241226106bf2a9ac605fa4a5 Mon Sep 17 00:00:00 2001 From: fryorcraken Date: Thu, 11 Sep 2025 11:19:07 +1000 Subject: [PATCH] match spec name (config) --- library/libwaku_api.nim | 2 +- library/libwaku_conf.nim | 47 +++++++++++------------ tests/library/test_libwaku.nim | 24 ++++++------ tests/library/test_libwaku_conf.nim | 58 ++++++++++++++--------------- 4 files changed, 66 insertions(+), 65 deletions(-) diff --git a/library/libwaku_api.nim b/library/libwaku_api.nim index b7d98b675..a13f68d14 100644 --- a/library/libwaku_api.nim +++ b/library/libwaku_api.nim @@ -4,7 +4,7 @@ import waku/factory/waku import ./libwaku_conf -proc createNode*(config: LibWakuConf): Future[Result[Waku, string]] {.async.} = +proc createNode*(config: LibWakuConfig): Future[Result[Waku, string]] {.async.} = let wakuConf = toWakuConf(config).valueOr: return err("Failed to handle the configuration: " & error) diff --git a/library/libwaku_conf.nim b/library/libwaku_conf.nim index f0e1d1aac..8eb84d33a 100644 --- a/library/libwaku_conf.nim +++ b/library/libwaku_conf.nim @@ -9,7 +9,7 @@ type ShardingMode* = enum AutoSharding = "auto" StaticSharding = "static" -type AutoShardingConf* = object +type AutoShardingConfig* = object numShardsInCluster*: uint16 type RlnConfig* = object @@ -21,32 +21,32 @@ type MessageValidation* = object maxMessageSizeBytes*: uint64 rlnConfig*: Option[RlnConfig] -type NetworkConf* = object +type NetworkConfig* = object bootstrapNodes*: seq[string] staticStoreNodes*: seq[string] clusterId*: uint16 shardingMode*: Option[ShardingMode] - autoShardingConf*: Option[AutoShardingConf] + autoShardingConfig*: Option[AutoShardingConfig] messageValidation*: Option[MessageValidation] type WakuMode* = enum Edge = "edge" Relay = "relay" -type LibWakuConf* = object +type LibWakuConfig* = object mode*: WakuMode - networkConf*: Option[NetworkConf] + networkConfig*: Option[NetworkConfig] storeConfirmation*: bool ethRpcEndpoints*: seq[string] proc DefaultShardingMode(): ShardingMode = return ShardingMode.Autosharding -proc DefaultAutoShardingConf(): AutoShardingConf = - return AutoShardingConf(numShardsInCluster: 1) +proc DefaultAutoShardingConfig(): AutoShardingConfig = + return AutoShardingConfig(numShardsInCluster: 1) -proc DefaultNetworkConf(): NetworkConf = - return NetworkConf( +proc DefaultNetworkConfig(): NetworkConfig = + return NetworkConfig( bootstrapNodes: @[ "enrtree://AIRVQ5DDA4FFWLRBCHJWUWOO6X6S4ZTZ5B667LQ6AJU6PEYDLRD5O@sandbox.waku.nodes.status.im" @@ -54,7 +54,7 @@ proc DefaultNetworkConf(): NetworkConf = staticStoreNodes: @[], # TODO clusterId: 1, shardingMode: some(ShardingMode.AutoSharding), - autoShardingConf: some(AutoShardingConf(numShardsInCluster: 8)), + autoShardingConfig: some(AutoShardingConfig(numShardsInCluster: 8)), messageValidation: some( MessageValidation( maxMessageSizeBytes: 153600, @@ -72,10 +72,10 @@ proc DefaultNetworkConf(): NetworkConf = proc DefaultMessageValidation(): MessageValidation = return MessageValidation(maxMessageSizeBytes: 153600, rlnConfig: none(RlnConfig)) -proc toWakuConf*(libConf: LibWakuConf): Result[WakuConf, string] = +proc toWakuConf*(config: LibWakuConfig): Result[WakuConf, string] = var b = WakuConfBuilder.init() - case libConf.mode + case config.mode of Relay: b.withRelay(true) @@ -94,32 +94,33 @@ proc toWakuConf*(libConf: LibWakuConf): Result[WakuConf, string] = #TODO: store confirmation ## Network Conf - let networkConf = libConf.networkConf.get(DefaultNetworkConf()) + let networkConfig = config.networkConfig.get(DefaultNetworkConfig()) # Set cluster ID - b.withClusterId(networkConf.clusterId) + b.withClusterId(networkConfig.clusterId) # Set sharding configuration - case networkConf.shardingMode.get(DefaultShardingMode()) + case networkConfig.shardingMode.get(DefaultShardingMode()) of AutoSharding: b.withShardingConf(ShardingConfKind.AutoSharding) - let autoShardingConf = networkConf.autoShardingConf.get(DefaultAutoShardingConf()) - b.withNumShardsInCluster(autoShardingConf.numShardsInCluster) + let autoShardingConfig = + networkConfig.autoShardingConfig.get(DefaultAutoShardingConfig()) + b.withNumShardsInCluster(autoShardingConfig.numShardsInCluster) of StaticSharding: b.withShardingConf(ShardingConfKind.StaticSharding) # Set bootstrap nodes - if networkConf.bootstrapNodes.len > 0: - b.discv5Conf.withBootstrapNodes(networkConf.bootstrapNodes) + if networkConfig.bootstrapNodes.len > 0: + b.discv5Conf.withBootstrapNodes(networkConfig.bootstrapNodes) # TODO: verify behaviour # Set static store nodes - if networkConf.staticStoreNodes.len > 0: - b.withStaticNodes(networkConf.staticStoreNodes) + if networkConfig.staticStoreNodes.len > 0: + b.withStaticNodes(networkConfig.staticStoreNodes) # Set message validation - let msgValidation = networkConf.messageValidation.get(DefaultMessageValidation()) + let msgValidation = networkConfig.messageValidation.get(DefaultMessageValidation()) b.withMaxMessageSize(msgValidation.maxMessageSizeBytes) # Set RLN config if provided @@ -130,7 +131,7 @@ proc toWakuConf*(libConf: LibWakuConf): Result[WakuConf, string] = b.rlnRelayConf.withChainId(rlnConfig.chainId) b.rlnRelayConf.withEpochSizeSec(rlnConfig.epochSizeSec) b.rlnRelayConf.withDynamic(true) - b.rlnRelayConf.withEthClientUrls(libConf.ethRpcEndpoints) + b.rlnRelayConf.withEthClientUrls(config.ethRpcEndpoints) # TODO: we should get rid of those two b.rlnRelayconf.withUserMessageLimit(100) diff --git a/tests/library/test_libwaku.nim b/tests/library/test_libwaku.nim index 3c13e9308..a34ab3fc2 100644 --- a/tests/library/test_libwaku.nim +++ b/tests/library/test_libwaku.nim @@ -6,15 +6,15 @@ import library/libwaku_api, library/libwaku_conf, waku/factory/waku suite "LibWaku - createNode": asyncTest "Create node with minimal Relay configuration": ## Given - let libConf = LibWakuConf( + let libConf = LibWakuConfig( mode: Relay, - networkConf: some( - libwaku_conf.NetworkConf( + networkConfig: some( + libwaku_conf.NetworkConfig( bootstrapNodes: @[], staticStoreNodes: @[], clusterId: 1, shardingMode: some(StaticSharding), - autoShardingConf: none(AutoShardingConf), + autoShardingConfig: none(AutoShardingConfig), messageValidation: none(MessageValidation), ) ), @@ -33,15 +33,15 @@ suite "LibWaku - createNode": asyncTest "Create node with auto-sharding configuration": ## Given - let libConf = LibWakuConf( + let libConf = LibWakuConfig( mode: Relay, - networkConf: some( - libwaku_conf.NetworkConf( + networkConfig: some( + libwaku_conf.NetworkConfig( bootstrapNodes: @[], staticStoreNodes: @[], clusterId: 42, shardingMode: some(AutoSharding), - autoShardingConf: some(AutoShardingConf(numShardsInCluster: 8)), + autoShardingConfig: some(AutoShardingConfig(numShardsInCluster: 8)), messageValidation: none(MessageValidation), ) ), @@ -60,10 +60,10 @@ suite "LibWaku - createNode": asyncTest "Create node with full configuration": ## Given - let libConf = LibWakuConf( + let libConf = LibWakuConfig( mode: Relay, - networkConf: some( - libwaku_conf.NetworkConf( + networkConfig: some( + libwaku_conf.NetworkConfig( bootstrapNodes: @[ "enr:-QESuEC1p_s3xJzAC_XlOuuNrhVUETmfhbm1wxRGis0f7DlqGSw2FM-p2Vn7gmfkTTnAe8Ys2cgGBN8ufJnvzKQFZqFMBgmlkgnY0iXNlY3AyNTZrMaEDS8-D878DrdbNwcuY-3p1qdDp5MOoCurhdsNPJTXZ3c5g3RjcIJ2X4N1ZHCCd2g" @@ -74,7 +74,7 @@ suite "LibWaku - createNode": ], clusterId: 99, shardingMode: some(AutoSharding), - autoShardingConf: some(AutoShardingConf(numShardsInCluster: 16)), + autoShardingConfig: some(AutoShardingConfig(numShardsInCluster: 16)), messageValidation: some( MessageValidation( maxMessageSizeBytes: 1024'u64 * 1024'u64, # 1MB diff --git a/tests/library/test_libwaku_conf.nim b/tests/library/test_libwaku_conf.nim index a552bba67..d2a86aedb 100644 --- a/tests/library/test_libwaku_conf.nim +++ b/tests/library/test_libwaku_conf.nim @@ -6,15 +6,15 @@ import library/libwaku_conf, waku/factory/waku_conf, waku/factory/networks_confi suite "LibWaku Conf - toWakuConf": test "Relay mode configuration": ## Given - let libConf = LibWakuConf( + let libConf = LibWakuConfig( mode: Relay, - networkConf: some( - libwaku_conf.NetworkConf( + networkConfig: some( + libwaku_conf.NetworkConfig( bootstrapNodes: @[], staticStoreNodes: @[], clusterId: 1, shardingMode: some(ShardingMode.StaticSharding), - autoShardingConf: none(AutoShardingConf), + autoShardingConfig: none(AutoShardingConfig), messageValidation: none(MessageValidation), ) ), @@ -37,15 +37,15 @@ suite "LibWaku Conf - toWakuConf": test "Auto-sharding configuration": ## Given - let libConf = LibWakuConf( + let libConf = LibWakuConfig( mode: Relay, - networkConf: some( - libwaku_conf.NetworkConf( + networkConfig: some( + libwaku_conf.NetworkConfig( bootstrapNodes: @[], staticStoreNodes: @[], clusterId: 42, shardingMode: some(ShardingMode.AutoSharding), - autoShardingConf: some(AutoShardingConf(numShardsInCluster: 16)), + autoShardingConfig: some(AutoShardingConfig(numShardsInCluster: 16)), messageValidation: none(MessageValidation), ) ), @@ -71,15 +71,15 @@ suite "LibWaku Conf - toWakuConf": "enr:-QESuEC1p_s3xJzAC_XlOuuNrhVUETmfhbm1wxRGis0f7DlqGSw2FM-p2Vn7gmfkTTnAe8Ys2cgGBN8ufJnvzKQFZqFMBgmlkgnY0iXNlY3AyNTZrMaEDS8-D878DrdbNwcuY-3p1qdDp5MOoCurhdsNPJTXZ3c5g3RjcIJ2X4N1ZHCCd2g", "enr:-QEkuECnZ3IbVAgkOzv-QLnKC4dRKAPRY80m1-R7G8jZ7yfT3ipEfBrhKN7ARcQgQ-vg-h40AQzyvAkPYlHPaFKk6u9MBgmlkgnY0iXNlY3AyNTZrMaEDk49D8JjMSns4p1XVNBvJquOUzT4PENSJknkROspfAFGg3RjcIJ2X4N1ZHCCd2g", ] - let libConf = LibWakuConf( + let libConf = LibWakuConfig( mode: Relay, - networkConf: some( - libwaku_conf.NetworkConf( + networkConfig: some( + libwaku_conf.NetworkConfig( bootstrapNodes: bootstrapNodes, staticStoreNodes: @[], clusterId: 1, shardingMode: some(ShardingMode.StaticSharding), - autoShardingConf: none(AutoShardingConf), + autoShardingConfig: none(AutoShardingConfig), messageValidation: none(MessageValidation), ) ), @@ -104,15 +104,15 @@ suite "LibWaku Conf - toWakuConf": "/ip4/127.0.0.1/tcp/60000/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYc", "/ip4/192.168.1.1/tcp/60001/p2p/16Uuu2HBmAcHvhLqQKwSSbX6BG5JLWUDRcaLVrehUVqpw7fz1hbYd", ] - let libConf = LibWakuConf( + let libConf = LibWakuConfig( mode: Relay, - networkConf: some( - libwaku_conf.NetworkConf( + networkConfig: some( + libwaku_conf.NetworkConfig( bootstrapNodes: @[], staticStoreNodes: staticStoreNodes, clusterId: 1, shardingMode: some(ShardingMode.StaticSharding), - autoShardingConf: none(AutoShardingConf), + autoShardingConfig: none(AutoShardingConfig), messageValidation: none(MessageValidation), ) ), @@ -131,15 +131,15 @@ suite "LibWaku Conf - toWakuConf": test "Message validation with max message size": ## Given - let libConf = LibWakuConf( + let libConf = LibWakuConfig( mode: Relay, - networkConf: some( - libwaku_conf.NetworkConf( + networkConfig: some( + libwaku_conf.NetworkConfig( bootstrapNodes: @[], staticStoreNodes: @[], clusterId: 1, shardingMode: some(ShardingMode.StaticSharding), - autoShardingConf: none(AutoShardingConf), + autoShardingConfig: none(AutoShardingConfig), messageValidation: some( MessageValidation( maxMessageSizeBytes: 100'u64 * 1024'u64, # 100kB @@ -163,15 +163,15 @@ suite "LibWaku Conf - toWakuConf": test "Message validation with RLN config": ## Given - let libConf = LibWakuConf( + let libConf = LibWakuConfig( mode: Relay, - networkConf: some( - libwaku_conf.NetworkConf( + networkConfig: some( + libwaku_conf.NetworkConfig( bootstrapNodes: @[], staticStoreNodes: @[], clusterId: 1, shardingMode: some(ShardingMode.StaticSharding), - autoShardingConf: none(AutoShardingConf), + autoShardingConfig: none(AutoShardingConfig), messageValidation: some( MessageValidation( maxMessageSizeBytes: 150'u64 * 1024'u64, # 150KB @@ -210,10 +210,10 @@ suite "LibWaku Conf - toWakuConf": test "Full Relay mode configuration with all fields": ## Given - let libConf = LibWakuConf( + let libConf = LibWakuConfig( mode: Relay, - networkConf: some( - libwaku_conf.NetworkConf( + networkConfig: some( + libwaku_conf.NetworkConfig( bootstrapNodes: @[ "enr:-QESuEC1p_s3xJzAC_XlOuuNrhVUETmfhbm1wxRGis0f7DlqGSw2FM-p2Vn7gmfkTTnAe8Ys2cgGBN8ufJnvzKQFZqFMBgmlkgnY0iXNlY3AyNTZrMaEDS8-D878DrdbNwcuY-3p1qdDp5MOoCurhdsNPJTXZ3c5g3RjcIJ2X4N1ZHCCd2g" @@ -224,7 +224,7 @@ suite "LibWaku Conf - toWakuConf": ], clusterId: 99, shardingMode: some(ShardingMode.AutoSharding), - autoShardingConf: some(AutoShardingConf(numShardsInCluster: 8)), + autoShardingConfig: some(AutoShardingConfig(numShardsInCluster: 8)), messageValidation: some( MessageValidation( maxMessageSizeBytes: 512'u64 * 1024'u64, # 512KB @@ -290,7 +290,7 @@ suite "LibWaku Conf - toWakuConf": test "Minimal configuration": ## Given - let libConf = LibWakuConf(mode: Relay, ethRpcEndpoints: @["http://someaddress"]) + let libConf = LibWakuConfig(mode: Relay, ethRpcEndpoints: @["http://someaddress"]) ## When let wakuConfRes = toWakuConf(libConf)