[RWF] pallet-scored-pool: fix pool sort logic - #12333
Conversation
|
/cmd prdoc --audience runtime_dev --bump patch |
|
Command "prdoc --audience runtime_dev --bump patch" has failed ❌! See logs here |
|
/cmd prdoc --audience runtime_dev --bump patch |
…time_dev --bump patch'
|
@xlc, please review. |
|
Code change looks right. One wording nit here polkadot-sdk/substrate/frame/scored-pool/src/lib.rs Lines 404 to 407 in 5d6d424 natural Option order is None < Some(_); Reverse<Option<_>> is what makes None end up last. Sorting fix itself looks good.
|
Oops! You're right. The comment had it the other way round. I've updated the code comment, the prdoc, and the PR description. |
| .binary_search_by_key(&Reverse(score), |(_, maybe_score)| { | ||
| Reverse(maybe_score.unwrap_or_default()) | ||
| .binary_search_by_key(&Reverse(Some(score)), |(_, maybe_score)| { | ||
| Reverse(*maybe_score) |
There was a problem hiding this comment.
Would need to check if this causes issues with the current staking system, if that pallet is still used.
There was a problem hiding this comment.
Staking does not interact with this pallet.
|
This pallet doesn't seem to be used by any of our runtimes. Any reason to keep it, or should we deprecate and remove? |
|
/cmd fmt |
1 similar comment
|
/cmd fmt |
sigurpol
left a comment
There was a problem hiding this comment.
LGTM - +1 on Ankan's question (do we need to keep this pallet around? ) but that's a separate discussion
|
Following up on my question above — I've opened #12746 to remove this pallet. Rationale: it isn't used by any runtime in the repo, has had no functional changes in years (only mechanical maintenance touches), and the membership/ranking use cases are covered by @naijauser sorry for the wasted effort here — the bug you found is real, and it's part of why the removal came up. If reviewers on #12746 decide to keep the pallet (or to follow the deprecate-then-remove path in the deprecation checklist first), then this PR should go in and I'll rebase mine on top. Let's hold this one until #12746 is resolved either way. |
No worries, thanks. |
Closes #12259.
Summary
score()usedReverse(maybe_score.unwrap_or_default())as its binary-search key, which maps bothNoneandSome(0)toReverse(0). Rescoring a candidate to0could then insert it after existingNoneentries, violating the documented "descending by score,Nonelast" invariant. Same issue existed in the genesispool.sort_by_key.Fix: key on
Reverse(Option<Score>)instead (Reverse(*maybe_score)/Reverse(Some(score))), sinceOption'sOrdplacesNonebefore allSome(_)(None<Some(_)).Test: added
scoring_to_zero_must_sort_before_none_entriescovering this case.