From ec8dd7d7e12c6edfe3a39f2bc9c499bbb020d8ab Mon Sep 17 00:00:00 2001 From: Phillip LeBlanc Date: Fri, 3 Nov 2023 14:00:29 +0900 Subject: [PATCH 1/4] `trace_filter` matches all transactions on empty addresses --- crates/rpc/rpc-types/src/eth/trace/filter.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/rpc/rpc-types/src/eth/trace/filter.rs b/crates/rpc/rpc-types/src/eth/trace/filter.rs index cf9c9c23ff53..f3965e4a5d1e 100644 --- a/crates/rpc/rpc-types/src/eth/trace/filter.rs +++ b/crates/rpc/rpc-types/src/eth/trace/filter.rs @@ -63,6 +63,11 @@ pub struct TraceFilterMatcher { impl TraceFilterMatcher { /// Returns `true` if the given `from` and `to` addresses match this filter. pub fn matches(&self, from: Address, to: Option
) -> bool { + // If `from_addresses` and `to_addresses` are empty, then match all transactions. + if self.from_addresses.is_empty() && self.to_addresses.is_empty() { + return true; + } + match self.mode { TraceFilterMode::Union => { self.from_addresses.contains(&from) || From 528ed595776c26cca39114bdf316fd2d8e803f47 Mon Sep 17 00:00:00 2001 From: Phillip LeBlanc Date: Fri, 3 Nov 2023 14:30:10 +0900 Subject: [PATCH 2/4] Add basic tests for filter matcher --- crates/rpc/rpc-types/src/eth/trace/filter.rs | 31 +++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/crates/rpc/rpc-types/src/eth/trace/filter.rs b/crates/rpc/rpc-types/src/eth/trace/filter.rs index f3965e4a5d1e..ba309b5ce9c1 100644 --- a/crates/rpc/rpc-types/src/eth/trace/filter.rs +++ b/crates/rpc/rpc-types/src/eth/trace/filter.rs @@ -70,12 +70,12 @@ impl TraceFilterMatcher { match self.mode { TraceFilterMode::Union => { - self.from_addresses.contains(&from) || - to.map_or(false, |to| self.to_addresses.contains(&to)) + self.from_addresses.contains(&from) + || to.map_or(false, |to| self.to_addresses.contains(&to)) } TraceFilterMode::Intersection => { - self.from_addresses.contains(&from) && - to.map_or(false, |to| self.to_addresses.contains(&to)) + self.from_addresses.contains(&from) + && to.map_or(false, |to| self.to_addresses.contains(&to)) } } } @@ -92,4 +92,27 @@ mod tests { assert_eq!(filter.from_block, Some(3)); assert_eq!(filter.to_block, Some(5)); } + + #[test] + fn test_filter_matcher() { + let s = r#"{"fromBlock": "0x3","toBlock": "0x5"}"#; + let filter: TraceFilter = serde_json::from_str(s).unwrap(); + let matcher = filter.matcher(); + assert!( + matcher.matches("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045".parse().unwrap(), None) + ); + assert!( + matcher.matches("0x160f5f00288e9e1cc8655b327e081566e580a71d".parse().unwrap(), None) + ); + + let s = r#"{"fromBlock": "0x3","toBlock": "0x5", "fromAddress": ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"]}"#; + let filter: TraceFilter = serde_json::from_str(s).unwrap(); + let matcher = filter.matcher(); + assert!( + matcher.matches("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045".parse().unwrap(), None) + ); + assert!( + !matcher.matches("0x160f5f00288e9e1cc8655b327e081566e580a71d".parse().unwrap(), None) + ); + } } From c5c073efcffdf736e0e9cd894d73e01c00e6a6f2 Mon Sep 17 00:00:00 2001 From: Phillip LeBlanc Date: Fri, 3 Nov 2023 14:30:57 +0900 Subject: [PATCH 3/4] revert formatting --- crates/rpc/rpc-types/src/eth/trace/filter.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/rpc/rpc-types/src/eth/trace/filter.rs b/crates/rpc/rpc-types/src/eth/trace/filter.rs index ba309b5ce9c1..53b485584c1e 100644 --- a/crates/rpc/rpc-types/src/eth/trace/filter.rs +++ b/crates/rpc/rpc-types/src/eth/trace/filter.rs @@ -70,12 +70,12 @@ impl TraceFilterMatcher { match self.mode { TraceFilterMode::Union => { - self.from_addresses.contains(&from) - || to.map_or(false, |to| self.to_addresses.contains(&to)) + self.from_addresses.contains(&from) || + to.map_or(false, |to| self.to_addresses.contains(&to)) } TraceFilterMode::Intersection => { - self.from_addresses.contains(&from) - && to.map_or(false, |to| self.to_addresses.contains(&to)) + self.from_addresses.contains(&from) && + to.map_or(false, |to| self.to_addresses.contains(&to)) } } } From 0c2c0f0e1cb7321921a0653889b19f140e748b3e Mon Sep 17 00:00:00 2001 From: Phillip LeBlanc Date: Fri, 3 Nov 2023 14:31:17 +0900 Subject: [PATCH 4/4] space --- crates/rpc/rpc-types/src/eth/trace/filter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rpc/rpc-types/src/eth/trace/filter.rs b/crates/rpc/rpc-types/src/eth/trace/filter.rs index 53b485584c1e..0a18d954b522 100644 --- a/crates/rpc/rpc-types/src/eth/trace/filter.rs +++ b/crates/rpc/rpc-types/src/eth/trace/filter.rs @@ -70,7 +70,7 @@ impl TraceFilterMatcher { match self.mode { TraceFilterMode::Union => { - self.from_addresses.contains(&from) || + self.from_addresses.contains(&from) || to.map_or(false, |to| self.to_addresses.contains(&to)) } TraceFilterMode::Intersection => {