Skip to content

Commit

Permalink
feat(rollup): engine api rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Sep 22, 2024
1 parent bdd68f7 commit 89acec2
Show file tree
Hide file tree
Showing 15 changed files with 583 additions and 106 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ lcov.info

# Rust bug report
rustc-ice-*

# Used for testing
jwt.hex
120 changes: 99 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ alloy = { version = "0.3.6", features = [
"consensus",
"rpc-types",
"rpc-types-engine",
"json-rpc",
"network",
"ssz"
] }
alloy-primitives = { version = "0.8", features = ["serde"] }
alloy-rlp = "0.3"
op-alloy-protocol = { version = "0.2.12", default-features = false }
op-alloy-rpc-types = { version = "0.2.12", default-features = false }
op-alloy-rpc-types-engine = { version = "0.2.12", default-features = false }
op-alloy-genesis = { version = "0.2.12", default-features = false }
# TODO: Use a new version once it's released
op-alloy-rpc-types-engine = { git = "https://github.com/alloy-rs/op-alloy", rev = "f6d9d72", default-features = false }
op-alloy-provider = { git = "https://github.com/alloy-rs/op-alloy", rev = "f6d9d72", default-features = false }

# Tokio
tokio = { version = "1.21", default-features = false }
Expand Down Expand Up @@ -110,6 +113,7 @@ hashbrown = "0.14.5"
parking_lot = "0.12.3"
unsigned-varint = "0.8.0"
rand = { version = "0.8.3", features = ["small_rng"], default-features = false }
thiserror = "1.0.63"
url = "2.5.2"

[workspace.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion bin/op-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() -> Result<()> {

let cfg = hera_args.get_l2_config()?;
let node = EthereumNode::default();
let hera = move |ctx| async { Ok(Driver::exex(ctx, hera_args, cfg).start()) };
let hera = move |ctx| async { Ok(Driver::exex(ctx, hera_args, cfg).await.start()) };
let handle = builder.node(node).install_exex(HERA_EXEX_ID, hera).launch().await?;
handle.wait_for_node_exit().await
} else {
Expand Down
8 changes: 7 additions & 1 deletion crates/net/src/discovery/driver.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Discovery Module.

use eyre::Result;
use std::time::Duration;
use std::{fmt::Debug, time::Duration};
use tokio::{
sync::mpsc::{channel, Receiver},
time::sleep,
Expand All @@ -26,6 +26,12 @@ pub struct DiscoveryDriver {
pub chain_id: u64,
}

impl Debug for DiscoveryDriver {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DiscoveryDriver").field("chain_id", &self.chain_id).finish()
}
}

impl DiscoveryDriver {
/// Returns a new [DiscoveryBuilder] instance.
pub fn builder() -> DiscoveryBuilder {
Expand Down
1 change: 1 addition & 0 deletions crates/net/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use tokio::{select, sync::watch};
/// There are two core services that are run by the driver:
/// - Block gossip through Gossipsub.
/// - Peer discovery with `discv5`.
#[derive(Debug)]
pub struct NetworkDriver {
/// Channel to receive unsafe blocks.
pub(crate) unsafe_block_recv: Option<Receiver<ExecutionPayloadEnvelope>>,
Expand Down
8 changes: 8 additions & 0 deletions crates/net/src/gossip/driver.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Consensus-layer gossipsub driver for Optimism.

use std::fmt::Debug;

use crate::gossip::{
behaviour::Behaviour,
event::Event,
Expand All @@ -20,6 +22,12 @@ pub struct GossipDriver {
pub handler: BlockHandler,
}

impl Debug for GossipDriver {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("GossipDriver").field("addr", &self.addr).finish()
}
}

impl GossipDriver {
/// Creates a new [GossipDriver] instance.
pub fn new(swarm: Swarm<Behaviour>, addr: Multiaddr, handler: BlockHandler) -> Self {
Expand Down
6 changes: 6 additions & 0 deletions crates/rollup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ keywords.workspace = true
categories.workspace = true

[dependencies]
# Workspace
kona-providers.workspace = true

# OP Stack Dependencies
kona-derive.workspace = true
op-alloy-genesis.workspace = true
op-alloy-protocol.workspace = true
op-alloy-rpc-types-engine.workspace = true
op-alloy-provider.workspace = true
superchain = { workspace = true, default-features = false }

# Reth Dependencies
Expand All @@ -29,6 +31,9 @@ reth-execution-types.workspace = true
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "fmt"] }
metrics-exporter-prometheus = { version = "0.15.3", features = ["http-listener"] }

# Async
tower = "0.4"

# Misc
url.workspace = true
reqwest.workspace = true
Expand All @@ -41,6 +46,7 @@ tokio.workspace = true
futures.workspace = true
alloy.workspace = true
hashbrown.workspace = true
thiserror.workspace = true

[features]
default = ["online"]
Expand Down
9 changes: 7 additions & 2 deletions crates/rollup/src/driver/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ impl Blocks {
*self.0.last_key_value().expect("Blocks should have at least one block").0
}

/// Returns the block at the fork point of the chain.
pub fn fork_block(&self) -> BlockNumber {
/// Returns a reference to the block at the tip of the chain.
pub fn tip_block(&self) -> &Block<TxEnvelope> {
self.0.get(&self.tip()).expect("Blocks should have at least one block")
}

/// Returns the block number at the fork point of the chain (the block before the first).
pub fn fork_block_number(&self) -> BlockNumber {
let first = self.0.first_key_value().expect("Blocks should have at least one block").0;
first.saturating_sub(1)
}
Expand Down
Loading

0 comments on commit 89acec2

Please sign in to comment.