Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
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 changes: 2 additions & 0 deletions crates/supervisor/core/src/rpc/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl Metrics {
"cross_derived_to_source";
pub(crate) const SUPERVISOR_RPC_METHOD_DEPENDENCY_SET: &'static str = "dependency_set";
pub(crate) const SUPERVISOR_RPC_METHOD_LOCAL_UNSAFE: &'static str = "local_unsafe";
pub(crate) const SUPERVISOR_RPC_METHOD_LOCAL_SAFE: &'static str = "local_safe";
pub(crate) const SUPERVISOR_RPC_METHOD_CROSS_SAFE: &'static str = "cross_safe";
pub(crate) const SUPERVISOR_RPC_METHOD_FINALIZED: &'static str = "finalized";
pub(crate) const SUPERVISOR_RPC_METHOD_FINALIZED_L1: &'static str = "finalized_l1";
Expand Down Expand Up @@ -83,6 +84,7 @@ impl Metrics {
fn zero() {
Self::zero_rpc_method(Self::SUPERVISOR_RPC_METHOD_CROSS_DERIVED_TO_SOURCE);
Self::zero_rpc_method(Self::SUPERVISOR_RPC_METHOD_LOCAL_UNSAFE);
Self::zero_rpc_method(Self::SUPERVISOR_RPC_METHOD_LOCAL_SAFE);
Self::zero_rpc_method(Self::SUPERVISOR_RPC_METHOD_CROSS_SAFE);
Self::zero_rpc_method(Self::SUPERVISOR_RPC_METHOD_FINALIZED);
Self::zero_rpc_method(Self::SUPERVISOR_RPC_METHOD_FINALIZED_L1);
Expand Down
20 changes: 20 additions & 0 deletions crates/supervisor/core/src/rpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ where
)
}

async fn local_safe(&self, chain_id_hex: HexStringU64) -> RpcResult<DerivedIdPair> {
let chain_id = ChainId::from(chain_id_hex);
crate::observe_rpc_call!(
Metrics::SUPERVISOR_RPC_METHOD_LOCAL_SAFE,
async {
trace!(target: "supervisor::rpc",
%chain_id,
"Received local_safe request"
);

let derived = self.supervisor.local_safe(chain_id)?.id();
let source = self.supervisor.derived_to_source_block(chain_id, derived)?.id();

Ok(DerivedIdPair { source, derived })
}
.await
)
}

async fn dependency_set_v1(&self) -> RpcResult<DependencySet> {
crate::observe_rpc_call!(
Metrics::SUPERVISOR_RPC_METHOD_DEPENDENCY_SET,
Expand Down Expand Up @@ -333,6 +352,7 @@ mod tests {
fn latest_block_from(&self, l1_block: BlockNumHash, chain: ChainId) -> Result<BlockInfo, SupervisorError>;
fn derived_to_source_block(&self, chain: ChainId, derived: BlockNumHash) -> Result<BlockInfo, SupervisorError>;
fn local_unsafe(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError>;
fn local_safe(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError>;
fn cross_safe(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError>;
fn finalized(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError>;
fn finalized_l1(&self) -> Result<BlockInfo, SupervisorError>;
Expand Down
12 changes: 12 additions & 0 deletions crates/supervisor/core/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ pub trait SupervisorService: Debug + Send + Sync {
/// [`LocalUnsafe`]: SafetyLevel::LocalUnsafe
fn local_unsafe(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError>;

/// Returns [`LocalSafe`] block for the given chain.
///
/// [`LocalSafe`]: SafetyLevel::LocalSafe
fn local_safe(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError>;

/// Returns [`CrossSafe`] block for the given chain.
///
/// [`CrossSafe`]: SafetyLevel::CrossSafe
Expand Down Expand Up @@ -190,6 +195,13 @@ where
})?)
}

fn local_safe(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError> {
Ok(self.get_db(chain)?.get_safety_head_ref(SafetyLevel::LocalSafe).map_err(|err| {
error!(target: "supervisor::service", %chain, %err, "Failed to get local safe head ref for chain");
SpecError::from(err)
})?)
}

fn cross_safe(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError> {
Ok(self.get_db(chain)?.get_safety_head_ref(SafetyLevel::CrossSafe).map_err(|err| {
error!(target: "supervisor::service", %chain, %err, "Failed to get cross safe head ref for chain");
Expand Down
7 changes: 7 additions & 0 deletions crates/supervisor/rpc/src/jsonrpsee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ pub trait SupervisorApi {
#[method(name = "localUnsafe")]
async fn local_unsafe(&self, chain_id: HexStringU64) -> RpcResult<BlockNumHash>;

/// Returns the [`LocalSafe`] block for given chain.
///
/// [`LocalSafe`]: SafetyLevel::LocalSafe
// todo: link to spec after PR(https://github.com/ethereum-optimism/specs/pull/753) is merged
#[method(name = "localSafe")]
async fn local_safe(&self, chain_id: HexStringU64) -> RpcResult<DerivedIdPair>;

/// Returns the [`CrossSafe`] block for given chain.
///
/// Spec: <https://github.com/ethereum-optimism/specs/blob/main/specs/interop/supervisor.md#supervisor_crosssafe>
Expand Down
1 change: 1 addition & 0 deletions crates/supervisor/service/src/actors/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ mod tests {
fn latest_block_from(&self, l1_block: BlockNumHash, chain: ChainId) -> Result<BlockInfo, SupervisorError>;
fn derived_to_source_block(&self, chain: ChainId, derived: BlockNumHash) -> Result<BlockInfo, SupervisorError>;
fn local_unsafe(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError>;
fn local_safe(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError>;
fn cross_safe(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError>;
fn finalized(&self, chain: ChainId) -> Result<BlockInfo, SupervisorError>;
fn finalized_l1(&self) -> Result<BlockInfo, SupervisorError>;
Expand Down
Loading