Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/waku_rln_relay/test_rln_group_manager_onchain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe?

Suggested change
raiseAssert $error
assert false, "Failed to init group manager: " & $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
8 changes: 8 additions & 0 deletions tools/confutils/cli_args.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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* {.
Expand Down Expand Up @@ -885,6 +892,7 @@ proc toKeystoreGeneratorConf*(n: WakuNodeConf): RlnKeystoreGeneratorConf =
ethPrivateKey: n.rlnRelayEthPrivateKey,
credPath: n.rlnRelayCredPath,
credPassword: n.rlnRelayCredPassword,
useMaxGasPrice: n.rlnRelayMaxGasPrice,
)

proc toNetworkConf(
Expand Down
2 changes: 2 additions & 0 deletions tools/rln_keystore_generator/rln_keystore_generator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type RlnKeystoreGeneratorConf* = object
credPassword*: string
userMessageLimit*: uint64
ethPrivateKey*: string
useMaxGasPrice*: bool

proc doRlnKeystoreGenerator*(conf: RlnKeystoreGeneratorConf) =
# 1. load configuration
Expand Down Expand Up @@ -59,6 +60,7 @@ proc doRlnKeystoreGenerator*(conf: RlnKeystoreGeneratorConf) =
keystorePath: none(string),
keystorePassword: none(string),
ethPrivateKey: some(conf.ethPrivateKey),
useMaxGasPrice: conf.useMaxGasPrice,
onFatalErrorAction: onFatalErrorAction,
)
try:
Expand Down
20 changes: 18 additions & 2 deletions waku/waku_rln_relay/group_manager/on_chain/group_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Loading