Skip to content

Conversation

JonoPrest
Copy link
Contributor

@JonoPrest JonoPrest commented Sep 26, 2025

Summary by CodeRabbit

  • New Features

    • Unified Selection model with include/exclude and new Filter types for blocks, logs, transactions, and traces.
    • From conversions added for simpler selection construction.
  • Refactor

    • Client helpers updated to use new filter-based selections with no behavior change.
  • Tests

    • Tests updated to construct selections via the new From-based conversions.
  • Chores

    • CI workflow formatting and added rustfmt/clippy lint checks.
    • Package version bumps: net-types -> 0.11.0, client -> 0.20.0.

Copy link

coderabbitai bot commented Sep 26, 2025

Walkthrough

Refactors hypersync-net-types to introduce a generic Selection and new Filter types (BlockFilter, LogFilter, TransactionFilter, TraceFilter) with From conversions; updates hypersync-client code/tests to construct selections via Selection::from(Filter); bumps hypersync-net-types and hypersync-client versions; reformats CI workflow and adds rustfmt/clippy to lint job.

Changes

Cohort / File(s) Summary of changes
CI workflow formatting & lint additions
.github/workflows/ci.yaml
Re-indented and restructured workflow steps without changing executed commands; added rustfmt and clippy components to the lint job; adjusted multi-line run blocks for consistent alignment.
Generic Selection & Filter types
hypersync-net-types/src/lib.rs, hypersync-net-types/Cargo.toml
Replaced concrete selection structs with Selection<T> (fields: include: T, exclude: Option<T>) and From<T> impl; added BlockFilter, LogFilter, TransactionFilter, TraceFilter and type aliases BlockSelection/LogSelection/TransactionSelection/TraceSelection = Selection<...>; documented JoinMode; bumped package version 0.10.0 → 0.11.0.
Client adaptations & tests
hypersync-client/src/preset_query.rs, hypersync-client/tests/api_test.rs, hypersync-client/Cargo.toml
Updated imports to include LogFilter and TransactionFilter; construct selections via LogSelection::from(LogFilter { ... }) / TransactionSelection::from(TransactionFilter { ... }) instead of direct struct literals; updated tests accordingly; bumped client version 0.19.0 → 0.20.0 and updated dependency to hypersync-net-types = "0.11".

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant Client as hypersync-client
  participant Filter as *Filter (e.g., LogFilter)
  participant Selection as Selection<T>
  participant Query as Query Builder

  Dev->>Client: call helper (e.g., logs_of_event)
  Client->>Filter: build Filter struct (fields populated)
  Filter-->>Client: Filter instance
  Client->>Selection: Selection::from(Filter)
  Selection-->>Client: Selection<Filter> (include=Filter, exclude=None)
  Client->>Query: assemble Query using Selection<Filter>
  Query-->>Dev: returned Query / executed request

  note right of Selection: Selection allows later exclude modifications
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • JasoonS

Poem

A twitch of whiskers, ears held high,
I wrap filters snug and give a sigh—
Include, exclude, neat and spry,
Selections hop and hop nearby,
With clippy polish, fmt to try. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title “Jp/hack negative queries” primarily reflects a branch name and a vague reference to “negative queries” but does not clearly summarize the core changes introduced—namely the refactoring of filter types into a generic Selection wrapper, the addition of negative filtering support via From implementations, and related client updates—so it fails to inform a reviewer or future reader of the PR’s main intent. Please rename the pull request to a concise, descriptive title that captures the main change, for example “Introduce generic Selection filters and add negative query support,” so that reviewers immediately understand the purpose and scope of the modifications.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jp/hack-negative-queries

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ad7595 and d440d69.

📒 Files selected for processing (2)
  • hypersync-client/Cargo.toml (2 hunks)
  • hypersync-net-types/Cargo.toml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • hypersync-net-types/Cargo.toml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test_release
🔇 Additional comments (2)
hypersync-client/Cargo.toml (2)

3-3: LGTM!

The version bump from 0.19.0 to 0.20.0 is appropriate for the breaking API changes introduced by the new Selection and Filter types.


50-50: LGTM!

The dependency update to hypersync-net-types 0.11 correctly aligns with the new Selection and Filter type APIs used throughout the codebase.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Comment @coderabbitai help to get the list of available commands and usage tips.

@JonoPrest JonoPrest force-pushed the jp/hack-negative-queries branch from 237777d to b566eab Compare September 26, 2025 12:38
@JonoPrest JonoPrest requested a review from JasoonS September 30, 2025 08:56
@JonoPrest JonoPrest marked this pull request as ready for review September 30, 2025 08:56
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1ec5d3 and 5ad7595.

📒 Files selected for processing (5)
  • .github/workflows/ci.yaml (1 hunks)
  • hypersync-client/src/preset_query.rs (4 hunks)
  • hypersync-client/tests/api_test.rs (2 hunks)
  • hypersync-net-types/Cargo.toml (1 hunks)
  • hypersync-net-types/src/lib.rs (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
hypersync-client/tests/api_test.rs (1)
hypersync-net-types/src/lib.rs (1)
  • from (27-32)
hypersync-client/src/preset_query.rs (1)
hypersync-net-types/src/lib.rs (1)
  • from (27-32)
🪛 actionlint (1.7.7)
.github/workflows/ci.yaml

22-22: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


23-23: the runner of "actions-rs/toolchain@v1" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


45-45: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


46-46: the runner of "actions-rs/toolchain@v1" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


68-68: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


69-69: the runner of "actions-rs/toolchain@v1" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (14)
.github/workflows/ci.yaml (2)

72-72: Good addition of explicit component dependencies.

Explicitly declaring rustfmt and clippy as required components ensures the lint job has the necessary tools. This is a best practice for CI reliability.


22-40: LGTM: Consistent formatting improvements.

The indentation and structure changes improve readability and maintain consistency across all three jobs. The workflow logic remains unchanged aside from the beneficial addition of explicit components in the lint job.

Also applies to: 45-63, 68-87

hypersync-client/src/preset_query.rs (4)

6-8: LGTM! Import updates align with the new API.

The imports correctly bring in the new LogFilter and TransactionFilter types required for the refactored selection constructors.


86-89: LGTM! Correct usage of the new From-based construction.

The LogSelection::from(LogFilter { ... }) pattern correctly leverages the new generic Selection<T> API, preserving the original filter semantics while adopting the new type structure.


121-125: LGTM! Consistent with the new filter construction pattern.

The construction correctly uses LogSelection::from(LogFilter { ... }) with topics and address fields, maintaining the original query semantics.


175-178: LGTM! Transaction filter construction follows the established pattern.

The TransactionSelection::from(TransactionFilter { ... }) correctly constructs the selection with the from field, consistent with the refactored API.

hypersync-client/tests/api_test.rs (2)

8-8: LGTM! Import correctly updated for the new API.

The addition of TransactionFilter to the imports enables the test to use the new filter construction pattern.


461-464: LGTM! Test correctly updated to use the new From-based construction.

The test properly constructs TransactionSelection via TransactionSelection::from(TransactionFilter { ... }), using the from_filter field with a bloom filter. This maintains the original test semantics while adopting the refactored API.

hypersync-net-types/src/lib.rs (6)

26-33: LGTM! From implementation provides ergonomic construction.

The From<T> implementation allows users to construct Selection<T> from just a filter, defaulting exclude to None. This maintains backward compatibility for users who don't need negative filtering while enabling the new feature.


35-47: LGTM! BlockFilter correctly encapsulates block filtering logic.

The BlockSelection type alias and BlockFilter struct cleanly separate the selection wrapper from the filter criteria. The hash and miner fields are well-documented with their empty-vector semantics.


49-63: LGTM! LogFilter properly encapsulates log filtering criteria.

The LogSelection alias and LogFilter struct correctly expose address, address_filter (bloom), and topics fields with clear documentation.


65-108: LGTM! TransactionFilter comprehensively covers transaction filtering.

The TransactionSelection alias and TransactionFilter struct provide extensive filtering capabilities including from/to addresses (with bloom filter support), sighash, status, type, contract address, hash, and authorization list. Field documentation is clear about AND/OR relationships.


120-145: LGTM! TraceFilter follows consistent design pattern.

The TraceSelection alias and TraceFilter struct maintain consistency with other filter types, providing from/to/address filtering (with bloom support), call_type, reward_type, kind, and sighash fields.


209-216: LGTM! Documentation added to JoinMode variants.

The added documentation clarifies the behavior of each JoinMode variant, improving API usability.

Comment on lines +22 to +23
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
Copy link

@coderabbitai coderabbitai bot Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Upgrade outdated GitHub Actions.

The static analysis tool correctly identifies that these actions are outdated and may fail on GitHub Actions:

  • actions/checkout@v3 uses Node 16, which is deprecated. Upgrade to actions/checkout@v4.
  • actions-rs/toolchain@v1 is from an archived repository and is no longer maintained. Consider using dtolnay/rust-toolchain or the official actions/setup-rust instead.

Apply this diff to upgrade the actions across all jobs:

-      - uses: actions/checkout@v3
-      - uses: actions-rs/toolchain@v1
+      - uses: actions/checkout@v4
+      - uses: dtolnay/rust-toolchain@stable
-        with:
-          toolchain: stable
-          override: true

Note: dtolnay/rust-toolchain uses the version as a tag (e.g., @stable), so the with block is no longer needed.

Also applies to: 45-46, 68-69

🧰 Tools
🪛 actionlint (1.7.7)

22-22: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


23-23: the runner of "actions-rs/toolchain@v1" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🤖 Prompt for AI Agents
.github/workflows/ci.yaml lines 22-23 (and similarly update lines 45-46 and
68-69): replace the outdated actions by upgrading actions/checkout@v3 to
actions/checkout@v4 and remove the archived actions-rs/toolchain@v1; instead use
a maintained Rust action such as actions/setup-rust@v1 (or
dtolnay/rust-toolchain@stable if you prefer tag syntax) and adjust any with:
block accordingly (dtolnay variant does not need a with block,
actions/setup-rust keeps the toolchain input).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix this as a separate PR

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JasoonS, understood! I'll defer this change to a separate PR to keep this one focused on the negative queries work.

Would you like me to create a GitHub issue to track the GitHub Actions upgrade (actions/checkout@v3 → v4 and replacing actions-rs/toolchain@v1 with a maintained alternative like dtolnay/rust-toolchain)?

[package]
name = "hypersync-net-types"
version = "0.10.0"
version = "0.10.1"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify the version bump is appropriate for the API changes.

The version was bumped from 0.10.0 to 0.10.1 (patch), but the changes introduce new generic Selection<T> types and convert existing concrete types to type aliases. While the From<T> implementation may preserve some backward compatibility for construction, any code that pattern-matches or explicitly constructs these types will break.

For semver 0.x.y, breaking changes typically warrant a minor version bump (0.10.0 -> 0.11.0). Consider whether this patch bump is appropriate.

Let me verify if there are any external dependents that might be affected:


🏁 Script executed:

#!/bin/bash
# Description: Check if hypersync-net-types is used by external crates or only internally
# Expected: Find usage patterns that might break with this change

# Check for any Cargo.toml files that depend on hypersync-net-types
rg -t toml 'hypersync-net-types' --no-heading

# Look for direct struct construction patterns that would break
rg -n 'BlockSelection\s*\{' --type rust
rg -n 'LogSelection\s*\{' --type rust  
rg -n 'TransactionSelection\s*\{' --type rust
rg -n 'TraceSelection\s*\{' --type rust

Length of output: 201


Bump crate version to 0.11.0 — introducing the generic Selection<T> types and converting the old concrete types into aliases is a breaking change under 0.x semver rules; a patch bump to 0.10.1 isn’t sufficient. Update this crate’s version to 0.11.0 and adjust the hypersync-client dependency to "0.11" accordingly.

🤖 Prompt for AI Agents
In hypersync-net-types/Cargo.toml around line 3, the crate version was
incorrectly bumped to 0.10.1 for a breaking change; update the version to
"0.11.0" and then update the hypersync-client dependency reference to "0.11" to
match the new minor version so consumers see the semver-breaking change.

Comment on lines 14 to +24
#[derive(Default, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct BlockSelection {
pub struct Selection<T> {
/// Filters where matching values should be included in the response
/// Default::default() means include everything
#[serde(default, flatten)]
pub include: T,
/// Filters where matching values should be excluded from the response
/// None means exclude nothing, Some(Default::default()) means exclude everything
#[serde(default)]
pub exclude: Option<T>,
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Document the exclude field behavior and validate the design.

The new Selection<T> generic introduces an include/exclude pattern that enables negative queries (matching the PR title). However, the exclude field lacks documentation on:

  1. How exclude interacts with include (e.g., is it applied after include filtering?)
  2. What Some(Default::default()) means in practice (exclude everything that passes include?)
  3. Server-side implementation requirements for this pattern

Additionally, the #[serde(flatten)] on include will merge its fields into the parent during serialization, which may cause naming conflicts if T has an exclude field.

Consider adding comprehensive documentation:

 #[derive(Default, Serialize, Deserialize, Clone, Debug, PartialEq)]
 pub struct Selection<T> {
     /// Filters where matching values should be included in the response
-    /// Default::default() means include everything
+    /// Default::default() means include everything.
+    /// Items must match the include filter to be considered for the response.
     #[serde(default, flatten)]
     pub include: T,
     /// Filters where matching values should be excluded from the response
-    /// None means exclude nothing, Some(Default::default()) means exclude everything
+    /// None means exclude nothing. Some(Default::default()) means exclude everything.
+    /// Exclusion is applied after inclusion, so an item matching both include and exclude
+    /// filters will be excluded from the response.
     #[serde(default)]
     pub exclude: Option<T>,
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[derive(Default, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct BlockSelection {
pub struct Selection<T> {
/// Filters where matching values should be included in the response
/// Default::default() means include everything
#[serde(default, flatten)]
pub include: T,
/// Filters where matching values should be excluded from the response
/// None means exclude nothing, Some(Default::default()) means exclude everything
#[serde(default)]
pub exclude: Option<T>,
}
#[derive(Default, Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct Selection<T> {
/// Filters where matching values should be included in the response
/// Default::default() means include everything.
/// Items must match the include filter to be considered for the response.
#[serde(default, flatten)]
pub include: T,
/// Filters where matching values should be excluded from the response
/// None means exclude nothing. Some(Default::default()) means exclude everything.
/// Exclusion is applied after inclusion, so an item matching both include and exclude
/// filters will be excluded from the response.
#[serde(default)]
pub exclude: Option<T>,
}

JasoonS
JasoonS previously approved these changes Sep 30, 2025
Copy link
Contributor

@JasoonS JasoonS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the '/examples'

@JonoPrest
Copy link
Contributor Author

Check the '/examples'

Checked, they all build and they were part of the workspace to begin with 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants