Skip to content

Commit e11d792

Browse files
committed
feat(rpc): add signet_networkStatus endpoint (ENG-479)
Adds a new signet_networkStatus RPC endpoint that returns Signet-specific network information: - chain_id: The Signet rollup chain ID - genesis: The genesis block hash (block 0) - head: The current head block hash - headNumber: The current head block number This addresses the TODOs from the original SignetNoopNetwork implementation which returned Default::default() for these values. The new endpoint exposes the actual Signet network state rather than delegating to the host network. The endpoint is exposed as signet_networkStatus and returns a JSON object with camelCase field names. Closes ENG-479
1 parent 8cbd42a commit e11d792

3 files changed

Lines changed: 65 additions & 2 deletions

File tree

crates/rpc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ mod eth;
6363
pub use eth::{CallErrorData, EthError, eth};
6464

6565
mod signet;
66-
pub use signet::{error::SignetError, signet};
66+
pub use signet::{SignetNetworkStatus, error::SignetError, signet};
6767

6868
mod inspect;
6969
pub use inspect::inspect;

crates/rpc/src/signet/endpoints.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,71 @@ use crate::{
44
utils::{await_handler, response_tri},
55
};
66
use ajj::{HandlerCtx, ResponsePayload};
7+
use alloy::{eips::BlockId, primitives::B256};
8+
use reth::providers::{BlockHashReader, BlockNumReader};
79
use reth_node_api::FullNodeComponents;
10+
use serde::Serialize;
811
use signet_bundle::{SignetBundleDriver, SignetCallBundle, SignetCallBundleResponse};
912
use signet_node_types::Pnt;
1013
use signet_types::SignedOrder;
1114
use std::time::Duration;
1215
use tokio::select;
1316

17+
/// Signet network status information.
18+
///
19+
/// This provides Signet-specific network status, as opposed to the host
20+
/// network status which would be returned by `eth_protocolVersion`.
21+
#[derive(Debug, Clone, Serialize)]
22+
#[serde(rename_all = "camelCase")]
23+
pub struct SignetNetworkStatus {
24+
/// The Signet chain ID.
25+
pub chain_id: u64,
26+
/// The genesis block hash.
27+
pub genesis: B256,
28+
/// The current head block hash.
29+
pub head: B256,
30+
/// The current head block number.
31+
pub head_number: u64,
32+
}
33+
34+
/// Returns the Signet network status including genesis and head block info.
35+
///
36+
/// This endpoint provides Signet-specific network information that reflects
37+
/// the rollup's state rather than the underlying host network.
38+
pub(super) async fn network_status<Host, Signet>(
39+
hctx: HandlerCtx,
40+
ctx: RpcCtx<Host, Signet>,
41+
) -> Result<SignetNetworkStatus, String>
42+
where
43+
Host: FullNodeComponents,
44+
Signet: Pnt,
45+
{
46+
let task = async move {
47+
let provider = ctx.signet().provider();
48+
49+
// Get the genesis block hash (block 0)
50+
let genesis = provider
51+
.block_hash(0)
52+
.map_err(|e| e.to_string())?
53+
.ok_or_else(|| "genesis block hash not found".to_string())?;
54+
55+
// Get the current head block number and hash
56+
let head_number = provider.last_block_number().map_err(|e| e.to_string())?;
57+
58+
let head = provider
59+
.block_hash(head_number)
60+
.map_err(|e| e.to_string())?
61+
.ok_or_else(|| "head block hash not found".to_string())?;
62+
63+
// Get the chain ID from constants
64+
let chain_id = ctx.signet().constants().ru_chain_id();
65+
66+
Ok(SignetNetworkStatus { chain_id, genesis, head, head_number })
67+
};
68+
69+
await_handler!(@option hctx.spawn_blocking(task))
70+
}
71+
1472
pub(super) async fn send_order<Host, Signet>(
1573
hctx: HandlerCtx,
1674
order: SignedOrder,

crates/rpc/src/signet/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use endpoints::*;
55

66
pub(crate) mod error;
77

8+
pub use endpoints::SignetNetworkStatus;
9+
810
use crate::ctx::RpcCtx;
911
use reth_node_api::FullNodeComponents;
1012
use signet_node_types::Pnt;
@@ -15,5 +17,8 @@ where
1517
Host: FullNodeComponents,
1618
Signet: Pnt,
1719
{
18-
ajj::Router::new().route("sendOrder", send_order).route("callBundle", call_bundle)
20+
ajj::Router::new()
21+
.route("sendOrder", send_order)
22+
.route("callBundle", call_bundle)
23+
.route("networkStatus", network_status)
1924
}

0 commit comments

Comments
 (0)