Skip to content

feat: add unbounded partial addresses matching over address filters #953

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

Merged
merged 1 commit into from
May 26, 2025

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented May 23, 2025

Fixes LX-46

@gfyrag gfyrag requested a review from a team as a code owner May 23, 2025 14:17
Copy link

coderabbitai bot commented May 23, 2025

Walkthrough

The changes introduce and refine support for partial account address matching using the "..." syntax. This includes updates to address filtering logic, type safety improvements, and new test cases for both account and transaction queries. The function isSegmentedAddress is renamed and enhanced, and related test coverage is expanded.

Changes

File(s) Change Summary
internal/storage/ledger/accounts_test.go, internal/storage/ledger/transactions_test.go Added new test cases to verify filtering with partial address patterns and unbounded segment lists.
internal/storage/ledger/resource_aggregated_balances.go, internal/storage/ledger/resource_volumes.go Updated filter predicate usage for address filtering to ensure type safety by casting values to string.
internal/storage/ledger/transactions.go Refactored address filtering logic to use isPartialAddress, improved handling of partial addresses in queries.
internal/storage/ledger/utils.go Renamed and enhanced isSegmentedAddress to isPartialAddress, removed redundant function, updated logic.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant Storage
    participant Utils

    Client->>API: Query accounts/transactions with address filter (e.g., "wallet:xxx:...")
    API->>Storage: Build dataset/query with address filter
    Storage->>Utils: Call isPartialAddress(address)
    Utils-->>Storage: Return true if address ends with "..."
    Storage->>Storage: Construct query for partial match
    Storage-->>API: Return filtered results
    API-->>Client: Respond with filtered accounts/transactions
Loading

Assessment against linked issues

Objective Addressed Explanation
Support for $startWith or $match syntax to find all accounts starting with an identifier (LX-46)
Ability to filter accounts/transactions using "wallet:xxx..." pattern (LX-46)
Test coverage for partial address matching with new syntax (LX-46)

Suggested reviewers

  • Dav-14
  • ascandone

Poem

In the ledger's warren, deep and wide,
Partial addresses now can hide.
With dots and segments, filters flow,
To find all kin, above, below.
Rabbits cheer with every match—
Hop, skip, and fetch each batch!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 1

🧹 Nitpick comments (1)
internal/storage/ledger/transactions.go (1)

297-344: Consider adding input validation for malformed addresses.

While the current logic handles the main use cases correctly, consider adding validation for potentially malformed address patterns to provide better error handling.

func filterAccountAddressOnTransactions(address string, source, destination bool) string {
+	if address == "" {
+		return ""
+	}
+	
	src := strings.Split(address, ":")
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7755c7 and 1b5c04e.

⛔ Files ignored due to path filters (2)
  • go.mod is excluded by !**/*.mod
  • tools/generator/go.mod is excluded by !**/*.mod
📒 Files selected for processing (6)
  • internal/storage/ledger/accounts_test.go (1 hunks)
  • internal/storage/ledger/resource_aggregated_balances.go (2 hunks)
  • internal/storage/ledger/resource_volumes.go (1 hunks)
  • internal/storage/ledger/transactions.go (2 hunks)
  • internal/storage/ledger/transactions_test.go (1 hunks)
  • internal/storage/ledger/utils.go (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/storage/ledger/transactions_test.go (2)
internal/storage/common/resource.go (2)
  • ColumnPaginatedQuery (406-415)
  • ResourceQuery (359-365)
internal/transaction.go (2)
  • Transaction (38-50)
  • Transaction (52-59)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Tests
  • GitHub Check: Dirty
🔇 Additional comments (10)
internal/storage/ledger/transactions_test.go (1)

780-788: LGTM! Good test coverage for unbounded partial address matching.

The new test case correctly validates the "..." syntax for partial address matching. The expected result [tx5, tx4, tx3] aligns with the test data where all these transactions involve accounts with the "users:" prefix.

internal/storage/ledger/resource_volumes.go (2)

69-71: LGTM! Good type safety improvement.

The explicit string casting before calling isPartialAddress improves type safety and makes the code more robust.


113-115: LGTM! Consistent type safety pattern.

The same type safety improvement is applied consistently throughout the file, which is good for maintainability.

internal/storage/ledger/accounts_test.go (1)

182-191: LGTM! Good test coverage for unbounded partial address matching.

The new test case correctly validates the "..." syntax for account address filtering. The expected result of 3 accounts matches the test data where accounts "account:1", "account:2", and "account:3" exist.

internal/storage/ledger/resource_aggregated_balances.go (2)

77-79: LGTM! Good type safety improvement.

The explicit string casting before calling isPartialAddress improves type safety and makes the code more robust. This change is consistent with the pattern used in other resource handlers.


113-115: LGTM! Consistent type safety pattern.

The same type safety improvement is applied consistently, matching the approach used in the PIT branch above and in other resource handlers.

internal/storage/ledger/utils.go (2)

8-21: LGTM! Enhanced partial address detection logic.

The updated isPartialAddress function correctly implements unbounded partial matching by checking if the last segment is "...". The logic properly handles both traditional partial addresses (with empty segments) and the new unbounded syntax.


33-34: Consistent filtering logic for unbounded partial addresses.

The updated condition correctly skips both empty segments and "..." segments during filtering, which aligns with the unbounded partial matching feature. This ensures that "..." segments don't generate specific position constraints.

internal/storage/ledger/transactions.go (2)

300-301: Improved consistency by using isPartialAddress function.

Good refactoring to use the centralized isPartialAddress function instead of manual segment checking. The change from initializing m with a length entry to an empty map is correct for unbounded partial address handling.


308-315: Correct implementation of unbounded partial address logic.

The logic properly handles unbounded partial addresses by:

  1. Breaking early when "..." is encountered as the last segment (lines 308-310)
  2. Only adding the length constraint when the last segment is not "..." (lines 313-315)

This ensures that addresses ending with "..." can match any number of trailing segments.

Comment on lines +28 to +30
if src[len(src)-1] != "" {
parts = append(parts, fmt.Sprintf("jsonb_array_length(%s_array) = %d", key, len(src)))
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify edge case handling for address ending with ":"

The condition src[len(src)-1] != "" prevents adding the array length constraint when the last segment is "...". However, consider the edge case where an address ends with ":" (e.g., "account:"), which would create an empty last segment.


🏁 Script executed:

#!/bin/bash
# Test edge cases for addresses ending with colon
echo "Testing address patterns that end with colon..."

# Search for test cases that might cover this scenario
rg -A 10 -B 2 ".*:\"?\s*$" --type go

# Look for existing test coverage of edge cases
ast-grep --pattern 'func $_(t *testing.T) {
  $$$
  address := "$_:"
  $$$
}'

Length of output: 72841


#!/bin/bash

Show the implementation of filterAccountAddress in utils.go

rg -n "func filterAccountAddress" -A 50 internal/storage/ledger/utils.go

Also dump the file around the array-length check

sed -n '1,200p' internal/storage/ledger/utils.go | sed -n '1,80p'


#!/bin/bash

Extract the full implementation of filterAccountAddress to inspect edge-case handling

rg -n "func filterAccountAddress" -A50 -B2 internal/storage/ledger/utils.go


Add tests and clarify trailing-colon behavior in filterAccountAddress

The if src[len(src)-1] != "" check in internal/storage/ledger/utils.go (lines ~28–30) intentionally skips the length constraint for addresses ending with “:”, but we have no coverage or documentation for this edge case.

• File: internal/storage/ledger/utils.go, around lines 27–30

if src[len(src)-1] != "" {
    parts = append(parts, fmt.Sprintf("jsonb_array_length(%s_array) = %d", key, len(src)))
}

• Add unit tests for inputs like "account:" to verify the generated SQL (it should only enforce prefix matching, no array-length check).
• Document in code (or GoDoc) that a trailing colon enables prefix/sub-account matching by design.

🤖 Prompt for AI Agents
In internal/storage/ledger/utils.go around lines 27 to 30, the condition
src[len(src)-1] != "" skips adding the array length constraint for addresses
ending with a colon, but this behavior is undocumented and lacks test coverage.
Add unit tests for inputs like "account:" to verify that the generated SQL
enforces only prefix matching without the array-length check. Also, update the
function's comments or GoDoc to clearly document that a trailing colon enables
prefix or sub-account matching by design.

Copy link

codecov bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.42%. Comparing base (83c057f) to head (1b5c04e).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #953      +/-   ##
==========================================
+ Coverage   82.36%   82.42%   +0.06%     
==========================================
  Files         141      141              
  Lines        7829     7835       +6     
==========================================
+ Hits         6448     6458      +10     
+ Misses       1056     1054       -2     
+ Partials      325      323       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gfyrag gfyrag added this pull request to the merge queue May 26, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 26, 2025
@gfyrag gfyrag added this pull request to the merge queue May 26, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 26, 2025
@gfyrag gfyrag added this pull request to the merge queue May 26, 2025
Merged via the queue into main with commit 56a0090 May 26, 2025
10 checks passed
@gfyrag gfyrag deleted the feat/unbounded-partial-addresses branch May 26, 2025 14:00
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