170 lines
7.8 KiB
Rust
170 lines
7.8 KiB
Rust
// file: crates/ksp-onchain-transport-lib/tests/yellowstone_publicnode_smoke.rs
|
|
// version: 5
|
|
|
|
//! Opt-in live PublicNode Mainnet/Testnet smokes for authenticated provider-neutral Yellowstone gRPC Subscribe.
|
|
|
|
use std::io::IsTerminal; // rust-rules: trait-import
|
|
|
|
struct PublicNodeTokens {
|
|
mainnet: std::string::String,
|
|
testnet: std::string::String,
|
|
}
|
|
|
|
static PUBLICNODE_X_TOKENS: std::sync::OnceLock<PublicNodeTokens> = std::sync::OnceLock::new();
|
|
|
|
fn read_token_line(label: &str) -> std::string::String {
|
|
let mut token = std::string::String::new();
|
|
match std::io::stdin().read_line(&mut token) {
|
|
std::result::Result::Ok(_) => {},
|
|
std::result::Result::Err(error) => panic!("PublicNode {label} x-token must be readable from smoke stdin: {error}"),
|
|
}
|
|
let token = token.trim().to_owned();
|
|
assert!(!token.is_empty(), "PublicNode {label} x-token provided on smoke stdin must not be empty");
|
|
return token;
|
|
}
|
|
|
|
fn publicnode_x_tokens() -> &'static PublicNodeTokens {
|
|
return PUBLICNODE_X_TOKENS.get_or_init(|| {
|
|
assert!(
|
|
!std::io::stdin().is_terminal(),
|
|
"pipe two PublicNode personal x-tokens to this ignored smoke on stdin: Mainnet first, Testnet second; never pass them as command-line arguments"
|
|
);
|
|
return PublicNodeTokens { mainnet: read_token_line("Mainnet"), testnet: read_token_line("Testnet") };
|
|
});
|
|
}
|
|
|
|
fn publicnode_endpoint(
|
|
name: &str,
|
|
cluster: &str,
|
|
url: &str,
|
|
x_token: &str,
|
|
) -> ksp_core_lib::Result<ksp_onchain_transport_lib::YellowstoneGrpcEndpointSettings> {
|
|
let url = match ksp_onchain_transport_lib::YellowstoneGrpcEndpointUrl::parse(url) {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
let session = ksp_onchain_transport_lib::YellowstoneGrpcSessionSettings::new(
|
|
std::time::Duration::from_secs(10),
|
|
std::time::Duration::from_secs(10),
|
|
std::time::Duration::from_secs(5),
|
|
ksp_onchain_transport_lib::YellowstoneGrpcReconnectSettings::new(0, std::time::Duration::from_millis(250), std::time::Duration::from_secs(2)),
|
|
8,
|
|
8,
|
|
16 * 1024 * 1024,
|
|
4 * 1024 * 1024,
|
|
);
|
|
let endpoint = ksp_onchain_transport_lib::YellowstoneGrpcEndpointSettings::new(
|
|
name,
|
|
true,
|
|
ksp_onchain_transport_lib::YellowstoneGrpcProviderName::new("publicnode"),
|
|
ksp_onchain_transport_lib::YellowstoneGrpcClusterName::new(cluster),
|
|
url,
|
|
session,
|
|
);
|
|
let metadata = match ksp_onchain_transport_lib::YellowstoneGrpcMetadataEntry::secret("x-token", x_token) {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
return endpoint.with_metadata(vec![metadata]);
|
|
}
|
|
|
|
fn slot_request() -> ksp_core_lib::Result<ksp_onchain_transport_lib::YellowstoneSubscribeRequest> {
|
|
let mut request = ksp_onchain_transport_lib::YellowstoneSubscribeRequest::new();
|
|
let name = match ksp_onchain_transport_lib::YellowstoneSubscribeFilterName::new("slots") {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
match request.insert_slot_filter(name, ksp_onchain_transport_lib::YellowstoneSubscribeSlotFilter::new()) {
|
|
std::result::Result::Ok(()) => {},
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
}
|
|
return std::result::Result::Ok(request);
|
|
}
|
|
|
|
async fn assert_publicnode_slot_stream(name: &str, cluster: &str, url: &str, x_token: &str) {
|
|
let endpoint = match publicnode_endpoint(name, cluster, url, x_token) {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => panic!("programmatic PublicNode Yellowstone settings must accept secret x-token metadata: {error:?}"),
|
|
};
|
|
let endpoint_debug = format!("{endpoint:?}");
|
|
assert!(!endpoint_debug.contains(x_token), "PublicNode x-token must not appear in endpoint Debug");
|
|
let channel = match ksp_onchain_transport_lib::YellowstoneGrpcChannel::connect(&endpoint).await {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => panic!("PublicNode Yellowstone TLS connection must succeed: {error:?}"),
|
|
};
|
|
assert_eq!(channel.endpoint_name(), name);
|
|
assert_eq!(channel.provider().as_str(), "publicnode");
|
|
assert_eq!(channel.cluster().as_str(), cluster);
|
|
let request = match slot_request() {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => panic!("PublicNode Yellowstone slot request must be valid: {error:?}"),
|
|
};
|
|
let mut session = match channel.open_standard_subscribe(request).await {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => panic!("PublicNode Yellowstone authenticated Subscribe must open: {error:?}"),
|
|
};
|
|
let slot_result = tokio::time::timeout(std::time::Duration::from_secs(20), async {
|
|
loop {
|
|
let next_update = match session.next_update().await {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => panic!("PublicNode Yellowstone Subscribe update must decode: {error:?}"),
|
|
};
|
|
match next_update {
|
|
std::option::Option::Some(ksp_onchain_transport_lib::YellowstoneSubscribeUpdate::Slot(update)) => return update.slot(),
|
|
std::option::Option::Some(_) => {},
|
|
std::option::Option::None => panic!("PublicNode Yellowstone Subscribe ended before a slot update"),
|
|
}
|
|
}
|
|
})
|
|
.await;
|
|
let slot = match slot_result {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => panic!("PublicNode Yellowstone Subscribe must publish a slot update before the smoke deadline: {error}"),
|
|
};
|
|
assert!(slot > 0);
|
|
let close_timeout_result = tokio::time::timeout(std::time::Duration::from_secs(7), session.close()).await;
|
|
let close_result = match close_timeout_result {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => {
|
|
panic!("KSP Yellowstone Subscribe close must remain bounded beyond the configured five-second provider half-close deadline: {error}")
|
|
},
|
|
};
|
|
match close_result {
|
|
std::result::Result::Ok(()) => {},
|
|
std::result::Result::Err(error) => {
|
|
assert_eq!(
|
|
error.code(),
|
|
ksp_onchain_transport_lib::ERROR_CODE_TIMEOUT,
|
|
"after a live slot was observed, PublicNode close may time out waiting for provider half-close but must not fail for another reason: {error:?}"
|
|
);
|
|
},
|
|
}
|
|
return;
|
|
}
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
#[ignore = "opt-in live PublicNode Mainnet Yellowstone gRPC smoke; reads the first personal x-token line from stdin and performs an external TLS/Subscribe request"]
|
|
async fn publicnode_mainnet_yellowstone_streams_slots_with_network_scoped_secret_x_token() {
|
|
let tokens = publicnode_x_tokens();
|
|
assert_publicnode_slot_stream(
|
|
"publicnode_mainnet_yellowstone",
|
|
"mainnet-beta",
|
|
"https://solana-yellowstone-grpc.publicnode.com:443",
|
|
tokens.mainnet.as_str(),
|
|
)
|
|
.await;
|
|
}
|
|
|
|
#[tokio::test(flavor = "current_thread")]
|
|
#[ignore = "opt-in live PublicNode Testnet Yellowstone gRPC smoke; reads the second personal x-token line from stdin and performs an external TLS/Subscribe request"]
|
|
async fn publicnode_testnet_yellowstone_streams_slots_with_network_scoped_secret_x_token() {
|
|
let tokens = publicnode_x_tokens();
|
|
assert_publicnode_slot_stream(
|
|
"publicnode_testnet_yellowstone",
|
|
"testnet",
|
|
"https://solana-testnet-yellowstone-grpc.publicnode.com:443",
|
|
tokens.testnet.as_str(),
|
|
)
|
|
.await;
|
|
}
|