Skip to content

Commit

Permalink
Bump nim-chornicles, nim-libp2p, nimcrypto
Browse files Browse the repository at this point in the history
Bump nim-web3, nim-eth and deps - on_chain/group_manager.nim adaption
Added status-im/nim-minilru submodule required by latest nim-eth
Added nim-quic and nim-ngtcp2 as new deps of nim-libp2p
Fixing tests.

 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
	modified:   vendor/nim-metrics
	new file:   vendor/nim-minilru
	modified:   vendor/nim-nat-traversal
	new file:   vendor/nim-ngtcp2
	modified:   vendor/nim-presto
	new file:   vendor/nim-quic
	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
	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
  • Loading branch information
NagyZoltanPeter committed Oct 8, 2024
1 parent 3ad613c commit 7f1ea08
Show file tree
Hide file tree
Showing 39 changed files with 142 additions and 81 deletions.
15 changes: 15 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/waku_discv5/utils.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import
std/options,
stew/results,
stew/shims/net,
chronos,
Expand Down
1 change: 1 addition & 0 deletions tests/waku_enr/utils.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import
std/options,
sequtils,
stew/results,
stew/shims/net,
Expand Down
4 changes: 2 additions & 2 deletions tests/waku_rln_relay/test_rln_group_manager_onchain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 9 additions & 8 deletions tests/waku_rln_relay/utils.nim
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import web3, chronos, options, stint
import web3, chronos, options, stint, stew/byteutils

proc deployContract*(
web3: Web3, code: string, gasPrice = 0, contractInput = ""
): Future[ReceiptObject] {.async.} =
# 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()

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)
Expand Down
31 changes: 23 additions & 8 deletions tests/waku_rln_relay/utils_onchain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import
chronicles,
stint,
web3,
web3/conversions,
web3/eth_api_types,
json,
libp2p/crypto/crypto,
eth/keys
Expand All @@ -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()
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion vendor/nim-chronicles
2 changes: 1 addition & 1 deletion vendor/nim-eth
Submodule nim-eth updated 135 files
2 changes: 1 addition & 1 deletion vendor/nim-http-utils
2 changes: 1 addition & 1 deletion vendor/nim-json-rpc
Submodule nim-json-rpc updated 47 files
+32 −8 .github/workflows/ci.yml
+84 −66 README.md
+9 −0 config.nims
+24 −15 json_rpc.nimble
+233 −158 json_rpc/client.nim
+115 −56 json_rpc/clients/httpclient.nim
+87 −20 json_rpc/clients/socketclient.nim
+16 −116 json_rpc/clients/websocketclient.nim
+155 −0 json_rpc/clients/websocketclientimpl.nim
+29 −2 json_rpc/errors.nim
+23 −283 json_rpc/jsonmarshal.nim
+163 −0 json_rpc/private/client_handler_wrapper.nim
+321 −0 json_rpc/private/jrpc_sys.nim
+319 −0 json_rpc/private/server_handler_wrapper.nim
+70 −0 json_rpc/private/shared_wrapper.nim
+199 −119 json_rpc/router.nim
+9 −0 json_rpc/rpcclient.nim
+22 −7 json_rpc/rpcproxy.nim
+0 −3 json_rpc/rpcsecureserver.nim
+9 −0 json_rpc/rpcserver.nim
+61 −8 json_rpc/server.nim
+81 −35 json_rpc/servers/httpserver.nim
+41 −22 json_rpc/servers/socketserver.nim
+60 −24 json_rpc/servers/websocketserver.nim
+9 −0 nim.cfg
+16 −1 tests/all.nim
+0 −12 tests/helpers.nim
+0 −9 tests/private/ethcallsigs.nim
+44 −27 tests/private/ethhexstrings.nim
+24 −6 tests/private/ethprocs.nim
+0 −0 tests/private/ethtypes.nim
+11 −0 tests/private/file_callsigs.nim
+19 −0 tests/private/helpers.nim
+44 −0 tests/private/stintjson.nim
+0 −32 tests/stintjson.nim
+145 −0 tests/test_batch_call.nim
+154 −0 tests/test_callsigs.nim
+302 −0 tests/test_client_hook.nim
+255 −0 tests/test_jrpc_sys.nim
+146 −0 tests/test_router_rpc.nim
+42 −14 tests/testethcalls.nim
+24 −13 tests/testhook.nim
+44 −16 tests/testhttp.nim
+27 −17 tests/testhttps.nim
+19 −11 tests/testproxy.nim
+106 −35 tests/testrpcmacro.nim
+40 −13 tests/testserverclient.nim
2 changes: 1 addition & 1 deletion vendor/nim-libp2p
Submodule nim-libp2p updated 58 files
+1 −0 .github/workflows/ci.yml
+1 −0 .github/workflows/coverage.yml
+1 −1 .github/workflows/daily_amd64.yml
+14 −1 .github/workflows/daily_common.yml
+1 −1 .github/workflows/daily_devel.yml
+1 −1 .github/workflows/daily_i386.yml
+15 −0 .github/workflows/daily_sat.yml
+1 −0 .github/workflows/interop.yml
+3 −1 .github/workflows/linters.yml
+3 −1 .pinned
+3 −0 config.nims
+5 −0 funding.json
+1 −0 libp2p.nim
+7 −6 libp2p.nimble
+10 −7 libp2p/connmanager.nim
+10 −8 libp2p/crypto/crypto.nim
+7 −5 libp2p/dialer.nim
+1 −1 libp2p/discovery/rendezvousinterface.nim
+3 −3 libp2p/errors.nim
+18 −12 libp2p/multiaddress.nim
+1 −1 libp2p/multistream.nim
+3 −3 libp2p/muxers/mplex/lpchannel.nim
+5 −5 libp2p/muxers/mplex/mplex.nim
+8 −8 libp2p/muxers/yamux/yamux.nim
+1 −1 libp2p/nameresolving/dnsresolver.nim
+4 −4 libp2p/protocols/connectivity/autonat/server.nim
+4 −4 libp2p/protocols/connectivity/autonat/service.nim
+3 −3 libp2p/protocols/connectivity/dcutr/client.nim
+3 −3 libp2p/protocols/connectivity/dcutr/server.nim
+6 −6 libp2p/protocols/connectivity/relay/client.nim
+8 −7 libp2p/protocols/connectivity/relay/relay.nim
+1 −1 libp2p/protocols/connectivity/relay/utils.nim
+2 −2 libp2p/protocols/identify.nim
+1 −1 libp2p/protocols/perf/server.nim
+1 −1 libp2p/protocols/ping.nim
+3 −3 libp2p/protocols/pubsub/floodsub.nim
+6 −6 libp2p/protocols/pubsub/gossipsub.nim
+1 −1 libp2p/protocols/pubsub/gossipsub/scoring.nim
+4 −4 libp2p/protocols/pubsub/pubsub.nim
+8 −8 libp2p/protocols/pubsub/pubsubpeer.nim
+2 −2 libp2p/protocols/pubsub/rpc/protobuf.nim
+4 −4 libp2p/protocols/rendezvous.nim
+1 −1 libp2p/protocols/secure/secure.nim
+1 −1 libp2p/stream/lpstream.nim
+4 −4 libp2p/switch.nim
+224 −0 libp2p/transports/quictransport.nim
+16 −5 libp2p/transports/tcptransport.nim
+12 −12 libp2p/transports/wstransport.nim
+2 −1 libp2p/utility.nim
+2 −2 libp2p/wire.nim
+0 −4 tests/config.nims
+1 −1 tests/hole-punching-interop/hole_punching.nim
+1 −1 tests/pubsub/testgossipinternal.nim
+2 −2 tests/pubsub/testgossipsub.nim
+17 −7 tests/testmultiaddress.nim
+24 −0 tests/testquic.nim
+37 −0 tests/testswitch.nim
+11 −15 tests/testutility.nim
2 changes: 1 addition & 1 deletion vendor/nim-metrics
1 change: 1 addition & 0 deletions vendor/nim-minilru
Submodule nim-minilru added at 2682cf
2 changes: 1 addition & 1 deletion vendor/nim-nat-traversal
1 change: 1 addition & 0 deletions vendor/nim-ngtcp2
Submodule nim-ngtcp2 added at 6834f4
2 changes: 1 addition & 1 deletion vendor/nim-presto
1 change: 1 addition & 0 deletions vendor/nim-quic
Submodule nim-quic added at ddcb31
2 changes: 1 addition & 1 deletion vendor/nim-secp256k1
2 changes: 1 addition & 1 deletion vendor/nim-taskpools
2 changes: 1 addition & 1 deletion vendor/nim-testutils
2 changes: 1 addition & 1 deletion vendor/nim-unicodedb
Submodule nim-unicodedb updated 60 files
+1 −1 .github/workflows/ci.yml
+1 −0 .gitignore
+5 −0 CHANGELOG.md
+4 −4 README.md
+16 −4 gen/UCD/Blocks.txt
+34 −4 gen/UCD/CaseFolding.txt
+898 −111 gen/UCD/DerivedCoreProperties.txt
+6,303 −16 gen/UCD/DerivedNormalizationProps.txt
+2,652 −2,585 gen/UCD/EastAsianWidth.txt
+188 −27 gen/UCD/PropList.txt
+128 −31 gen/UCD/Scripts.txt
+11 −11 gen/UCD/SpecialCasing.txt
+5,201 −9 gen/UCD/UnicodeData.txt
+72 −24 gen/UCD/auxiliary/WordBreakProperty.txt
+31 −11 gen/UCD/emoji/emoji-data.txt
+100 −37 gen/UCD/extracted/DerivedBidiClass.txt
+23 −6 gen/UCD/extracted/DerivedNumericType.txt
+2 −2 gen/blocks.nim
+5 −5 gen/casing.nim
+13 −11 gen/compositions.nim
+6 −6 gen/min_perfect_hash.nim
+3 −1 gen/names.nim
+5 −5 gen/properties.nim
+35 −0 gen/scripts.nim
+4 −8 gen/test_data.nim
+2 −2 gen/two_stage_table.nim
+6 −6 gen/types.nim
+1 −1 gen/unicode_data.nim
+2 −2 gen/utils.nim
+6 −6 gen/widths.nim
+4 −4 gen/widths_legacy.nim
+6 −6 src/unicodedb.nim
+22 −0 src/unicodedb/blocks_data.nim
+6 −6 src/unicodedb/casing.nim
+1,007 −931 src/unicodedb/casing_data.nim
+4 −2 src/unicodedb/collation.nim
+13 −10 src/unicodedb/compositions.nim
+971 −949 src/unicodedb/compositions_data.nim
+646 −530 src/unicodedb/decompositions_data.nim
+8 −5 src/unicodedb/names.nim
+36,880 −35,444 src/unicodedb/names_data.nim
+2 −2 src/unicodedb/properties.nim
+518 −439 src/unicodedb/properties_data.nim
+11 −4 src/unicodedb/scripts.nim
+474 −382 src/unicodedb/scripts_data.nim
+3 −3 src/unicodedb/segmentation.nim
+410 −358 src/unicodedb/segmentation_data.nim
+2 −2 src/unicodedb/types.nim
+563 −503 src/unicodedb/types_data.nim
+4 −4 src/unicodedb/widths.nim
+108 −108 src/unicodedb/widths_data.nim
+77 −44 tests/bidi_test_data.nim
+82 −43 tests/category_test_data.nim
+70 −45 tests/combining_test_data.nim
+62 −0 tests/decompositions_test_data.nim
+0 −1 tests/nim.cfg
+58 −39 tests/tests.nim
+71 −51 tests/types_test_data.nim
+44 −14 tests/word_break_test_data.nim
+2 −1 unicodedb.nimble
2 changes: 1 addition & 1 deletion vendor/nim-unittest2
2 changes: 1 addition & 1 deletion vendor/nim-web3
2 changes: 1 addition & 1 deletion vendor/nim-websock
2 changes: 1 addition & 1 deletion vendor/nim-zlib
4 changes: 3 additions & 1 deletion waku.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 3 additions & 3 deletions waku/common/enr/builder.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
15 changes: 14 additions & 1 deletion waku/common/enr/typed_record.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions waku/common/utils/nat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.}:
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions waku/discovery/waku_discv5.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
5 changes: 5 additions & 0 deletions waku/waku_rln_relay/conversion_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading

0 comments on commit 7f1ea08

Please sign in to comment.