cache getLogs with blockhash
This commit is contained in:
parent
f8f5e7a1c8
commit
475e521918
1
TODO.md
1
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
|
- 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.
|
- 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] 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
|
- [-] 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 benchmarking all backends
|
||||||
- [-] proxy mode for sending to multiple backends
|
- [-] proxy mode for sending to multiple backends
|
||||||
|
|
|
@ -68,7 +68,7 @@ pub static APP_USER_AGENT: &str = concat!(
|
||||||
/// TODO: allow customizing the request period?
|
/// TODO: allow customizing the request period?
|
||||||
pub static REQUEST_PERIOD: u64 = 60;
|
pub static REQUEST_PERIOD: u64 = 60;
|
||||||
|
|
||||||
#[derive(From)]
|
#[derive(Debug, From)]
|
||||||
struct ResponseCacheKey {
|
struct ResponseCacheKey {
|
||||||
// if none, this is cached until evicted
|
// if none, this is cached until evicted
|
||||||
from_block: Option<Web3ProxyBlock>,
|
from_block: Option<Web3ProxyBlock>,
|
||||||
|
@ -1598,6 +1598,7 @@ impl Web3ProxyApp {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
trace!("cache_key: {:#?}", cache_key);
|
||||||
|
|
||||||
let mut response = {
|
let mut response = {
|
||||||
let request_metadata = request_metadata.clone();
|
let request_metadata = request_metadata.clone();
|
||||||
|
|
|
@ -4,7 +4,7 @@ use ethers::{
|
||||||
prelude::{BlockNumber, U64},
|
prelude::{BlockNumber, U64},
|
||||||
types::H256,
|
types::H256,
|
||||||
};
|
};
|
||||||
use log::warn;
|
use log::{debug, trace, warn};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -176,13 +176,13 @@ pub async fn block_needed(
|
||||||
"eth_getLogs" => {
|
"eth_getLogs" => {
|
||||||
// TODO: think about this more
|
// TODO: think about this more
|
||||||
// TODO: jsonrpc has a specific code for this
|
// 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]
|
let obj = params[0]
|
||||||
.as_object_mut()
|
.as_object_mut()
|
||||||
.ok_or_else(|| anyhow::anyhow!("invalid format"))?;
|
.ok_or_else(|| anyhow::anyhow!("invalid format"))?;
|
||||||
|
|
||||||
if obj.contains_key("blockHash") {
|
if obj.contains_key("blockHash") {
|
||||||
1
|
return Ok(BlockNeeded::CacheSuccessForever);
|
||||||
} else {
|
} else {
|
||||||
let from_block_num = if let Some(x) = obj.get_mut("fromBlock") {
|
let from_block_num = if let Some(x) = obj.get_mut("fromBlock") {
|
||||||
// TODO: use .take instead of clone
|
// 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);
|
let (block_num, change) = block_num_to_U64(block_num, head_block_num);
|
||||||
|
|
||||||
if change {
|
if change {
|
||||||
|
trace!("changing fromBlock in eth_getLogs. {} -> {}", x, block_num);
|
||||||
*x = json!(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);
|
let (block_num, change) = block_num_to_U64(block_num, head_block_num);
|
||||||
|
|
||||||
if change {
|
if change {
|
||||||
|
trace!("changing toBlock in eth_getLogs. {} -> {}", x, block_num);
|
||||||
*x = json!(block_num);
|
*x = json!(block_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue