Skip to content
Closed
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 changes: 1 addition & 1 deletion crates/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mod eth;
pub use eth::{CallErrorData, EthError, eth};

mod signet;
pub use signet::{error::SignetError, signet};
pub use signet::{SignetNetworkStatus, error::SignetError, signet};

mod inspect;
pub use inspect::inspect;
Expand Down
58 changes: 58 additions & 0 deletions crates/rpc/src/signet/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,71 @@ use crate::{
utils::{await_handler, response_tri},
};
use ajj::{HandlerCtx, ResponsePayload};
use alloy::{eips::BlockId, primitives::B256};
use reth::providers::{BlockHashReader, BlockNumReader};
use reth_node_api::FullNodeComponents;
use serde::Serialize;
use signet_bundle::{SignetBundleDriver, SignetCallBundle, SignetCallBundleResponse};
use signet_node_types::Pnt;
use signet_types::SignedOrder;
use std::time::Duration;
use tokio::select;

/// Signet network status information.
///
/// This provides Signet-specific network status, as opposed to the host
/// network status which would be returned by `eth_protocolVersion`.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SignetNetworkStatus {
/// The Signet chain ID.
pub chain_id: u64,
/// The genesis block hash.
pub genesis: B256,
/// The current head block hash.
pub head: B256,
/// The current head block number.
pub head_number: u64,
}

/// Returns the Signet network status including genesis and head block info.
///
/// This endpoint provides Signet-specific network information that reflects
/// the rollup's state rather than the underlying host network.
pub(super) async fn network_status<Host, Signet>(
hctx: HandlerCtx,
ctx: RpcCtx<Host, Signet>,
) -> Result<SignetNetworkStatus, String>
where
Host: FullNodeComponents,
Signet: Pnt,
{
let task = async move {
let provider = ctx.signet().provider();

// Get the genesis block hash (block 0)
let genesis = provider
.block_hash(0)
.map_err(|e| e.to_string())?
.ok_or_else(|| "genesis block hash not found".to_string())?;

// Get the current head block number and hash
let head_number = provider.last_block_number().map_err(|e| e.to_string())?;

let head = provider
.block_hash(head_number)
.map_err(|e| e.to_string())?
.ok_or_else(|| "head block hash not found".to_string())?;

// Get the chain ID from constants
let chain_id = ctx.signet().constants().ru_chain_id();

Ok(SignetNetworkStatus { chain_id, genesis, head, head_number })
};

await_handler!(@option hctx.spawn_blocking(task))
}

pub(super) async fn send_order<Host, Signet>(
hctx: HandlerCtx,
order: SignedOrder,
Expand Down
7 changes: 6 additions & 1 deletion crates/rpc/src/signet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use endpoints::*;

pub(crate) mod error;

pub use endpoints::SignetNetworkStatus;

use crate::ctx::RpcCtx;
use reth_node_api::FullNodeComponents;
use signet_node_types::Pnt;
Expand All @@ -15,5 +17,8 @@ where
Host: FullNodeComponents,
Signet: Pnt,
{
ajj::Router::new().route("sendOrder", send_order).route("callBundle", call_bundle)
ajj::Router::new()
.route("sendOrder", send_order)
.route("callBundle", call_bundle)
.route("networkStatus", network_status)
}
Loading