Fix off-by-one error in child bounty limit validation (fixes #10652) #10713
+97
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #10652
This PR fixes an off-by-one error in
pallet-child-bountieswhere theadd_child_bountyfunction allowed creatingMaxActiveChildBountyCount + 1child bounties instead of being capped atMaxActiveChildBountyCount.The validation check used
<=(less than or equal) instead of<(less than), allowing the count to exceed the limit by one when the current count equaledMaxActiveChildBountyCount. Since the count is incremented immediately after the validation check, this resulted inMaxActiveChildBountyCount + 1active child bounties.Integration
No integration changes required. This is a bug fix that ensures runtime configuration limits are properly enforced. Downstream projects will automatically benefit from the corrected limit enforcement without any code changes needed.
Impact:
Review Notes
Problem Analysis
The bug was located in
substrate/frame/child-bounties/src/lib.rsat line 290. The validation check:When
ParentChildBounties::<T>::get(parent_bounty_id)equalsMaxActiveChildBountyCount, the check passes (because<=), and then the count is incremented on line 323, resulting inMaxActiveChildBountyCount + 1.Solution
File:
substrate/frame/child-bounties/src/lib.rsChanged the comparison operator from
<=to<and removed the unnecessaryas u32cast:Rationale:
<ensures that when the count equalsMaxActiveChildBountyCount, the check fails before incrementingas u32cast is a cleanup sinceMaxActiveChildBountyCount::get()already returnsu32Test Coverage
File:
substrate/frame/child-bounties/src/tests.rsNew test:
max_active_child_bounty_count_is_strictly_enforced()MaxActiveChildBountyCount(2 in test config) child bounties successfullyMaxActiveChildBountyCountError::TooManyChildBountiesMaxActiveChildBountyCount(not incremented)Fixed existing test:
accept_curator_handles_different_deposit_calculationsTesting
Code Quality
Checklist
Trequired)/cmd label T1-FRAME D0-easy I2-bugto add labels after PR creationprdoc/pr_10652.prdoc)Bot Commands
After creating the PR, use these commands in a comment:
Labeling:
Verify PRDoc (optional):
Format code (if needed):