mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-03 14:33:12 +00:00
Add flag to use larger gas price when registering RLN membership
This commit is contained in:
parent
262d33e394
commit
b3def2cd4b
@ -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
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user