Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = [
"crates/foreign-chain-config-tester",
"crates/foreign-chain-health-check",
"crates/foreign-chain-inspector",
"crates/foreign-chain-rpc-auth",
"crates/foreign-chain-rpc-factory",
"crates/foreign-chain-rpc-interfaces",
"crates/include-measurements",
"crates/launcher-interface",
Expand Down Expand Up @@ -57,7 +57,7 @@ chain-gateway-test-contract = { path = "crates/chain-gateway-test-contract" }
contract-history = { path = "crates/contract-history" }
foreign-chain-health-check = { path = "crates/foreign-chain-health-check" }
foreign-chain-inspector = { path = "crates/foreign-chain-inspector" }
foreign-chain-rpc-auth = { path = "crates/foreign-chain-rpc-auth" }
foreign-chain-rpc-factory = { path = "crates/foreign-chain-rpc-factory" }
foreign-chain-rpc-interfaces = { path = "crates/foreign-chain-rpc-interfaces" }
include-measurements = { path = "crates/include-measurements" }
launcher-interface = { path = "crates/launcher-interface" }
Expand Down
3 changes: 2 additions & 1 deletion crates/foreign-chain-health-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ anyhow = { workspace = true }
bs58 = { workspace = true }
clap = { workspace = true, optional = true }
foreign-chain-inspector = { workspace = true }
foreign-chain-rpc-auth = { workspace = true }
foreign-chain-rpc-factory = { workspace = true }
foreign-chain-rpc-interfaces = { workspace = true }
futures = { workspace = true }
hex = { workspace = true }
Expand All @@ -24,6 +24,7 @@ tokio = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
foreign-chain-inspector = { workspace = true, features = ["test-utils"] }
httpmock = { workspace = true }
rstest = { workspace = true }
serde_json = { workspace = true }
Expand Down
58 changes: 11 additions & 47 deletions crates/foreign-chain-health-check/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ use foreign_chain_inspector::base::inspector::Base;
use foreign_chain_inspector::bnb::inspector::Bnb;
use foreign_chain_inspector::ethereum::inspector::Ethereum;
use foreign_chain_inspector::evm::inspector::EvmChain;
use foreign_chain_inspector::http_client::HttpClient;
use foreign_chain_inspector::hyperevm::inspector::HyperEvm;
use foreign_chain_inspector::polygon::inspector::Polygon;
use foreign_chain_inspector::{RpcAuthentication, build_http_client};
use foreign_chain_rpc_auth::auth_config_to_rpc_auth;
use foreign_chain_rpc_factory::{build_http_client, resolve_provider_auth};
use foreign_chain_rpc_interfaces::sui::GrpcSuiClient;
use http::{HeaderName, HeaderValue};
use mpc_node_config::foreign_chains::RpcProviderName;
use mpc_node_config::{ForeignChainConfig, ForeignChainProviderConfig, ForeignChainsConfig};

Expand Down Expand Up @@ -134,35 +131,10 @@ fn no_reference_reason(network: Network) -> String {
)
}

fn timeout_of(cfg: &ForeignChainConfig) -> Duration {
Duration::from_secs(cfg.timeout_sec.get())
}

fn provider_name(name: &RpcProviderName) -> String {
name.as_str().to_owned()
}

fn prepare_jsonrpc(provider: &ForeignChainProviderConfig) -> anyhow::Result<HttpClient> {
let mut url = provider.rpc_url.clone();
let auth = auth_config_to_rpc_auth(provider.auth.clone(), &mut url)?;
build_http_client(url, auth).map_err(|e| anyhow::anyhow!("failed to build HTTP client: {e}"))
}

fn prepare_aptos(
provider: &ForeignChainProviderConfig,
) -> anyhow::Result<(String, Option<(HeaderName, HeaderValue)>)> {
let mut url = provider.rpc_url.clone();
let auth = auth_config_to_rpc_auth(provider.auth.clone(), &mut url)?;
let header = match auth {
RpcAuthentication::KeyInUrl => None,
RpcAuthentication::CustomHeader {
header_name,
header_value,
} => Some((header_name, header_value)),
};
Ok((url, header))
}

async fn run_check(timeout: Duration, fut: impl Future<Output = anyhow::Result<()>>) -> Status {
match tokio::time::timeout(timeout, fut).await {
Ok(Ok(())) => Status::Passed,
Expand All @@ -182,11 +154,11 @@ async fn run_evm<Chain: EvmChain + Send + Sync>(
mark_skipped(chain, cfg, &no_reference_reason(network), out);
return;
};
let timeout = timeout_of(cfg);
let timeout = cfg.timeout_duration();
let parsed =
golden::hex32(vector.tx).and_then(|tx| golden::hex32(vector.block_hash).map(|bh| (tx, bh)));
for (name, provider) in cfg.providers.iter() {
let status = match (&parsed, prepare_jsonrpc(provider)) {
let status = match (&parsed, build_http_client(provider)) {
(Err(e), _) => Status::Failed(format!("invalid golden vector: {e:#}")),
(Ok(_), Err(e)) => Status::Failed(format!("{e:#}")),
(Ok((tx, bh)), Ok(client)) => {
Expand All @@ -211,11 +183,11 @@ async fn run_bitcoin(
mark_skipped("bitcoin", cfg, &no_reference_reason(network), out);
return;
};
let timeout = timeout_of(cfg);
let timeout = cfg.timeout_duration();
let parsed =
golden::hex32(vector.tx).and_then(|tx| golden::hex32(vector.block_hash).map(|bh| (tx, bh)));
for (name, provider) in cfg.providers.iter() {
let status = match (&parsed, prepare_jsonrpc(provider)) {
let status = match (&parsed, build_http_client(provider)) {
(Err(e), _) => Status::Failed(format!("invalid golden vector: {e:#}")),
(Ok(_), Err(e)) => Status::Failed(format!("{e:#}")),
(Ok((tx, bh)), Ok(client)) => {
Expand All @@ -240,11 +212,11 @@ async fn run_starknet(
mark_skipped("starknet", cfg, &no_reference_reason(network), out);
return;
};
let timeout = timeout_of(cfg);
let timeout = cfg.timeout_duration();
let parsed = golden::felt32(vector.tx)
.and_then(|tx| golden::felt32(vector.block_hash).map(|bh| (tx, bh)));
for (name, provider) in cfg.providers.iter() {
let status = match (&parsed, prepare_jsonrpc(provider)) {
let status = match (&parsed, build_http_client(provider)) {
(Err(e), _) => Status::Failed(format!("invalid golden vector: {e:#}")),
(Ok(_), Err(e)) => Status::Failed(format!("{e:#}")),
(Ok((tx, bh)), Ok(client)) => {
Expand All @@ -269,10 +241,10 @@ async fn run_aptos(
mark_skipped("aptos", cfg, &no_reference_reason(network), out);
return;
};
let timeout = timeout_of(cfg);
let timeout = cfg.timeout_duration();
let parsed_tx = golden::hex32(vector.tx);
for (name, provider) in cfg.providers.iter() {
let status = match (&parsed_tx, prepare_aptos(provider)) {
let status = match (&parsed_tx, resolve_provider_auth(provider)) {
(Err(e), _) => Status::Failed(format!("invalid golden vector: {e:#}")),
(Ok(_), Err(e)) => Status::Failed(format!("{e:#}")),
(Ok(tx), Ok((url, header))) => {
Expand Down Expand Up @@ -312,7 +284,7 @@ async fn run_sui(
mark_skipped("sui", cfg, &no_reference_reason(network), out);
return;
};
let timeout = timeout_of(cfg);
let timeout = cfg.timeout_duration();
for (name, provider) in cfg.providers.iter() {
let status = match prepare_sui(provider, timeout) {
Err(e) => Status::Failed(format!("{e:#}")),
Expand All @@ -330,15 +302,7 @@ fn prepare_sui(
provider: &ForeignChainProviderConfig,
timeout: Duration,
) -> anyhow::Result<GrpcSuiClient> {
let mut url = provider.rpc_url.clone();
let auth = auth_config_to_rpc_auth(provider.auth.clone(), &mut url)?;
let header = match auth {
RpcAuthentication::KeyInUrl => None,
RpcAuthentication::CustomHeader {
header_name,
header_value,
} => Some((header_name, header_value)),
};
let (url, header) = resolve_provider_auth(provider)?;
GrpcSuiClient::new(url, header, timeout)
.map_err(|e| anyhow::anyhow!("failed to build the Sui gRPC client: {e}"))
}
Expand Down
Loading
Loading