Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evm: Make filters in eth_getLogs order dependent #2072

Merged
merged 4 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>>>,
}