From 40668283876048dea2e7d24bc5de87ed631a6b4e Mon Sep 17 00:00:00 2001 From: Noah Citron Date: Wed, 8 Feb 2023 18:12:41 -0500 Subject: [PATCH] fix: prevent logs for unseen blocks (#192) --- execution/src/execution.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/execution/src/execution.rs b/execution/src/execution.rs index 3a16028..c103437 100644 --- a/execution/src/execution.rs +++ b/execution/src/execution.rs @@ -291,7 +291,22 @@ impl ExecutionClient { filter: &Filter, payloads: &BTreeMap, ) -> Result> { - let logs = self.rpc.get_logs(filter).await?; + let filter = filter.clone(); + + // avoid fetching logs for a block helios hasn't seen yet + let filter = if filter.get_to_block().is_none() && filter.get_block_hash().is_none() { + let block = *payloads.last_key_value().unwrap().0; + let filter = filter.to_block(block); + if filter.get_from_block().is_none() { + filter.from_block(block) + } else { + filter + } + } else { + filter + }; + + let logs = self.rpc.get_logs(&filter).await?; if logs.len() > MAX_SUPPORTED_LOGS_NUMBER { return Err( ExecutionError::TooManyLogsToProve(logs.len(), MAX_SUPPORTED_LOGS_NUMBER).into(),