Skip to content

Commit

Permalink
fix: RocksDB eth_getLogs filtering address by transaction instead o…
Browse files Browse the repository at this point in the history
…f log (#1616)

* chore: ignore old raft test
  • Loading branch information
marcospb19-cw authored Aug 7, 2024
1 parent 6b88f54 commit 1e06e3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/eth/consensus/raft/tests/test_simple_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use crate::eth::primitives::SlotIndex;
use crate::eth::storage::StoragePointInTime;

#[tokio::test]
// TODO: remove it or fix it
#[ignore = "this test depends on a wrong implementation of read_logs for rocksdb"]
async fn test_append_entries_transaction_executions_and_block() {
let consensus = create_follower_consensus_with_leader(None).await;
let service = AppendEntryServiceImpl {
Expand Down
16 changes: 4 additions & 12 deletions src/eth/storage/rocks/rocks_state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::collections::HashSet;
use std::fmt;
use std::fmt::Debug;
use std::sync::atomic::AtomicU64;
Expand Down Expand Up @@ -249,9 +248,7 @@ impl RocksStorageState {
}

pub fn read_logs(&self, filter: &LogFilter) -> Result<Vec<LogMined>> {
let addresses: HashSet<AddressRocksdb> = filter.addresses.iter().map(|&address| AddressRocksdb::from(address)).collect();

let end_block_range_filter = |number: BlockNumber| match filter.to_block.as_ref() {
let is_block_number_in_end_range = |number: BlockNumber| match filter.to_block.as_ref() {
Some(&last_block) => number <= last_block,
None => true,
};
Expand All @@ -265,17 +262,11 @@ impl RocksStorageState {
for next in iter {
let (number, block) = next?;

if !end_block_range_filter(number.into()) {
if !is_block_number_in_end_range(number.into()) {
break;
}
let transactions_with_matching_addresses = block
.transactions
.into_iter()
.filter(|transaction| transaction.input.to.is_some_and(|to| addresses.contains(&to)));

let logs = transactions_with_matching_addresses
.flat_map(|transaction| transaction.logs)
.map(LogMined::from);
let logs = block.transactions.into_iter().flat_map(|transaction| transaction.logs).map(LogMined::from);

let filtered_logs = logs.filter(|log| filter.matches(log));
logs_result.extend(filtered_logs);
Expand Down Expand Up @@ -599,6 +590,7 @@ impl fmt::Debug for RocksStorageState {

#[cfg(test)]
mod tests {
use std::collections::HashSet;
use std::fs;

use fake::Fake;
Expand Down

0 comments on commit 1e06e3a

Please sign in to comment.