diff --git a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim index cf697961a4..7750efad2b 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim @@ -436,3 +436,26 @@ suite "Onchain group manager": check: isReady == true + + test "register: should use max gas price when useMaxGasPrice flag is set": + (waitFor manager.init()).isOkOr: + raiseAssert $error + + manager.useMaxGasPrice = true + + let idCredentials = generateCredentials() + let merkleRootBefore = waitFor manager.fetchMerkleRoot() + + try: + waitFor manager.register(idCredentials, UserMessageLimit(20)) + except Exception, CatchableError: + assert false, + "exception raised when calling register with useMaxGasPrice: " & + getCurrentExceptionMsg() + + let merkleRootAfter = waitFor manager.fetchMerkleRoot() + + check: + merkleRootAfter != merkleRootBefore + manager.latestIndex == 1 + manager.useMaxGasPrice == true diff --git a/tools/confutils/cli_args.nim b/tools/confutils/cli_args.nim index fb84372993..4ad9310563 100644 --- a/tools/confutils/cli_args.nim +++ b/tools/confutils/cli_args.nim @@ -138,6 +138,13 @@ type WakuNodeConf* = object defaultValue: false, name: "execute" .}: bool + + rlnRelayMaxGasPrice* {. + desc: + "Use fixed large gas price (1000 Gwei) for the registration transaction. If not set, will use 2x current gas price.", + defaultValue: false, + name: "rln-relay-max-gas-price" + .}: bool of noCommand: ## Application-level configuration protectedShards* {. @@ -885,6 +892,7 @@ proc toKeystoreGeneratorConf*(n: WakuNodeConf): RlnKeystoreGeneratorConf = ethPrivateKey: n.rlnRelayEthPrivateKey, credPath: n.rlnRelayCredPath, credPassword: n.rlnRelayCredPassword, + useMaxGasPrice: n.rlnRelayMaxGasPrice, ) proc toNetworkConf( diff --git a/tools/rln_keystore_generator/rln_keystore_generator.nim b/tools/rln_keystore_generator/rln_keystore_generator.nim index 85df379827..aac9288e35 100644 --- a/tools/rln_keystore_generator/rln_keystore_generator.nim +++ b/tools/rln_keystore_generator/rln_keystore_generator.nim @@ -25,6 +25,7 @@ type RlnKeystoreGeneratorConf* = object credPassword*: string userMessageLimit*: uint64 ethPrivateKey*: string + useMaxGasPrice*: bool proc doRlnKeystoreGenerator*(conf: RlnKeystoreGeneratorConf) = # 1. load configuration @@ -59,6 +60,7 @@ proc doRlnKeystoreGenerator*(conf: RlnKeystoreGeneratorConf) = keystorePath: none(string), keystorePassword: none(string), ethPrivateKey: some(conf.ethPrivateKey), + useMaxGasPrice: conf.useMaxGasPrice, onFatalErrorAction: onFatalErrorAction, ) try: diff --git a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim index db68b2289f..5c136a2144 100644 --- a/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim +++ b/waku/waku_rln_relay/group_manager/on_chain/group_manager.nim @@ -43,6 +43,7 @@ type registrationHandler*: Option[RegistrationHandler] latestProcessedBlock*: BlockNumber merkleProofCache*: seq[byte] + useMaxGasPrice*: bool # The below code is not working with the latest web3 version due to chainId being null (specifically on linea-sepolia) # TODO: find better solution than this custom sendEthCallWithoutParams call @@ -227,9 +228,24 @@ method register*( let ethRpc = g.ethRpc.get() let wakuRlnContract = g.wakuRlnContract.get() + # Large gas price: 1000 Gwei (1e12 wei) for testing and extreme conditions + const MAX_PRACTICAL_GAS_PRICE = 1_000_000_000_000 + var gasPrice: int - g.retryWrapper(gasPrice, "Failed to get gas price"): - int(await ethRpc.provider.eth_gasPrice()) * 2 + if g.useMaxGasPrice: + gasPrice = MAX_PRACTICAL_GAS_PRICE + debug "using maximum practical gas price", gasPrice = gasPrice + else: + g.retryWrapper(gasPrice, "Failed to get gas price"): + let currentGasPrice = int(await ethRpc.provider.eth_gasPrice()) + # Check for potential overflow when multiplying by 2 + if currentGasPrice > int.high div 2: + warn "gas price would overflow when doubled, using maximum practical gas price", + currentGasPrice = currentGasPrice + MAX_PRACTICAL_GAS_PRICE + else: + currentGasPrice * 2 + debug "using dynamic gas price (2x current)", gasPrice = gasPrice let idCommitmentHex = identityCredential.idCommitment.inHex() info "identityCredential idCommitmentHex", idCommitment = idCommitmentHex let idCommitment = identityCredential.idCommitment.toUInt256()