diff --git a/.gitmodules b/.gitmodules index 5cdb516b..b5213f75 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "JAMTests/jamtestvectors"] path = JAMTests/jamtestvectors - url = https://github.com/AcalaNetwork/jamtestvectors.git + url = https://github.com/open-web3-stack/jamtestvectors.git diff --git a/Networking/Sources/Networking/Connection.swift b/Networking/Sources/Networking/Connection.swift index 3d4acc8d..9a0e4a99 100644 --- a/Networking/Sources/Networking/Connection.swift +++ b/Networking/Sources/Networking/Connection.swift @@ -11,6 +11,8 @@ public protocol ConnectionInfoProtocol { var role: PeerRole { get } var remoteAddress: NetAddr { get } var publicKey: Data? { get } + + func ready() async throws } enum ConnectionError: Error { diff --git a/Node/Sources/Node/NetworkingProtocol/NetworkManager.swift b/Node/Sources/Node/NetworkingProtocol/NetworkManager.swift index 44e3afa3..bbc687bd 100644 --- a/Node/Sources/Node/NetworkingProtocol/NetworkManager.swift +++ b/Node/Sources/Node/NetworkingProtocol/NetworkManager.swift @@ -23,7 +23,7 @@ public final class NetworkManager: Sendable { // This is for development only // Those peers will receive all the messages regardless the target - private let devPeers: Set + private let devPeers: Set> public init( config: Network.Config, @@ -46,13 +46,23 @@ public final class NetworkManager: Sendable { subscriptions = EventSubscriptions(eventBus: eventBus) - self.devPeers = devPeers + var selfDevPeers = Set>() + + logger.info("P2P Listening on \(try! network.listenAddress())") for peer in devPeers { - _ = try network.connect(to: peer, role: .validator) + let conn = try network.connect(to: peer, role: .validator) + try? await conn.ready() + let pubkey = conn.publicKey + if let pubkey { + selfDevPeers.insert(.left(PeerId(publicKey: pubkey, address: peer))) + } else { + // unable to connect, add as address + selfDevPeers.insert(.right(peer)) + } } - logger.info("P2P Listening on \(try! network.listenAddress())") + self.devPeers = selfDevPeers Task { await subscriptions.subscribe( @@ -76,10 +86,10 @@ public final class NetworkManager: Sendable { switch target { case .safroleStep1Validator: // TODO: only send to the selected validator in the spec - Set(devPeers.map { .right($0) }) + devPeers case .currentValidators: // TODO: read onchain state for validators - Set(devPeers.map { .right($0) }) + devPeers } } diff --git a/README.md b/README.md index 2ed1d5ca..7ba96462 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Boka -JAM built with Swift +Boka / 波卡 / bō kǎ: A JAM implementation built with Swift, brought to you by Laminar Labs. ## Development Environment diff --git a/Utils/Sources/Utils/EventBus/LogMiddleware.swift b/Utils/Sources/Utils/EventBus/LogMiddleware.swift index cbd7ebde..2e2b4b5d 100644 --- a/Utils/Sources/Utils/EventBus/LogMiddleware.swift +++ b/Utils/Sources/Utils/EventBus/LogMiddleware.swift @@ -13,7 +13,7 @@ public final class LogMiddleware: MiddlewareProtocol { logger.debug(">>> dispatching event: \(event)") do { try await next(event) - logger.debug("<<< event dispatched: \(event)") + logger.debug("<<< event dispatched: \(T.self)") } catch { logger.error("<