kona-net

Crates.iokona-net
lib.rskona-net
version0.1.0
created_at2025-02-13 23:30:06.13704+00
updated_at2025-02-13 23:30:06.13704+00
descriptionConsensus networking library for the OP Stack
homepagehttps://github.com/op-rs/kona
repositoryhttps://github.com/op-rs/kona
max_upload_size
id1555205
size67,031
(clabby)

documentation

README

kona-net

A consensus network library for the OP Stack.

Contains a gossipsub driver to run discv5 peer discovery and block gossip.

Example

Warning

Notice, the socket address uses 0.0.0.0. If you are experiencing issues connecting to peers for discovery, check to make sure you are not using the loopback address, 127.0.0.1 aka "localhost", which can prevent outward facing connections.

use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use alloy_primitives::address;
use kona_net::driver::NetworkDriver;

// Build the network driver.
let signer = address!("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9099);
let driver = NetworkDriver::builder()
    .with_chain_id(10) // op mainnet chain id
    .with_unsafe_block_signer(signer)
    .with_gossip_addr(socket)
    .build()
    .expect("Failed to builder network driver");

// Call `.start()` on the driver.
driver.start().expect("Failed to start network driver");

println!("NetworkDriver started.");

Acknowledgements

Largely based off magi's p2p module.

Commit count: 1842

cargo fmt