Skip to content

feat(minibf): adjust max scan limit via config#911

Merged
scarmuega merged 1 commit intomainfrom
feat/max-scan-config
Feb 17, 2026
Merged

feat(minibf): adjust max scan limit via config#911
scarmuega merged 1 commit intomainfrom
feat/max-scan-config

Conversation

@scarmuega
Copy link
Member

@scarmuega scarmuega commented Feb 17, 2026

Summary by CodeRabbit

  • New Features
    • Added configurable maximum scan item limit for pagination operations, allowing customization of how many items can be scanned per request. The default limit is set to 3,000 items.

@coderabbitai
Copy link

coderabbitai bot commented Feb 17, 2026

📝 Walkthrough

Walkthrough

This change introduces a configurable maximum scan items limit to the MinibfConfig struct and updates the pagination enforcement mechanism to use this configurable value. The new field is threaded through route handlers to enforce per-request scan limits instead of using a hardcoded default.

Changes

Cohort / File(s) Summary
Configuration
crates/core/src/config.rs, crates/minibf/src/test_support.rs, src/bin/dolos/init.rs
Added max_scan_items: Option<u64> field to MinibfConfig and initialized it in test and initialization code paths.
Pagination Logic
crates/minibf/src/pagination.rs
Introduced public DEFAULT_MAX_SCAN_ITEMS constant (3_000) and updated enforce_max_scan_limit method to accept an optional max_scan_items parameter, falling back to the default when None.
Route Handlers
crates/minibf/src/routes/accounts.rs, crates/minibf/src/routes/addresses.rs, crates/minibf/src/routes/assets.rs, crates/minibf/src/routes/metadata.rs
Updated multiple call sites to pass domain.config.max_scan_items to enforce_max_scan_limit instead of invoking it without arguments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • chore: Relax max pagination limit #876: Modifies MAX_SCAN_ITEMS constant in pagination logic—this PR builds on similar pagination scan-limit changes by making the limit configurable across the system.

Poem

🐰 Hops through configs with glee,
A limit now set by thee!
No hardcoded chains,
Just flexible reins—
Pagination flows wild and free! 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: making the max scan limit configurable via a new optional config field rather than using a hardcoded value.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/max-scan-config

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.

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/minibf/src/pagination.rs (1)

211-217: ⚠️ Potential issue | 🟡 Minor

Some(0) silently disables all scan-protected endpoints.

When max_scan_items is explicitly configured as 0, limit becomes 0 and the first request with page=1, count=1 (yielding 1 * 1 = 1 > 0) immediately returns ScanLimitExceeded. Every paginated call to every protected endpoint will be rejected with an unhelpful 400 error, with no indication that the endpoint is effectively disabled.

Consider clamping the configured value to a minimum of 1 (or count_max = 100) at resolution time:

🛡️ Proposed fix
 pub fn enforce_max_scan_limit(&self, max_scan_items: Option<u64>) -> Result<(), PaginationError> {
-    let limit = max_scan_items.unwrap_or(DEFAULT_MAX_SCAN_ITEMS);
+    let limit = max_scan_items
+        .filter(|&v| v > 0)
+        .unwrap_or(DEFAULT_MAX_SCAN_ITEMS);
     if self.page * self.count as u64 > limit {

Alternatively, document in MinibfConfig that max_scan_items = 0 is treated as "use default" rather than "allow zero items".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/minibf/src/pagination.rs` around lines 211 - 217, The current
enforce_max_scan_limit (max_scan_items: Option<u64>) treats Some(0) as a hard
zero which disables endpoints; change the resolution of max_scan_items so 0 is
not allowed—either clamp to a minimum of 1 (or to DEFAULT_MAX_SCAN_ITEMS) when
computing limit or treat Some(0) as None (use DEFAULT_MAX_SCAN_ITEMS); update
the logic in enforce_max_scan_limit to derive limit from max_scan_items with
that clamp/translate and then keep the existing comparison (return
Err(PaginationError::ScanLimitExceeded) only when the computed limit is
exceeded).
🧹 Nitpick comments (1)
crates/minibf/src/pagination.rs (1)

300-342: Consider adding unit tests for enforce_max_scan_limit.

The test module covers should_skip and the InvalidFromTo error message, but enforce_max_scan_limit has no direct unit tests. Given this is the primary change, tests covering (a) None → default fallback, (b) Some(custom_limit) enforced correctly, and (c) ScanLimitExceeded returned when limit is exceeded would prevent regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/minibf/src/pagination.rs` around lines 300 - 342, Add three unit tests
in the existing tests module that exercise enforce_max_scan_limit: (1) a test
where PaginationParameters.scan_limit is None and enforce_max_scan_limit returns
the default fallback limit (assert returned limit equals expected
DEFAULT_SCAN_LIMIT), (2) a test where scan_limit is Some(custom) and
enforce_max_scan_limit returns that custom value, and (3) a test that simulates
a scan count greater than the enforced limit and asserts the function returns
PaginationError::ScanLimitExceeded (or that calling code converts it into the
appropriate response body/message). Locate and call the enforce_max_scan_limit
function (or the method on Pagination if it’s implemented there) and use
PaginationParameters/Pagination constructors as needed to set up parameters and
trigger each branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@crates/minibf/src/pagination.rs`:
- Around line 211-217: The current enforce_max_scan_limit (max_scan_items:
Option<u64>) treats Some(0) as a hard zero which disables endpoints; change the
resolution of max_scan_items so 0 is not allowed—either clamp to a minimum of 1
(or to DEFAULT_MAX_SCAN_ITEMS) when computing limit or treat Some(0) as None
(use DEFAULT_MAX_SCAN_ITEMS); update the logic in enforce_max_scan_limit to
derive limit from max_scan_items with that clamp/translate and then keep the
existing comparison (return Err(PaginationError::ScanLimitExceeded) only when
the computed limit is exceeded).

---

Nitpick comments:
In `@crates/minibf/src/pagination.rs`:
- Around line 300-342: Add three unit tests in the existing tests module that
exercise enforce_max_scan_limit: (1) a test where
PaginationParameters.scan_limit is None and enforce_max_scan_limit returns the
default fallback limit (assert returned limit equals expected
DEFAULT_SCAN_LIMIT), (2) a test where scan_limit is Some(custom) and
enforce_max_scan_limit returns that custom value, and (3) a test that simulates
a scan count greater than the enforced limit and asserts the function returns
PaginationError::ScanLimitExceeded (or that calling code converts it into the
appropriate response body/message). Locate and call the enforce_max_scan_limit
function (or the method on Pagination if it’s implemented there) and use
PaginationParameters/Pagination constructors as needed to set up parameters and
trigger each branch.

@scarmuega scarmuega merged commit 16674d7 into main Feb 17, 2026
12 checks passed
@scarmuega scarmuega deleted the feat/max-scan-config branch February 17, 2026 23:10
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.

1 participant