v0.2.4-pre.005

This commit is contained in:
2026-08-18 21:03:00 +02:00
parent 561b6678ed
commit d3cc7c93f0
8 changed files with 544 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/src/rpc_blocks.rs
// version: 4
// version: 5
/// Transaction detail level accepted by modern `getBlock` requests.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
@@ -143,7 +143,6 @@ impl SolanaBlockProductionRange {
/// Serializes this range to the exact Solana JSON-RPC object.
#[must_use]
#[cfg(test)]
pub(crate) fn to_json_value(self) -> serde_json::Value {
let mut object = serde_json::Map::new();
object.insert("firstSlot".to_owned(), serde_json::Value::Number(self.first_slot.into()));
@@ -192,14 +191,12 @@ impl SolanaBlockProductionConfig {
}
/// Returns whether this config would serialize to an empty object.
#[cfg(test)]
pub(crate) const fn is_empty(&self) -> bool {
return self.commitment.is_none() && self.identity.is_none() && self.range.is_none();
}
/// Serializes this config to the exact Solana JSON-RPC object.
#[must_use]
#[cfg(test)]
pub(crate) fn to_json_value(&self) -> serde_json::Value {
let mut object = serde_json::Map::new();
if let std::option::Option::Some(commitment) = self.commitment {
@@ -287,7 +284,6 @@ impl SolanaBlockProduction {
}
/// Decodes a block-production result from its Solana JSON wire shape.
#[cfg(test)]
pub(crate) fn decode_wire(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<Self> {
let decoded = crate::decode_wire_json::<WireBlockProduction>(method, value);
let wire = match decoded {
@@ -672,6 +668,38 @@ impl crate::HttpTransportPool {
return self.get_blocks_u64_list("getBlocksWithLimit", role, params).await;
}
/// Executes typed `getBlockProduction` with optional identity, range, and commitment filters.
pub async fn get_block_production(
&self,
role: &crate::HttpRoleName,
config: std::option::Option<&crate::SolanaBlockProductionConfig>,
) -> ksp_core_lib::Result<crate::SolanaRpcResponse<crate::SolanaBlockProduction>> {
if let std::option::Option::Some(config) = config
&& let std::option::Option::Some(range) = config.range()
&& let std::option::Option::Some(last_slot) = range.last_slot()
&& last_slot < range.first_slot()
{
return std::result::Result::Err(
ksp_core_lib::Error::new(crate::ERROR_CODE_INVALID_RPC_PARAMETERS, "getBlockProduction lastSlot must not be less than firstSlot")
.with_context("rpc_method", "getBlockProduction")
.with_context("first_slot", range.first_slot().to_string())
.with_context("last_slot", last_slot.to_string()),
);
}
let mut params = std::vec::Vec::new();
if let std::option::Option::Some(config) = config
&& !config.is_empty()
{
params.push(config.to_json_value());
}
let value = self.execute_blocks_rpc("getBlockProduction", role, params).await;
let value = match value {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
return decode_block_production_response("getBlockProduction", value);
}
/// Executes typed `getRecentPerformanceSamples`, preserving runtime order and older sample shapes.
pub async fn get_recent_performance_samples(
&self,
@@ -770,6 +798,24 @@ fn invalid_blocks_limit<T>(method: &'static str, message: &'static str, limit: u
);
}
fn decode_block_production_response(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<crate::SolanaRpcResponse<crate::SolanaBlockProduction>> {
let decoded = crate::decode_wire_json::<WireBlockProductionRpcResponse>(method, value);
let wire = match decoded {
std::result::Result::Ok(wire) => wire,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
let context = crate::SolanaRpcContext::decode_wire(method, wire.context);
let context = match context {
std::result::Result::Ok(context) => context,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
let value = crate::SolanaBlockProduction::decode_wire(method, wire.value);
return match value {
std::result::Result::Ok(value) => std::result::Result::Ok(crate::SolanaRpcResponse::new(context, value)),
std::result::Result::Err(error) => std::result::Result::Err(error),
};
}
fn decode_performance_samples(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<std::vec::Vec<crate::SolanaPerformanceSample>> {
let values = crate::decode_wire_json::<std::vec::Vec<serde_json::Value>>(method, value);
let values = match values {
@@ -878,7 +924,6 @@ struct WireBlockCommitment {
total_stake: u64,
}
#[cfg(test)]
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct WireBlockProductionRange {
@@ -886,7 +931,6 @@ struct WireBlockProductionRange {
last_slot: u64,
}
#[cfg(test)]
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct WireBlockProduction {
@@ -894,6 +938,12 @@ struct WireBlockProduction {
range: WireBlockProductionRange,
}
#[derive(serde::Deserialize)]
struct WireBlockProductionRpcResponse {
context: serde_json::Value,
value: serde_json::Value,
}
#[cfg(test)]
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]