fix(market): bound bids per order with a monotonic bids-ever-created counter#2071
fix(market): bound bids per order with a monotonic bids-ever-created counter#2071renezander030 wants to merge 2 commits into
Conversation
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>
…counter CreateBid enforced OrderMaxBids by scanning the order's open, active and closed bids on every call. Counting closed bids was the only backpressure on an order, so the count doubled as a lifetime cap; the scan also missed lost bids entirely and cost O(n) across three state indexes per bid. Replace the scan with a per-order monotonic counter (bids-ever-created), bumped on CreateBid and never decremented when a bid closes or loses. The cap check reads the counter in O(1), and total bid records per order stay bounded by OrderMaxBids regardless of create/close churn, which closes the state-inflation loop where a provider cycles CreateBid > CloseBid forever without ever hitting the cap. Orders that predate the counter are seeded lazily from a scan of all stored bids (including lost and closed), so the cap carries over an upgrade or genesis import unchanged and no store migration is needed. BidCountForOrder now returns only live (open or active) bids for consumers that care about current competition on an order. Follow-up to akash-network#2068, as discussed in akash-network#2068 (comment) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughThis PR replaces bid capacity enforcement based on live bid count with a monotonic "bids ever created" counter, preventing bid-create/close loops from exhausting state. The keeper adds persistent counter storage, exports a new ChangesBid Capacity Counter Implementation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Tools execution failed with the following error: Failed to run tools: Ping-pong health check failed 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. Comment |
Follow-up to #2068, implementing the design discussed in #2068 (comment) (ack: #2068 (comment)).
Note: stacked on #2068 — the first commit here is that PR's commit; the diff collapses to the second commit once #2068 merges.
Problem
CreateBidenforcedOrderMaxBidsby scanning the order's open, active and closed bids on every call:CreateBid>CloseBidforever, never hits the cap, and every cycle leaves aBidClosedrecord behind.BidLostentirely, so lost bids escaped the cap.CreateBid.Change
bid_counts, prefix0x12 0x06): bumped onCreateBid, never decremented when a bid closes or loses. The cap check reads it in O(1), and total bid records per order stay bounded byOrderMaxBidsregardless of churn — closed and lost bids included.BidCountForOrdernow returns only live (open or active) bids, for consumers that care about current competition on an order rather than the lifetime cap.Tests
TestCreateBidCapSurvivesBidChurn— closing a bid drops the live count to zero but does not free cap capacity; a further bid is rejected.TestBidsEverCreatedLazySeedsFromStore— bids seeded directly in the store (genesis-style, no counter record) still count toward the cap, including closed and lost ones.TestCreateBidExceedsOrderMaxBidsfrom fix(market): enforce OrderMaxBids with >= instead of > #2068 passes unchanged, now exercising the counter path.go test ./x/market/... -count=1passes; full repo builds.🤖 Generated with Claude Code