From f36ca5e70252c24de2727d7db8413ac72343da16 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 30 Jun 2022 00:52:04 +0000 Subject: [PATCH] getTransaction from the private rpcs --- TODO.md | 2 ++ web3-proxy/src/app.rs | 25 +++++++++++++++++++------ web3-proxy/src/connections.rs | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 72286666..b8504b7b 100644 --- a/TODO.md +++ b/TODO.md @@ -30,6 +30,7 @@ - even after removing a bunch of the locks, the deadlock still happens. i can't reliably reproduce. i just let it run for awhile and it happens. - running gdb shows the thread at tokio tungstenite thread is spinning near 100% cpu and none of the rest of the program is proceeding - fixed by https://github.com/gakonst/ethers-rs/pull/1287 +- [ ] when sending with private relays, brownie's tx.wait can think the transaction was dropped. smarter retry on eth_getTransactionByHash and eth_getTransactionReceipt (maybe only if we sent the transaction ourselves) - [ ] rpc errors propagate too far. one subscription failing ends the app. isolate the providers more - [ ] if web3 proxy gets an http error back, retry another node - [ ] endpoint for health checks. if no synced servers, give a 502 error @@ -41,6 +42,7 @@ ## V1 +- [ ] some things that are cached locally should probably be in shared redis caches - [ ] stats when forks are resolved (and what chain they were on?) - [ ] incoming rate limiting (by api key) - [ ] failsafe. if no blocks or transactions in the last second, warn and reset the connection diff --git a/web3-proxy/src/app.rs b/web3-proxy/src/app.rs index cb465649..a1d80c2f 100644 --- a/web3-proxy/src/app.rs +++ b/web3-proxy/src/app.rs @@ -570,7 +570,10 @@ impl Web3ProxyApp { | "personal_unlockAccount" | "personal_sendTransaction" | "personal_sign" - | "personal_ecRecover" => Err(anyhow::anyhow!("unimplemented")), + | "personal_ecRecover" => { + // TODO: proper error code + Err(anyhow::anyhow!("unimplemented")) + } "eth_sendRawTransaction" => { // there are private rpcs configured and the request is eth_sendSignedTransaction. send to all private rpcs // TODO: think more about this lock. i think it won't actually help the herd. it probably makes it worse if we have a tight lag_limit @@ -579,7 +582,7 @@ impl Web3ProxyApp { .instrument(span) .await } - _ => { + method => { // this is not a private transaction (or no private relays are configured) let (cache_key, response_cache) = match self.get_cached_response(&request) { @@ -631,10 +634,20 @@ impl Web3ProxyApp { } } - let response = self - .balanced_rpcs - .try_send_best_upstream_server(request) - .await?; + let response = match method { + "eth_getTransactionByHash" | "eth_getTransactionReceipt" => { + // TODO: try_send_all serially with retries instead of parallel + self.private_rpcs + .try_send_all_upstream_servers(request) + .await? + } + _ => { + // TODO: retries? + self.balanced_rpcs + .try_send_best_upstream_server(request) + .await? + } + }; // TODO: small race condidition here. parallel requests with the same query will both be saved to the cache let mut response_cache = response_cache.write(); diff --git a/web3-proxy/src/connections.rs b/web3-proxy/src/connections.rs index d5af0509..026f16c9 100644 --- a/web3-proxy/src/connections.rs +++ b/web3-proxy/src/connections.rs @@ -715,6 +715,7 @@ impl Web3Connections { warn!(?self, "No servers in sync!"); // TODO: sleep how long? until synced_connections changes or rate limits are available + // TODO: subscribe to head_block_sender sleep(Duration::from_millis(200)).await; continue;