Skip to content
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
1 change: 1 addition & 0 deletions crates/chain-orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ serde = [
"scroll-alloy-hardforks/serde",
"scroll-engine/serde",
"scroll-network/serde",
"rollup-node-primitives/serde",
]
11 changes: 10 additions & 1 deletion crates/chain-orchestrator/src/handle/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{ChainOrchestratorEvent, ChainOrchestratorStatus};
use reth_network_api::FullNetwork;
use reth_scroll_node::ScrollNetworkPrimitives;
use reth_tokio_util::EventStream;
use rollup_node_primitives::BlockInfo;
use rollup_node_primitives::{BlockInfo, L1MessageEnvelope};
use scroll_network::ScrollNetworkHandle;
use tokio::sync::oneshot;

Expand All @@ -24,7 +24,16 @@ pub enum ChainOrchestratorCommand<N: FullNetwork<Primitives = ScrollNetworkPrimi
EnableAutomaticSequencing(oneshot::Sender<bool>),
/// Disable automatic sequencing.
DisableAutomaticSequencing(oneshot::Sender<bool>),
/// Send a database query to the rollup manager.
DatabaseQuery(DatabaseQuery),
/// Enable gossiping of blocks to peers.
#[cfg(feature = "test-utils")]
SetGossip((bool, oneshot::Sender<()>)),
}

/// The database queries that can be sent to the rollup manager.
#[derive(Debug)]
pub enum DatabaseQuery {
/// Get L1 message by its index.
GetL1MessageByIndex(u64, oneshot::Sender<Option<L1MessageEnvelope>>),
}
16 changes: 14 additions & 2 deletions crates/chain-orchestrator/src/handle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use super::ChainOrchestratorEvent;
use reth_network_api::FullNetwork;
use reth_scroll_node::ScrollNetworkPrimitives;
use reth_tokio_util::EventStream;
use rollup_node_primitives::BlockInfo;
use rollup_node_primitives::{BlockInfo, L1MessageEnvelope};
use scroll_network::ScrollNetworkHandle;
use tokio::sync::{mpsc, oneshot};
use tracing::error;

mod command;
pub use command::ChainOrchestratorCommand;
pub use command::{ChainOrchestratorCommand, DatabaseQuery};

mod metrics;
use metrics::ChainOrchestratorHandleMetrics;
Expand Down Expand Up @@ -90,6 +90,18 @@ impl<N: FullNetwork<Primitives = ScrollNetworkPrimitives>> ChainOrchestratorHand
rx.await
}

/// Get an L1 message by its index.
pub async fn get_l1_message_by_index(
&self,
index: u64,
) -> Result<Option<L1MessageEnvelope>, oneshot::error::RecvError> {
let (tx, rx) = oneshot::channel();
self.send_command(ChainOrchestratorCommand::DatabaseQuery(
DatabaseQuery::GetL1MessageByIndex(index, tx),
));
rx.await
}

/// Sends a command to the rollup manager to enable or disable gossiping of blocks to peers.
#[cfg(feature = "test-utils")]
pub async fn set_gossip(&self, enabled: bool) -> Result<(), oneshot::error::RecvError> {
Expand Down
12 changes: 11 additions & 1 deletion crates/chain-orchestrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod error;
pub use error::ChainOrchestratorError;

mod handle;
pub use handle::{ChainOrchestratorCommand, ChainOrchestratorHandle};
pub use handle::{ChainOrchestratorCommand, ChainOrchestratorHandle, DatabaseQuery};

mod metrics;
pub use metrics::{ChainOrchestratorItem, ChainOrchestratorMetrics};
Expand Down Expand Up @@ -376,6 +376,16 @@ impl<
let _ = tx.send(false);
}
}
ChainOrchestratorCommand::DatabaseQuery(query) => match query {
DatabaseQuery::GetL1MessageByIndex(index, sender) => {
let l1_message = self
.database
.get_n_l1_messages(Some(L1MessageKey::from_queue_index(index)), 1)
.await?
.pop();
let _ = sender.send(l1_message);
}
},
#[cfg(feature = "test-utils")]
ChainOrchestratorCommand::SetGossip((enabled, tx)) => {
self.network.handle().set_gossip(enabled).await;
Expand Down
1 change: 1 addition & 0 deletions crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ serde = [
"reth-primitives-traits/serde",
"alloy-consensus/serde",
"scroll-alloy-consensus/serde",
"rollup-node-primitives/serde",
]
1 change: 1 addition & 0 deletions crates/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ serde = [
"reth-primitives-traits/serde",
"reth-storage-api/serde",
"scroll-alloy-hardforks/serde",
"rollup-node-primitives/serde",
]
test-utils = [
"reth-chainspec/test-utils",
Expand Down
23 changes: 23 additions & 0 deletions crates/node/src/add_ons/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use jsonrpsee::{
use reth_network_api::FullNetwork;
use reth_scroll_node::ScrollNetworkPrimitives;
use rollup_node_chain_orchestrator::{ChainOrchestratorHandle, ChainOrchestratorStatus};
use rollup_node_primitives::L1MessageEnvelope;
use tokio::sync::{oneshot, Mutex, OnceCell};

/// RPC extension for rollup node management operations.
Expand Down Expand Up @@ -79,6 +80,10 @@ pub trait RollupNodeExtApi {
/// Returns the current status of the rollup node.
#[method(name = "status")]
async fn status(&self) -> RpcResult<ChainOrchestratorStatus>;

/// Returns the L1 message by index.
#[method(name = "getL1MessageByIndex")]
async fn get_l1_message_by_index(&self, index: u64) -> RpcResult<Option<L1MessageEnvelope>>;
}

#[async_trait]
Expand Down Expand Up @@ -139,4 +144,22 @@ where
)
})
}

async fn get_l1_message_by_index(&self, index: u64) -> RpcResult<Option<L1MessageEnvelope>> {
let handle = self.rollup_manager_handle().await.map_err(|e| {
ErrorObjectOwned::owned(
error::INTERNAL_ERROR_CODE,
format!("Failed to get rollup manager handle: {}", e),
None::<()>,
)
})?;

handle.get_l1_message_by_index(index).await.map_err(|e| {
ErrorObjectOwned::owned(
error::INTERNAL_ERROR_CODE,
format!("Failed to get L1 message by index: {}", e),
None::<()>,
)
})
}
}
11 changes: 11 additions & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ arbitrary = [
"alloy-chains/arbitrary",
"reth-chainspec/arbitrary",
]
serde = [
"alloy-chains/serde",
"alloy-consensus/serde",
"alloy-eips/serde",
"alloy-primitives/serde",
"alloy-rpc-types-engine/serde",
"reth-primitives-traits/serde",
"reth-scroll-primitives/serde",
"scroll-alloy-consensus/serde",
"scroll-alloy-rpc-types-engine/serde",
]
1 change: 1 addition & 0 deletions crates/primitives/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use scroll_alloy_consensus::TxL1Message;

/// A L1 message envelope, containing extra information about the message.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct L1MessageEnvelope {
/// The L1 transaction.
pub transaction: TxL1Message,
Expand Down
Loading