mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-03-27 11:23:07 +00:00
allow override user-message-rate-limit (#3778)
This commit is contained in:
parent
6a20ee9c83
commit
0b86093247
@ -4,7 +4,7 @@ import
|
||||
libp2p/crypto/[crypto, secp],
|
||||
libp2p/multiaddress,
|
||||
nimcrypto/utils,
|
||||
std/[options, sequtils],
|
||||
std/[options, random, sequtils],
|
||||
results,
|
||||
testutils/unittests
|
||||
import
|
||||
@ -22,11 +22,13 @@ suite "Waku Conf - build with cluster conf":
|
||||
builder.withRelayServiceRatio("50:50")
|
||||
# Mount all shards in network
|
||||
let expectedShards = toSeq[0.uint16 .. 7.uint16]
|
||||
let userMessageLimit = rand(1 .. 1000).uint64
|
||||
|
||||
## Given
|
||||
builder.rlnRelayConf.withEthClientUrls(@["https://my_eth_rpc_url/"])
|
||||
builder.withNetworkConf(networkConf)
|
||||
builder.withRelay(true)
|
||||
builder.rlnRelayConf.withUserMessageLimit(userMessageLimit)
|
||||
|
||||
## When
|
||||
let resConf = builder.build()
|
||||
@ -54,7 +56,7 @@ suite "Waku Conf - build with cluster conf":
|
||||
check rlnRelayConf.dynamic == networkConf.rlnRelayDynamic
|
||||
check rlnRelayConf.chainId == networkConf.rlnRelayChainId
|
||||
check rlnRelayConf.epochSizeSec == networkConf.rlnEpochSizeSec
|
||||
check rlnRelayConf.userMessageLimit == networkConf.rlnRelayUserMessageLimit
|
||||
check rlnRelayConf.userMessageLimit == userMessageLimit.uint
|
||||
|
||||
test "Cluster Conf is passed, but relay is disabled":
|
||||
## Setup
|
||||
@ -174,11 +176,13 @@ suite "Waku Conf - build with cluster conf":
|
||||
# Mount all shards in network
|
||||
let expectedShards = toSeq[0.uint16 .. 7.uint16]
|
||||
let contractAddress = "0x0123456789ABCDEF"
|
||||
let userMessageLimit = rand(1 .. 1000).uint64
|
||||
|
||||
## Given
|
||||
builder.rlnRelayConf.withEthContractAddress(contractAddress)
|
||||
builder.withNetworkConf(networkConf)
|
||||
builder.withRelay(true)
|
||||
builder.rlnRelayConf.withUserMessageLimit(userMessageLimit)
|
||||
|
||||
## When
|
||||
let resConf = builder.build()
|
||||
@ -207,7 +211,7 @@ suite "Waku Conf - build with cluster conf":
|
||||
check rlnRelayConf.dynamic == networkConf.rlnRelayDynamic
|
||||
check rlnRelayConf.chainId == networkConf.rlnRelayChainId
|
||||
check rlnRelayConf.epochSizeSec == networkConf.rlnEpochSizeSec
|
||||
check rlnRelayConf.userMessageLimit == networkConf.rlnRelayUserMessageLimit
|
||||
check rlnRelayConf.userMessageLimit == userMessageLimit.uint
|
||||
|
||||
suite "Waku Conf - node key":
|
||||
test "Node key is generated":
|
||||
|
||||
@ -141,43 +141,6 @@ suite "Waku external config - apply preset":
|
||||
## Then
|
||||
assert res.isErr(), "Invalid shard was accepted"
|
||||
|
||||
test "Apply TWN preset when cluster id = 1":
|
||||
## Setup
|
||||
let expectedConf = NetworkConf.TheWakuNetworkConf()
|
||||
|
||||
## Given
|
||||
let preConfig = WakuNodeConf(
|
||||
cmd: noCommand,
|
||||
clusterId: 1.uint16,
|
||||
relay: true,
|
||||
ethClientUrls: @["http://someaddress".EthRpcUrl],
|
||||
)
|
||||
|
||||
## When
|
||||
let res = preConfig.toWakuConf()
|
||||
assert res.isOk(), $res.error
|
||||
|
||||
## Then
|
||||
let conf = res.get()
|
||||
check conf.maxMessageSizeBytes ==
|
||||
uint64(parseCorrectMsgSize(expectedConf.maxMessageSize))
|
||||
check conf.clusterId == expectedConf.clusterId
|
||||
check conf.rlnRelayConf.isSome() == expectedConf.rlnRelay
|
||||
if conf.rlnRelayConf.isSome():
|
||||
let rlnRelayConf = conf.rlnRelayConf.get()
|
||||
check rlnRelayConf.ethContractAddress == expectedConf.rlnRelayEthContractAddress
|
||||
check rlnRelayConf.dynamic == expectedConf.rlnRelayDynamic
|
||||
check rlnRelayConf.chainId == expectedConf.rlnRelayChainId
|
||||
check rlnRelayConf.epochSizeSec == expectedConf.rlnEpochSizeSec
|
||||
check rlnRelayConf.userMessageLimit == expectedConf.rlnRelayUserMessageLimit
|
||||
check conf.shardingConf.kind == expectedConf.shardingConf.kind
|
||||
check conf.shardingConf.numShardsInCluster ==
|
||||
expectedConf.shardingConf.numShardsInCluster
|
||||
check conf.discv5Conf.isSome() == expectedConf.discv5Discovery
|
||||
if conf.discv5Conf.isSome():
|
||||
let discv5Conf = conf.discv5Conf.get()
|
||||
check discv5Conf.bootstrapNodes == expectedConf.discv5BootstrapNodes
|
||||
|
||||
suite "Waku external config - node key":
|
||||
test "Passed node key is used":
|
||||
## Setup
|
||||
|
||||
@ -948,6 +948,12 @@ proc toNetworkConf(
|
||||
proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] =
|
||||
var b = WakuConfBuilder.init()
|
||||
|
||||
let networkConf = toNetworkConf(n.preset, some(n.clusterId)).valueOr:
|
||||
return err("Error determining cluster from preset: " & $error)
|
||||
|
||||
if networkConf.isSome():
|
||||
b.withNetworkConf(networkConf.get())
|
||||
|
||||
b.withLogLevel(n.logLevel)
|
||||
b.withLogFormat(n.logFormat)
|
||||
|
||||
@ -976,12 +982,6 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] =
|
||||
b.withProtectedShards(n.protectedShards)
|
||||
b.withClusterId(n.clusterId)
|
||||
|
||||
let networkConf = toNetworkConf(n.preset, some(n.clusterId)).valueOr:
|
||||
return err("Error determining cluster from preset: " & $error)
|
||||
|
||||
if networkConf.isSome():
|
||||
b.withNetworkConf(networkConf.get())
|
||||
|
||||
b.withAgentString(n.agentString)
|
||||
|
||||
if n.nodeKey.isSome():
|
||||
|
||||
@ -353,10 +353,13 @@ proc applyNetworkConf(builder: var WakuConfBuilder) =
|
||||
builder.rlnRelayConf.withEpochSizeSec(networkConf.rlnEpochSizeSec)
|
||||
|
||||
if builder.rlnRelayConf.userMessageLimit.isSome():
|
||||
warn "RLN Relay Dynamic was provided alongside a network conf",
|
||||
warn "RLN Relay User Message Limit was provided alongside a network conf",
|
||||
used = networkConf.rlnRelayUserMessageLimit,
|
||||
discarded = builder.rlnRelayConf.userMessageLimit
|
||||
builder.rlnRelayConf.withUserMessageLimit(networkConf.rlnRelayUserMessageLimit)
|
||||
if builder.rlnRelayConf.userMessageLimit.get(0) == 0:
|
||||
## only override with the "preset" value if there was not explicit set value
|
||||
builder.rlnRelayConf.withUserMessageLimit(networkConf.rlnRelayUserMessageLimit)
|
||||
|
||||
# End Apply relay parameters
|
||||
|
||||
case builder.maxMessageSize.kind
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user