From 4585724c08b48b5d0590aa86c1baee474d58eef7 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 20 Oct 2023 15:33:20 -0700 Subject: [PATCH] 1.43.56. check web3_clientVersion --- Cargo.lock | 27 ++------------------------ web3_proxy/Cargo.toml | 4 ++-- web3_proxy/src/rpcs/one.rs | 35 ++++++++++++++++++++++++++++++++-- web3_proxy_cli/Cargo.toml | 2 +- wrk/getBlockNumber.lua | 9 +++++++++ wrk/getLatestBlockByNumber.lua | 9 +++++++++ 6 files changed, 56 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c509eb56..8afef707 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6412,9 +6412,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" dependencies = [ "getrandom 0.2.10", - "rand 0.8.5", "serde", - "zerocopy", ] [[package]] @@ -6575,7 +6573,7 @@ dependencies = [ [[package]] name = "web3_proxy" -version = "1.43.55" +version = "1.43.56" dependencies = [ "anyhow", "arc-swap", @@ -6650,7 +6648,7 @@ dependencies = [ [[package]] name = "web3_proxy_cli" -version = "1.43.55" +version = "1.43.56" dependencies = [ "console-subscriber", "env_logger", @@ -6846,27 +6844,6 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" -[[package]] -name = "zerocopy" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96f8f25c15a0edc9b07eb66e7e6e97d124c0505435c382fde1ab7ceb188aa956" -dependencies = [ - "byteorder", - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "855e0f6af9cd72b87d8a6c586f3cb583f5cdcc62c2c80869d8cd7e96fdf7ee20" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - [[package]] name = "zeroize" version = "1.6.0" diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 15bb4555..479e775f 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "web3_proxy" -version = "1.43.55" +version = "1.43.56" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -91,7 +91,7 @@ tower-http = { version = "0.4.4", features = ["cors", "normalize-path", "sensiti tracing = "0.1" ulid = { version = "1.1.0", features = ["rand", "uuid", "serde"] } url = { version = "2.4.1" } -uuid = { version = "1.5.0", default-features = false, features = ["fast-rng", "v4", "zerocopy"] } +uuid = { version = "1.5.0", default-features = false } # TODO: why doesn't this work in dev-dependencies. i think because of how we split web3_proxy and web3_proxy_cli. im not sure that is even helping anymore test-log = { version = "0.2.13", default-features = false, features = ["trace"] } diff --git a/web3_proxy/src/rpcs/one.rs b/web3_proxy/src/rpcs/one.rs index b3fb11d1..1b900b51 100644 --- a/web3_proxy/src/rpcs/one.rs +++ b/web3_proxy/src/rpcs/one.rs @@ -42,6 +42,7 @@ use url::Url; pub struct Web3Rpc { pub name: String, pub chain_id: u64, + pub client_version: RwLock>, pub block_interval: Duration, pub display_name: Option, pub db_conn: Option, @@ -492,6 +493,34 @@ impl Web3Rpc { /// query the web3 provider to confirm it is on the expected chain with the expected data available /// TODO: this currently checks only the http if both http and ws are set. it should check both and make sure they match async fn check_provider(self: &Arc, chain_id: u64) -> Web3ProxyResult<()> { + // TODO: different handlers for backup vs primary + let error_handler = Some(Level::TRACE.into()); + + match self + .internal_request::<_, String>( + "web3_clientVersion".into(), + &(), + error_handler, + Some(Duration::from_secs(5)), + ) + .await + { + Ok(client_version) => { + // this is a sync lock, but we only keep it open for a short time + // TODO: something more friendly to async that also works with serde's Serialize + let mut lock = self.client_version.write(); + + *lock = Some(client_version); + } + Err(err) => { + let mut lock = self.client_version.write(); + + *lock = Some(format!("error: {}", err)); + + error!(?err, "failed fetching client version of {}", self); + } + } + // check the server's chain_id here // TODO: some public rpcs (on bsc and fantom) do not return an id and so this ends up being an error // TODO: what should the timeout be? should there be a request timeout? @@ -500,7 +529,7 @@ impl Web3Rpc { .internal_request( "eth_chainId".into(), &[(); 0], - Some(Level::TRACE.into()), + error_handler, Some(Duration::from_secs(5)), ) .await?; @@ -1337,7 +1366,7 @@ impl Serialize for Web3Rpc { where S: Serializer, { - let mut state = serializer.serialize_struct("Web3Rpc", 15)?; + let mut state = serializer.serialize_struct("Web3Rpc", 16)?; // the url is excluded because it likely includes private information. just show the name that we use in keys state.serialize_field("name", &self.name)?; @@ -1346,6 +1375,8 @@ impl Serialize for Web3Rpc { state.serialize_field("backup", &self.backup)?; + state.serialize_field("web3_clientVersion", &self.client_version.read().as_ref())?; + match self.block_data_limit.load(atomic::Ordering::Acquire) { u64::MAX => { state.serialize_field("block_data_limit", &None::<()>)?; diff --git a/web3_proxy_cli/Cargo.toml b/web3_proxy_cli/Cargo.toml index 786e906c..70eaa95f 100644 --- a/web3_proxy_cli/Cargo.toml +++ b/web3_proxy_cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "web3_proxy_cli" -version = "1.43.55" +version = "1.43.56" edition = "2021" default-run = "web3_proxy_cli" diff --git a/wrk/getBlockNumber.lua b/wrk/getBlockNumber.lua index e3dd78bd..2bebe14c 100644 --- a/wrk/getBlockNumber.lua +++ b/wrk/getBlockNumber.lua @@ -1,3 +1,12 @@ wrk.method = "POST" wrk.body = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_blockNumber\",\"params\":[],\"id\":420}" wrk.headers["Content-Type"] = "application/json" + +response = function(status, headers, body) + if status ~= 200 then + io.write("Status: ".. status .."\n") + io.write("Body:\n") + io.write(body .. "\n") + end + end + \ No newline at end of file diff --git a/wrk/getLatestBlockByNumber.lua b/wrk/getLatestBlockByNumber.lua index bea1576e..d79224e8 100644 --- a/wrk/getLatestBlockByNumber.lua +++ b/wrk/getLatestBlockByNumber.lua @@ -1,3 +1,12 @@ wrk.method = "POST" wrk.body = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getBlockByNumber\",\"params\":[\"latest\", false],\"id\":420}" wrk.headers["Content-Type"] = "application/json" + +response = function(status, headers, body) + if status ~= 200 then + io.write("Status: ".. status .."\n") + io.write("Body:\n") + io.write(body .. "\n") + end + end + \ No newline at end of file