mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-07 16:33:08 +00:00
Use chronosStrictException for Waku v1 code (#609)
* Use chronosStrictException for Waku v1 code And accompanying changes and clean-up * Fix chronosStrictException changes for wakubridge
This commit is contained in:
parent
26ccf51987
commit
a78ae76c00
@ -1,8 +1,8 @@
|
|||||||
{.used.}
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[unittest, options, os, strutils],
|
std/[options, os, strutils],
|
||||||
stew/byteutils, json_rpc/[rpcserver, rpcclient],
|
testutils/unittests, stew/byteutils, json_rpc/[rpcserver, rpcclient],
|
||||||
eth/common as eth_common, eth/[rlp, keys, p2p],
|
eth/common as eth_common, eth/[rlp, keys, p2p],
|
||||||
../../waku/v1/protocol/waku_protocol,
|
../../waku/v1/protocol/waku_protocol,
|
||||||
../../waku/v1/node/rpc/[hexstrings, rpc_types, waku, key_storage]
|
../../waku/v1/node/rpc/[hexstrings, rpc_types, waku, key_storage]
|
||||||
@ -26,28 +26,25 @@ proc setupNode(capabilities: varargs[ProtocolInfo, `protocolInfo`],
|
|||||||
result.addCapability capability
|
result.addCapability capability
|
||||||
|
|
||||||
proc doTests {.async.} =
|
proc doTests {.async.} =
|
||||||
let rng = keys.newRng()
|
suite "Waku Remote Procedure Calls":
|
||||||
var ethNode = setupNode(Waku, rng)
|
let
|
||||||
|
rng = keys.newRng()
|
||||||
# Create Ethereum RPCs
|
ethNode = setupNode(Waku, rng)
|
||||||
let rpcPort = 8545
|
rpcPort = 8545
|
||||||
var
|
|
||||||
rpcServer = newRpcSocketServer(["localhost:" & $rpcPort])
|
rpcServer = newRpcSocketServer(["localhost:" & $rpcPort])
|
||||||
client = newRpcSocketClient()
|
client = newRpcSocketClient()
|
||||||
let keys = newKeyStorage()
|
keys = newKeyStorage()
|
||||||
setupWakuRPC(ethNode, keys, rpcServer, rng)
|
|
||||||
|
|
||||||
# Begin tests
|
setupWakuRPC(ethNode, keys, rpcServer, rng)
|
||||||
rpcServer.start()
|
rpcServer.start()
|
||||||
await client.connect("localhost", Port(rpcPort))
|
await client.connect("localhost", Port(rpcPort))
|
||||||
|
|
||||||
suite "Waku Remote Procedure Calls":
|
asyncTest "waku_version":
|
||||||
test "waku_version":
|
|
||||||
check await(client.waku_version()) == wakuVersionStr
|
check await(client.waku_version()) == wakuVersionStr
|
||||||
test "waku_info":
|
asyncTest "waku_info":
|
||||||
let info = await client.waku_info()
|
let info = await client.waku_info()
|
||||||
check info.maxMessageSize == defaultMaxMsgSize
|
check info.maxMessageSize == defaultMaxMsgSize
|
||||||
test "waku_setMaxMessageSize":
|
asyncTest "waku_setMaxMessageSize":
|
||||||
let testValue = 1024'u64
|
let testValue = 1024'u64
|
||||||
check await(client.waku_setMaxMessageSize(testValue)) == true
|
check await(client.waku_setMaxMessageSize(testValue)) == true
|
||||||
var info = await client.waku_info()
|
var info = await client.waku_info()
|
||||||
@ -56,14 +53,14 @@ proc doTests {.async.} =
|
|||||||
discard await(client.waku_setMaxMessageSize(defaultMaxMsgSize + 1))
|
discard await(client.waku_setMaxMessageSize(defaultMaxMsgSize + 1))
|
||||||
info = await client.waku_info()
|
info = await client.waku_info()
|
||||||
check info.maxMessageSize == testValue
|
check info.maxMessageSize == testValue
|
||||||
test "waku_setMinPoW":
|
asyncTest "waku_setMinPoW":
|
||||||
let testValue = 0.0001
|
let testValue = 0.0001
|
||||||
check await(client.waku_setMinPoW(testValue)) == true
|
check await(client.waku_setMinPoW(testValue)) == true
|
||||||
let info = await client.waku_info()
|
let info = await client.waku_info()
|
||||||
check info.minPow == testValue
|
check info.minPow == testValue
|
||||||
# test "waku_markTrustedPeer":
|
# test "waku_markTrustedPeer":
|
||||||
# TODO: need to connect a peer to test
|
# TODO: need to connect a peer to test
|
||||||
test "waku asymKey tests":
|
asyncTest "waku asymKey tests":
|
||||||
let keyID = await client.waku_newKeyPair()
|
let keyID = await client.waku_newKeyPair()
|
||||||
check:
|
check:
|
||||||
await(client.waku_hasKeyPair(keyID)) == true
|
await(client.waku_hasKeyPair(keyID)) == true
|
||||||
@ -83,7 +80,7 @@ proc doTests {.async.} =
|
|||||||
await(client.waku_hasKeyPair(keyID2)) == false
|
await(client.waku_hasKeyPair(keyID2)) == false
|
||||||
expect ValueError:
|
expect ValueError:
|
||||||
discard await(client.waku_deleteKeyPair(keyID2))
|
discard await(client.waku_deleteKeyPair(keyID2))
|
||||||
test "waku symKey tests":
|
asyncTest "waku symKey tests":
|
||||||
let keyID = await client.waku_newSymKey()
|
let keyID = await client.waku_newSymKey()
|
||||||
check:
|
check:
|
||||||
await(client.waku_hasSymKey(keyID)) == true
|
await(client.waku_hasSymKey(keyID)) == true
|
||||||
@ -126,7 +123,7 @@ proc doTests {.async.} =
|
|||||||
powTarget = 0.001
|
powTarget = 0.001
|
||||||
powTime = 1.0
|
powTime = 1.0
|
||||||
|
|
||||||
test "waku filter create and delete":
|
asyncTest "waku filter create and delete":
|
||||||
let
|
let
|
||||||
topic = topicStr.toTopic()
|
topic = topicStr.toTopic()
|
||||||
symKeyID = await client.waku_newSymKey()
|
symKeyID = await client.waku_newSymKey()
|
||||||
@ -140,7 +137,7 @@ proc doTests {.async.} =
|
|||||||
expect ValueError:
|
expect ValueError:
|
||||||
discard await(client.waku_deleteMessageFilter(filterID))
|
discard await(client.waku_deleteMessageFilter(filterID))
|
||||||
|
|
||||||
test "waku symKey post and filter loop":
|
asyncTest "waku symKey post and filter loop":
|
||||||
let
|
let
|
||||||
topic = topicStr.toTopic()
|
topic = topicStr.toTopic()
|
||||||
symKeyID = await client.waku_newSymKey()
|
symKeyID = await client.waku_newSymKey()
|
||||||
@ -170,7 +167,7 @@ proc doTests {.async.} =
|
|||||||
|
|
||||||
await(client.waku_deleteMessageFilter(filterID)) == true
|
await(client.waku_deleteMessageFilter(filterID)) == true
|
||||||
|
|
||||||
test "waku asymKey post and filter loop":
|
asyncTest "waku asymKey post and filter loop":
|
||||||
let
|
let
|
||||||
topic = topicStr.toTopic()
|
topic = topicStr.toTopic()
|
||||||
privateKeyID = await client.waku_newKeyPair()
|
privateKeyID = await client.waku_newKeyPair()
|
||||||
@ -200,7 +197,7 @@ proc doTests {.async.} =
|
|||||||
|
|
||||||
await(client.waku_deleteMessageFilter(filterID)) == true
|
await(client.waku_deleteMessageFilter(filterID)) == true
|
||||||
|
|
||||||
test "waku signature in post and filter loop":
|
asyncTest "waku signature in post and filter loop":
|
||||||
let
|
let
|
||||||
topic = topicStr.toTopic()
|
topic = topicStr.toTopic()
|
||||||
symKeyID = await client.waku_newSymKey()
|
symKeyID = await client.waku_newSymKey()
|
||||||
|
|||||||
@ -25,8 +25,8 @@ proc resetMessageQueues(nodes: varargs[EthereumNode]) =
|
|||||||
|
|
||||||
# check on a condition until true or return a future containing false
|
# check on a condition until true or return a future containing false
|
||||||
# if timeout expires first
|
# if timeout expires first
|
||||||
proc eventually(timeout: Duration, condition: proc(): bool {.gcsafe.}):
|
proc eventually(timeout: Duration,
|
||||||
Future[bool] =
|
condition: proc(): bool {.gcsafe, raises: [Defect].}): Future[bool] =
|
||||||
let wrappedCondition = proc(): Future[bool] {.async.} =
|
let wrappedCondition = proc(): Future[bool] {.async.} =
|
||||||
let f = newFuture[bool]()
|
let f = newFuture[bool]()
|
||||||
while not condition():
|
while not condition():
|
||||||
|
|||||||
19
waku.nimble
19
waku.nimble
@ -34,27 +34,30 @@ proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
|
|||||||
extra_params &= " " & paramStr(i)
|
extra_params &= " " & paramStr(i)
|
||||||
exec "nim " & lang & " --out:build/" & name & " " & extra_params & " " & srcDir & name & ".nim"
|
exec "nim " & lang & " --out:build/" & name & " " & extra_params & " " & srcDir & name & ".nim"
|
||||||
|
|
||||||
proc test(name: string, lang = "c") =
|
proc test(name: string, params = "-d:chronicles_log_level=DEBUG", lang = "c") =
|
||||||
# XXX: When running `> NIM_PARAMS="-d:chronicles_log_level=INFO" make test2`
|
# XXX: When running `> NIM_PARAMS="-d:chronicles_log_level=INFO" make test2`
|
||||||
# I expect compiler flag to be overridden, however it stays with whatever is
|
# I expect compiler flag to be overridden, however it stays with whatever is
|
||||||
# specified here.
|
# specified here.
|
||||||
buildBinary name, "tests/", "-d:chronicles_log_level=DEBUG"
|
buildBinary name, "tests/", params
|
||||||
#buildBinary name, "tests/", "-d:chronicles_log_level=ERROR"
|
|
||||||
exec "build/" & name
|
exec "build/" & name
|
||||||
|
|
||||||
### Waku v1 tasks
|
### Waku v1 tasks
|
||||||
task wakunode1, "Build Waku v1 cli node":
|
task wakunode1, "Build Waku v1 cli node":
|
||||||
buildBinary "wakunode1", "waku/v1/node/", "-d:chronicles_log_level=DEBUG"
|
buildBinary "wakunode1", "waku/v1/node/",
|
||||||
|
"-d:chronicles_log_level=DEBUG -d:chronosStrictException"
|
||||||
|
|
||||||
task sim1, "Build Waku v1 simulation tools":
|
task sim1, "Build Waku v1 simulation tools":
|
||||||
buildBinary "quicksim", "waku/v1/node/", "-d:chronicles_log_level=INFO"
|
buildBinary "quicksim", "waku/v1/node/",
|
||||||
buildBinary "start_network", "waku/v1/node/", "-d:chronicles_log_level=DEBUG"
|
"-d:chronicles_log_level=INFO -d:chronosStrictException"
|
||||||
|
buildBinary "start_network", "waku/v1/node/",
|
||||||
|
"-d:chronicles_log_level=DEBUG -d:chronosStrictException"
|
||||||
|
|
||||||
task example1, "Build Waku v1 example":
|
task example1, "Build Waku v1 example":
|
||||||
buildBinary "example", "examples/v1/", "-d:chronicles_log_level=DEBUG"
|
buildBinary "example", "examples/v1/",
|
||||||
|
"-d:chronicles_log_level=DEBUG -d:chronosStrictException"
|
||||||
|
|
||||||
task test1, "Build & run Waku v1 tests":
|
task test1, "Build & run Waku v1 tests":
|
||||||
test "all_tests_v1"
|
test "all_tests_v1", "-d:chronicles_log_level=WARN -d:chronosStrictException"
|
||||||
|
|
||||||
### Waku v2 tasks
|
### Waku v2 tasks
|
||||||
task wakunode2, "Build Waku v2 (experimental) cli node":
|
task wakunode2, "Build Waku v2 (experimental) cli node":
|
||||||
|
|||||||
@ -161,9 +161,9 @@ proc start*(bridge: WakuBridge) {.async.} =
|
|||||||
|
|
||||||
# Bridging
|
# Bridging
|
||||||
# Handle messages on Waku v1 and bridge to Waku v2
|
# Handle messages on Waku v1 and bridge to Waku v2
|
||||||
proc handleEnvReceived(envelope: Envelope) {.gcsafe.} =
|
proc handleEnvReceived(envelope: Envelope) {.gcsafe, raises: [Defect].} =
|
||||||
trace "Bridging envelope from V1 to V2", envelope=envelope
|
trace "Bridging envelope from V1 to V2", envelope=envelope
|
||||||
waitFor bridge.toWakuV2(envelope)
|
asyncSpawn bridge.toWakuV2(envelope)
|
||||||
|
|
||||||
bridge.nodev1.registerEnvReceivedHandler(handleEnvReceived)
|
bridge.nodev1.registerEnvReceivedHandler(handleEnvReceived)
|
||||||
|
|
||||||
|
|||||||
@ -85,9 +85,10 @@ type
|
|||||||
received: HashSet[Hash]
|
received: HashSet[Hash]
|
||||||
accounting*: Accounting
|
accounting*: Accounting
|
||||||
|
|
||||||
P2PRequestHandler* = proc(peer: Peer, envelope: Envelope) {.gcsafe.}
|
P2PRequestHandler* = proc(peer: Peer, envelope: Envelope)
|
||||||
|
{.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
EnvReceivedHandler* = proc(envelope: Envelope) {.gcsafe.}
|
EnvReceivedHandler* = proc(envelope: Envelope) {.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
WakuNetwork = ref object
|
WakuNetwork = ref object
|
||||||
queue*: ref Queue
|
queue*: ref Queue
|
||||||
@ -227,7 +228,7 @@ proc initProtocolState*(network: WakuNetwork, node: EthereumNode) {.gcsafe.} =
|
|||||||
network.config.rateLimits = none(RateLimits)
|
network.config.rateLimits = none(RateLimits)
|
||||||
network.config.maxMsgSize = defaultMaxMsgSize
|
network.config.maxMsgSize = defaultMaxMsgSize
|
||||||
network.config.topics = none(seq[Topic])
|
network.config.topics = none(seq[Topic])
|
||||||
asyncCheck node.run(network)
|
asyncSpawn node.run(network)
|
||||||
|
|
||||||
p2pProtocol Waku(version = wakuVersion,
|
p2pProtocol Waku(version = wakuVersion,
|
||||||
rlpxName = "waku",
|
rlpxName = "waku",
|
||||||
@ -274,7 +275,7 @@ p2pProtocol Waku(version = wakuVersion,
|
|||||||
|
|
||||||
# No timer based queue processing for a light node.
|
# No timer based queue processing for a light node.
|
||||||
if not wakuNet.config.isLightNode:
|
if not wakuNet.config.isLightNode:
|
||||||
traceAsyncErrors peer.run()
|
asyncSpawn peer.run()
|
||||||
|
|
||||||
debug "Waku peer initialized", peer
|
debug "Waku peer initialized", peer
|
||||||
|
|
||||||
@ -461,7 +462,13 @@ proc sendP2PMessage(node: EthereumNode, peerId: NodeId,
|
|||||||
envelopes: openarray[Envelope]): bool =
|
envelopes: openarray[Envelope]): bool =
|
||||||
for peer in node.peers(Waku):
|
for peer in node.peers(Waku):
|
||||||
if peer.remote.id == peerId:
|
if peer.remote.id == peerId:
|
||||||
asyncCheck peer.p2pMessage(envelopes)
|
let f = peer.p2pMessage(envelopes)
|
||||||
|
# Can't make p2pMessage not raise so this is the "best" option I can think
|
||||||
|
# of instead of using asyncSpawn and still keeping the call not async.
|
||||||
|
f.callback = proc(data: pointer) {.gcsafe, raises: [Defect].} =
|
||||||
|
if f.failed:
|
||||||
|
warn "P2PMessage send failed", msg = f.readError.msg
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
proc queueMessage(node: EthereumNode, msg: Message): bool =
|
proc queueMessage(node: EthereumNode, msg: Message): bool =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user