diff --git a/.gitmodules b/.gitmodules index 5650701b4..eb05c758d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -179,3 +179,18 @@ branch = master path = vendor/nph url = https://github.com/arnetheduck/nph.git +[submodule "vendor/nim-minilru"] + path = vendor/nim-minilru + url = https://github.com/status-im/nim-minilru.git + ignore = untracked + branch = master +[submodule "vendor/nim-quic"] + path = vendor/nim-quic + url = https://github.com/status-im/nim-quic.git + ignore = untracked + branch = master +[submodule "vendor/nim-ngtcp2"] + path = vendor/nim-ngtcp2 + url = https://github.com/vacp2p/nim-ngtcp2.git + ignore = untracked + branch = master diff --git a/tests/waku_discv5/utils.nim b/tests/waku_discv5/utils.nim index 10026155c..679d206ea 100644 --- a/tests/waku_discv5/utils.nim +++ b/tests/waku_discv5/utils.nim @@ -1,4 +1,5 @@ import + std/options, stew/results, stew/shims/net, chronos, diff --git a/tests/waku_enr/utils.nim b/tests/waku_enr/utils.nim index 5cc36f607..6dd017add 100644 --- a/tests/waku_enr/utils.nim +++ b/tests/waku_enr/utils.nim @@ -1,4 +1,5 @@ import + std/options, sequtils, stew/results, stew/shims/net, 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 5ef6913f7..3e6980db6 100644 --- a/tests/waku_rln_relay/test_rln_group_manager_onchain.nim +++ b/tests/waku_rln_relay/test_rln_group_manager_onchain.nim @@ -42,14 +42,14 @@ suite "Onchain group manager": manager.ethRpc.isSome() manager.wakuRlnContract.isSome() manager.initialized - manager.rlnContractDeployedBlockNumber > 0 + manager.rlnContractDeployedBlockNumber > 0.Quantity manager.rlnRelayMaxMessageLimit == 100 await manager.stop() asyncTest "should error on initialization when chainId does not match": let manager = await setup() - manager.chainId = CHAIN_ID + 1 + manager.chainId = utils_onchain.CHAIN_ID + 1 (await manager.init()).isErrOr: raiseAssert "Expected error when chainId does not match" diff --git a/tests/waku_rln_relay/utils.nim b/tests/waku_rln_relay/utils.nim index 548414fb7..2086acb88 100644 --- a/tests/waku_rln_relay/utils.nim +++ b/tests/waku_rln_relay/utils.nim @@ -1,4 +1,4 @@ -import web3, chronos, options, stint +import web3, chronos, options, stint, stew/byteutils proc deployContract*( web3: Web3, code: string, gasPrice = 0, contractInput = "" @@ -6,13 +6,13 @@ proc deployContract*( # the contract input is the encoded version of contract constructor's input # use nim-web3/encoding.nim module to find the appropriate encoding procedure for different argument types # e.g., consider the following contract constructor in solidity - # constructor(uint256 x, uint256 y) + # constructor(uint256 x, uint256 y) # # the contractInput can be calculated as follows # let # x = 1.u256 # y = 5.u256 - # contractInput = encode(x).data & encode(y).data + # contractInput = encode(x).data & encode(y).data # Note that the order of encoded inputs should match the order of the constructor inputs let provider = web3.provider let accounts = await provider.eth_accounts() @@ -20,12 +20,13 @@ proc deployContract*( var code = code if code[1] notin {'x', 'X'}: code = "0x" & code - var tr: EthSend - tr.source = web3.defaultAccount - tr.data = code & contractInput - tr.gas = Quantity(3000000000000).some + var tr: TransactionArgs + tr.`from` = Opt.some(web3.defaultAccount) + let sData = code & contractInput + tr.data = Opt.some(sData.toBytes()) + tr.gas = Opt.some(Quantity(3000000000000)) if gasPrice != 0: - tr.gasPrice = some(gasPrice) + tr.gasPrice = Opt.some(gasPrice.Quantity) let r = await web3.send(tr) return await web3.getMinedTransactionReceipt(r) diff --git a/tests/waku_rln_relay/utils_onchain.nim b/tests/waku_rln_relay/utils_onchain.nim index 272ddffa6..0c89f10c1 100644 --- a/tests/waku_rln_relay/utils_onchain.nim +++ b/tests/waku_rln_relay/utils_onchain.nim @@ -10,6 +10,8 @@ import chronicles, stint, web3, + web3/conversions, + web3/eth_api_types, json, libp2p/crypto/crypto, eth/keys @@ -27,6 +29,18 @@ import const CHAIN_ID* = 1337 +template skip0xPrefix(hexStr: string): int = + ## Returns the index of the first meaningful char in `hexStr` by skipping + ## "0x" prefix + if hexStr.len > 1 and hexStr[0] == '0' and hexStr[1] in {'x', 'X'}: 2 else: 0 + +func strip0xPrefix(s: string): string = + let prefixLen = skip0xPrefix(s) + if prefixLen != 0: + s[prefixLen .. ^1] + else: + s + proc generateCredentials*(rlnInstance: ptr RLN): IdentityCredential = let credRes = membershipKeyGen(rlnInstance) return credRes.get() @@ -85,12 +99,13 @@ proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} = debug "Address of the deployed rlnv2 contract: ", wakuRlnContractAddress # need to send concat: impl & init_bytes - let contractInput = encode(wakuRlnContractAddress).data & Erc1967ProxyContractInput + let contractInput = + byteutils.toHex(encode(wakuRlnContractAddress)) & Erc1967ProxyContractInput debug "contractInput", contractInput let proxyReceipt = await web3.deployContract(Erc1967Proxy, contractInput = contractInput) - debug "proxy receipt", proxyReceipt + debug "proxy receipt", contractAddress = proxyReceipt.contractAddress.get() let proxyAddress = proxyReceipt.contractAddress.get() let newBalance = await web3.provider.eth_getBalance(web3.defaultAccount, "latest") @@ -106,17 +121,17 @@ proc createEthAccount*( ): Future[(keys.PrivateKey, Address)] {.async.} = let web3 = await newWeb3(EthClient) let accounts = await web3.provider.eth_accounts() - let gasPrice = int(await web3.provider.eth_gasPrice()) + let gasPrice = Quantity(await web3.provider.eth_gasPrice()) web3.defaultAccount = accounts[0] let pk = keys.PrivateKey.random(rng[]) let acc = Address(toCanonicalAddress(pk.toPublicKey())) - var tx: EthSend - tx.source = accounts[0] - tx.value = some(ethToWei(ethAmount)) - tx.to = some(acc) - tx.gasPrice = some(gasPrice) + var tx: TransactionArgs + tx.`from` = Opt.some(accounts[0]) + tx.value = Opt.some(ethToWei(ethAmount)) + tx.to = Opt.some(acc) + tx.gasPrice = Opt.some(gasPrice) # Send ethAmount to acc discard await web3.send(tx) diff --git a/vendor/nim-chronicles b/vendor/nim-chronicles index a28bb9781..4524912fc 160000 --- a/vendor/nim-chronicles +++ b/vendor/nim-chronicles @@ -1 +1 @@ -Subproject commit a28bb9781ce74e725796c307ad05083e646872be +Subproject commit 4524912fcacfd3965e32a9fe23c9bb12d48177ff diff --git a/vendor/nim-eth b/vendor/nim-eth index bb5cb6a4d..84664b0fc 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit bb5cb6a4d0dbb592b395ab41cda3fd3f1fdc443e +Subproject commit 84664b0fc0b9128b4316afb85274271389aab00f diff --git a/vendor/nim-http-utils b/vendor/nim-http-utils index 8b88ad6dd..e8fc71aee 160000 --- a/vendor/nim-http-utils +++ b/vendor/nim-http-utils @@ -1 +1 @@ -Subproject commit 8b88ad6dd9a6326c29f82067800c483d9410d873 +Subproject commit e8fc71aee15203a852f6321e4dd8d87517502847 diff --git a/vendor/nim-json-rpc b/vendor/nim-json-rpc index 33360528d..be16a6528 160000 --- a/vendor/nim-json-rpc +++ b/vendor/nim-json-rpc @@ -1 +1 @@ -Subproject commit 33360528d208aaa70a6ed914619fe76321760d54 +Subproject commit be16a6528acfcfdaab381c4900240e454f7cdc63 diff --git a/vendor/nim-json-serialization b/vendor/nim-json-serialization index 8a4ed98bb..ab1a06175 160000 --- a/vendor/nim-json-serialization +++ b/vendor/nim-json-serialization @@ -1 +1 @@ -Subproject commit 8a4ed98bbd0a9479df15af2fa31da38a586ea6d5 +Subproject commit ab1a061756bb6fc2e0f98cb57852f2bb0c6f9772 diff --git a/vendor/nim-libp2p b/vendor/nim-libp2p index 18a2e79ce..09fe199b6 160000 --- a/vendor/nim-libp2p +++ b/vendor/nim-libp2p @@ -1 +1 @@ -Subproject commit 18a2e79ce209d2f21d8c5db7a41659cc39dbe0b4 +Subproject commit 09fe199b6bee6c3d0cc0e8750e67bbc0d52da138 diff --git a/vendor/nim-metrics b/vendor/nim-metrics index 29bb7ba63..f1f886957 160000 --- a/vendor/nim-metrics +++ b/vendor/nim-metrics @@ -1 +1 @@ -Subproject commit 29bb7ba63cd884770169891687595348a70cf166 +Subproject commit f1f886957831e9f2f16ffa728abb4bf44bfd5b98 diff --git a/vendor/nim-minilru b/vendor/nim-minilru new file mode 160000 index 000000000..2682cffa8 --- /dev/null +++ b/vendor/nim-minilru @@ -0,0 +1 @@ +Subproject commit 2682cffa8733f3b61751c65a963941315e887bac diff --git a/vendor/nim-nat-traversal b/vendor/nim-nat-traversal index a3aa0c5f9..05e76accb 160000 --- a/vendor/nim-nat-traversal +++ b/vendor/nim-nat-traversal @@ -1 +1 @@ -Subproject commit a3aa0c5f9d2a2870f1fd0f7a613d4fe025c84ab7 +Subproject commit 05e76accbc7811273fadc23d8886ac1a2f83bb81 diff --git a/vendor/nim-ngtcp2 b/vendor/nim-ngtcp2 new file mode 160000 index 000000000..6834f4756 --- /dev/null +++ b/vendor/nim-ngtcp2 @@ -0,0 +1 @@ +Subproject commit 6834f4756b6af58356ac9c4fef3d71db3c3ae5fe diff --git a/vendor/nim-presto b/vendor/nim-presto index 2190421e0..5d5dc51ba 160000 --- a/vendor/nim-presto +++ b/vendor/nim-presto @@ -1 +1 @@ -Subproject commit 2190421e09938696cd95d54b1f4753446c84c7a2 +Subproject commit 5d5dc51bac4aafb26c03d2d813a47e80093bd0c7 diff --git a/vendor/nim-quic b/vendor/nim-quic new file mode 160000 index 000000000..ddcb31ffb --- /dev/null +++ b/vendor/nim-quic @@ -0,0 +1 @@ +Subproject commit ddcb31ffb74b5460ab37fd13547eca90594248bc diff --git a/vendor/nim-secp256k1 b/vendor/nim-secp256k1 index 4470f49bc..641902d49 160000 --- a/vendor/nim-secp256k1 +++ b/vendor/nim-secp256k1 @@ -1 +1 @@ -Subproject commit 4470f49bcd6bcbfb59f0eeb67315ca9ddac0bdc0 +Subproject commit 641902d492aff3910b0240217fa0b28b5471baad diff --git a/vendor/nim-serialization b/vendor/nim-serialization index 298a9554a..7950ac1e8 160000 --- a/vendor/nim-serialization +++ b/vendor/nim-serialization @@ -1 +1 @@ -Subproject commit 298a9554a885b2df59737bb3461aac8d0d339724 +Subproject commit 7950ac1e8c9f0019c798f97ab1fe1d9367cc2e6d diff --git a/vendor/nim-stew b/vendor/nim-stew index d4634c540..b7b596955 160000 --- a/vendor/nim-stew +++ b/vendor/nim-stew @@ -1 +1 @@ -Subproject commit d4634c5405ac188e7050d348332edb6c3b09a527 +Subproject commit b7b596955726a65788561d2d69978223d4484c95 diff --git a/vendor/nim-taskpools b/vendor/nim-taskpools index d4c43137c..66585e2e9 160000 --- a/vendor/nim-taskpools +++ b/vendor/nim-taskpools @@ -1 +1 @@ -Subproject commit d4c43137c0590cb47f893a66ca8cb027fa6c217e +Subproject commit 66585e2e960b7695e48ea60377fb3aeac96406e8 diff --git a/vendor/nim-testutils b/vendor/nim-testutils index ae476c673..c36724c46 160000 --- a/vendor/nim-testutils +++ b/vendor/nim-testutils @@ -1 +1 @@ -Subproject commit ae476c67314ac4b294d21040315e0f716189a70e +Subproject commit c36724c469b657435f40fb7d365ad14640341606 diff --git a/vendor/nim-toml-serialization b/vendor/nim-toml-serialization index cb1fc73f3..53ae081cc 160000 --- a/vendor/nim-toml-serialization +++ b/vendor/nim-toml-serialization @@ -1 +1 @@ -Subproject commit cb1fc73f3519fed5f3a8fbfa90afc9a96d5f5f5c +Subproject commit 53ae081cc9a3e61095cab49862658a46b00eacf7 diff --git a/vendor/nim-unicodedb b/vendor/nim-unicodedb index 8c8959d84..15c5e25e2 160000 --- a/vendor/nim-unicodedb +++ b/vendor/nim-unicodedb @@ -1 +1 @@ -Subproject commit 8c8959d84c12ecda6ea14c67bd68675b1936f8cf +Subproject commit 15c5e25e2a49a924bc97647481ff50125bba2c76 diff --git a/vendor/nim-unittest2 b/vendor/nim-unittest2 index e96f32150..11f7cff92 160000 --- a/vendor/nim-unittest2 +++ b/vendor/nim-unittest2 @@ -1 +1 @@ -Subproject commit e96f3215030cbfa13abc2f5827069b6f8ba87e38 +Subproject commit 11f7cff9280933067fba1c736eac9d05b9bfca79 diff --git a/vendor/nim-web3 b/vendor/nim-web3 index 428b931e7..62a0005b0 160000 --- a/vendor/nim-web3 +++ b/vendor/nim-web3 @@ -1 +1 @@ -Subproject commit 428b931e7c4f1284b4272bc2c11fca2bd70991cd +Subproject commit 62a0005b0907a64090827d4e5d691682587f5b2a diff --git a/vendor/nim-websock b/vendor/nim-websock index 63bcc2902..179f81ded 160000 --- a/vendor/nim-websock +++ b/vendor/nim-websock @@ -1 +1 @@ -Subproject commit 63bcc2902d884c63101e144555ad99421734a70a +Subproject commit 179f81dedaddb5ba8d02534ccc8b7a8335981f49 diff --git a/vendor/nim-zlib b/vendor/nim-zlib index 45b06fca1..02311a356 160000 --- a/vendor/nim-zlib +++ b/vendor/nim-zlib @@ -1 +1 @@ -Subproject commit 45b06fca15ce0f09586067d950da30c10227865a +Subproject commit 02311a35623964a3ef37da8cd896ed95be06e6da diff --git a/vendor/nimcrypto b/vendor/nimcrypto index 71bca1550..a0b65f2a0 160000 --- a/vendor/nimcrypto +++ b/vendor/nimcrypto @@ -1 +1 @@ -Subproject commit 71bca15508e2c0548f32b42a69bcfb1ccd9ab9ff +Subproject commit a0b65f2a0dba987c75eadf03f811fb5508fd3372 diff --git a/waku.nimble b/waku.nimble index fccb6f6b1..48a8bb148 100644 --- a/waku.nimble +++ b/waku.nimble @@ -23,7 +23,9 @@ requires "nim >= 2.0.8", "web3", "presto", "regex", - "db_connector" + "db_connector", + "minilru", + "quic" ### Helper functions proc buildModule(filePath, params = "", lang = "c"): bool = diff --git a/waku/common/enr/builder.nim b/waku/common/enr/builder.nim index f4b3b472f..49e906413 100644 --- a/waku/common/enr/builder.nim +++ b/waku/common/enr/builder.nim @@ -41,9 +41,9 @@ proc build*(builder: EnrBuilder): EnrResult[enr.Record] = enr.Record.init( seqNum = builder.seqNumber, pk = builder.privateKey, - ip = none(IpAddress), - tcpPort = none(Port), - udpPort = none(Port), + ip = Opt.none(IpAddress), + tcpPort = Opt.none(Port), + udpPort = Opt.none(Port), extraFields = builder.fields, ) diff --git a/waku/common/enr/typed_record.nim b/waku/common/enr/typed_record.nim index 23ff6cc89..261e56d9a 100644 --- a/waku/common/enr/typed_record.nim +++ b/waku/common/enr/typed_record.nim @@ -4,6 +4,19 @@ import std/options, results, eth/keys as eth_keys, libp2p/crypto/crypto as libp2 import eth/p2p/discoveryv5/enr except TypedRecord, toTypedRecord +## Since enr changed to result.Opt[T] from Option[T] for intercompatibility introduce a conversion between +func toOpt*[T](o: Option[T]): Opt[T] = + if o.isSome(): + return Opt.some(o.get()) + else: + return Opt.none(T) + +func toOption*[T](o: Opt[T]): Option[T] = + if o.isSome(): + return some(o.get()) + else: + return none(T) + ## ENR typed record # Record identity scheme @@ -31,7 +44,7 @@ proc init(T: type TypedRecord, record: Record): T = TypedRecord(raw: record) proc tryGet*(record: TypedRecord, field: string, T: type): Option[T] = - record.raw.tryGet(field, T) + return record.raw.tryGet(field, T).toOption() func toTyped*(record: Record): EnrResult[TypedRecord] = let tr = TypedRecord.init(record) diff --git a/waku/common/utils/nat.nim b/waku/common/utils/nat.nim index 893e8d8a8..355f63aec 100644 --- a/waku/common/utils/nat.nim +++ b/waku/common/utils/nat.nim @@ -44,7 +44,7 @@ proc setupNat*( endpoint.ip = some(extIp.get()) # RedirectPorts in considered a gcsafety violation # because it obtains the address of a non-gcsafe proc? - var extPorts: Option[(Port, Port)] + var extPorts: Opt[(Port, Port)] try: extPorts = ( {.gcsafe.}: @@ -55,7 +55,7 @@ proc setupNat*( except CatchableError: # TODO: nat.nim Error: can raise an unlisted exception: Exception. Isolate here for now. error "unable to determine external ports" - extPorts = none((Port, Port)) + extPorts = Opt.none((Port, Port)) if extPorts.isSome(): let (extTcpPort, extUdpPort) = extPorts.get() diff --git a/waku/discovery/waku_discv5.nim b/waku/discovery/waku_discv5.nim index 5841b5685..badbe9c02 100644 --- a/waku/discovery/waku_discv5.nim +++ b/waku/discovery/waku_discv5.nim @@ -87,10 +87,10 @@ proc new*( privKey = conf.privateKey, bootstrapRecords = conf.bootstrapRecords, enrAutoUpdate = conf.autoupdateRecord, - previousRecord = record, - enrIp = none(IpAddress), - enrTcpPort = none(Port), - enrUdpPort = none(Port), + previousRecord = record.toOpt(), + enrIp = Opt.none(IpAddress), + enrTcpPort = Opt.none(Port), + enrUdpPort = Opt.none(Port), ) let shardPredOp = diff --git a/waku/waku_rln_relay/conversion_utils.nim b/waku/waku_rln_relay/conversion_utils.nim index d8be773d6..e710fea62 100644 --- a/waku/waku_rln_relay/conversion_utils.nim +++ b/waku/waku_rln_relay/conversion_utils.nim @@ -128,3 +128,8 @@ proc fromEpoch*(epoch: Epoch): uint64 = ## decodes bytes of `epoch` (in little-endian) to uint64 let t = fromBytesLE(uint64, array[32, byte](epoch)) return t + +func `+`*(a, b: Quantity): Quantity {.borrow.} + +func u256*(n: Quantity): UInt256 {.inline.} = + n.uint64.stuint(256) 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 1fada3a95..5415595fc 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 @@ -3,10 +3,11 @@ import os, web3, - web3/ethtypes, + web3/eth_api_types, + web3/primitives, eth/keys as keys, chronicles, - nimcrypto/keccak, + nimcrypto/keccak as keccak, stint, json, std/tables, @@ -30,11 +31,11 @@ logScope: # using the when predicate does not work within the contract macro, hence need to dupe contract(WakuRlnContract): # this serves as an entrypoint into the rln membership set - proc register(idCommitment: UInt256, userMessageLimit: UInt32) + proc register(idCommitment: UInt256, userMessageLimit: StUint[32]) # Initializes the implementation contract (only used in unit tests) proc initialize(maxMessageLimit: UInt256) # this event is raised when a new member is registered - proc MemberRegistered(rateCommitment: UInt256, index: Uint32) {.event.} + proc MemberRegistered(rateCommitment: UInt256, index: StUint[32]) {.event.} # this function denotes existence of a given user proc memberExists(idCommitment: Uint256): UInt256 {.view.} @@ -100,7 +101,7 @@ proc setMetadata*( try: let metadataSetRes = g.rlnInstance.setMetadata( RlnMetadata( - lastProcessedBlock: normalizedBlock, + lastProcessedBlock: normalizedBlock.uint64, chainId: g.chainId, contractAddress: g.ethContractAddress, validRoots: g.validRoots.toSeq(), @@ -190,15 +191,15 @@ method register*( g.registrationTxHash = some(txHash) # the receipt topic holds the hash of signature of the raised events # TODO: make this robust. search within the event list for the event - debug "ts receipt", tsReceipt + # debug "ts receipt", tsReceipt let firstTopic = tsReceipt.logs[0].topics[0] # the hash of the signature of MemberRegistered(uint256,uint32) event is equal to the following hex value if firstTopic != - cast[FixedBytes[32]](keccak256.digest("MemberRegistered(uint256,uint32)").data): + cast[FixedBytes[32]](keccak.keccak256.digest("MemberRegistered(uint256,uint32)").data): raise newException(ValueError, "unexpected event signature") # the arguments of the raised event i.e., MemberRegistered are encoded inside the data field - # data = rateCommitment encoded as 256 bits || index encoded as 32 bits + # data = rateCommitment encoded as 256 bits || index encoded as 32 bits let arguments = tsReceipt.logs[0].data debug "tx log data", arguments = arguments let @@ -231,11 +232,10 @@ proc parseEvent( ## returns an error if it cannot parse the `data` parameter var rateCommitment: UInt256 var index: UInt256 - var data: string - # Remove the 0x prefix + var data: seq[byte] try: - data = strip0xPrefix(log["data"].getStr()) - except CatchableError: + data = hexToSeqByte(log["data"].getStr()) + except ValueError: return err( "failed to parse the data field of the MemberRegistered event: " & getCurrentExceptionMsg() @@ -243,9 +243,9 @@ proc parseEvent( var offset = 0 try: # Parse the rateCommitment - offset += decode(data, offset, rateCommitment) + offset += decode(data, 0, offset, rateCommitment) # Parse the index - offset += decode(data, offset, index) + offset += decode(data, 0, offset, index) return ok( Membership( rateCommitment: rateCommitment.toRateCommitment(), @@ -291,13 +291,18 @@ proc getRawEvents( let ethRpc = g.ethRpc.get() let wakuRlnContract = g.wakuRlnContract.get() - var events: JsonNode - g.retryWrapper(events, "Failed to get the events"): + var eventStrs: seq[JsonString] + g.retryWrapper(eventStrs, "Failed to get the events"): await wakuRlnContract.getJsonLogs( MemberRegistered, - fromBlock = some(fromBlock.blockId()), - toBlock = some(toBlock.blockId()), + fromBlock = Opt.some(fromBlock.blockId()), + toBlock = Opt.some(toBlock.blockId()), ) + + var events: JsonNode + if events.len == 0: + for eventStr in eventStrs: + events.add(parseJson($eventStr)) return events proc getBlockTable( @@ -314,7 +319,7 @@ proc getBlockTable( return blockTable for event in events: - let blockNumber = parseHexInt(event["blockNumber"].getStr()).uint + let blockNumber = parseHexInt(event["blockNumber"].getStr()).Quantity let removed = event["removed"].getBool() let parsedEventRes = parseEvent(MemberRegistered, event) if parsedEventRes.isErr(): @@ -450,13 +455,13 @@ proc startOnchainSync( let ethRpc = g.ethRpc.get() # static block chunk size - let blockChunkSize = 2_000 + let blockChunkSize = 2_000.BlockNumber # delay between rpc calls to not overload the rate limit let rpcDelay = 200.milliseconds # max number of futures to run concurrently let maxFutures = 10 - var fromBlock = + var fromBlock: BlockNumber = if g.latestProcessedBlock > g.rlnContractDeployedBlockNumber: info "syncing from last processed block", blockNumber = g.latestProcessedBlock g.latestProcessedBlock + 1 @@ -479,11 +484,11 @@ proc startOnchainSync( if fromBlock >= currentLatestBlock: break - if fromBlock + blockChunkSize.uint > currentLatestBlock.uint: + if fromBlock + blockChunkSize > currentLatestBlock: g.retryWrapper(currentLatestBlock, "Failed to get the latest block number"): cast[BlockNumber](await ethRpc.provider.eth_blockNumber()) - let toBlock = min(fromBlock + BlockNumber(blockChunkSize), currentLatestBlock) + let toBlock = min(fromBlock + blockChunkSize, currentLatestBlock) debug "fetching events", fromBlock = fromBlock, toBlock = toBlock await sleepAsync(rpcDelay) futs.add(g.getAndHandleEvents(fromBlock, toBlock)) @@ -551,7 +556,7 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.} let pk = g.ethPrivateKey.get() let parsedPk = keys.PrivateKey.fromHex(pk).valueOr: return err("failed to parse the private key" & ": " & $error) - ethRpc.privateKey = some(parsedPk) + ethRpc.privateKey = Opt.some(parsedPk) ethRpc.defaultAccount = ethRpc.privateKey.get().toPublicKey().toCanonicalAddress().Address @@ -605,7 +610,7 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.} if metadata.contractAddress != g.ethContractAddress.toLower(): return err("persisted data: contract address mismatch") - g.latestProcessedBlock = metadata.lastProcessedBlock + g.latestProcessedBlock = metadata.lastProcessedBlock.BlockNumber g.validRoots = metadata.validRoots.toDeque() var deployedBlockNumber: Uint256 @@ -661,10 +666,10 @@ method stop*(g: OnchainGroupManager): Future[void] {.async, gcsafe.} = proc isSyncing*(g: OnchainGroupManager): Future[bool] {.async, gcsafe.} = let ethRpc = g.ethRpc.get() - var syncing: JsonNode + var syncing: SyncingStatus g.retryWrapper(syncing, "Failed to get the syncing status"): await ethRpc.provider.eth_syncing() - return syncing.getBool() + return syncing.syncing method isReady*(g: OnchainGroupManager): Future[bool] {.async.} = initializedGuard(g) @@ -677,7 +682,7 @@ method isReady*(g: OnchainGroupManager): Future[bool] {.async.} = cast[BlockNumber](await g.ethRpc.get().provider.eth_blockNumber()) # the node is still able to process messages if it is behind the latest block by a factor of the valid roots - if u256(g.latestProcessedBlock) < (u256(currentBlock) - u256(g.validRoots.len)): + if u256(g.latestProcessedBlock.uint64) < (u256(currentBlock) - u256(g.validRoots.len)): return false return not (await g.isSyncing()) diff --git a/waku/waku_rln_relay/rln/wrappers.nim b/waku/waku_rln_relay/rln/wrappers.nim index 3d2b62e21..24682dda6 100644 --- a/waku/waku_rln_relay/rln/wrappers.nim +++ b/waku/waku_rln_relay/rln/wrappers.nim @@ -87,7 +87,7 @@ proc createRLNInstanceLocal( ## generates an instance of RLN ## An RLN instance supports both zkSNARKs logics and Merkle tree data structure and operations ## d indicates the depth of Merkle tree - ## tree_path indicates the path of the Merkle tree + ## tree_path indicates the path of the Merkle tree ## Returns an error if the instance creation fails let rln_config = RlnConfig( diff --git a/waku/waku_rln_relay/rln_relay.nim b/waku/waku_rln_relay/rln_relay.nim index 0c86f0746..535cee4a2 100644 --- a/waku/waku_rln_relay/rln_relay.nim +++ b/waku/waku_rln_relay/rln_relay.nim @@ -8,7 +8,7 @@ import stint, web3, json, - web3/ethtypes, + web3/eth_api_types, eth/keys, libp2p/protocols/pubsub/rpc/messages, libp2p/protocols/pubsub/pubsub, @@ -277,7 +277,7 @@ proc validateMessageAndUpdateLog*( if proofMetadataRes.isErr(): return MessageValidationResult.Invalid - # insert the message to the log (never errors) only if the + # insert the message to the log (never errors) only if the # message is valid. if isValidMessage == MessageValidationResult.Valid: discard rlnPeer.updateLog(msgProof.epoch, proofMetadataRes.get())