Crate kona_net

Source
Expand description

§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.

Modules§

builder
Network Builder Module.
discovery
Discovery Module for Optimism
driver
Driver for network services.
gossip
Module containing consensus-layer gossipsub for optimism.
types
Common types for the Networking Crate.