1 unstable release

new 0.1.0 Feb 13, 2025

#577 in Magic Beans

Download history 129/week @ 2025-02-11

129 downloads per month

MIT license

68KB
1K SLoC

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.

Dependencies

~45–85MB
~1.5M SLoC