Skip to content

Commit

Permalink
chore(services): Networking Crate (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Feb 13, 2025
1 parent b31d080 commit 96aba6a
Show file tree
Hide file tree
Showing 25 changed files with 3,861 additions and 102 deletions.
2,120 changes: 2,027 additions & 93 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ kona-driver = { path = "crates/protocol/driver", version = "0.2.3", default-feat
kona-interop = { path = "crates/protocol/interop", version = "0.1.1", default-features = false }

# Workspace Services
kona-net = { path = "crates/services/net", version = "0.1.0", default-features = false }
kona-providers-alloy = { path = "crates/services/providers-alloy", version = "0.1.0", default-features = false }

# Workspace Proof
Expand Down Expand Up @@ -116,25 +117,36 @@ clap = "4.5.29"
tokio = "1.43.0"
cfg-if = "1.0.0"
rstest = "0.24.0"
futures = "0.3.31"
reqwest = "0.12.12"
tempfile = "3.16.0"
arbitrary = "1.4.1"
async-trait = "0.1.86"
async-channel = "2.3.1"
linked_list_allocator = "0.10.5"
lazy_static = { version = "1.5.0", default-features = false }

# General
sha2 = { version = "0.10.8", default-features = false }
c-kzg = { version = "2.0.0", default-features = false }
anyhow = { version = "1.0.95", default-features = false }
thiserror = { version = "2.0.11", default-features = false }

# Networking
snap = "1.1.1"
discv5 = "0.9.1"
libp2p = "0.54.1"
openssl = "0.10.70"
libp2p-identity = "0.2.10"

# Tracing
tracing-loki = "0.2.6"
tracing-subscriber = "0.3.19"
tracing = { version = "0.1.41", default-features = false }

# Testing
pprof = "0.14.0"
arbtest = "0.3.2"
proptest = "1.6.0"
criterion = "0.5.1"

Expand Down
2 changes: 1 addition & 1 deletion book/src/sdk/pipeline/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ the [`PipelineBuilder`][builder] to instantiate a [`DerivationPipeline`][dp].
use std::sync::Arc;
use maili_protocol::BlockInfo;
use maili_genesis::RollupConfig;
use hilo_providers_alloy::*;
use kona_providers_alloy::*;
// Use a default rollup config.
let rollup_config = Arc::new(RollupConfig::default());
Expand Down
6 changes: 2 additions & 4 deletions crates/protocol/interop/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,8 @@ mod test {

let (headers, provider) = superchain.build();

let cfgs = HashMap::from([(
0xDEAD,
RollupConfig { interop_time: Some(50), ..Default::default() },
)]);
let mut cfgs = HashMap::default();
cfgs.insert(0xDEAD, RollupConfig { interop_time: Some(50), ..Default::default() });
let graph = MessageGraph::derive(headers.as_slice(), &provider, &cfgs).await.unwrap();
assert_eq!(
graph.resolve().await.unwrap_err(),
Expand Down
49 changes: 49 additions & 0 deletions crates/services/net/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[package]
name = "kona-net"
version = "0.1.0"
description = "Consensus networking library for the OP Stack"

edition.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
keywords.workspace = true
categories.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
# Alloy
alloy-rlp.workspace = true
alloy-primitives = { workspace = true, features = ["k256", "getrandom"] }
alloy-rpc-types-engine = { workspace = true, features = ["std"] }

# Op Alloy
op-alloy-rpc-types-engine = { workspace = true, features = ["std"] }

# Networking
snap.workspace = true
futures.workspace = true
discv5.workspace = true
libp2p = { workspace = true, features = ["macros", "tokio", "tcp", "noise", "gossipsub", "ping", "yamux"] }
openssl = { workspace = true, features = ["vendored"] }
libp2p-identity = { workspace = true, features = ["secp256k1"] }

# Misc
tokio.workspace = true
tracing.workspace = true
thiserror.workspace = true
lazy_static.workspace = true
unsigned-varint.workspace = true

# `arbitrary` feature dependencies
arbitrary = { workspace = true, features = ["derive"], optional = true }

[dev-dependencies]
arbtest.workspace = true
arbitrary = { workspace = true, features = ["derive"] }
alloy-primitives = { workspace = true, features = ["arbitrary"] }

[features]
default = []
arbitrary = ["dep:arbitrary", "alloy-primitives/arbitrary"]
46 changes: 46 additions & 0 deletions crates/services/net/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# `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.
```rust,no_run
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.");
```

[!WARNING]: ###example

### Acknowledgements

Largely based off [magi]'s [p2p module][p2p].

<!-- Links -->

[magi]: https://github.com/a16z/magi
[p2p]: https://github.com/a16z/magi/tree/master/src/network
Loading

0 comments on commit 96aba6a

Please sign in to comment.