v0.2.9-pre.002-fix.001

This commit is contained in:
2026-08-24 10:05:05 +02:00
parent 835de48cb7
commit 61fba107ef
7 changed files with 203 additions and 50 deletions

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/src/grpc_channel.rs
// version: 1
// version: 2
/// Prepared Yellowstone gRPC channel owned by KSP Transport.
///
@@ -9,7 +9,7 @@ pub struct YellowstoneGrpcChannel {
endpoint_name: std::string::String,
provider: crate::YellowstoneGrpcProviderName,
cluster: crate::YellowstoneGrpcClusterName,
channel: tonic::transport::Channel,
_channel: tonic::transport::Channel,
}
impl YellowstoneGrpcChannel {
@@ -28,6 +28,19 @@ impl YellowstoneGrpcChannel {
.with_context("endpoint_name", endpoint.name()),
);
}
if tokio::runtime::Handle::try_current().is_err() {
ksp_logging_lib::warn!(
target: crate::TRACING_TARGET,
endpoint_name = endpoint.name(),
provider = endpoint.provider().as_str(),
cluster = endpoint.cluster().as_str(),
"Yellowstone gRPC channel preparation requires an active Tokio runtime"
);
return std::result::Result::Err(
ksp_core_lib::Error::new(crate::ERROR_CODE_GRPC_CHANNEL_FAILED, "Yellowstone gRPC channel requires an active Tokio runtime")
.with_context("endpoint_name", endpoint.name()),
);
}
let tonic_endpoint = match tonic::transport::Endpoint::from_shared(endpoint.url().as_str().to_owned()) {
std::result::Result::Ok(value) => value,
std::result::Result::Err(_) => {
@@ -60,7 +73,7 @@ impl YellowstoneGrpcChannel {
endpoint_name: endpoint.name().to_owned(),
provider: endpoint.provider().clone(),
cluster: endpoint.cluster().clone(),
channel,
_channel: channel,
});
}

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/unit_tests/grpc_channel.rs
// version: 1
// version: 2
fn endpoint(enabled: bool, value: &str) -> crate::YellowstoneGrpcEndpointSettings {
let parsed = crate::YellowstoneGrpcEndpointUrl::parse(value).expect("fixture Yellowstone gRPC URL must parse");
@@ -13,8 +13,8 @@ fn endpoint(enabled: bool, value: &str) -> crate::YellowstoneGrpcEndpointSetting
);
}
#[test]
fn grpc_channel_prepare_is_lazy_safe_and_keeps_tonic_private() {
#[tokio::test(flavor = "current_thread")]
async fn grpc_channel_prepare_is_lazy_safe_and_keeps_tonic_private() {
let endpoint = endpoint(true, "http://127.0.0.1:10000/GRPC-SECRET-CANARY");
let channel = crate::YellowstoneGrpcChannel::prepare(&endpoint);
assert!(channel.is_ok());
@@ -28,10 +28,20 @@ fn grpc_channel_prepare_is_lazy_safe_and_keeps_tonic_private() {
let rendered = format!("{channel:?}");
assert!(!rendered.contains("GRPC-SECRET-CANARY"));
assert!(!rendered.contains("127.0.0.1"));
let _channel_type = std::any::type_name_of_val(&channel.channel);
let _channel_type = std::any::type_name_of_val(&channel._channel);
let _wire_type = std::any::type_name::<yellowstone_grpc_proto::geyser::SubscribeRequest>();
}
#[test]
fn grpc_channel_prepare_requires_active_tokio_runtime_without_panicking() {
let endpoint = endpoint(true, "http://127.0.0.1:10000/GRPC-SECRET-CANARY");
let result = crate::YellowstoneGrpcChannel::prepare(&endpoint);
assert!(result.is_err());
let rendered = format!("{result:?}");
assert!(!rendered.contains("GRPC-SECRET-CANARY"));
assert!(!rendered.contains("127.0.0.1"));
}
#[test]
fn grpc_channel_prepare_rejects_disabled_endpoint_before_network_io() {
let endpoint = endpoint(false, "http://127.0.0.1:10000");

View File

@@ -1,5 +1,5 @@
// file: crates/ksp-onchain-transport-lib/unit_tests/grpc_settings.rs
// version: 1
// version: 2
fn endpoint(name: &str, enabled: bool, url: &str, session: crate::YellowstoneGrpcSessionSettings) -> crate::YellowstoneGrpcEndpointSettings {
let parsed = crate::YellowstoneGrpcEndpointUrl::parse(url).expect("fixture Yellowstone gRPC URL must parse");
@@ -130,14 +130,14 @@ fn grpc_transport_settings_reject_excessive_descriptor_and_endpoint_count() {
let parsed = crate::YellowstoneGrpcEndpointUrl::parse("http://127.0.0.1:10000").expect("fixture Yellowstone gRPC URL must parse");
let endpoints = (0..=super::MAX_GRPC_ENDPOINT_COUNT)
.map(|index| {
crate::YellowstoneGrpcEndpointSettings::new(
return crate::YellowstoneGrpcEndpointSettings::new(
format!("endpoint-{index}"),
true,
crate::YellowstoneGrpcProviderName::new("fixture"),
crate::YellowstoneGrpcClusterName::new("devnet"),
parsed.clone(),
crate::YellowstoneGrpcSessionSettings::default(),
)
);
})
.collect();
assert!(crate::YellowstoneGrpcTransportSettings::new(endpoints).validate().is_err());