mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: use caching layer when fetching blocks for logs (#2350)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -48,8 +48,8 @@ where
|
||||
{
|
||||
// spawn a new cache task
|
||||
let eth_cache = EthStateCache::spawn_with(client.clone(), Default::default(), executor);
|
||||
let eth_api = EthApi::new(client.clone(), pool.clone(), network, eth_cache);
|
||||
let eth_filter = EthFilter::new(client, pool);
|
||||
let eth_api = EthApi::new(client.clone(), pool.clone(), network, eth_cache.clone());
|
||||
let eth_filter = EthFilter::new(client, pool, eth_cache.clone());
|
||||
launch_with_eth_api(eth_api, eth_filter, engine_api, socket_addr, secret).await
|
||||
}
|
||||
|
||||
|
||||
@ -754,7 +754,7 @@ where
|
||||
self.network.clone(),
|
||||
cache.clone(),
|
||||
);
|
||||
let filter = EthFilter::new(self.client.clone(), self.pool.clone());
|
||||
let filter = EthFilter::new(self.client.clone(), self.pool.clone(), cache.clone());
|
||||
|
||||
let pubsub = EthPubSub::new(
|
||||
self.client.clone(),
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
use super::cache::EthStateCache;
|
||||
use crate::{
|
||||
eth::{error::EthApiError, logs_utils},
|
||||
result::{internal_rpc_err, rpc_error_with_code, ToRpcResult},
|
||||
@ -26,13 +27,14 @@ pub struct EthFilter<Client, Pool> {
|
||||
|
||||
impl<Client, Pool> EthFilter<Client, Pool> {
|
||||
/// Creates a new, shareable instance.
|
||||
pub fn new(client: Client, pool: Pool) -> Self {
|
||||
pub fn new(client: Client, pool: Pool, eth_cache: EthStateCache) -> Self {
|
||||
let inner = EthFilterInner {
|
||||
client,
|
||||
active_filters: Default::default(),
|
||||
pool,
|
||||
id_provider: Arc::new(EthSubscriptionIdProvider::default()),
|
||||
max_logs_in_response: DEFAULT_MAX_LOGS_IN_RESPONSE,
|
||||
eth_cache,
|
||||
};
|
||||
Self { inner: Arc::new(inner) }
|
||||
}
|
||||
@ -172,6 +174,8 @@ struct EthFilterInner<Client, Pool> {
|
||||
id_provider: Arc<dyn IdProvider>,
|
||||
/// Maximum number of logs that can be returned in a response
|
||||
max_logs_in_response: usize,
|
||||
/// The async cache frontend for eth related data
|
||||
eth_cache: EthStateCache,
|
||||
}
|
||||
|
||||
impl<Client, Pool> EthFilterInner<Client, Pool>
|
||||
@ -185,10 +189,10 @@ where
|
||||
FilterBlockOption::AtBlockHash(block_hash) => {
|
||||
let mut all_logs = Vec::new();
|
||||
// all matching logs in the block, if it exists
|
||||
if let Some(block) = self.client.block(block_hash.into()).to_rpc_result()? {
|
||||
if let Some(block) = self.eth_cache.get_block(block_hash).await.to_rpc_result()? {
|
||||
// get receipts for the block
|
||||
if let Some(receipts) =
|
||||
self.client.receipts_by_block(block.number.into()).to_rpc_result()?
|
||||
self.eth_cache.get_receipts(block_hash).await.to_rpc_result()?
|
||||
{
|
||||
let filter = FilteredParams::new(Some(filter));
|
||||
logs_utils::append_matching_block_logs(
|
||||
|
||||
Reference in New Issue
Block a user