Skip to content

Commit

Permalink
misc (#207)
Browse files Browse the repository at this point in the history
* improve dev peers handling and logging

* readme

* update jamtestvectors

* ci
  • Loading branch information
xlc authored Oct 29, 2024
1 parent a6bb5d3 commit 83bfd09
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions Networking/Sources/Networking/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 16 additions & 6 deletions Node/Sources/Node/NetworkingProtocol/NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<NetAddr>
private let devPeers: Set<Either<PeerId, NetAddr>>

public init(
config: Network.Config,
Expand All @@ -46,13 +46,23 @@ public final class NetworkManager: Sendable {

subscriptions = EventSubscriptions(eventBus: eventBus)

self.devPeers = devPeers
var selfDevPeers = Set<Either<PeerId, NetAddr>>()

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(
Expand All @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion Utils/Sources/Utils/EventBus/LogMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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("<<! event dispatch failed: \(event) with error: \(error)")
if propagateError {
Expand Down
2 changes: 2 additions & 0 deletions scripts/devnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ create_node() {
local p2p_port=$((19000 + node_number))

tmux send-keys -t boka "LOG_LEVEL=trace $bin_path --chain=minimal --rpc 127.0.0.1:$port --validator --dev-seed $node_number --p2p 127.0.0.1:$p2p_port --peers=127.0.0.1:19001 --peers=127.0.0.1:19002 --peers=127.0.0.1:19003 --name=node-$node_number" C-m

sleep 1
}

# Start a new tmux session
Expand Down

0 comments on commit 83bfd09

Please sign in to comment.