1.43.56. check web3_clientVersion

This commit is contained in:
Bryan Stitt 2023-10-20 15:33:20 -07:00
parent da7bb4b07c
commit 4585724c08
6 changed files with 56 additions and 30 deletions

27
Cargo.lock generated

@ -6412,9 +6412,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc"
dependencies = [ dependencies = [
"getrandom 0.2.10", "getrandom 0.2.10",
"rand 0.8.5",
"serde", "serde",
"zerocopy",
] ]
[[package]] [[package]]
@ -6575,7 +6573,7 @@ dependencies = [
[[package]] [[package]]
name = "web3_proxy" name = "web3_proxy"
version = "1.43.55" version = "1.43.56"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"arc-swap", "arc-swap",
@ -6650,7 +6648,7 @@ dependencies = [
[[package]] [[package]]
name = "web3_proxy_cli" name = "web3_proxy_cli"
version = "1.43.55" version = "1.43.56"
dependencies = [ dependencies = [
"console-subscriber", "console-subscriber",
"env_logger", "env_logger",
@ -6846,27 +6844,6 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" 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]] [[package]]
name = "zeroize" name = "zeroize"
version = "1.6.0" version = "1.6.0"

@ -1,6 +1,6 @@
[package] [package]
name = "web3_proxy" name = "web3_proxy"
version = "1.43.55" version = "1.43.56"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # 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" tracing = "0.1"
ulid = { version = "1.1.0", features = ["rand", "uuid", "serde"] } ulid = { version = "1.1.0", features = ["rand", "uuid", "serde"] }
url = { version = "2.4.1" } 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 # 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"] } test-log = { version = "0.2.13", default-features = false, features = ["trace"] }

@ -42,6 +42,7 @@ use url::Url;
pub struct Web3Rpc { pub struct Web3Rpc {
pub name: String, pub name: String,
pub chain_id: u64, pub chain_id: u64,
pub client_version: RwLock<Option<String>>,
pub block_interval: Duration, pub block_interval: Duration,
pub display_name: Option<String>, pub display_name: Option<String>,
pub db_conn: Option<DatabaseConnection>, pub db_conn: Option<DatabaseConnection>,
@ -492,6 +493,34 @@ impl Web3Rpc {
/// query the web3 provider to confirm it is on the expected chain with the expected data available /// 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 /// 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<Self>, chain_id: u64) -> Web3ProxyResult<()> { async fn check_provider(self: &Arc<Self>, 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 // 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: 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? // TODO: what should the timeout be? should there be a request timeout?
@ -500,7 +529,7 @@ impl Web3Rpc {
.internal_request( .internal_request(
"eth_chainId".into(), "eth_chainId".into(),
&[(); 0], &[(); 0],
Some(Level::TRACE.into()), error_handler,
Some(Duration::from_secs(5)), Some(Duration::from_secs(5)),
) )
.await?; .await?;
@ -1337,7 +1366,7 @@ impl Serialize for Web3Rpc {
where where
S: Serializer, 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 // 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)?; state.serialize_field("name", &self.name)?;
@ -1346,6 +1375,8 @@ impl Serialize for Web3Rpc {
state.serialize_field("backup", &self.backup)?; 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) { match self.block_data_limit.load(atomic::Ordering::Acquire) {
u64::MAX => { u64::MAX => {
state.serialize_field("block_data_limit", &None::<()>)?; state.serialize_field("block_data_limit", &None::<()>)?;

@ -1,6 +1,6 @@
[package] [package]
name = "web3_proxy_cli" name = "web3_proxy_cli"
version = "1.43.55" version = "1.43.56"
edition = "2021" edition = "2021"
default-run = "web3_proxy_cli" default-run = "web3_proxy_cli"

@ -1,3 +1,12 @@
wrk.method = "POST" wrk.method = "POST"
wrk.body = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_blockNumber\",\"params\":[],\"id\":420}" wrk.body = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_blockNumber\",\"params\":[],\"id\":420}"
wrk.headers["Content-Type"] = "application/json" 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

@ -1,3 +1,12 @@
wrk.method = "POST" wrk.method = "POST"
wrk.body = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getBlockByNumber\",\"params\":[\"latest\", false],\"id\":420}" wrk.body = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getBlockByNumber\",\"params\":[\"latest\", false],\"id\":420}"
wrk.headers["Content-Type"] = "application/json" 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