Skip to content

fix(market): narrow owner queries to the filtered deployment - #2085

Open
baktun14 wants to merge 1 commit into
akash-network:mainfrom
baktun14:fix/market-owner-query-dseq-prefix
Open

baktun14 wants to merge 1 commit into
akash-network:mainfrom
baktun14:fix/market-owner-query-dseq-prefix

Conversation

@baktun14

@baktun14 baktun14 commented Oct 6, 2026

Copy link
Copy Markdown

Description

Closes: N/A, no tracking issue

When filters.owner is set, the orders, bids and leases queries walk every entry under the owner prefix and check dseq, gseq and oseq on each one. A query for one deployment therefore reads everything the owner has in state, closed and lost entries included. Its cost follows the owner's history, not the size of the result.

This extends the range prefix with the dseq, gseq and oseq filters in key order (ownerOrderPrefix in x/market/keeper/grpc_query.go). The filters are still applied per entry, so results don't change. A pagination key that falls outside the narrowed prefix keeps the owner-wide prefix, because that range would otherwise fail with collections: invalid iterator.

On mainnet today, bids/list?filters.owner=...&filters.dseq=... takes about 1.1 s on a public API node for an owner with more than 10k bids in state (30 ms for an owner with none), and the same for a dseq that doesn't exist. Console polls this query while a deployment waits for bids, and one busy owner polling it was enough to push the shared API nodes past our proxy's timeout.

Tests:

  • TestGRPCQueryOwnerFiltersReadOnlyMatchingEntries measures store gas for owner queries filtered by dseq, by dseq+gseq and by the full order ID, before and after the owner gains 99 other deployments and a second group. The gas has to stay identical. On main the dseq-filtered orders query goes from 4,674 to 282,903 gas.
  • TestGRPCQueryOwnerResumeKeyOutsideDSeqFilter covers the pagination fallback.

This is a query-only change with no state or consensus impact. Could it go into a v2.1.x patch, so API node operators can roll it without an upgrade?


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow-up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change (not breaking)
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification (none exists)
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md (not updated per fix in recent PRs)
  • included comments for documenting Go code
  • updated the relevant documentation or specification (no behavior change to document)
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

The owner paths of the orders, bids and leases queries iterated every
entry under the owner prefix and applied the dseq, gseq and oseq filters
per entry. A query for one deployment therefore read everything the
owner has in state, closed and lost entries included, so its cost grew
with the owner's history rather than with the result.

Extend the prefix with the dseq, gseq and oseq filters in key order.
Results are unchanged since the filters are still applied per entry. A
resume key that falls outside the narrowed prefix keeps the owner-wide
prefix, as before.

Signed-off-by: Maxime Beauchamp <15185355+baktun14@users.noreply.github.com>
@baktun14
baktun14 requested a review from a team as a code owner October 6, 2026 20:56
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: akash-network/node/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: b3520963-5dea-4f5d-b44f-299fd830c109
📥 Commits

Reviewing files that changed from the base of the PR and between 5193e54 and a9b5c74.

📒 Files selected for processing (3)
  • x/market/keeper/grpc_query.go
  • x/market/keeper/grpc_query_test.go
  • x/market/keeper/keeper_test.go

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 3 remain after this review.


Walkthrough

Owner-scoped order, bid, and lease queries now use request filters and resume keys to narrow primary-map scans. New tests check query gas use and pagination behavior. Test setup helpers now accept group identifiers.

Changes

Owner-Scoped Market Queries

Layer / File(s) Summary
Filter-aware owner scan prefixes
x/market/keeper/grpc_query.go
Order, bid, and lease owner scans build narrower prefixes from DSeq, GSeq, and OSeq filters. Bid and lease scans use the order portion of the resume key when available.
Gas and pagination coverage
x/market/keeper/grpc_query_test.go, x/market/keeper/keeper_test.go
Query tests check that unrelated deployments and sibling groups do not increase gas for filtered scans. They also check pagination resumes outside a DSeq filter. Test setup helpers accept a group ID when creating orders, bids, and leases.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: troian

Merge Risk: ⚪ Minimal · up to a9b5c

No identified issue blocks merging this query change after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: narrowing owner queries to the filtered deployment.
Description check ✅ Passed The description explains the query inefficiency, the prefix change, pagination handling, and the tests. It is directly related to the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the order keys,
Then bounds each scan with careful ease.
The bids and leases follow suit,
While gas tests measure each route.
Page by page, the filters hold,
And group IDs join the fold.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant