Fix mix imports

This commit is contained in:
NagyZoltanPeter 2025-03-28 15:50:09 +01:00 committed by Prem Chaitanya Prathi
parent 3ef75a2d47
commit 09bac967be
5 changed files with 32 additions and 25 deletions

View File

@ -12,8 +12,7 @@ import
eth/keys,
eth/p2p/discoveryv5/enr
import entry_connection,
app_protocols
import mix/entry_connection, mix/protocol
import
waku/[
@ -25,7 +24,7 @@ import
waku_enr,
discovery/waku_discv5,
factory/builder,
waku_lightpush/client
waku_lightpush/client,
]
proc now*(): Timestamp =
@ -81,28 +80,34 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
node.mountMetadata(clusterId).expect("failed to mount waku metadata protocol")
node.mountLightPushClient()
try:
await node.mountPeerExchange(
some(uint16(clusterId))
)
await node.mountPeerExchange(some(uint16(clusterId)))
except CatchableError:
error "failed to mount waku peer-exchange protocol: ", errmsg = getCurrentExceptionMsg()
error "failed to mount waku peer-exchange protocol: ",
errmsg = getCurrentExceptionMsg()
return
let pxPeerInfo = RemotePeerInfo.init(
"16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o",
@[MultiAddress.init("/ip4/127.0.0.1/tcp/60001").get()]
@[MultiAddress.init("/ip4/127.0.0.1/tcp/60001").get()],
)
node.peerManager.addServicePeer(pxPeerInfo, WakuPeerExchangeCodec)
let pxPeerInfo2 = RemotePeerInfo.init(
"16Uiu2HAmRhxmCHBYdXt1RibXrjAUNJbduAhzaTHwFCZT4qWnqZAu",
@[MultiAddress.init("/ip4/127.0.0.1/tcp/60005").get()]
@[MultiAddress.init("/ip4/127.0.0.1/tcp/60005").get()],
)
node.peerManager.addServicePeer(pxPeerInfo2, WakuPeerExchangeCodec)
(
await node.mountMix(intoCurve25519Key(ncrutils.fromHex("401dd1eb5582f6dc9488d424aa26ed1092becefcf8543172e6d92c17ed07265a")))
await node.mountMix(
intoCurve25519Key(
ncrutils.fromHex(
"401dd1eb5582f6dc9488d424aa26ed1092becefcf8543172e6d92c17ed07265a"
)
)
)
).isOkOr:
error "failed to mount waku mix protocol: ", error = $error
return
return
#discard node.setMixBootStrapNodes()
let destPeerId = PeerId.init("16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o").valueOr:
@ -113,7 +118,8 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
"/ip4/127.0.0.1/tcp/60001",
destPeerId,
ProtocolType.fromString(WakuLightPushCodec),
node.mix)
node.mix,
)
await node.start()
node.peerManager.start()
@ -123,7 +129,8 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
warn "Cannot fetch peers from peer exchange", cause = error
while node.getMixNodePoolSize() < 3:
info "waiting for mix nodes to be discovered", currentpoolSize = node.getMixNodePoolSize()
info "waiting for mix nodes to be discovered",
currentpoolSize = node.getMixNodePoolSize()
await sleepAsync(1000)
notice "publisher service started"
@ -139,8 +146,9 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
timestamp: now(),
) # current timestamp
let res =
await node.wakuLightpushClient.publishWithConn(LightpushPubsubTopic, message, conn)
let res = await node.wakuLightpushClient.publishWithConn(
LightpushPubsubTopic, message, conn
)
if res.isOk:
notice "published message",
@ -153,7 +161,6 @@ proc setupAndPublish(rng: ref HmacDrbgContext) {.async.} =
await sleepAsync(1000)
when isMainModule:
let rng = crypto.newRng()
asyncSpawn setupAndPublish(rng)

2
vendor/mix vendored

@ -1 +1 @@
Subproject commit 6b4787e5899a839deca84c11c6bcf7000353cb9b
Subproject commit 5f9633df51e557ff99f030bc0ad9b3fca29566ab

View File

@ -38,7 +38,7 @@ import
../waku_lightpush_legacy/common,
../common/rate_limit/setting,
../common/databases/dburl,
curve25519_utils
mix/curve25519_utils
## Peer persistence

View File

@ -23,10 +23,10 @@ import
libp2p/transports/tcptransport,
libp2p/transports/wstransport,
libp2p/utility,
mix_node,
mix_protocol,
curve25519_utils,
app_protocols
mix/mix_node,
mix/mix_protocol,
mix/curve25519_utils,
mix/app_protocols
import
../waku_core,
@ -251,7 +251,7 @@ proc mountSharding*(
#TODO: Ideally these procs should be moved out into mix specific file, but keeping it here for now.
proc mixPoolFilter*(cluster: Option[uint16], peer: RemotePeerInfo): bool =
# Note that origin based(discv5) filtering is not done intentionally
# Note that origin based(discv5) filtering is not done intentionally
# so that more mix nodes can be discovered.
if peer.enr.isNone():
trace "peer has no ENR", peer = $peer
@ -356,7 +356,7 @@ proc mountMix*(
node.switch.peerInfo.publicKey.skkey,
node.switch.peerInfo.privateKey.skkey,
)
# TODO: Pass bootnodes from config,
# TODO: Pass bootnodes from config,
# TODO : ideally mix should not be marked ready until certain min pool of mixNodes are discovered
let protoRes =
MixProtocol.initMix(localMixNodeInfo, node.switch, initTable[PeerId, MixPubInfo]())

View File

@ -3,7 +3,7 @@
import
std/[options, bitops, sequtils, net, tables], results, eth/keys, libp2p/crypto/crypto
import ../common/enr, ../waku_core/codecs
import mix_protocol
import mix/mix_protocol
const CapabilitiesEnrField* = "waku2"