mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 14:03:06 +00:00
chore: bump dependencies for v0.35 (#3255)
Changes:
modified: .gitmodules
modified: tests/waku_discv5/utils.nim
modified: tests/waku_enr/utils.nim
modified: tests/waku_rln_relay/test_rln_group_manager_onchain.nim
modified: tests/waku_rln_relay/utils.nim
modified: tests/waku_rln_relay/utils_onchain.nim
modified: vendor/nim-chronicles
modified: vendor/nim-eth
modified: vendor/nim-http-utils
modified: vendor/nim-json-rpc
modified: vendor/nim-json-serialization
modified: vendor/nim-libp2p - 1.8.0!
modified: vendor/nim-metrics
new file: vendor/nim-minilru
modified: vendor/nim-nat-traversal
modified: vendor/nim-presto
modified: vendor/nim-secp256k1
modified: vendor/nim-serialization
modified: vendor/nim-stew
modified: vendor/nim-taskpools
modified: vendor/nim-testutils
modified: vendor/nim-toml-serialization
modified: vendor/nim-unicodedb
modified: vendor/nim-unittest2
modified: vendor/nim-web3 - from distinct branch that solves Ethereum ABI issue.
modified: vendor/nim-websock
modified: vendor/nim-zlib
modified: vendor/nimcrypto
modified: waku.nimble
modified: waku/common/enr/builder.nim
modified: waku/common/enr/typed_record.nim
modified: waku/common/utils/nat.nim
modified: waku/discovery/waku_discv5.nim
modified: waku/waku_rln_relay/conversion_utils.nim
modified: waku/waku_rln_relay/group_manager/on_chain/group_manager.nim
modified: waku/waku_rln_relay/rln/wrappers.nim
modified: waku/waku_rln_relay/rln_relay.nim
* Eliminate C compilation issue with chat2bridge due to an overcomplicating import from json_rpc instead of using std/json
* Adapt ENR Record handling to new interface of nim-eth
* Fix chrash in group_manager on_chain
* Fix signature of register and MemberRegister to UInt256, check transaction success in register
* Upgrade json-rpc and serialization
* Update to match latest enr and nat interface
* Using of extracted result of contract macro - with necessary adaption
* Bump nim-chornicles, nim-libp2p, nimcrypto
* Bump nim-web3, nim-eth and deps - on_chain/group_manager.nim adaption
* Added status-im/nim-minilru submodule required by latest nim-eth
Fixing tests.
* group_manager: adapt smart contract param types
* update web3 vendor
* bump vendors for v0.35.0
* protobuf.nim: fix compilation error after nim-libp2p bump
* changes to make it compile after rebase from master
---------
Co-authored-by: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com>
This commit is contained in:
parent
cc864a8e91
commit
c01a21e01f
15
.gitmodules
vendored
15
.gitmodules
vendored
@ -174,3 +174,18 @@
|
|||||||
branch = master
|
branch = master
|
||||||
path = vendor/nph
|
path = vendor/nph
|
||||||
url = https://github.com/arnetheduck/nph.git
|
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
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[tables, times, strutils, hashes, sequtils],
|
std/[tables, times, strutils, hashes, sequtils, json],
|
||||||
chronos,
|
chronos,
|
||||||
confutils,
|
confutils,
|
||||||
chronicles,
|
chronicles,
|
||||||
@ -11,7 +11,6 @@ import
|
|||||||
metrics/chronos_httpserver,
|
metrics/chronos_httpserver,
|
||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
eth/net/nat,
|
eth/net/nat,
|
||||||
json_rpc/rpcserver,
|
|
||||||
# Matterbridge client imports
|
# Matterbridge client imports
|
||||||
# Waku v2 imports
|
# Waku v2 imports
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
|
|||||||
@ -120,7 +120,7 @@ suite "nim-eth ENR - Ext: IP address and TCP/UDP ports":
|
|||||||
@(record.secp256k1.get()) == expectedPubKey
|
@(record.secp256k1.get()) == expectedPubKey
|
||||||
record.ip == none(array[4, byte])
|
record.ip == none(array[4, byte])
|
||||||
record.tcp == none(uint16)
|
record.tcp == none(uint16)
|
||||||
record.udp == none(uint16)
|
|
||||||
record.ip6 == some(enrIpAddr.address_v6)
|
record.ip6 == some(enrIpAddr.address_v6)
|
||||||
record.tcp6 == none(uint16)
|
record.tcp6 == none(uint16)
|
||||||
record.udp6 == some(enrUdpPort.uint16)
|
record.udp6 == some(enrUdpPort.uint16)
|
||||||
|
record.udp == some(enrUdpPort.uint16)
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import
|
import
|
||||||
|
std/options,
|
||||||
stew/results,
|
stew/results,
|
||||||
stew/shims/net,
|
stew/shims/net,
|
||||||
chronos,
|
chronos,
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import
|
import
|
||||||
|
std/options,
|
||||||
sequtils,
|
sequtils,
|
||||||
stew/results,
|
stew/results,
|
||||||
stew/shims/net,
|
stew/shims/net,
|
||||||
|
|||||||
@ -50,11 +50,11 @@ suite "Onchain group manager":
|
|||||||
manager.ethRpc.isSome()
|
manager.ethRpc.isSome()
|
||||||
manager.wakuRlnContract.isSome()
|
manager.wakuRlnContract.isSome()
|
||||||
manager.initialized
|
manager.initialized
|
||||||
manager.rlnContractDeployedBlockNumber > 0
|
manager.rlnContractDeployedBlockNumber > 0.Quantity
|
||||||
manager.rlnRelayMaxMessageLimit == 100
|
manager.rlnRelayMaxMessageLimit == 100
|
||||||
|
|
||||||
asyncTest "should error on initialization when chainId does not match":
|
asyncTest "should error on initialization when chainId does not match":
|
||||||
manager.chainId = CHAIN_ID + 1
|
manager.chainId = utils_onchain.CHAIN_ID + 1
|
||||||
|
|
||||||
(await manager.init()).isErrOr:
|
(await manager.init()).isErrOr:
|
||||||
raiseAssert "Expected error when chainId does not match"
|
raiseAssert "Expected error when chainId does not match"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import web3, chronos, options, stint
|
import web3, chronos, options, stint, stew/byteutils
|
||||||
|
|
||||||
proc deployContract*(
|
proc deployContract*(
|
||||||
web3: Web3, code: string, gasPrice = 0, contractInput = ""
|
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
|
# 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
|
# 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
|
# 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
|
# the contractInput can be calculated as follows
|
||||||
# let
|
# let
|
||||||
# x = 1.u256
|
# x = 1.u256
|
||||||
# y = 5.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
|
# Note that the order of encoded inputs should match the order of the constructor inputs
|
||||||
let provider = web3.provider
|
let provider = web3.provider
|
||||||
let accounts = await provider.eth_accounts()
|
let accounts = await provider.eth_accounts()
|
||||||
@ -20,12 +20,13 @@ proc deployContract*(
|
|||||||
var code = code
|
var code = code
|
||||||
if code[1] notin {'x', 'X'}:
|
if code[1] notin {'x', 'X'}:
|
||||||
code = "0x" & code
|
code = "0x" & code
|
||||||
var tr: EthSend
|
var tr: TransactionArgs
|
||||||
tr.source = web3.defaultAccount
|
tr.`from` = Opt.some(web3.defaultAccount)
|
||||||
tr.data = code & contractInput
|
let sData = code & contractInput
|
||||||
tr.gas = Quantity(3000000000000).some
|
tr.data = Opt.some(hexToSeqByte(sData))
|
||||||
|
tr.gas = Opt.some(Quantity(3000000000000))
|
||||||
if gasPrice != 0:
|
if gasPrice != 0:
|
||||||
tr.gasPrice = some(gasPrice)
|
tr.gasPrice = Opt.some(gasPrice.Quantity)
|
||||||
|
|
||||||
let r = await web3.send(tr)
|
let r = await web3.send(tr)
|
||||||
return await web3.getMinedTransactionReceipt(r)
|
return await web3.getMinedTransactionReceipt(r)
|
||||||
|
|||||||
@ -10,6 +10,8 @@ import
|
|||||||
chronicles,
|
chronicles,
|
||||||
stint,
|
stint,
|
||||||
web3,
|
web3,
|
||||||
|
web3/conversions,
|
||||||
|
web3/eth_api_types,
|
||||||
json,
|
json,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
@ -28,6 +30,18 @@ import
|
|||||||
|
|
||||||
const CHAIN_ID* = 1337
|
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 =
|
proc generateCredentials*(rlnInstance: ptr RLN): IdentityCredential =
|
||||||
let credRes = membershipKeyGen(rlnInstance)
|
let credRes = membershipKeyGen(rlnInstance)
|
||||||
return credRes.get()
|
return credRes.get()
|
||||||
@ -86,12 +100,13 @@ proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
|
|||||||
debug "Address of the deployed rlnv2 contract: ", wakuRlnContractAddress
|
debug "Address of the deployed rlnv2 contract: ", wakuRlnContractAddress
|
||||||
|
|
||||||
# need to send concat: impl & init_bytes
|
# need to send concat: impl & init_bytes
|
||||||
let contractInput = encode(wakuRlnContractAddress).data & Erc1967ProxyContractInput
|
let contractInput =
|
||||||
|
byteutils.toHex(encode(wakuRlnContractAddress)) & Erc1967ProxyContractInput
|
||||||
debug "contractInput", contractInput
|
debug "contractInput", contractInput
|
||||||
let proxyReceipt =
|
let proxyReceipt =
|
||||||
await web3.deployContract(Erc1967Proxy, contractInput = contractInput)
|
await web3.deployContract(Erc1967Proxy, contractInput = contractInput)
|
||||||
|
|
||||||
debug "proxy receipt", proxyReceipt
|
debug "proxy receipt", contractAddress = proxyReceipt.contractAddress.get()
|
||||||
let proxyAddress = proxyReceipt.contractAddress.get()
|
let proxyAddress = proxyReceipt.contractAddress.get()
|
||||||
|
|
||||||
let newBalance = await web3.provider.eth_getBalance(web3.defaultAccount, "latest")
|
let newBalance = await web3.provider.eth_getBalance(web3.defaultAccount, "latest")
|
||||||
@ -119,11 +134,11 @@ proc sendEthTransfer*(
|
|||||||
|
|
||||||
let gasPrice = int(await web3.provider.eth_gasPrice())
|
let gasPrice = int(await web3.provider.eth_gasPrice())
|
||||||
|
|
||||||
var tx: EthSend
|
var tx: TransactionArgs
|
||||||
tx.source = accountFrom
|
tx.`from` = Opt.some(accountFrom)
|
||||||
tx.to = some(accountTo)
|
tx.to = Opt.some(accountTo)
|
||||||
tx.value = some(amountWei)
|
tx.value = Opt.some(amountWei)
|
||||||
tx.gasPrice = some(gasPrice)
|
tx.gasPrice = Opt.some(Quantity(gasPrice))
|
||||||
|
|
||||||
# TODO: handle the error if sending fails
|
# TODO: handle the error if sending fails
|
||||||
let txHash = await web3.send(tx)
|
let txHash = await web3.send(tx)
|
||||||
@ -136,6 +151,34 @@ proc sendEthTransfer*(
|
|||||||
|
|
||||||
return txHash
|
return txHash
|
||||||
|
|
||||||
|
proc ethToWei(eth: UInt256): UInt256 =
|
||||||
|
eth * 1000000000000000000.u256
|
||||||
|
|
||||||
|
proc createEthAccount*(
|
||||||
|
ethAmount: UInt256 = 1000.u256
|
||||||
|
): Future[(keys.PrivateKey, Address)] {.async.} =
|
||||||
|
let web3 = await newWeb3(EthClient)
|
||||||
|
let accounts = await web3.provider.eth_accounts()
|
||||||
|
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: TransactionArgs
|
||||||
|
tx.`from` = Opt.some(accounts[0])
|
||||||
|
tx.value = Opt.some(ethToWei(ethAmount))
|
||||||
|
tx.to = Opt.some(acc)
|
||||||
|
tx.gasPrice = Opt.some(Quantity(gasPrice))
|
||||||
|
|
||||||
|
# Send ethAmount to acc
|
||||||
|
discard await web3.send(tx)
|
||||||
|
let balance = await web3.provider.eth_getBalance(acc, "latest")
|
||||||
|
assert balance == ethToWei(ethAmount),
|
||||||
|
fmt"Balance is {balance} but expected {ethToWei(ethAmount)}"
|
||||||
|
|
||||||
|
return (pk, acc)
|
||||||
|
|
||||||
proc createEthAccount*(web3: Web3): (keys.PrivateKey, Address) =
|
proc createEthAccount*(web3: Web3): (keys.PrivateKey, Address) =
|
||||||
let pk = keys.PrivateKey.random(rng[])
|
let pk = keys.PrivateKey.random(rng[])
|
||||||
let acc = Address(toCanonicalAddress(pk.toPublicKey()))
|
let acc = Address(toCanonicalAddress(pk.toPublicKey()))
|
||||||
@ -205,9 +248,6 @@ proc stopAnvil*(runAnvil: Process) {.used.} =
|
|||||||
except:
|
except:
|
||||||
error "Anvil daemon termination failed: ", err = getCurrentExceptionMsg()
|
error "Anvil daemon termination failed: ", err = getCurrentExceptionMsg()
|
||||||
|
|
||||||
proc ethToWei(eth: UInt256): UInt256 =
|
|
||||||
eth * 1000000000000000000.u256
|
|
||||||
|
|
||||||
proc setupOnchainGroupManager*(
|
proc setupOnchainGroupManager*(
|
||||||
ethClientAddress: string = EthClient, amountEth: UInt256 = 10.u256
|
ethClientAddress: string = EthClient, amountEth: UInt256 = 10.u256
|
||||||
): Future[OnchainGroupManager] {.async.} =
|
): Future[OnchainGroupManager] {.async.} =
|
||||||
|
|||||||
2
vendor/db_connector
vendored
2
vendor/db_connector
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 70d2ab3ff9907cb5b1d863bfb333a0ced5ee1596
|
Subproject commit 74aef399e5c232f95c9fc5c987cebac846f09d62
|
||||||
2
vendor/nim-chronicles
vendored
2
vendor/nim-chronicles
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 4524912fcacfd3965e32a9fe23c9bb12d48177ff
|
Subproject commit 32ac8679680ea699f7dbc046e8e0131cac97d41a
|
||||||
2
vendor/nim-confutils
vendored
2
vendor/nim-confutils
vendored
@ -1 +1 @@
|
|||||||
Subproject commit cb640db2cd66d7f4a1810a7df51b55f6f59cf3c5
|
Subproject commit e214b3992a31acece6a9aada7d0a1ad37c928f3b
|
||||||
2
vendor/nim-eth
vendored
2
vendor/nim-eth
vendored
@ -1 +1 @@
|
|||||||
Subproject commit bb5cb6a4d0dbb592b395ab41cda3fd3f1fdc443e
|
Subproject commit c6c9dc7ae01656eba8126b913e84bdfb95c8c323
|
||||||
2
vendor/nim-faststreams
vendored
2
vendor/nim-faststreams
vendored
@ -1 +1 @@
|
|||||||
Subproject commit dbc4a95df60238157dcf286f6125188cb72f37c1
|
Subproject commit 2b08c774afaafd600cf4c6f994cf78b8aa090c0c
|
||||||
2
vendor/nim-http-utils
vendored
2
vendor/nim-http-utils
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 8b88ad6dd9a6326c29f82067800c483d9410d873
|
Subproject commit 79cbab1460f4c0cdde2084589d017c43a3d7b4f1
|
||||||
2
vendor/nim-json-rpc
vendored
2
vendor/nim-json-rpc
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 33360528d208aaa70a6ed914619fe76321760d54
|
Subproject commit c0ac848733e42e672081f429fb146451894f7711
|
||||||
2
vendor/nim-json-serialization
vendored
2
vendor/nim-json-serialization
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 8a4ed98bbd0a9479df15af2fa31da38a586ea6d5
|
Subproject commit 2b1c5eb11df3647a2cee107cd4cce3593cbb8bcf
|
||||||
2
vendor/nim-libbacktrace
vendored
2
vendor/nim-libbacktrace
vendored
@ -1 +1 @@
|
|||||||
Subproject commit b6e26f03c091a8e3bba6adc06198fc3055bacc66
|
Subproject commit dbade9ba250da7db519c5cdfb225d03ca1255efc
|
||||||
2
vendor/nim-libp2p
vendored
2
vendor/nim-libp2p
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 8855bce0854ecf4adad7a0556bb2b2d2f98e0e20
|
Subproject commit c5aa3736f96e4d66f6aa653a2351ded74b7d21a9
|
||||||
2
vendor/nim-metrics
vendored
2
vendor/nim-metrics
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 29bb7ba63cd884770169891687595348a70cf166
|
Subproject commit 25ffd054fd774f8cf7935e75d6cad542306d7802
|
||||||
1
vendor/nim-minilru
vendored
Submodule
1
vendor/nim-minilru
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 2682cffa8733f3b61751c65a963941315e887bac
|
||||||
2
vendor/nim-nat-traversal
vendored
2
vendor/nim-nat-traversal
vendored
@ -1 +1 @@
|
|||||||
Subproject commit a3aa0c5f9d2a2870f1fd0f7a613d4fe025c84ab7
|
Subproject commit 213ac13dfe5c4830474912c48181b86b73f1ec1f
|
||||||
2
vendor/nim-presto
vendored
2
vendor/nim-presto
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 2190421e09938696cd95d54b1f4753446c84c7a2
|
Subproject commit 3ccb356220b70f7d9eb0fbd58b674c4080f78014
|
||||||
2
vendor/nim-regex
vendored
2
vendor/nim-regex
vendored
@ -1 +1 @@
|
|||||||
Subproject commit cb8b7bfdcdc2272aadf92153c668acd3c901bd6b
|
Subproject commit 0673df07cb266e15942c3b5f5b8a4732f049cd73
|
||||||
2
vendor/nim-results
vendored
2
vendor/nim-results
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 71d404b314479a6205bfd050f4fe5fe49cdafc69
|
Subproject commit df8113dda4c2d74d460a8fa98252b0b771bf1f27
|
||||||
2
vendor/nim-secp256k1
vendored
2
vendor/nim-secp256k1
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 4470f49bcd6bcbfb59f0eeb67315ca9ddac0bdc0
|
Subproject commit 62e16b4dff513f1eea7148a8cbba8a8c547b9546
|
||||||
2
vendor/nim-serialization
vendored
2
vendor/nim-serialization
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 298a9554a885b2df59737bb3461aac8d0d339724
|
Subproject commit 2086c99608b4bf472e1ef5fe063710f280243396
|
||||||
2
vendor/nim-sqlite3-abi
vendored
2
vendor/nim-sqlite3-abi
vendored
@ -1 +1 @@
|
|||||||
Subproject commit acd3c327433784226b412757bdb5455b5be04c55
|
Subproject commit cc4fefd538aa43814c5864c540fb75b567c2dcc3
|
||||||
2
vendor/nim-stew
vendored
2
vendor/nim-stew
vendored
@ -1 +1 @@
|
|||||||
Subproject commit d4634c5405ac188e7050d348332edb6c3b09a527
|
Subproject commit 687d1b4ab1a91e6cc9c92e4fd4d98bec7874c259
|
||||||
2
vendor/nim-stint
vendored
2
vendor/nim-stint
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 7c81df9adc80088f46a4c2b8bf2a46c26fab057c
|
Subproject commit 1a2c661e3f50ff696b0b6692fab0d7bb2abf10cc
|
||||||
2
vendor/nim-taskpools
vendored
2
vendor/nim-taskpools
vendored
@ -1 +1 @@
|
|||||||
Subproject commit d4c43137c0590cb47f893a66ca8cb027fa6c217e
|
Subproject commit 7b74a716a40249720fd7da428113147942b9642d
|
||||||
2
vendor/nim-testutils
vendored
2
vendor/nim-testutils
vendored
@ -1 +1 @@
|
|||||||
Subproject commit ae476c67314ac4b294d21040315e0f716189a70e
|
Subproject commit 14a56ae5aada81bed43e29d2368fc8ab8a449bf5
|
||||||
2
vendor/nim-toml-serialization
vendored
2
vendor/nim-toml-serialization
vendored
@ -1 +1 @@
|
|||||||
Subproject commit cb1fc73f3519fed5f3a8fbfa90afc9a96d5f5f5c
|
Subproject commit fea85b27f0badcf617033ca1bc05444b5fd8aa7a
|
||||||
2
vendor/nim-unicodedb
vendored
2
vendor/nim-unicodedb
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 8c8959d84c12ecda6ea14c67bd68675b1936f8cf
|
Subproject commit 66f2458710dc641dd4640368f9483c8a0ec70561
|
||||||
2
vendor/nim-unittest2
vendored
2
vendor/nim-unittest2
vendored
@ -1 +1 @@
|
|||||||
Subproject commit e96f3215030cbfa13abc2f5827069b6f8ba87e38
|
Subproject commit 88a613ffa4dbe452971beb937ea2db736dc9a9f4
|
||||||
2
vendor/nim-web3
vendored
2
vendor/nim-web3
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 428b931e7c4f1284b4272bc2c11fca2bd70991cd
|
Subproject commit 94aac8a77cd265fe779ce8ed25a028340b925fd1
|
||||||
2
vendor/nim-websock
vendored
2
vendor/nim-websock
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 63bcc2902d884c63101e144555ad99421734a70a
|
Subproject commit ebe308a79a7b440a11dfbe74f352be86a3883508
|
||||||
2
vendor/nim-zlib
vendored
2
vendor/nim-zlib
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 45b06fca15ce0f09586067d950da30c10227865a
|
Subproject commit 3f7998095264d262a8d99e2be89045e6d9301537
|
||||||
2
vendor/nimcrypto
vendored
2
vendor/nimcrypto
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 71bca15508e2c0548f32b42a69bcfb1ccd9ab9ff
|
Subproject commit dc07e3058c6904eef965394493b6ea99aa2adefc
|
||||||
2
vendor/nph
vendored
2
vendor/nph
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 31bdced07d3dc3d254669bd94210101c701deeda
|
Subproject commit 0d8000e741fa11ed48fdd116f24b4251b92aa9b5
|
||||||
2
vendor/zerokit
vendored
2
vendor/zerokit
vendored
@ -1 +1 @@
|
|||||||
Subproject commit e6238fd7228dd645eb7d6f3bf2077a8623c38fcf
|
Subproject commit b9d27039c3266af108882d7a8bafc37400d29855
|
||||||
@ -23,7 +23,9 @@ requires "nim >= 2.0.8",
|
|||||||
"web3",
|
"web3",
|
||||||
"presto",
|
"presto",
|
||||||
"regex",
|
"regex",
|
||||||
"db_connector"
|
"db_connector",
|
||||||
|
"minilru",
|
||||||
|
"quic"
|
||||||
|
|
||||||
### Helper functions
|
### Helper functions
|
||||||
proc buildModule(filePath, params = "", lang = "c"): bool =
|
proc buildModule(filePath, params = "", lang = "c"): bool =
|
||||||
|
|||||||
@ -7,15 +7,27 @@ import
|
|||||||
eth/p2p/discoveryv5/enr,
|
eth/p2p/discoveryv5/enr,
|
||||||
libp2p/crypto/crypto as libp2p_crypto
|
libp2p/crypto/crypto as libp2p_crypto
|
||||||
|
|
||||||
|
import ./typed_record
|
||||||
|
|
||||||
## Builder
|
## Builder
|
||||||
|
|
||||||
type EnrBuilder* = object
|
type EnrBuilder* = object
|
||||||
seqNumber: uint64
|
seqNumber: uint64
|
||||||
privateKey: eth_keys.PrivateKey
|
privateKey: eth_keys.PrivateKey
|
||||||
|
ipAddress: Opt[IpAddress]
|
||||||
|
tcpPort: Opt[Port]
|
||||||
|
udpPort: Opt[Port]
|
||||||
fields: seq[FieldPair]
|
fields: seq[FieldPair]
|
||||||
|
|
||||||
proc init*(T: type EnrBuilder, key: eth_keys.PrivateKey, seqNum: uint64 = 1): T =
|
proc init*(T: type EnrBuilder, key: eth_keys.PrivateKey, seqNum: uint64 = 1): T =
|
||||||
EnrBuilder(seqNumber: seqNum, privateKey: key, fields: newSeq[FieldPair]())
|
EnrBuilder(
|
||||||
|
seqNumber: seqNum,
|
||||||
|
privateKey: key,
|
||||||
|
ipAddress: Opt.none(IpAddress),
|
||||||
|
tcpPort: Opt.none(Port),
|
||||||
|
udpPort: Opt.none(Port),
|
||||||
|
fields: newSeq[FieldPair](),
|
||||||
|
)
|
||||||
|
|
||||||
proc init*(T: type EnrBuilder, key: libp2p_crypto.PrivateKey, seqNum: uint64 = 1): T =
|
proc init*(T: type EnrBuilder, key: libp2p_crypto.PrivateKey, seqNum: uint64 = 1): T =
|
||||||
# TODO: Inconvenient runtime assertion. Move this assertion to compile time
|
# TODO: Inconvenient runtime assertion. Move this assertion to compile time
|
||||||
@ -41,9 +53,9 @@ proc build*(builder: EnrBuilder): EnrResult[enr.Record] =
|
|||||||
enr.Record.init(
|
enr.Record.init(
|
||||||
seqNum = builder.seqNumber,
|
seqNum = builder.seqNumber,
|
||||||
pk = builder.privateKey,
|
pk = builder.privateKey,
|
||||||
ip = none(IpAddress),
|
ip = builder.ipAddress,
|
||||||
tcpPort = none(Port),
|
tcpPort = builder.tcpPort,
|
||||||
udpPort = none(Port),
|
udpPort = builder.udpPort,
|
||||||
extraFields = builder.fields,
|
extraFields = builder.fields,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,38 +64,14 @@ proc build*(builder: EnrBuilder): EnrResult[enr.Record] =
|
|||||||
proc addAddressAndPorts(
|
proc addAddressAndPorts(
|
||||||
builder: var EnrBuilder, ip: IpAddress, tcpPort, udpPort: Option[Port]
|
builder: var EnrBuilder, ip: IpAddress, tcpPort, udpPort: Option[Port]
|
||||||
) =
|
) =
|
||||||
# Based on: https://github.com/status-im/nim-eth/blob/4b22fcd/eth/p2p/discoveryv5/enr.nim#L166
|
builder.ipAddress = Opt.some(ip)
|
||||||
let isV6 = ip.family == IPv6
|
builder.tcpPort = tcpPort.toOpt()
|
||||||
|
builder.udpPort = udpPort.toOpt()
|
||||||
let ipField =
|
|
||||||
if isV6:
|
|
||||||
toFieldPair("ip6", ip.address_v6)
|
|
||||||
else:
|
|
||||||
toFieldPair("ip", ip.address_v4)
|
|
||||||
builder.addFieldPair(ipField)
|
|
||||||
|
|
||||||
if tcpPort.isSome():
|
|
||||||
let
|
|
||||||
tcpPortFieldKey = if isV6: "tcp6" else: "tcp"
|
|
||||||
tcpPortFieldValue = tcpPort.get()
|
|
||||||
builder.addFieldPair(tcpPortFieldKey, tcpPortFieldValue.uint16)
|
|
||||||
|
|
||||||
if udpPort.isSome():
|
|
||||||
let
|
|
||||||
udpPortFieldKey = if isV6: "udp6" else: "udp"
|
|
||||||
udpPortFieldValue = udpPort.get()
|
|
||||||
builder.addFieldPair(udpPortFieldKey, udpPortFieldValue.uint16)
|
|
||||||
|
|
||||||
proc addPorts(builder: var EnrBuilder, tcp, udp: Option[Port]) =
|
proc addPorts(builder: var EnrBuilder, tcp, udp: Option[Port]) =
|
||||||
# Based on: https://github.com/status-im/nim-eth/blob/4b22fcd/eth/p2p/discoveryv5/enr.nim#L166
|
# Based on: https://github.com/status-im/nim-eth/blob/4b22fcd/eth/p2p/discoveryv5/enr.nim#L166
|
||||||
|
builder.tcpPort = tcp.toOpt()
|
||||||
if tcp.isSome():
|
builder.udpPort = udp.toOpt()
|
||||||
let tcpPort = tcp.get()
|
|
||||||
builder.addFieldPair("tcp", tcpPort.uint16)
|
|
||||||
|
|
||||||
if udp.isSome():
|
|
||||||
let udpPort = udp.get()
|
|
||||||
builder.addFieldPair("udp", udpPort.uint16)
|
|
||||||
|
|
||||||
proc withIpAddressAndPorts*(
|
proc withIpAddressAndPorts*(
|
||||||
builder: var EnrBuilder,
|
builder: var EnrBuilder,
|
||||||
|
|||||||
@ -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
|
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
|
## ENR typed record
|
||||||
|
|
||||||
# Record identity scheme
|
# Record identity scheme
|
||||||
@ -31,7 +44,7 @@ proc init(T: type TypedRecord, record: Record): T =
|
|||||||
TypedRecord(raw: record)
|
TypedRecord(raw: record)
|
||||||
|
|
||||||
proc tryGet*(record: TypedRecord, field: string, T: type): Option[T] =
|
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] =
|
func toTyped*(record: Record): EnrResult[TypedRecord] =
|
||||||
let tr = TypedRecord.init(record)
|
let tr = TypedRecord.init(record)
|
||||||
@ -71,10 +84,16 @@ func tcp*(record: TypedRecord): Option[uint16] =
|
|||||||
record.tryGet("tcp", uint16)
|
record.tryGet("tcp", uint16)
|
||||||
|
|
||||||
func tcp6*(record: TypedRecord): Option[uint16] =
|
func tcp6*(record: TypedRecord): Option[uint16] =
|
||||||
record.tryGet("tcp6", uint16)
|
let port = record.tryGet("tcp6", uint16)
|
||||||
|
if port.isNone():
|
||||||
|
return record.tcp()
|
||||||
|
return port
|
||||||
|
|
||||||
func udp*(record: TypedRecord): Option[uint16] =
|
func udp*(record: TypedRecord): Option[uint16] =
|
||||||
record.tryGet("udp", uint16)
|
record.tryGet("udp", uint16)
|
||||||
|
|
||||||
func udp6*(record: TypedRecord): Option[uint16] =
|
func udp6*(record: TypedRecord): Option[uint16] =
|
||||||
record.tryGet("udp6", uint16)
|
let port = record.tryGet("udp6", uint16)
|
||||||
|
if port.isNone():
|
||||||
|
return record.udp()
|
||||||
|
return port
|
||||||
|
|||||||
@ -57,21 +57,7 @@ proc `==`*(a: zint64, b: zint64): bool =
|
|||||||
proc `$`*(err: ProtobufError): string =
|
proc `$`*(err: ProtobufError): string =
|
||||||
case err.kind
|
case err.kind
|
||||||
of DecodeFailure:
|
of DecodeFailure:
|
||||||
case err.error
|
return $err.error ## assume that ProtoError is pure
|
||||||
of VarintDecode:
|
|
||||||
return "VarintDecode"
|
|
||||||
of MessageIncomplete:
|
|
||||||
return "MessageIncomplete"
|
|
||||||
of BufferOverflow:
|
|
||||||
return "BufferOverflow"
|
|
||||||
of MessageTooBig:
|
|
||||||
return "MessageTooBig"
|
|
||||||
of BadWireType:
|
|
||||||
return "BadWireType"
|
|
||||||
of IncorrectBlob:
|
|
||||||
return "IncorrectBlob"
|
|
||||||
of RequiredFieldMissing:
|
|
||||||
return "RequiredFieldMissing"
|
|
||||||
of MissingRequiredField:
|
of MissingRequiredField:
|
||||||
return "MissingRequiredField " & err.field
|
return "MissingRequiredField " & err.field
|
||||||
of InvalidLengthField:
|
of InvalidLengthField:
|
||||||
|
|||||||
@ -39,7 +39,7 @@ proc setupNat*(
|
|||||||
warn "NAT already initialized, skipping as cannot be done multiple times"
|
warn "NAT already initialized, skipping as cannot be done multiple times"
|
||||||
else:
|
else:
|
||||||
singletonNat = true
|
singletonNat = true
|
||||||
var extIp = none(IpAddress)
|
var extIp = Opt.none(IpAddress)
|
||||||
try:
|
try:
|
||||||
extIp = getExternalIP(strategy)
|
extIp = getExternalIP(strategy)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -49,7 +49,7 @@ proc setupNat*(
|
|||||||
endpoint.ip = some(extIp.get())
|
endpoint.ip = some(extIp.get())
|
||||||
# RedirectPorts in considered a gcsafety violation
|
# RedirectPorts in considered a gcsafety violation
|
||||||
# because it obtains the address of a non-gcsafe proc?
|
# because it obtains the address of a non-gcsafe proc?
|
||||||
var extPorts: Option[(Port, Port)]
|
var extPorts: Opt[(Port, Port)]
|
||||||
try:
|
try:
|
||||||
extPorts = (
|
extPorts = (
|
||||||
{.gcsafe.}:
|
{.gcsafe.}:
|
||||||
@ -60,7 +60,7 @@ proc setupNat*(
|
|||||||
except CatchableError:
|
except CatchableError:
|
||||||
# TODO: nat.nim Error: can raise an unlisted exception: Exception. Isolate here for now.
|
# TODO: nat.nim Error: can raise an unlisted exception: Exception. Isolate here for now.
|
||||||
error "unable to determine external ports"
|
error "unable to determine external ports"
|
||||||
extPorts = none((Port, Port))
|
extPorts = Opt.none((Port, Port))
|
||||||
|
|
||||||
if extPorts.isSome():
|
if extPorts.isSome():
|
||||||
let (extTcpPort, extUdpPort) = extPorts.get()
|
let (extTcpPort, extUdpPort) = extPorts.get()
|
||||||
|
|||||||
@ -87,10 +87,10 @@ proc new*(
|
|||||||
privKey = conf.privateKey,
|
privKey = conf.privateKey,
|
||||||
bootstrapRecords = conf.bootstrapRecords,
|
bootstrapRecords = conf.bootstrapRecords,
|
||||||
enrAutoUpdate = conf.autoupdateRecord,
|
enrAutoUpdate = conf.autoupdateRecord,
|
||||||
previousRecord = record,
|
previousRecord = record.toOpt(),
|
||||||
enrIp = none(IpAddress),
|
enrIp = Opt.none(IpAddress),
|
||||||
enrTcpPort = none(Port),
|
enrTcpPort = Opt.none(Port),
|
||||||
enrUdpPort = none(Port),
|
enrUdpPort = Opt.none(Port),
|
||||||
)
|
)
|
||||||
|
|
||||||
let shardPredOp =
|
let shardPredOp =
|
||||||
|
|||||||
@ -357,7 +357,7 @@ proc updateAddressInENR(waku: ptr Waku): Result[void, string] =
|
|||||||
return err("failed to parse the private key: " & $error)
|
return err("failed to parse the private key: " & $error)
|
||||||
|
|
||||||
let enrFields = @[toFieldPair(MultiaddrEnrField, encodedAddrs)]
|
let enrFields = @[toFieldPair(MultiaddrEnrField, encodedAddrs)]
|
||||||
waku[].node.enr.update(parsedPk, enrFields).isOkOr:
|
waku[].node.enr.update(parsedPk, extraFields = enrFields).isOkOr:
|
||||||
return err("failed to update multiaddress in ENR updateAddressInENR: " & $error)
|
return err("failed to update multiaddress in ENR updateAddressInENR: " & $error)
|
||||||
|
|
||||||
debug "Waku node ENR updated successfully with new multiaddress",
|
debug "Waku node ENR updated successfully with new multiaddress",
|
||||||
|
|||||||
@ -128,3 +128,8 @@ proc fromEpoch*(epoch: Epoch): uint64 =
|
|||||||
## decodes bytes of `epoch` (in little-endian) to uint64
|
## decodes bytes of `epoch` (in little-endian) to uint64
|
||||||
let t = fromBytesLE(uint64, array[32, byte](epoch))
|
let t = fromBytesLE(uint64, array[32, byte](epoch))
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
func `+`*(a, b: Quantity): Quantity {.borrow.}
|
||||||
|
|
||||||
|
func u256*(n: Quantity): UInt256 {.inline.} =
|
||||||
|
n.uint64.stuint(256)
|
||||||
|
|||||||
@ -3,10 +3,11 @@
|
|||||||
import
|
import
|
||||||
os,
|
os,
|
||||||
web3,
|
web3,
|
||||||
web3/ethtypes,
|
web3/eth_api_types,
|
||||||
|
web3/primitives,
|
||||||
eth/keys as keys,
|
eth/keys as keys,
|
||||||
chronicles,
|
chronicles,
|
||||||
nimcrypto/keccak,
|
nimcrypto/keccak as keccak,
|
||||||
stint,
|
stint,
|
||||||
json,
|
json,
|
||||||
std/tables,
|
std/tables,
|
||||||
@ -30,12 +31,11 @@ logScope:
|
|||||||
# using the when predicate does not work within the contract macro, hence need to dupe
|
# using the when predicate does not work within the contract macro, hence need to dupe
|
||||||
contract(WakuRlnContract):
|
contract(WakuRlnContract):
|
||||||
# this serves as an entrypoint into the rln membership set
|
# this serves as an entrypoint into the rln membership set
|
||||||
proc register(idCommitment: UInt256, userMessageLimit: UInt32)
|
proc register(idCommitment: UInt256, userMessageLimit: EthereumUInt32)
|
||||||
# Initializes the implementation contract (only used in unit tests)
|
# Initializes the implementation contract (only used in unit tests)
|
||||||
proc initialize(maxMessageLimit: UInt256)
|
proc initialize(maxMessageLimit: UInt256)
|
||||||
# this event is raised when a new member is registered
|
# this event is raised when a new member is registered
|
||||||
proc MemberRegistered(rateCommitment: UInt256, index: Uint32) {.event.}
|
proc MemberRegistered(rateCommitment: UInt256, index: EthereumUInt32) {.event.}
|
||||||
|
|
||||||
# this function denotes existence of a given user
|
# this function denotes existence of a given user
|
||||||
proc memberExists(idCommitment: Uint256): UInt256 {.view.}
|
proc memberExists(idCommitment: Uint256): UInt256 {.view.}
|
||||||
# this constant describes the next index of a new member
|
# this constant describes the next index of a new member
|
||||||
@ -100,7 +100,7 @@ proc setMetadata*(
|
|||||||
try:
|
try:
|
||||||
let metadataSetRes = g.rlnInstance.setMetadata(
|
let metadataSetRes = g.rlnInstance.setMetadata(
|
||||||
RlnMetadata(
|
RlnMetadata(
|
||||||
lastProcessedBlock: normalizedBlock,
|
lastProcessedBlock: normalizedBlock.uint64,
|
||||||
chainId: g.chainId,
|
chainId: g.chainId,
|
||||||
contractAddress: g.ethContractAddress,
|
contractAddress: g.ethContractAddress,
|
||||||
validRoots: g.validRoots.toSeq(),
|
validRoots: g.validRoots.toSeq(),
|
||||||
@ -190,15 +190,19 @@ method register*(
|
|||||||
g.registrationTxHash = some(txHash)
|
g.registrationTxHash = some(txHash)
|
||||||
# the receipt topic holds the hash of signature of the raised events
|
# the receipt topic holds the hash of signature of the raised events
|
||||||
# TODO: make this robust. search within the event list for the event
|
# TODO: make this robust. search within the event list for the event
|
||||||
debug "ts receipt", tsReceipt
|
debug "ts receipt", receipt = tsReceipt[]
|
||||||
|
|
||||||
|
if tsReceipt.status.isNone() or tsReceipt.status.get() != 1.Quantity:
|
||||||
|
raise newException(ValueError, "register: transaction failed")
|
||||||
|
|
||||||
let firstTopic = tsReceipt.logs[0].topics[0]
|
let firstTopic = tsReceipt.logs[0].topics[0]
|
||||||
# the hash of the signature of MemberRegistered(uint256,uint32) event is equal to the following hex value
|
# the hash of the signature of MemberRegistered(uint256,uint32) event is equal to the following hex value
|
||||||
if firstTopic !=
|
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")
|
raise newException(ValueError, "register: unexpected event signature")
|
||||||
|
|
||||||
# the arguments of the raised event i.e., MemberRegistered are encoded inside the data field
|
# 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
|
let arguments = tsReceipt.logs[0].data
|
||||||
debug "tx log data", arguments = arguments
|
debug "tx log data", arguments = arguments
|
||||||
let
|
let
|
||||||
@ -231,11 +235,10 @@ proc parseEvent(
|
|||||||
## returns an error if it cannot parse the `data` parameter
|
## returns an error if it cannot parse the `data` parameter
|
||||||
var rateCommitment: UInt256
|
var rateCommitment: UInt256
|
||||||
var index: UInt256
|
var index: UInt256
|
||||||
var data: string
|
var data: seq[byte]
|
||||||
# Remove the 0x prefix
|
|
||||||
try:
|
try:
|
||||||
data = strip0xPrefix(log["data"].getStr())
|
data = hexToSeqByte(log["data"].getStr())
|
||||||
except CatchableError:
|
except ValueError:
|
||||||
return err(
|
return err(
|
||||||
"failed to parse the data field of the MemberRegistered event: " &
|
"failed to parse the data field of the MemberRegistered event: " &
|
||||||
getCurrentExceptionMsg()
|
getCurrentExceptionMsg()
|
||||||
@ -243,9 +246,9 @@ proc parseEvent(
|
|||||||
var offset = 0
|
var offset = 0
|
||||||
try:
|
try:
|
||||||
# Parse the rateCommitment
|
# Parse the rateCommitment
|
||||||
offset += decode(data, offset, rateCommitment)
|
offset += decode(data, 0, offset, rateCommitment)
|
||||||
# Parse the index
|
# Parse the index
|
||||||
offset += decode(data, offset, index)
|
offset += decode(data, 0, offset, index)
|
||||||
return ok(
|
return ok(
|
||||||
Membership(
|
Membership(
|
||||||
rateCommitment: rateCommitment.toRateCommitment(),
|
rateCommitment: rateCommitment.toRateCommitment(),
|
||||||
@ -291,13 +294,17 @@ proc getRawEvents(
|
|||||||
let ethRpc = g.ethRpc.get()
|
let ethRpc = g.ethRpc.get()
|
||||||
let wakuRlnContract = g.wakuRlnContract.get()
|
let wakuRlnContract = g.wakuRlnContract.get()
|
||||||
|
|
||||||
var events: JsonNode
|
var eventStrs: seq[JsonString]
|
||||||
g.retryWrapper(events, "Failed to get the events"):
|
g.retryWrapper(eventStrs, "Failed to get the events"):
|
||||||
await wakuRlnContract.getJsonLogs(
|
await wakuRlnContract.getJsonLogs(
|
||||||
MemberRegistered,
|
MemberRegistered,
|
||||||
fromBlock = some(fromBlock.blockId()),
|
fromBlock = Opt.some(fromBlock.blockId()),
|
||||||
toBlock = some(toBlock.blockId()),
|
toBlock = Opt.some(toBlock.blockId()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var events = newJArray()
|
||||||
|
for eventStr in eventStrs:
|
||||||
|
events.add(parseJson(eventStr.string))
|
||||||
return events
|
return events
|
||||||
|
|
||||||
proc getBlockTable(
|
proc getBlockTable(
|
||||||
@ -314,7 +321,7 @@ proc getBlockTable(
|
|||||||
return blockTable
|
return blockTable
|
||||||
|
|
||||||
for event in events:
|
for event in events:
|
||||||
let blockNumber = parseHexInt(event["blockNumber"].getStr()).uint
|
let blockNumber = parseHexInt(event["blockNumber"].getStr()).BlockNumber
|
||||||
let removed = event["removed"].getBool()
|
let removed = event["removed"].getBool()
|
||||||
let parsedEventRes = parseEvent(MemberRegistered, event)
|
let parsedEventRes = parseEvent(MemberRegistered, event)
|
||||||
if parsedEventRes.isErr():
|
if parsedEventRes.isErr():
|
||||||
@ -450,13 +457,13 @@ proc startOnchainSync(
|
|||||||
let ethRpc = g.ethRpc.get()
|
let ethRpc = g.ethRpc.get()
|
||||||
|
|
||||||
# static block chunk size
|
# static block chunk size
|
||||||
let blockChunkSize = 2_000
|
let blockChunkSize = 2_000.BlockNumber
|
||||||
# delay between rpc calls to not overload the rate limit
|
# delay between rpc calls to not overload the rate limit
|
||||||
let rpcDelay = 200.milliseconds
|
let rpcDelay = 200.milliseconds
|
||||||
# max number of futures to run concurrently
|
# max number of futures to run concurrently
|
||||||
let maxFutures = 10
|
let maxFutures = 10
|
||||||
|
|
||||||
var fromBlock =
|
var fromBlock: BlockNumber =
|
||||||
if g.latestProcessedBlock > g.rlnContractDeployedBlockNumber:
|
if g.latestProcessedBlock > g.rlnContractDeployedBlockNumber:
|
||||||
info "syncing from last processed block", blockNumber = g.latestProcessedBlock
|
info "syncing from last processed block", blockNumber = g.latestProcessedBlock
|
||||||
g.latestProcessedBlock + 1
|
g.latestProcessedBlock + 1
|
||||||
@ -479,11 +486,11 @@ proc startOnchainSync(
|
|||||||
if fromBlock >= currentLatestBlock:
|
if fromBlock >= currentLatestBlock:
|
||||||
break
|
break
|
||||||
|
|
||||||
if fromBlock + blockChunkSize.uint > currentLatestBlock.uint:
|
if fromBlock + blockChunkSize > currentLatestBlock:
|
||||||
g.retryWrapper(currentLatestBlock, "Failed to get the latest block number"):
|
g.retryWrapper(currentLatestBlock, "Failed to get the latest block number"):
|
||||||
cast[BlockNumber](await ethRpc.provider.eth_blockNumber())
|
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
|
debug "fetching events", fromBlock = fromBlock, toBlock = toBlock
|
||||||
await sleepAsync(rpcDelay)
|
await sleepAsync(rpcDelay)
|
||||||
futs.add(g.getAndHandleEvents(fromBlock, toBlock))
|
futs.add(g.getAndHandleEvents(fromBlock, toBlock))
|
||||||
@ -551,7 +558,7 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
|
|||||||
let pk = g.ethPrivateKey.get()
|
let pk = g.ethPrivateKey.get()
|
||||||
let parsedPk = keys.PrivateKey.fromHex(pk).valueOr:
|
let parsedPk = keys.PrivateKey.fromHex(pk).valueOr:
|
||||||
return err("failed to parse the private key" & ": " & $error)
|
return err("failed to parse the private key" & ": " & $error)
|
||||||
ethRpc.privateKey = some(parsedPk)
|
ethRpc.privateKey = Opt.some(parsedPk)
|
||||||
ethRpc.defaultAccount =
|
ethRpc.defaultAccount =
|
||||||
ethRpc.privateKey.get().toPublicKey().toCanonicalAddress().Address
|
ethRpc.privateKey.get().toPublicKey().toCanonicalAddress().Address
|
||||||
|
|
||||||
@ -605,7 +612,7 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
|
|||||||
|
|
||||||
if metadata.contractAddress != g.ethContractAddress.toLower():
|
if metadata.contractAddress != g.ethContractAddress.toLower():
|
||||||
return err("persisted data: contract address mismatch")
|
return err("persisted data: contract address mismatch")
|
||||||
g.latestProcessedBlock = metadata.lastProcessedBlock
|
g.latestProcessedBlock = metadata.lastProcessedBlock.BlockNumber
|
||||||
g.validRoots = metadata.validRoots.toDeque()
|
g.validRoots = metadata.validRoots.toDeque()
|
||||||
|
|
||||||
var deployedBlockNumber: Uint256
|
var deployedBlockNumber: Uint256
|
||||||
@ -661,10 +668,10 @@ method stop*(g: OnchainGroupManager): Future[void] {.async, gcsafe.} =
|
|||||||
proc isSyncing*(g: OnchainGroupManager): Future[bool] {.async, gcsafe.} =
|
proc isSyncing*(g: OnchainGroupManager): Future[bool] {.async, gcsafe.} =
|
||||||
let ethRpc = g.ethRpc.get()
|
let ethRpc = g.ethRpc.get()
|
||||||
|
|
||||||
var syncing: JsonNode
|
var syncing: SyncingStatus
|
||||||
g.retryWrapper(syncing, "Failed to get the syncing status"):
|
g.retryWrapper(syncing, "Failed to get the syncing status"):
|
||||||
await ethRpc.provider.eth_syncing()
|
await ethRpc.provider.eth_syncing()
|
||||||
return syncing.getBool()
|
return syncing.syncing
|
||||||
|
|
||||||
method isReady*(g: OnchainGroupManager): Future[bool] {.async.} =
|
method isReady*(g: OnchainGroupManager): Future[bool] {.async.} =
|
||||||
initializedGuard(g)
|
initializedGuard(g)
|
||||||
@ -677,7 +684,7 @@ method isReady*(g: OnchainGroupManager): Future[bool] {.async.} =
|
|||||||
cast[BlockNumber](await g.ethRpc.get().provider.eth_blockNumber())
|
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
|
# 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 false
|
||||||
|
|
||||||
return not (await g.isSyncing())
|
return not (await g.isSyncing())
|
||||||
|
|||||||
@ -87,7 +87,7 @@ proc createRLNInstanceLocal(
|
|||||||
## generates an instance of RLN
|
## generates an instance of RLN
|
||||||
## An RLN instance supports both zkSNARKs logics and Merkle tree data structure and operations
|
## An RLN instance supports both zkSNARKs logics and Merkle tree data structure and operations
|
||||||
## d indicates the depth of Merkle tree
|
## 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
|
## Returns an error if the instance creation fails
|
||||||
|
|
||||||
let rln_config = RlnConfig(
|
let rln_config = RlnConfig(
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import
|
|||||||
stint,
|
stint,
|
||||||
web3,
|
web3,
|
||||||
json,
|
json,
|
||||||
web3/ethtypes,
|
web3/eth_api_types,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
libp2p/protocols/pubsub/rpc/messages,
|
libp2p/protocols/pubsub/rpc/messages,
|
||||||
libp2p/protocols/pubsub/pubsub,
|
libp2p/protocols/pubsub/pubsub,
|
||||||
@ -277,7 +277,7 @@ proc validateMessageAndUpdateLog*(
|
|||||||
if proofMetadataRes.isErr():
|
if proofMetadataRes.isErr():
|
||||||
return MessageValidationResult.Invalid
|
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.
|
# message is valid.
|
||||||
if isValidMessage == MessageValidationResult.Valid:
|
if isValidMessage == MessageValidationResult.Valid:
|
||||||
discard rlnPeer.updateLog(msgProof.epoch, proofMetadataRes.get())
|
discard rlnPeer.updateLog(msgProof.epoch, proofMetadataRes.get())
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/sequtils,
|
std/[sequtils, options],
|
||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
results,
|
results,
|
||||||
chronicles,
|
chronicles,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user