Skip to content

fix(market): enforce OrderMaxBids with >= instead of >#2068

Open
renezander030 wants to merge 1 commit into
akash-network:mainfrom
renezander030:fix/market-ordermaxbids-off-by-one
Open

fix(market): enforce OrderMaxBids with >= instead of >#2068
renezander030 wants to merge 1 commit into
akash-network:mainfrom
renezander030:fix/market-ordermaxbids-off-by-one

Conversation

@renezander030
Copy link
Copy Markdown

Hi, and thanks for all the work on the node.

This fixes the OrderMaxBids off-by-one reported in akash-network/support#413.

CreateBid in x/market/handler/server.go compared the existing bid count against OrderMaxBids with >:

if ms.keepers.Market.BidCountForOrder(ctx, msg.ID.OrderID()) > params.OrderMaxBids {

BidCountForOrder counts Open, Active and Closed bids, so the count reaches OrderMaxBids exactly when the cap is hit. With >, the check only fired at OrderMaxBids + 1, so one extra bid was always allowed. This switches the comparison to >=.

Test

Added TestCreateBidExceedsOrderMaxBids: it sets the cap to 1, seeds one bid via the keeper, then asserts a second bid through the handler is rejected with "too many existing bids". It fails on the old > (the second bid falls through to an "unknown provider" error) and passes with >=.

go test ./x/market/handler/ and go vet ./x/market/handler/ pass, and gofmt is clean.

Note

This changes consensus behaviour (a bid that previously succeeded now fails), so it belongs in a coordinated upgrade. I saw the code freeze for the upcoming network upgrade, so feel free to queue it for whenever that lands. Happy to adjust if you would rather have BidCountForOrder exclude Closed bids, which the issue flags as a possible follow-up.

CreateBid compared the existing bid count against OrderMaxBids using `>`,
which let one extra bid through and allowed OrderMaxBids+1 bids per order.
BidCountForOrder counts Open, Active and Closed bids, so the count reaches
OrderMaxBids exactly at the cap and the check must reject at that point.

Switch the comparison to `>=` and add a regression test that seeds an
order to its cap and asserts a further bid is rejected with
"too many existing bids".

Closes akash-network/support#413

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@renezander030 renezander030 requested a review from a team as a code owner June 3, 2026 06:23
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 657cbd3c-7346-4535-87e5-cff05779947b

📥 Commits

Reviewing files that changed from the base of the PR and between 3efe26b and edce4db.

📒 Files selected for processing (2)
  • x/market/handler/handler_test.go
  • x/market/handler/server.go

Walkthrough

The PR fixes an off-by-one error in bid count validation. The CreateBid handler now rejects bids when the existing count reaches the maximum instead of only when it exceeds it, coupled with a regression test that validates the corrected boundary behavior.

Changes

Bid Maximum Boundary Condition Fix

Layer / File(s) Summary
Bid count boundary condition fix and regression test
x/market/handler/server.go, x/market/handler/handler_test.go
The CreateBid bid-count limit check changed from > params.OrderMaxBids to >= params.OrderMaxBids, correctly rejecting bids when the count reaches the configured maximum. A new regression test TestCreateBidExceedsOrderMaxBids validates the fix by configuring OrderMaxBids to 1, pre-seeding an order with one bid via the keeper, and verifying the handler rejects an additional bid request with mv1.ErrInvalidBid and "too many existing bids" message.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A hop, a skip, a boundary made tight,
Off-by-one gremlins fixed with new might,
Bid caps now respected at the line,
Tests ensure the logic's divine! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: changing the OrderMaxBids enforcement from '>' to '>=' comparison, which directly matches the primary change in server.go.
Description check ✅ Passed The description thoroughly explains the off-by-one bug, the fix rationale, test coverage, and relevant context about consensus behavior changes, all directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

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