Skip to content

Filter hardware offers and add bounded marketplace pages - #34

Merged
NetworkTheoryAppliedResearchInstitute merged 8 commits into
NTARI-RAND:mainfrom
nirmalhk7:nirmal/cloudy-market-offers
Nov 9, 2026
Merged

NetworkTheoryAppliedResearchInstitute merged 8 commits into
NTARI-RAND:mainfrom
nirmalhk7:nirmal/cloudy-market-offers

Conversation

@nirmalhk7

Copy link
Copy Markdown
Contributor

Marketplace browsing currently filters only by category and returns every matching offer. This adds exact maker-key and declared fiat/member-credit filters to GET /api/v1/market/listings, plus opt-in bounded pagination. Multiple selected rails match any selected rail; category and maker filters combine with that selection.

Supplying limit or cursor enables pages with a default of 50 offers and a maximum of 100. Append-position cursors skip sale records and remain stable as new entries arrive. Valid existing category-only requests retain their summary fields, ordering, and empty-category behavior. Malformed filters, duplicate singleton parameters, and invalid bounds return HTTP 400, including invalid nonempty categories that previously returned an empty result.

Traversal avoids copying the full catalogue, category result set, or sales histories, and responses are written after releasing the store lock. Sparse filters can still scan the remaining history, pages are live rather than frozen snapshots, and legacy unpaged requests remain unbounded. Payment filters describe signed acceptance only; escrow policy and credit-settlement authorization are unchanged. API documentation and conformance bindings describe these boundaries.

Validation: new HTTP regressions failed before implementation and pass with the change. Fresh local marketplace acceptance tests, the full go test -race ./... -count=1 suite, go build ./..., go vet ./..., formatting, and whitespace checks passed. Coverage includes combined filters, dual-rail offers, pagination across sales and appends, malformed queries, page bounds, and legacy responses. Hosted CI and human review remain pending.

Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
@nirmalhk7
nirmalhk7 marked this pull request as ready for review November 4, 2026 07:51

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, Nirmal. This is a careful, well-documented change.

What I tested: PR head 4c94728, via merge ref ca74c9d, which sits on current main 5cc982c.

  • CI passed gofmt, vet, build and go test ./... (18 packages ok, 0 failures, the same as main). DCO passes.
  • I read the code against the docs. I also ran a line-for-line port of Browse through a random property check: 20,000 logs, 37,970 pages, with new entries appended between pages. Every match came back exactly once, in append order, and no page went over its limit.
  • Input checks, last-page handling and the limits the docs state all match the code. The listing view still has the same nine fields.

Nothing blocking. A few small items, fine as a quick extra commit or a follow-up:

  1. internal/consumerapi/market_browse_test.go:117 checks that the row has 9 fields, but the comment at :99-100 and docs/marketplace-browse.md:87 say it checks the exact fields. Compare the sorted keys with the nine expected names, or reword the docs.
  2. market_browse_test.go:152: maker=aa&maker=bb gets a 400 because aa is not a valid key, so it would still pass without the repeat check at market_query.go:19. Use two valid 64-hex keys, e.g. strings.Repeat("ab", 32) and strings.Repeat("cd", 32).
  3. market_browse_test.go:176-177: nothing checks next_cursor on a cursor-only request. Asserting "50" for cursor=0 and "100" for limit=100 would pin the cursor-only rule from the docs.
  4. docs/marketplace-browse.md:36: the example {"listings": [], "next_cursor": "125"} can't happen, because next_cursor only comes with a full page. Showing [...] there would match the code.
  5. Cursors across a restart (internal/market/browse.go:32, server.go:254): once the new in-memory log grows past an old cursor, that cursor returns 200 and skips the earlier offers without an error. Tying the cursor to the instance would let clients notice the restart that docs/marketplace-browse.md:49-51 mentions: for example, prefix it with an epoch or the log ID and return 400 on a mismatch.
  6. Optional cleanup: Catalog.ByCategory (catalog.go:154) no longer has a production caller and repeats the category match in Browse. A thin wrapper over Browse would keep one code path. The SalesOf comment about the composition root was already out of date before this PR.
  7. Optional wording: at CONFORMANCE.md:84, the phrase from docs/marketplace-browse.md:5-6 ("Maker keys are the existing platform member keys") reads more clearly than "member identity" next to JFA line 7.

For later, not this PR: requests without limit or cursor are still unbounded. You document this, and this PR shortens how long the lock is held. Making paging the default in a follow-up would close it.

Approved at the tested commit 4c94728 on Jodson Graves's instruction.

Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>
Signed-off-by: Nirmal Khedkar <nirmalhk7@gmail.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, Nirmal. Re-reviewed at c7b0a7f.

What I checked:

  • I read the full diff against main and the commits since the 11-04 review (4c94728..c7b0a7f).
  • A dry-run merge onto current main is clean.
  • I reviewed by reading the code and didn't run it. CI hasn't run on this head yet: runs from a fork wait for a maintainer's OK. This approval holds only if it passes. If anything fails, I'll come back to you.

All seven items from last time are done:

  1. Exact field names: internal/consumerapi/market_browse_test.go:101-115.
  2. Two valid repeated maker keys: market_browse_test.go:170.
  3. next_cursor pinned: market_pagination_test.go:21-25.
  4. Exhausted-page example: docs/marketplace-browse.md:35-39.
  5. Restart: tokens are now <logID>:<pos> (market.go:164, market_query.go:89-98). A token from another run gets a 400, and market_restart_test.go covers both the restart and malformed tokens. The log ID was already public via /api/v1/drops/log, so nothing new is exposed. Nice.
  6. ByCategory now wraps browse() (internal/market/catalog.go:153-155), and the SalesOf comment is fixed.
  7. Wording: CONFORMANCE.md:83-84.

Two optional nits are inline, fine to skip or do later.

For later, not this PR:

  • Unpaged reads are still unbounded. That's documented and was deferred in the last review.
  • A maker or rail filter with no category returns nothing, so seeing all of one maker's offers takes one call per category.

Heads-up: once this merges, #36 needs a small rebase. Both PRs add a paragraph at the end of the same CONFORMANCE.md section, and keeping both resolves it.

Approved at c7b0a7f on Jodson Graves's instruction, conditional on CI passing on this commit.

return n, err
}

func marketCursorPosition(cursor, instance string) (int, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional: this check catches stale tokens only because NewServer generates a new operator key on every start (server.go:258, 287), so the log ID changes each run. Could you add a one-line comment saying so? Then if the operator key is ever loaded from disk while the catalogue is still in memory, whoever makes that change will know the tokens need a different per-run value.

Comment thread CONFORMANCE.md
`TestMarketplaceBrowseFilters`, `TestMarketplaceBrowsePagesAcrossSalesAndAppends`,
`TestMarketplaceBrowseRejectsMalformedFilters`,
`TestMarketplaceBrowseLegacyAndEmptyCategory`, `TestMarketplaceBrowsePageBounds`,
and `TestMarketplaceBrowseRejectsCursorFromPreviousInstance`. Continuation tokens

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional: TestMarketplaceBrowseSummaryFields and TestMarketplaceBrowseRejectsMalformedInstanceCursor also bind behavior this section describes, so they're worth listing here too.

@NetworkTheoryAppliedResearchInstitute
NetworkTheoryAppliedResearchInstitute merged commit 8bdbf17 into NTARI-RAND:main Nov 9, 2026
2 checks passed
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