mirror of https://github.com/waku-org/nwaku.git
fix: handle rln-relay-message-limit (#2867)
* fix: enforcing rln-contract max message limit and resolve early
This commit is contained in:
parent
6d385cefef
commit
8d107b0ded
|
@ -15,6 +15,9 @@ import
|
|||
eth/keys
|
||||
import
|
||||
waku/[
|
||||
waku_node,
|
||||
node/waku_node,
|
||||
waku_rln_relay,
|
||||
waku_rln_relay/protocol_types,
|
||||
waku_rln_relay/constants,
|
||||
waku_rln_relay/contract,
|
||||
|
@ -22,7 +25,7 @@ import
|
|||
waku_rln_relay/conversion_utils,
|
||||
waku_rln_relay/group_manager/on_chain/group_manager,
|
||||
],
|
||||
../testlib/common,
|
||||
../testlib/[wakucore, wakunode, common],
|
||||
./utils
|
||||
|
||||
const CHAIN_ID = 1337
|
||||
|
@ -232,6 +235,7 @@ suite "Onchain group manager":
|
|||
manager.wakuRlnContract.isSome()
|
||||
manager.initialized
|
||||
manager.rlnContractDeployedBlockNumber > 0
|
||||
manager.rlnRelayMaxMessageLimit == 100
|
||||
|
||||
await manager.stop()
|
||||
|
||||
|
@ -776,6 +780,26 @@ suite "Onchain group manager":
|
|||
|
||||
await manager.stop()
|
||||
|
||||
asyncTest "rln-relay-max-message-limit testing":
|
||||
let
|
||||
nodekey = generateSecp256k1Key()
|
||||
node = newTestWakuNode(nodekey, parseIpAddress("0.0.0.0"), Port(0))
|
||||
|
||||
await node.mountRelay(@[DefaultPubsubTopic])
|
||||
|
||||
let wakuRlnConfig = WakuRlnConfig(
|
||||
rlnRelayDynamic: false,
|
||||
rlnRelayCredIndex: some(0.uint),
|
||||
rlnRelayUserMessageLimit: 111,
|
||||
rlnRelayTreepath: genTempPath("rln_tree", "wakunode_0"),
|
||||
)
|
||||
|
||||
try:
|
||||
await node.mountRlnRelay(wakuRlnConfig)
|
||||
except CatchableError as e:
|
||||
check e.msg == "failed to mount WakuRlnRelay: rln-relay-user-message-limit can't be exceed then MAX_MESSAGE_LIMIT set by rln contract"
|
||||
|
||||
|
||||
################################
|
||||
## Terminating/removing Anvil
|
||||
################################
|
||||
|
|
|
@ -1089,6 +1089,8 @@ proc mountRlnRelay*(
|
|||
raise
|
||||
newException(CatchableError, "failed to mount WakuRlnRelay: " & rlnRelayRes.error)
|
||||
let rlnRelay = rlnRelayRes.get()
|
||||
if (rlnConf.rlnRelayUserMessageLimit > rlnRelay.groupManager.rlnRelayMaxMessageLimit):
|
||||
error "rln-relay-user-message-limit can't be exceed then MAX_MESSAGE_LIMIT set by rln contract"
|
||||
let validator = generateRlnValidator(rlnRelay, spamHandler)
|
||||
|
||||
# register rln validator as default validator
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -33,6 +33,7 @@ type GroupManager* = ref object of RootObj
|
|||
validRoots*: Deque[MerkleNode]
|
||||
onFatalErrorAction*: OnFatalErrorHandler
|
||||
userMessageLimit*: Option[UserMessageLimit]
|
||||
rlnRelayMaxMessageLimit*: uint64
|
||||
|
||||
# This proc is used to initialize the group manager
|
||||
# Any initialization logic should be implemented here
|
||||
|
|
|
@ -46,6 +46,8 @@ contract(WakuRlnContract):
|
|||
proc commitmentIndex(): UInt256 {.view.}
|
||||
# this constant describes the block number this contract was deployed on
|
||||
proc deployedBlockNumber(): UInt256 {.view.}
|
||||
# this constant describes max message limit of rln contract
|
||||
proc MAX_MESSAGE_LIMIT(): UInt256 {.view.}
|
||||
|
||||
type
|
||||
WakuRlnContractWithSender = Sender[WakuRlnContract]
|
||||
|
@ -617,6 +619,7 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
|
|||
debug "using rln contract", deployedBlockNumber, rlnContractAddress = contractAddress
|
||||
g.rlnContractDeployedBlockNumber = cast[BlockNumber](deployedBlockNumber)
|
||||
g.latestProcessedBlock = max(g.latestProcessedBlock, g.rlnContractDeployedBlockNumber)
|
||||
g.rlnRelayMaxMessageLimit = cast[uint64](await wakuRlnContract.MAX_MESSAGE_LIMIT().call())
|
||||
|
||||
proc onDisconnect() {.async.} =
|
||||
error "Ethereum client disconnected"
|
||||
|
|
Loading…
Reference in New Issue