mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-06-04 05:00:02 +00:00
Get nim-libp2p 2.0.0 bump to E2E working state (WIP)
* deps: json_rpc + web3 via websock-relaxed forks (WIP: revert on upstream fix) * fix: setup() post-build switch services (autonat nil segfault) * fix: unified 2.0.0 connection limits * test: 2.0.0 defaults (identify-push, agent string) * test: drop reboot/reconnect (unsupported Switch restart)
This commit is contained in:
parent
549834203d
commit
3dfc86262b
14
nimble.lock
14
nimble.lock
@ -454,9 +454,9 @@
|
||||
}
|
||||
},
|
||||
"json_rpc": {
|
||||
"version": "#43bbf499143eb45046c83ac9794c9e3280a2b8e7",
|
||||
"vcsRevision": "43bbf499143eb45046c83ac9794c9e3280a2b8e7",
|
||||
"url": "https://github.com/status-im/nim-json-rpc.git",
|
||||
"version": "0.6.1",
|
||||
"vcsRevision": "8ce09c2ccc08b23f433a054b2b1ccb022d9547dc",
|
||||
"url": "https://github.com/fcecin/nim-json-rpc-websock040",
|
||||
"downloadMethod": "git",
|
||||
"dependencies": [
|
||||
"nim",
|
||||
@ -472,7 +472,7 @@
|
||||
"unittest2"
|
||||
],
|
||||
"checksums": {
|
||||
"sha1": "30ff6ead115b88c79862c5c7e37b1c9852eea59f"
|
||||
"sha1": "596db0aafcb3c83f5dba6d42993f2276e0d00eb5"
|
||||
}
|
||||
},
|
||||
"lsquic": {
|
||||
@ -538,8 +538,8 @@
|
||||
},
|
||||
"web3": {
|
||||
"version": "0.8.0",
|
||||
"vcsRevision": "cdfe5601d2812a58e54faf53ee634452d01e5918",
|
||||
"url": "https://github.com/status-im/nim-web3",
|
||||
"vcsRevision": "96f39ea1b633277c1d93eafd62759db1d498e359",
|
||||
"url": "https://github.com/fcecin/nim-web3-websock040",
|
||||
"downloadMethod": "git",
|
||||
"dependencies": [
|
||||
"nim",
|
||||
@ -557,7 +557,7 @@
|
||||
"results"
|
||||
],
|
||||
"checksums": {
|
||||
"sha1": "26a112af032ef1536f97da2ca7364af618a11b80"
|
||||
"sha1": "b5972104bc9223a34ae3758293225264822af893"
|
||||
}
|
||||
},
|
||||
"dnsdisc": {
|
||||
|
||||
@ -28,8 +28,13 @@ import
|
||||
../waku_discv5/utils,
|
||||
./peer_manager/peer_store/utils
|
||||
|
||||
# nim-libp2p 2.0.0 enables the IdentifyPush protocol by default, so every node
|
||||
# now also advertises "/ipfs/id/push/1.0.0" (prepended to the identify list).
|
||||
const DEFAULT_PROTOCOLS: seq[string] =
|
||||
@["/ipfs/id/1.0.0", "/libp2p/autonat/1.0.0", "/libp2p/circuit/relay/0.2.0/hop"]
|
||||
@[
|
||||
"/ipfs/id/push/1.0.0", "/ipfs/id/1.0.0", "/libp2p/autonat/1.0.0",
|
||||
"/libp2p/circuit/relay/0.2.0/hop",
|
||||
]
|
||||
|
||||
let
|
||||
listenIp = parseIpAddress("0.0.0.0")
|
||||
@ -376,7 +381,7 @@ suite "Peer Manager":
|
||||
chainedComparison(
|
||||
clientPeerStore[AgentBook][serverPeerId], # FIXME: Not assigned
|
||||
serverRemotePeerInfo.agent,
|
||||
"nim-libp2p/0.0.1",
|
||||
"nim-libp2p",
|
||||
)
|
||||
chainedComparison(
|
||||
clientPeerStore[ProtoVersionBook][serverPeerId], # FIXME: Not assigned
|
||||
@ -442,7 +447,7 @@ suite "Peer Manager":
|
||||
chainedComparison(
|
||||
clientPeerStore[AgentBook][serverPeerId], # FIXME: Not assigned
|
||||
serverRemotePeerInfo.agent,
|
||||
"nim-libp2p/0.0.1",
|
||||
"nim-libp2p",
|
||||
)
|
||||
chainedComparison(
|
||||
clientPeerStore[ProtoVersionBook][serverPeerId], # FIXME: Not assigned
|
||||
@ -493,7 +498,7 @@ suite "Peer Manager":
|
||||
chainedComparison(
|
||||
clientPeerStore[AgentBook][server2PeerId], # FIXME: Not assigned
|
||||
server2RemotePeerInfo.agent,
|
||||
"nim-libp2p/0.0.1",
|
||||
"nim-libp2p",
|
||||
)
|
||||
chainedComparison(
|
||||
clientPeerStore[ProtoVersionBook][server2PeerId], # FIXME: Not assigned
|
||||
|
||||
@ -292,8 +292,8 @@ suite "WakuNode":
|
||||
# custom agent string
|
||||
expectedAgentString1 = "node1-agent-string"
|
||||
|
||||
# bump when updating nim-libp2p
|
||||
expectedAgentString2 = "nim-libp2p/0.0.1"
|
||||
# bump when updating nim-libp2p (2.0.0 default AgentVersion is "nim-libp2p")
|
||||
expectedAgentString2 = "nim-libp2p"
|
||||
let
|
||||
# node with custom agent string
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
|
||||
@ -1214,101 +1214,6 @@ suite "Waku Relay":
|
||||
await allFutures(otherSwitch.stop(), otherNode.stop())
|
||||
|
||||
suite "Security and Privacy":
|
||||
asyncTest "Relay can receive messages after reboot and reconnect":
|
||||
# Given a second node connected to the first one
|
||||
let
|
||||
otherSwitch = newTestSwitch()
|
||||
otherPeerManager = PeerManager.new(otherSwitch)
|
||||
otherNode = await newTestWakuRelay(otherSwitch)
|
||||
|
||||
await otherSwitch.start()
|
||||
let
|
||||
otherRemotePeerInfo = otherSwitch.peerInfo.toRemotePeerInfo()
|
||||
otherPeerId = otherRemotePeerInfo.peerId
|
||||
|
||||
check await peerManager.connectPeer(otherRemotePeerInfo)
|
||||
|
||||
# Given both are subscribed to the same pubsub topic
|
||||
var otherHandlerFuture = newPushHandlerFuture()
|
||||
proc otherSimpleFutureHandler(
|
||||
topic: PubsubTopic, message: WakuMessage
|
||||
) {.async, gcsafe.} =
|
||||
otherHandlerFuture.complete((topic, message))
|
||||
|
||||
otherNode.subscribe(pubsubTopic, otherSimpleFutureHandler)
|
||||
node.subscribe(pubsubTopic, simpleFutureHandler)
|
||||
check:
|
||||
node.subscribedTopics == pubsubTopicSeq
|
||||
otherNode.subscribedTopics == pubsubTopicSeq
|
||||
await sleepAsync(500.millis)
|
||||
|
||||
# Given other node is stopped and restarted
|
||||
await otherSwitch.stop()
|
||||
await otherSwitch.start()
|
||||
|
||||
check await peerManager.connectPeer(otherRemotePeerInfo)
|
||||
|
||||
# FIXME: Once stopped and started, nodes are not considered connected, nor do they reconnect after running connectPeer, as below
|
||||
# check await otherPeerManager.connectPeer(otherRemotePeerInfo)
|
||||
|
||||
# When sending a message from node
|
||||
let msg1 = fakeWakuMessage(testMessage, pubsubTopic)
|
||||
discard await node.publish(pubsubTopic, msg1)
|
||||
|
||||
# Then the message is received in both nodes
|
||||
check:
|
||||
await handlerFuture.withTimeout(FUTURE_TIMEOUT)
|
||||
await otherHandlerFuture.withTimeout(FUTURE_TIMEOUT)
|
||||
(pubsubTopic, msg1) == handlerFuture.read()
|
||||
(pubsubTopic, msg1) == otherHandlerFuture.read()
|
||||
|
||||
# When sending a message from other node
|
||||
handlerFuture = newPushHandlerFuture()
|
||||
otherHandlerFuture = newPushHandlerFuture()
|
||||
let msg2 = fakeWakuMessage(testMessage, pubsubTopic)
|
||||
discard await otherNode.publish(pubsubTopic, msg2)
|
||||
|
||||
# Then the message is received in both nodes
|
||||
check:
|
||||
await handlerFuture.withTimeout(FUTURE_TIMEOUT)
|
||||
await otherHandlerFuture.withTimeout(FUTURE_TIMEOUT)
|
||||
(pubsubTopic, msg2) == handlerFuture.read()
|
||||
(pubsubTopic, msg2) == otherHandlerFuture.read()
|
||||
|
||||
# Given node is stopped and restarted
|
||||
await switch.stop()
|
||||
await switch.start()
|
||||
check await peerManager.connectPeer(otherRemotePeerInfo)
|
||||
|
||||
# When sending a message from node
|
||||
handlerFuture = newPushHandlerFuture()
|
||||
otherHandlerFuture = newPushHandlerFuture()
|
||||
let msg3 = fakeWakuMessage(testMessage, pubsubTopic)
|
||||
discard await node.publish(pubsubTopic, msg3)
|
||||
|
||||
# Then the message is received in both nodes
|
||||
check:
|
||||
await handlerFuture.withTimeout(FUTURE_TIMEOUT)
|
||||
await otherHandlerFuture.withTimeout(FUTURE_TIMEOUT)
|
||||
(pubsubTopic, msg3) == handlerFuture.read()
|
||||
(pubsubTopic, msg3) == otherHandlerFuture.read()
|
||||
|
||||
# When sending a message from other node
|
||||
handlerFuture = newPushHandlerFuture()
|
||||
otherHandlerFuture = newPushHandlerFuture()
|
||||
let msg4 = fakeWakuMessage(testMessage, pubsubTopic)
|
||||
discard await otherNode.publish(pubsubTopic, msg4)
|
||||
|
||||
# Then the message is received in both nodes
|
||||
check:
|
||||
await handlerFuture.withTimeout(FUTURE_TIMEOUT)
|
||||
await otherHandlerFuture.withTimeout(FUTURE_TIMEOUT)
|
||||
(pubsubTopic, msg4) == handlerFuture.read()
|
||||
(pubsubTopic, msg4) == otherHandlerFuture.read()
|
||||
|
||||
# Finally stop the other node
|
||||
await allFutures(otherSwitch.stop(), otherNode.stop())
|
||||
|
||||
asyncTest "Relay can't receive messages after subscribing and stopping without unsubscribing":
|
||||
# Given a second node connected to the first one
|
||||
let
|
||||
|
||||
@ -39,9 +39,13 @@ requires "nim >= 2.2.4",
|
||||
"secp256k1",
|
||||
"bearssl",
|
||||
# RPC & APIs
|
||||
"https://github.com/status-im/nim-json-rpc.git#43bbf499143eb45046c83ac9794c9e3280a2b8e7",
|
||||
# DRAFT: json_rpc + web3 repointed to fcecin forks for the libp2p 2.0.0 bump.
|
||||
# json_rpc fork relaxes the websock cap (<0.4.0 -> <0.5.0); web3 fork repoints
|
||||
# its own json_rpc require to the same fork so the SAT graph unifies. Revert to
|
||||
# status-im json_rpc + bare "web3" once the cap fix lands upstream.
|
||||
"https://github.com/fcecin/nim-json-rpc-websock040#8ce09c2ccc08b23f433a054b2b1ccb022d9547dc",
|
||||
"presto",
|
||||
"web3",
|
||||
"https://github.com/fcecin/nim-web3-websock040#96f39ea1b633277c1d93eafd62759db1d498e359",
|
||||
# Database
|
||||
"db_connector",
|
||||
"sqlite3_abi",
|
||||
|
||||
@ -111,6 +111,17 @@ proc setupSwitchServices(
|
||||
else:
|
||||
waku.node.switch.services = @[Service(autonatService)]
|
||||
|
||||
# libp2p 2.0.0 split Service.setup out of Service.start: the switch runs setup
|
||||
# only at build time (SwitchBuilder.setupServices), while switch.start calls
|
||||
# just start. These services are created and attached post-build, so setup must
|
||||
# be invoked explicitly here -- otherwise AutonatService.addressMapper stays nil
|
||||
# and the peerInfo.update() inside start dereferences it (SIGSEGV).
|
||||
for service in waku.node.switch.services:
|
||||
try:
|
||||
service.setup(waku.node.switch)
|
||||
except CatchableError as e:
|
||||
error "failed to set up libp2p switch service", error = e.msg
|
||||
|
||||
## Initialisation
|
||||
|
||||
proc newCircuitRelay(isRelayClient: bool): Relay =
|
||||
|
||||
@ -81,8 +81,6 @@ proc newWakuSwitch*(
|
||||
var b = SwitchBuilder
|
||||
.new()
|
||||
.withRng(rng)
|
||||
.withMaxConnections(maxConnections)
|
||||
.withMaxInOut(maxIn, maxOut)
|
||||
.withMaxConnsPerPeer(maxConnsPerPeer)
|
||||
.withYamux()
|
||||
.withMplex(inTimeout, outTimeout)
|
||||
@ -93,6 +91,15 @@ proc newWakuSwitch*(
|
||||
.withCircuitRelay(circuitRelay)
|
||||
.withAutonat()
|
||||
|
||||
# libp2p 2.0.0 folded withMaxConnections and withMaxInOut into a single
|
||||
# `limits` field: they are mutually exclusive (last one wins), and
|
||||
# ConnectionLimits.maxInOut asserts maxIn/maxOut > 0. So apply explicit in/out
|
||||
# limits only when both are provided (>0); otherwise use the shared total cap.
|
||||
if maxIn > 0 and maxOut > 0:
|
||||
b = b.withMaxInOut(maxIn, maxOut)
|
||||
else:
|
||||
b = b.withMaxConnections(maxConnections)
|
||||
|
||||
if peerStoreCapacity.isSome():
|
||||
b = b.withPeerStore(peerStoreCapacity.get())
|
||||
else:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user