feat(api): add /mantle/sdp/snapshot (#3132)

This commit is contained in:
Youngjoon Lee
2026-07-16 07:57:43 +09:00
committed by GitHub
parent 1c871409b7
commit ac2a56545e
6 changed files with 78 additions and 2 deletions
+1
View File
@@ -1,6 +1,7 @@
pub const MANTLE_METRICS: &str = "/mantle/metrics";
pub const MANTLE_STATUS: &str = "/mantle/status";
pub const MANTLE_SDP_DECLARATIONS: &str = "/mantle/sdp/declarations";
pub const MANTLE_SDP_SNAPSHOT: &str = "/mantle/sdp/snapshot";
pub const MANTLE_GAS_PRICES: &str = "/mantle/gas-prices";
pub const CRYPTARCHIA_INFO: &str = "/cryptarchia/info";
pub const CRYPTARCHIA_HEADERS: &str = "/cryptarchia/headers";
+6 -2
View File
@@ -46,8 +46,8 @@ use utoipa_swagger_ui::SwaggerUi;
use super::handlers::{
add_tx, blend_info, block, block_events, blocks_range_stream, blocks_stream,
cryptarchia_headers, cryptarchia_info, cryptarchia_lib_stream, dial_peer, get_gas_prices,
get_sdp_declarations, immutable_blocks, libp2p_info, mantle_metrics, mantle_status,
mempool_view, time_info, transaction, wallet,
get_sdp_declarations, get_sdp_snapshot, immutable_blocks, libp2p_info, mantle_metrics,
mantle_status, mempool_view, time_info, transaction, wallet,
};
use crate::{
BlendBroadcastSettings, BlendService, TracingService, WalletService,
@@ -311,6 +311,10 @@ where
paths::MANTLE_SDP_DECLARATIONS,
routing::get(get_sdp_declarations::<RuntimeServiceId>),
)
.route(
paths::MANTLE_SDP_SNAPSHOT,
routing::get(get_sdp_snapshot::<RuntimeServiceId>),
)
.route(
paths::LEADER_CLAIM,
routing::post(leader_claim::<ChainLeader, RuntimeServiceId>),
+18
View File
@@ -1233,6 +1233,24 @@ where
make_request_and_return_response!(mantle::get_sdp_declarations::<RuntimeServiceId>(&handle))
}
#[utoipa::path(
get,
path = paths::MANTLE_SDP_SNAPSHOT,
responses(
(status = 200, description = "Get the SDP snapshot for the current epoch keyed by declaration id", body = std::collections::HashMap<lb_core::sdp::DeclarationId, lb_core::sdp::Declaration>),
(status = 500, description = "Internal server error", body = String),
)
)]
pub async fn get_sdp_snapshot<RuntimeServiceId>(
State(handle): State<OverwatchHandle<RuntimeServiceId>>,
) -> Response
where
RuntimeServiceId:
Debug + Send + Sync + Display + 'static + AsServiceId<Cryptarchia<RuntimeServiceId>>,
{
make_request_and_return_response!(mantle::get_sdp_snapshot::<RuntimeServiceId>(&handle))
}
#[utoipa::path(
post,
path = paths::LEADER_CLAIM,
+1
View File
@@ -21,6 +21,7 @@ use utoipa::OpenApi;
crate::api::handlers::post_activity,
crate::api::handlers::post_withdrawal,
crate::api::handlers::get_sdp_declarations,
crate::api::handlers::get_sdp_snapshot,
crate::api::handlers::leader_claim,
crate::api::handlers::immutable_blocks,
crate::api::handlers::block,
+25
View File
@@ -923,3 +923,28 @@ where
Ok(receiver.await?)
}
pub async fn get_sdp_snapshot<RuntimeServiceId>(
handle: &overwatch::overwatch::handle::OverwatchHandle<RuntimeServiceId>,
) -> Result<HashMap<DeclarationId, Declaration>, super::DynError>
where
RuntimeServiceId: Debug
+ Send
+ Sync
+ Display
+ 'static
+ AsServiceId<Cryptarchia<RuntimeServiceId>>
+ 'static,
{
let relay = handle.relay::<Cryptarchia<RuntimeServiceId>>().await?;
let (sender, receiver) = oneshot::channel();
relay
.send(ConsensusMsg::GetSdpSnapshot {
reply_channel: sender,
})
.await
.map_err(|(e, _)| e)?;
Ok(receiver.await?)
}
+27
View File
@@ -143,9 +143,14 @@ pub enum ConsensusMsg<Tx> {
block_id: HeaderId,
reply_channel: oneshot::Sender<Option<LedgerState>>,
},
/// Returns all declarations in the current SDP registry, not snapshot
GetSdpDeclarations {
reply_channel: oneshot::Sender<HashMap<DeclarationId, Declaration>>,
},
/// Returns the frozen SDP snapshot for the current epoch
GetSdpSnapshot {
reply_channel: oneshot::Sender<HashMap<DeclarationId, Declaration>>,
},
GetEpochState {
slot: Slot,
reply_channel: oneshot::Sender<Result<EpochState, Error>>,
@@ -939,6 +944,28 @@ where
error!("Could not send SDP declarations through channel");
});
}
ConsensusMsg::GetSdpSnapshot { reply_channel } => {
let tip = cryptarchia.tip();
let declarations = cryptarchia
.ledger
.state(&tip)
.map(|ledger_state| {
ledger_state
.epoch_state()
.active_declarations
.iter()
.flat_map(|(_, declarations)| {
declarations
.iter()
.map(|(id, declaration)| (*id, declaration.clone()))
})
.collect()
})
.unwrap_or_default();
reply_channel.send(declarations).unwrap_or_else(|_| {
error!("Could not send SDP snapshot through channel");
});
}
ConsensusMsg::GetEpochState {
slot,
reply_channel,