Skip to content

Commit

Permalink
evm: Make filters in eth_getLogs order dependent (#2072)
Browse files Browse the repository at this point in the history
* Make filters order dependent

* Remove unused import

---------

Co-authored-by: Peter John Bushnell <[email protected]>
  • Loading branch information
shohamc1 and Bushstar authored Jun 21, 2023
1 parent 8c528ea commit c3f246a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/ain-evm/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ethereum::ReceiptV3;
use log::debug;
use primitive_types::{H160, H256, U256};
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use std::sync::Arc;

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -66,7 +66,7 @@ impl LogHandler {
pub fn get_logs(
&self,
address: Option<Vec<H160>>,
topics: Option<Vec<H256>>,
topics: Option<Vec<Option<H256>>>,
block_number: U256,
) -> Vec<LogIndex> {
debug!("Getting logs for block {:#x?}", block_number);
Expand All @@ -89,8 +89,13 @@ impl LogHandler {
Some(topics) => logs
.into_iter()
.filter(|log| {
let set: HashSet<_> = log.topics.iter().copied().collect();
topics.iter().any(|item| set.contains(item))
topics
.iter() // for all topic filters
.zip(&log.topics) // construct tuple with corresponding log topics
.all(|(filter_item, log_item)| {
// check if topic filter at index matches log topic
filter_item.as_ref().map_or(true, |item| item == log_item)
})
})
.collect(),
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-grpc/src/transaction_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ pub struct GetLogsRequest {
pub block_hash: Option<H256>,
pub from_block: Option<BlockNumber>,
pub to_block: Option<BlockNumber>,
pub topics: Option<Vec<H256>>,
pub topics: Option<Vec<Option<H256>>>,
}

0 comments on commit c3f246a

Please sign in to comment.