From 475e521918b3d4e22e199fe76822aaaf41e88a36 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sun, 26 Feb 2023 22:59:42 -0800 Subject: [PATCH] cache getLogs with blockhash --- TODO.md | 1 + web3_proxy/src/app/mod.rs | 3 ++- web3_proxy/src/block_number.rs | 8 +++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/TODO.md b/TODO.md index 352fca4d..f843384c 100644 --- a/TODO.md +++ b/TODO.md @@ -357,6 +357,7 @@ These are not yet ordered. There might be duplicates. We might not actually need - erigon only streams the JSON over HTTP. that code isn't enabled for websockets. so this should save memory on the erigon servers - i think this also means we don't need to worry about changing the id that the user gives us. - [x] eth_getLogs is going to unsynced nodes because it only checks start block and not the end block +- [x] fix caching getLogs with blockhash - [-] if we subscribe to a server that is syncing, it gives us null block_data_limit. when it catches up, we don't ever send queries to it. we need to recheck block_data_limit - [-] proxy mode for benchmarking all backends - [-] proxy mode for sending to multiple backends diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 48ae6d72..d4c6ff10 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -68,7 +68,7 @@ pub static APP_USER_AGENT: &str = concat!( /// TODO: allow customizing the request period? pub static REQUEST_PERIOD: u64 = 60; -#[derive(From)] +#[derive(Debug, From)] struct ResponseCacheKey { // if none, this is cached until evicted from_block: Option, @@ -1598,6 +1598,7 @@ impl Web3ProxyApp { }) } }; + trace!("cache_key: {:#?}", cache_key); let mut response = { let request_metadata = request_metadata.clone(); diff --git a/web3_proxy/src/block_number.rs b/web3_proxy/src/block_number.rs index 2b68f432..69d289a1 100644 --- a/web3_proxy/src/block_number.rs +++ b/web3_proxy/src/block_number.rs @@ -4,7 +4,7 @@ use ethers::{ prelude::{BlockNumber, U64}, types::H256, }; -use log::warn; +use log::{debug, trace, warn}; use serde_json::json; use std::sync::Arc; @@ -176,13 +176,13 @@ pub async fn block_needed( "eth_getLogs" => { // TODO: think about this more // TODO: jsonrpc has a specific code for this - // TODO: this shouldn't be a 500. this should + // TODO: this shouldn't be a 500. this should be a 400. 500 will make haproxy retry a bunch let obj = params[0] .as_object_mut() .ok_or_else(|| anyhow::anyhow!("invalid format"))?; if obj.contains_key("blockHash") { - 1 + return Ok(BlockNeeded::CacheSuccessForever); } else { let from_block_num = if let Some(x) = obj.get_mut("fromBlock") { // TODO: use .take instead of clone @@ -191,6 +191,7 @@ pub async fn block_needed( let (block_num, change) = block_num_to_U64(block_num, head_block_num); if change { + trace!("changing fromBlock in eth_getLogs. {} -> {}", x, block_num); *x = json!(block_num); } @@ -208,6 +209,7 @@ pub async fn block_needed( let (block_num, change) = block_num_to_U64(block_num, head_block_num); if change { + trace!("changing toBlock in eth_getLogs. {} -> {}", x, block_num); *x = json!(block_num); }