v0.3.13-pre.009

This commit is contained in:
2026-09-10 19:56:16 +02:00
parent 1746d47412
commit 665d7d2bb6
15 changed files with 1051 additions and 45 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-worker-raw-transaction-ingest-lib/unit_tests/runtime_resources.rs
// version: 20
// version: 21
fn grpc_endpoint(cluster: &str) -> std::option::Option<ksp_onchain_transport_lib::YellowstoneGrpcEndpointSettings> {
return grpc_endpoint_with_identity(cluster, "yellowstone-fixture", "fixture-provider");
@@ -3008,7 +3008,7 @@ fn v0_3_13_pre_008_global_hydration_registry_coalesces_cross_source_key_to_one_l
network,
signature: ksp_store_lib::RawTransactionSignature::new([61_u8; 64]),
};
let registry = super::RawTransactionIngestGlobalHydrationRegistry::new(&settings);
let registry = super::RawTransactionIngestGlobalHydrationRegistry::new(settings.admission_queue_capacity(), settings.persistence_concurrency());
let (first_leader, _first_receiver) = match registry.subscribe_or_lead(&key) {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return,
@@ -3034,3 +3034,107 @@ fn v0_3_13_pre_008_global_hydration_registry_coalesces_cross_source_key_to_one_l
assert!(third_leader);
return;
}
#[test]
fn v0_3_13_pre_009_hydration_quotas_partition_exact_bounds_and_reject_underprovision() {
assert!(super::validate_hydration_fairness_capacity(8, 5, 3).is_ok());
let pending_error = match super::validate_hydration_fairness_capacity(2, 5, 3) {
std::result::Result::Ok(()) => return,
std::result::Result::Err(value) => value,
};
assert_eq!(pending_error.context()[0].value(), "runtime_resources.hydration_pending_capacity_insufficient");
let concurrency_error = match super::validate_hydration_fairness_capacity(8, 2, 3) {
std::result::Result::Ok(()) => return,
std::result::Result::Err(value) => value,
};
assert_eq!(concurrency_error.context()[0].value(), "runtime_resources.hydration_concurrency_insufficient");
let pending_limits = [super::hydration_pending_limit(8, 3, 0), super::hydration_pending_limit(8, 3, 1), super::hydration_pending_limit(8, 3, 2)];
assert_eq!(pending_limits, [3, 3, 2]);
assert_eq!(pending_limits.iter().copied().sum::<usize>(), 8);
assert!(pending_limits.iter().copied().all(|limit| return limit >= 1));
let in_flight_limits = [super::hydration_in_flight_limit(5, 3, 0), super::hydration_in_flight_limit(5, 3, 1), super::hydration_in_flight_limit(5, 3, 2)];
assert_eq!(in_flight_limits, [2, 2, 1]);
assert_eq!(in_flight_limits.iter().copied().sum::<usize>(), 5);
assert!(in_flight_limits.iter().copied().all(|limit| return limit >= 1));
assert!(super::validate_hydration_fairness_capacity(1, 1, 0).is_ok());
assert_eq!(super::hydration_pending_limit(1, 0, 0), 0);
assert_eq!(super::hydration_in_flight_limit(1, 0, 0), 0);
return;
}
#[test]
fn v0_3_13_pre_009_duplicate_hydration_storm_keeps_one_global_key_and_distinct_keys_bounded() {
let network = match ksp_store_lib::RawNetworkId::new("devnet") {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return,
};
let registry = super::RawTransactionIngestGlobalHydrationRegistry::new(2, 1);
let first_key = super::RawTransactionIngestHydrationKey {
commitment: ksp_onchain_transport_lib::SolanaCommitment::Confirmed.as_str(),
network: network.clone(),
signature: ksp_store_lib::RawTransactionSignature::new([71_u8; 64]),
};
for index in 0..32 {
let subscribed = registry.subscribe_or_lead(&first_key);
let (leader, _receiver) = match subscribed {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return,
};
assert_eq!(leader, index == 0);
}
let second_key = super::RawTransactionIngestHydrationKey {
commitment: ksp_onchain_transport_lib::SolanaCommitment::Confirmed.as_str(),
network: network.clone(),
signature: ksp_store_lib::RawTransactionSignature::new([72_u8; 64]),
};
let third_key = super::RawTransactionIngestHydrationKey {
commitment: ksp_onchain_transport_lib::SolanaCommitment::Confirmed.as_str(),
network,
signature: ksp_store_lib::RawTransactionSignature::new([73_u8; 64]),
};
assert!(matches!(registry.subscribe_or_lead(&second_key), std::result::Result::Ok((true, _))));
let saturated = registry.subscribe_or_lead(&third_key);
let error = match saturated {
std::result::Result::Ok(_) => return,
std::result::Result::Err(value) => value,
};
assert_eq!(error.code(), crate::ERROR_CODE_RAW_TRANSACTION_INGEST_RUNTIME_INVALID);
assert_eq!(error.context()[0].value(), "source.global_hydration_pending_saturated");
return;
}
#[tokio::test(flavor = "current_thread")]
async fn v0_3_13_pre_009_global_hydration_permit_and_leader_cleanup_are_bounded_and_fail_closed() {
let network = match ksp_store_lib::RawNetworkId::new("devnet") {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return,
};
let registry = std::sync::Arc::new(super::RawTransactionIngestGlobalHydrationRegistry::new(4, 1));
let first_permit = std::sync::Arc::clone(&registry.hydration_permits).try_acquire_owned();
let first_permit = match first_permit {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return,
};
assert!(std::sync::Arc::clone(&registry.hydration_permits).try_acquire_owned().is_err());
std::mem::drop(first_permit);
assert!(std::sync::Arc::clone(&registry.hydration_permits).try_acquire_owned().is_ok());
let key = super::RawTransactionIngestHydrationKey {
commitment: ksp_onchain_transport_lib::SolanaCommitment::Confirmed.as_str(),
network,
signature: ksp_store_lib::RawTransactionSignature::new([74_u8; 64]),
};
let subscribed = registry.subscribe_or_lead(&key);
let (leader, receiver) = match subscribed {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => return,
};
assert!(leader);
{
let _guard = super::RawTransactionIngestHydrationLeaderGuard::new(std::sync::Arc::clone(&registry), key.clone());
}
let published = receiver.borrow().clone();
assert!(matches!(published, std::option::Option::Some(super::RawTransactionIngestSharedHydrationResult::Failed(_))));
let resubscribed = registry.subscribe_or_lead(&key);
assert!(matches!(resubscribed, std::result::Result::Ok((true, _))));
return;
}