v0.2.4-pre.008

This commit is contained in:
2026-08-18 21:52:00 +02:00
parent 4252a21140
commit 37461ec248
14 changed files with 775 additions and 14 deletions

View File

@@ -0,0 +1 @@
{"jsonrpc":"2.0","result":[{"epoch":912,"effectiveSlot":431500010,"amount":777,"postBalance":1000777,"commission":5,"commissionBps":500},null,{"epoch":912,"effectiveSlot":431500010,"amount":777,"postBalance":1000777,"commission":5,"commissionBps":500}],"id":1}

View File

@@ -0,0 +1 @@
{"jsonrpc":"2.0","result":[],"id":1}

View File

@@ -0,0 +1 @@
{"jsonrpc":"2.0","error":{"code":-32017,"message":"Epoch rewards period still active at slot 431500000","data":{"slot":431500000,"currentBlockHeight":400000000,"rewardsCompleteBlockHeight":400000100}},"id":1}

View File

@@ -0,0 +1 @@
{"jsonrpc":"2.0","error":{"code":-32016,"message":"Minimum context slot has not been reached","data":{"contextSlot":431000000}},"id":1}

View File

@@ -0,0 +1 @@
{"jsonrpc":"2.0","result":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"id":1}

View File

@@ -0,0 +1 @@
{"jsonrpc":"2.0","result":[null],"id":1}

View File

@@ -0,0 +1 @@
{"jsonrpc":"2.0","result":[{"epoch":912,"effectiveSlot":431500001,"amount":2500000,"postBalance":1002500000,"commission":7,"commissionBps":725},null,{"epoch":912,"effectiveSlot":431500003,"amount":1250000,"postBalance":501250000,"commission":null},{"epoch":912,"effectiveSlot":431500004,"amount":500000,"postBalance":200500000,"commission":3,"commissionBps":null}],"id":1}

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/src/rpc_economics.rs
// version: 3
// version: 4
/// Inflation-governor values returned by `getInflationGovernor`.
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -142,14 +142,12 @@ impl SolanaInflationRewardConfig {
}
/// Returns whether this config would serialize to an empty object.
#[cfg(test)]
pub(crate) const fn is_empty(&self) -> bool {
return self.epoch.is_none() && self.commitment.is_none() && self.min_context_slot.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(epoch) = self.epoch {
@@ -214,7 +212,6 @@ impl SolanaInflationReward {
}
/// Decodes one non-null inflation reward 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::<WireInflationReward>(method, value);
return match decoded {
@@ -359,6 +356,40 @@ impl crate::HttpTransportPool {
};
}
/// Executes typed `getInflationReward`, preserving input order, positional nulls and runtime commission extensions.
pub async fn get_inflation_reward(
&self,
role: &crate::HttpRoleName,
addresses: &[ksp_core_lib::Pubkey],
config: std::option::Option<&crate::SolanaInflationRewardConfig>,
) -> ksp_core_lib::Result<std::vec::Vec<std::option::Option<crate::SolanaInflationReward>>> {
if let std::option::Option::Some(config) = config
&& config.commitment() == std::option::Option::Some(crate::SolanaCommitment::Processed)
{
return std::result::Result::Err(
ksp_core_lib::Error::new(
crate::ERROR_CODE_INVALID_RPC_PARAMETERS,
"getInflationReward commitment must be confirmed or finalized when explicitly provided",
)
.with_context("rpc_method", "getInflationReward")
.with_context("commitment", "processed"),
);
}
let address_values = addresses.iter().map(|address| serde_json::Value::String(address.to_string())).collect::<std::vec::Vec<_>>();
let mut params = std::vec![serde_json::Value::Array(address_values)];
if let std::option::Option::Some(config) = config
&& !config.is_empty()
{
params.push((*config).to_json_value());
}
let value = self.execute_economics_rpc("getInflationReward", 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_inflation_rewards("getInflationReward", value, addresses.len());
}
/// Executes typed `getStakeMinimumDelegation` and preserves the contextual runtime value in lamports.
pub async fn get_stake_minimum_delegation(
&self,
@@ -428,6 +459,40 @@ fn push_economics_context_config(params: &mut std::vec::Vec<serde_json::Value>,
return;
}
fn decode_inflation_rewards(
method: &str,
value: serde_json::Value,
expected_count: usize,
) -> ksp_core_lib::Result<std::vec::Vec<std::option::Option<crate::SolanaInflationReward>>> {
let decoded = crate::decode_wire_json::<std::vec::Vec<std::option::Option<serde_json::Value>>>(method, value);
let values = match decoded {
std::result::Result::Ok(values) => values,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
if values.len() != expected_count {
return std::result::Result::Err(
ksp_core_lib::Error::new(crate::ERROR_CODE_INVALID_RESPONSE, "getInflationReward result count does not match the requested address count")
.with_context("rpc_method", method)
.with_context("expected_count", expected_count.to_string())
.with_context("actual_count", values.len().to_string()),
);
}
let mut rewards = std::vec::Vec::with_capacity(values.len());
for value in values {
match value {
std::option::Option::Some(value) => {
let reward = crate::SolanaInflationReward::decode_wire(method, value);
match reward {
std::result::Result::Ok(reward) => rewards.push(std::option::Option::Some(reward)),
std::result::Result::Err(error) => return std::result::Result::Err(error),
}
},
std::option::Option::None => rewards.push(std::option::Option::None),
}
}
return std::result::Result::Ok(rewards);
}
fn decode_economics_u64_response(method: &str, value: serde_json::Value) -> ksp_core_lib::Result<crate::SolanaRpcResponse<u64>> {
let decoded = crate::decode_wire_json::<WireEconomicsRpcResponse<u64>>(method, value);
let wire = match decoded {
@@ -499,7 +564,6 @@ struct WireInflationRate {
epoch: u64,
}
#[cfg(test)]
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct WireInflationReward {

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/tests/public_api.rs
// version: 21
// version: 22
//! Integration tests for the public `ksp-onchain-transport-lib` consumer contract.
@@ -450,3 +450,16 @@ fn public_v0_2_4_pre_007_simple_economics_wrappers_are_available_from_crate_root
assert_eq!(supply_config.commitment(), std::option::Option::Some(ksp_onchain_transport_lib::SolanaCommitment::Processed));
assert_eq!(supply_config.exclude_non_circulating_accounts_list(), std::option::Option::Some(false));
}
#[test]
fn public_v0_2_4_pre_008_inflation_reward_wrapper_is_available_from_crate_root() {
let _get_inflation_reward = ksp_onchain_transport_lib::HttpTransportPool::get_inflation_reward;
let config = ksp_onchain_transport_lib::SolanaInflationRewardConfig::new(
std::option::Option::Some(912),
std::option::Option::Some(ksp_onchain_transport_lib::SolanaCommitment::Confirmed),
std::option::Option::Some(431_000_000),
);
assert_eq!(config.epoch(), std::option::Option::Some(912));
assert_eq!(config.commitment(), std::option::Option::Some(ksp_onchain_transport_lib::SolanaCommitment::Confirmed));
assert_eq!(config.min_context_slot(), std::option::Option::Some(431_000_000));
}

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/tests/release_completeness.rs
// version: 19
// version: 20
//! Release-level completeness canaries for the staged HTTP wrapper sequence.
@@ -432,7 +432,7 @@ fn release_pre_008_ksp_transport_007_retro_audit_covers_all_typed_current_method
}
#[test]
fn release_v0_2_4_descriptor_set_is_exact_and_remains_read_retry_safe_during_staged_wrappers() {
fn release_v0_2_4_descriptor_set_is_exact_and_remains_read_retry_safe_through_wrapper_completion() {
let mut expected_blocks = std::vec![
"getBlock",
"getBlockCommitment",
@@ -589,3 +589,22 @@ fn release_v0_2_4_pre_007_simple_economics_subset_is_exact_and_retry_safe() {
assert_eq!(actual, expected);
assert_eq!(actual.len(), 4);
}
#[test]
fn release_v0_2_4_pre_008_completes_all_five_economics_wrappers_exactly_and_retry_safe() {
let mut expected = std::vec!["getInflationGovernor", "getInflationRate", "getInflationReward", "getStakeMinimumDelegation", "getSupply"];
let mut actual = std::vec::Vec::new();
for descriptor in ksp_onchain_transport_lib::current_http_rpc_methods() {
if descriptor.coverage_release() == ksp_onchain_transport_lib::HttpRpcCoverageRelease::V0_2_4
&& descriptor.category() == ksp_onchain_transport_lib::HttpRpcCategory::Economics
{
actual.push(descriptor.method());
assert_eq!(descriptor.operation_kind(), ksp_onchain_transport_lib::RpcOperationKind::Read);
assert_eq!(descriptor.transport_retry_class(), ksp_onchain_transport_lib::TransportRetryClass::RetrySafe);
}
}
actual.sort_unstable();
expected.sort_unstable();
assert_eq!(actual, expected);
assert_eq!(actual.len(), 5);
}

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/unit_tests/rpc_economics.rs
// version: 2
// version: 3
#[test]
fn inflation_reward_config_preserves_epoch_commitment_and_min_context_slot() {
@@ -307,3 +307,186 @@ async fn typed_get_supply_preserves_scan_rpc_error() {
assert_eq!(error.code(), crate::ERROR_CODE_RPC_APPLICATION_ERROR);
handle.join().expect("fixture server must join");
}
fn inflation_reward_fixture_pubkey(value: &str) -> ksp_core_lib::Pubkey {
return value.parse::<ksp_core_lib::Pubkey>().expect("fixture inflation-reward pubkey must parse");
}
#[tokio::test(flavor = "current_thread")]
async fn typed_get_inflation_reward_serializes_full_config_and_preserves_position_and_commission_states() {
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.success.json"));
let pool = pool_for_url(url.as_str());
let addresses = std::vec![
inflation_reward_fixture_pubkey("11111111111111111111111111111111"),
inflation_reward_fixture_pubkey("Vote111111111111111111111111111111111111111"),
inflation_reward_fixture_pubkey("SysvarRent111111111111111111111111111111111"),
inflation_reward_fixture_pubkey("Stake11111111111111111111111111111111111111"),
];
let config = crate::SolanaInflationRewardConfig::new(
std::option::Option::Some(912),
std::option::Option::Some(crate::SolanaCommitment::Finalized),
std::option::Option::Some(431_000_000),
);
let rewards = pool
.get_inflation_reward(&crate::HttpRoleName::new("default"), addresses.as_slice(), std::option::Option::Some(&config))
.await
.expect("inflation reward fixture must succeed");
assert_eq!(rewards.len(), addresses.len());
let first = rewards[0].as_ref().expect("first reward must be present");
assert_eq!(first.epoch(), 912);
assert_eq!(first.effective_slot(), 431_500_001);
assert_eq!(first.amount(), 2_500_000);
assert_eq!(first.post_balance(), 1_002_500_000);
assert_eq!(first.commission(), std::option::Option::Some(7));
assert_eq!(first.commission_bps().value(), std::option::Option::Some(&725));
assert!(rewards[1].is_none());
let third = rewards[2].as_ref().expect("third reward must be present");
assert_eq!(third.commission(), std::option::Option::None);
assert!(third.commission_bps().is_omitted());
let fourth = rewards[3].as_ref().expect("fourth reward must be present");
assert_eq!(fourth.commission(), std::option::Option::Some(3));
assert!(fourth.commission_bps().is_null());
let request = handle.join().expect("fixture server must join");
let body = request_body(request.as_str());
assert_eq!(body["method"], serde_json::json!("getInflationReward"));
assert_eq!(
body["params"],
serde_json::json!([
[
"11111111111111111111111111111111",
"Vote111111111111111111111111111111111111111",
"SysvarRent111111111111111111111111111111111",
"Stake11111111111111111111111111111111111111"
],
{"epoch":912,"commitment":"finalized","minContextSlot":431000000}
])
);
}
#[tokio::test(flavor = "current_thread")]
async fn typed_get_inflation_reward_preserves_duplicate_input_order_and_positional_nulls() {
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.duplicates.json"));
let pool = pool_for_url(url.as_str());
let first = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
let second = inflation_reward_fixture_pubkey("Vote111111111111111111111111111111111111111");
let addresses = std::vec![first, second, first];
let rewards = pool
.get_inflation_reward(&crate::HttpRoleName::new("default"), addresses.as_slice(), std::option::Option::None)
.await
.expect("duplicate inflation reward fixture must succeed");
assert_eq!(rewards.len(), 3);
assert_eq!(rewards[0], rewards[2]);
assert!(rewards[1].is_none());
let request = handle.join().expect("fixture server must join");
assert_eq!(
request_body(request.as_str())["params"],
serde_json::json!([["11111111111111111111111111111111", "Vote111111111111111111111111111111111111111", "11111111111111111111111111111111"]])
);
}
#[tokio::test(flavor = "current_thread")]
async fn typed_get_inflation_reward_omits_absent_and_empty_config_but_keeps_address_parameter() {
let role = crate::HttpRoleName::new("default");
let address = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
let addresses = std::vec![address];
let empty = crate::SolanaInflationRewardConfig::default();
for config in [std::option::Option::None, std::option::Option::Some(&empty)] {
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.single_null.json"));
let pool = pool_for_url(url.as_str());
let rewards = pool.get_inflation_reward(&role, addresses.as_slice(), config).await.expect("single null inflation reward fixture must succeed");
assert_eq!(rewards, std::vec![std::option::Option::None]);
let request = handle.join().expect("fixture server must join");
assert_eq!(request_body(request.as_str())["params"], serde_json::json!([["11111111111111111111111111111111"]]));
}
}
#[tokio::test(flavor = "current_thread")]
async fn typed_get_inflation_reward_accepts_empty_address_list_without_inventing_a_minimum() {
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.empty.json"));
let pool = pool_for_url(url.as_str());
let rewards = pool
.get_inflation_reward(&crate::HttpRoleName::new("default"), &[], std::option::Option::None)
.await
.expect("empty inflation reward fixture must succeed");
assert!(rewards.is_empty());
let request = handle.join().expect("fixture server must join");
assert_eq!(request_body(request.as_str())["params"], serde_json::json!([[]]));
}
#[tokio::test(flavor = "current_thread")]
async fn typed_get_inflation_reward_does_not_invent_a_256_address_limit() {
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.many_nulls.json"));
let pool = pool_for_url(url.as_str());
let address = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
let addresses = std::vec![address; 300];
let rewards = pool
.get_inflation_reward(&crate::HttpRoleName::new("default"), addresses.as_slice(), std::option::Option::None)
.await
.expect("300-address inflation reward fixture must succeed without local cardinality cap");
assert_eq!(rewards.len(), 300);
assert!(rewards.iter().all(std::option::Option::is_none));
let request = handle.join().expect("fixture server must join");
let body = request_body(request.as_str());
assert_eq!(body["params"][0].as_array().expect("address parameter must be an array").len(), 300);
}
#[tokio::test(flavor = "current_thread")]
async fn typed_get_inflation_reward_rejects_processed_commitment_before_io() {
let role = crate::HttpRoleName::new("default");
let pool = pool_for_url("http://127.0.0.1:1");
let address = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
let config = crate::SolanaInflationRewardConfig::new(
std::option::Option::Some(912),
std::option::Option::Some(crate::SolanaCommitment::Processed),
std::option::Option::None,
);
let result = pool.get_inflation_reward(&role, &[address], std::option::Option::Some(&config)).await;
let error = result.expect_err("processed inflation-reward commitment must fail before I/O");
assert_eq!(error.code(), crate::ERROR_CODE_INVALID_RPC_PARAMETERS);
assert_eq!(error.context()[1].key(), "commitment");
assert_eq!(error.context()[1].value(), "processed");
}
#[tokio::test(flavor = "current_thread")]
async fn typed_get_inflation_reward_rejects_response_cardinality_mismatch() {
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.single_null.json"));
let pool = pool_for_url(url.as_str());
let first = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
let second = inflation_reward_fixture_pubkey("Vote111111111111111111111111111111111111111");
let result = pool.get_inflation_reward(&crate::HttpRoleName::new("default"), &[first, second], std::option::Option::None).await;
let error = result.expect_err("inflation reward response count mismatch must fail typed decoding");
assert_eq!(error.code(), crate::ERROR_CODE_INVALID_RESPONSE);
assert_eq!(error.context()[1].key(), "expected_count");
assert_eq!(error.context()[1].value(), "2");
assert_eq!(error.context()[2].key(), "actual_count");
assert_eq!(error.context()[2].value(), "1");
handle.join().expect("fixture server must join");
}
#[tokio::test(flavor = "current_thread")]
async fn typed_get_inflation_reward_preserves_min_context_slot_rpc_error() {
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.error_min_context.json"));
let pool = pool_for_url(url.as_str());
let address = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
let config = crate::SolanaInflationRewardConfig::new(
std::option::Option::Some(912),
std::option::Option::Some(crate::SolanaCommitment::Confirmed),
std::option::Option::Some(431_500_000),
);
let result = pool.get_inflation_reward(&crate::HttpRoleName::new("default"), &[address], std::option::Option::Some(&config)).await;
let error = result.expect_err("inflation reward min-context RPC error must propagate");
assert_eq!(error.code(), crate::ERROR_CODE_RPC_APPLICATION_ERROR);
handle.join().expect("fixture server must join");
}
#[tokio::test(flavor = "current_thread")]
async fn typed_get_inflation_reward_preserves_epoch_rewards_period_active_rpc_error() {
let (url, handle) = serve_once(include_str!("../fixtures/http/get_inflation_reward.error_epoch_rewards_active.json"));
let pool = pool_for_url(url.as_str());
let address = inflation_reward_fixture_pubkey("11111111111111111111111111111111");
let result = pool.get_inflation_reward(&crate::HttpRoleName::new("default"), &[address], std::option::Option::None).await;
let error = result.expect_err("active epoch-rewards RPC error must propagate");
assert_eq!(error.code(), crate::ERROR_CODE_RPC_APPLICATION_ERROR);
handle.join().expect("fixture server must join");
}