Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: net crate #102

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,479 changes: 2,303 additions & 176 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,39 @@ alloy-transport = { version = "0.6.1", default-features = false }
alloy-rpc-client = { version = "0.6.1", default-features = false }
alloy-node-bindings = { version = "0.6.1", default-features = false }
alloy-transport-http = { version = "0.6.1", default-features = false }
alloy-rpc-types-eth = { version = "0.6.1", default-features = false }
alloy-rpc-types-beacon = { version = "0.6.1", default-features = false }
alloy-rpc-types-engine = { version = "0.6.1", default-features = false }

# OP Alloy
op-alloy-genesis = { version = "0.6.2", default-features = false }
op-alloy-protocol = { version = "0.6.2", default-features = false }
op-alloy-consensus = { version = "0.6.2", default-features = false }
op-alloy-rpc-types-engine = { version = "0.6.2", default-features = false }

# Serialization
serde = { version = "1.0.214", default-features = false }
serde_json = { version = "1.0.132", default-features = false }

# Networking
snap = "1.1.1"
discv5 = "0.9.0"
libp2p = "0.54.1"
openssl = "0.10.68"
libp2p-identity = "0.2.9"

# Testing
arbtest = "0.3"
arbitrary = "1"

# Misc
lru = "0.12.5"
eyre = "0.6.12"
tokio = "1.41.0"
futures = "0.3.31"
reqwest = "0.12.9"
async-trait = "0.1.83"
unsigned-varint = "0.8.0"
tracing = { version = "0.1.40", default-features = false }
derive_more = { version = "1.0.0", default-features = false }
lazy_static = { version = "1.5.0", default-features = false }
47 changes: 47 additions & 0 deletions crates/net/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "superchain-net"
description = "Networking library for the OP Stack"
version = "0.0.0"
edition.workspace = true
authors.workspace = true
license.workspace = true
keywords.workspace = true
repository.workspace = true
categories.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
eyre.workspace = true
tokio.workspace = true
tracing.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"]
42 changes: 42 additions & 0 deletions crates/net/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## Consensus Network Library

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 superchain_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].

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