Skip to content

Add optional auto-rebag within on-idle#8684

Merged
nkpar merged 85 commits intomasterfrom
8403-pallet-bags-list-add-optional-auto-rebag-within-on-idle
Jul 1, 2025
Merged

Add optional auto-rebag within on-idle#8684
nkpar merged 85 commits intomasterfrom
8403-pallet-bags-list-add-optional-auto-rebag-within-on-idle

Conversation

@nkpar
Copy link
Contributor

@nkpar nkpar commented May 28, 2025

Implemented an on_idle hook for automatic rebagging of accounts, enabling incremental correction of account positions within the bags-list during the idle phase of block execution. Introduced new storages and configurable constants to support this functionality, along with improvements in logging and internal helpers.

Implemented an `on_idle` hook for automatic rebagging of accounts, enabling incremental correction of account positions within the bags-list during the idle phase of block execution. Introduced new storages and configurable constants to support this functionality, along with improvements in logging and internal helpers.
@nkpar nkpar linked an issue May 28, 2025 that may be closed by this pull request
Make it work on kitchensink-runtime
@nkpar nkpar added the T2-pallets This PR/Issue is related to a particular pallet. label May 28, 2025
@nkpar nkpar changed the title WIP Add optional auto-rebag within on-idle May 28, 2025
@Ank4n Ank4n self-requested a review May 28, 2025 14:37
nkpar added 3 commits May 28, 2025 16:29
Refactored rebagging logic into `rebag_internal` to simplify code and improve readability. Introduced the `AutoRebagPerBlock` type, including its integration into relevant runtimes.
Clarify the behavior of the `NextNodeAutoRebagging` pointer to indicate the next node for rebagging rather than the last auto-rebagged node. Adjust comments and logs for improved accuracy and readability, ensuring consistent and precise descriptions.
@nkpar
Copy link
Contributor Author

nkpar commented May 28, 2025

/cmd --help

@github-actions
Copy link
Contributor

Command help:
usage: /cmd  [--help] [--quiet] [--clean] [--image IMAGE]
             {bench,bench-omni,fmt,update-ui,prdoc} ...

A command runner for polkadot-sdk repo

positional arguments:
  {bench,bench-omni,fmt,update-ui,prdoc}
                        a command to run
    bench (bench-omni)  Runs benchmarks (frame omni bencher)
    fmt                 Formats code (cargo +nightly-VERSION fmt) and configs
                        (taplo format)
    update-ui           Updates UI tests
    prdoc               Generates PR documentation

options:
  --help                help for help if you need some help
  --quiet               Won't print start/end/failed messages in PR
  --clean               Clean up the previous bot's & author's comments in PR
  --image IMAGE         Override docker image '--image
                        docker.io/paritytech/ci-unified:latest'

### Command 'bench'
usage: /cmd bench [-h] [--quiet] [--clean] [--image IMAGE]
                  [--runtime [{dev,westend,rococo,asset-hub-westend,asset-hub-rococo,bridge-hub-rococo,bridge-hub-westend,collectives-westend,coretime-rococo,coretime-westend,glutton-westend,people-rococo,people-westend} ...]]
                  [--pallet [PALLET ...]] [--fail-fast]

options:
  -h, --help            show this help message and exit
  --quiet               Won't print start/end/failed messages in PR
  --clean               Clean up the previous bot's & author's comments in PR
  --image IMAGE         Override docker image '--image
                        docker.io/paritytech/ci-unified:latest'
  --runtime [{dev,westend,rococo,asset-hub-westend,asset-hub-rococo,bridge-hub-rococo,bridge-hub-westend,collectives-westend,coretime-rococo,coretime-westend,glutton-westend,people-rococo,people-westend} ...]
                        Runtime(s) space separated
  --pallet [PALLET ...]
                        Pallet(s) space separated
  --fail-fast           Fail fast on first failed benchmark

**Examples**:
 Runs all benchmarks 
 /cmd bench

 Runs benchmarks for pallet_balances and pallet_multisig for all runtimes which have these pallets. **--quiet** makes it to output nothing to PR but reactions
 /cmd bench --pallet pallet_balances pallet_xcm_benchmarks::generic --quiet
 
 Runs bench for all pallets for westend runtime and fails fast on first failed benchmark
 /cmd bench --runtime westend --fail-fast
 
 Does not output anything and cleans up the previous bot's & author command triggering comments in PR 
 /cmd bench --runtime westend rococo --pallet pallet_balances pallet_multisig --quiet --clean


### Command 'bench-omni'
usage: /cmd bench [-h] [--quiet] [--clean] [--image IMAGE]
                  [--runtime [{dev,westend,rococo,asset-hub-westend,asset-hub-rococo,bridge-hub-rococo,bridge-hub-westend,collectives-westend,coretime-rococo,coretime-westend,glutton-westend,people-rococo,people-westend} ...]]
                  [--pallet [PALLET ...]] [--fail-fast]

options:
  -h, --help            show this help message and exit
  --quiet               Won't print start/end/failed messages in PR
  --clean               Clean up the previous bot's & author's comments in PR
  --image IMAGE         Override docker image '--image
                        docker.io/paritytech/ci-unified:latest'
  --runtime [{dev,westend,rococo,asset-hub-westend,asset-hub-rococo,bridge-hub-rococo,bridge-hub-westend,collectives-westend,coretime-rococo,coretime-westend,glutton-westend,people-rococo,people-westend} ...]
                        Runtime(s) space separated
  --pallet [PALLET ...]
                        Pallet(s) space separated
  --fail-fast           Fail fast on first failed benchmark

**Examples**:
 Runs all benchmarks 
 /cmd bench

 Runs benchmarks for pallet_balances and pallet_multisig for all runtimes which have these pallets. **--quiet** makes it to output nothing to PR but reactions
 /cmd bench --pallet pallet_balances pallet_xcm_benchmarks::generic --quiet
 
 Runs bench for all pallets for westend runtime and fails fast on first failed benchmark
 /cmd bench --runtime westend --fail-fast
 
 Does not output anything and cleans up the previous bot's & author command triggering comments in PR 
 /cmd bench --runtime westend rococo --pallet pallet_balances pallet_multisig --quiet --clean


### Command 'fmt'
usage: /cmd fmt [-h] [--quiet] [--clean] [--image IMAGE]

options:
  -h, --help     show this help message and exit
  --quiet        Won't print start/end/failed messages in PR
  --clean        Clean up the previous bot's & author's comments in PR
  --image IMAGE  Override docker image '--image docker.io/paritytech/ci-
                 unified:latest'


### Command 'update-ui'
usage: /cmd update-ui [-h] [--quiet] [--clean] [--image IMAGE]

options:
  -h, --help     show this help message and exit
  --quiet        Won't print start/end/failed messages in PR
  --clean        Clean up the previous bot's & author's comments in PR
  --image IMAGE  Override docker image '--image docker.io/paritytech/ci-
                 unified:latest'


### Command 'prdoc'
usage: /cmd prdoc [-h] [--pr PR]
                  [--audience [{runtime_dev,runtime_user,node_dev,node_operator,todo} ...]]
                  [--bump {patch,minor,major,silent,ignore,none}] [--force]

options:
  -h, --help            show this help message and exit
  --pr PR               The PR number to generate the PrDoc for.
  --audience [{runtime_dev,runtime_user,node_dev,node_operator,todo} ...]
                        The audience of whom the changes may concern. Example:
                        --audience runtime_dev node_dev
  --bump {patch,minor,major,silent,ignore,none}
                        A default bump level for all crates. Example: --bump
                        patch
  --force               Whether to overwrite any existing PrDoc.

@nkpar
Copy link
Contributor Author

nkpar commented May 28, 2025

/cmd fmt

@nkpar
Copy link
Contributor Author

nkpar commented May 28, 2025

/cmd prdoc --audience runtime_dev --bump minor

github-actions bot and others added 4 commits May 28, 2025 17:17
Make tests work
Improve auto-rebagging with error tracking and logging.

Added detailed logging for weight limits, successful and failed rebags, and unexpected cursor states. Enhanced robustness by handling pallet lock states and iterator failures gracefully.
@nkpar
Copy link
Contributor Author

nkpar commented May 28, 2025

/cmd fmt

Copy link
Contributor

@Ank4n Ank4n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great — I just want to do one more pass before approving.

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good so far 👍 mainly missing some unit tests

nkpar added 2 commits May 29, 2025 11:42
Removed the requirement to pass the score provider function as a parameter to `rebag_internal`.
Use `defensive!` macro for logging in auto-rebag errors.
@paritytech paritytech deleted a comment from github-actions bot Jul 1, 2025
@paritytech paritytech deleted a comment from github-actions bot Jul 1, 2025
@paritytech paritytech deleted a comment from github-actions bot Jul 1, 2025
@nkpar
Copy link
Contributor Author

nkpar commented Jul 1, 2025

/cmd bench --pallet pallet_bags_list

@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2025

Command "bench --pallet pallet_bags_list" has started 🚀 See logs here

@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/16003434560
Failed job name: test-linux-stable-runtime-benchmarks

@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2025

Command "bench --pallet pallet_bags_list" has finished ✅ See logs here

Details

Subweight results:
File Extrinsic Old New Change [%]
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_bags_list.rs put_in_front_of 917.43us 1.08ms +17.20
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_bags_list.rs rebag_non_terminal 737.83us 862.27us +16.87
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_bags_list.rs rebag_terminal 735.59us 857.28us +16.54
substrate/frame/bags-list/src/weights.rs rebag_non_terminal 729.72us 773.70us +6.03
substrate/frame/bags-list/src/weights.rs rebag_terminal 728.18us 770.63us +5.83
substrate/frame/staking-async/runtimes/parachain/src/weights/pallet_bags_list.rs on_idle 8.07ms Added
substrate/frame/bags-list/src/weights.rs on_idle 8.17ms Added
polkadot/runtime/westend/src/weights/pallet_bags_list.rs on_idle 8.17ms Added
cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/pallet_bags_list.rs on_idle 8.54ms Added
Command output:

✅ Successful benchmarks of runtimes/pallets:
-- dev: ['pallet_bags_list']
-- westend: ['pallet_bags_list']
-- asset-hub-westend: ['pallet_bags_list']

@nkpar nkpar enabled auto-merge July 1, 2025 16:47
@nkpar nkpar added this pull request to the merge queue Jul 1, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 1, 2025
@nkpar nkpar added this pull request to the merge queue Jul 1, 2025
Merged via the queue into master with commit 6824a67 Jul 1, 2025
241 checks passed
@nkpar nkpar deleted the 8403-pallet-bags-list-add-optional-auto-rebag-within-on-idle branch July 1, 2025 18:08
bkchr pushed a commit that referenced this pull request Jul 2, 2025
Implemented an `on_idle` hook for automatic rebagging of accounts,
enabling incremental correction of account positions within the
bags-list during the idle phase of block execution. Introduced new
storages and configurable constants to support this functionality, along
with improvements in logging and internal helpers.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
github-merge-queue bot pushed a commit that referenced this pull request Jul 12, 2025
…9166)

quick follow-up to #8684,
ensuring all blocks don't have x events when the feature is enabled (as
it is now in WAH)

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
ordian added a commit that referenced this pull request Jul 24, 2025
* master: (91 commits)
  Add extra information to the harmless error logs during validate_transaction (#9047)
  `sp-tracing`: Remove `test-utils` feature (#9063)
  add try-state check for staking roles -- staker cannot be nominator a… (#9034)
  net/discovery: File persistence for `AddrCache` (#8839)
  dispute-coordinator: handle race with offchain disabling (#9050)
  Align parameters for `EventEmitter::emit_sent_event` (#9057)
  Fetch parent block `api_version` (#9059)
  [XCM Precompile] Rename functions and improve docs in the Solidity interface (#9023)
  Cleanup and improvements for `ControlledValidatorIndices` (#8896)
  reenable 0001-parachains-pvf (#9046)
  Add optional auto-rebag within on-idle (#8684)
  Fix flaxy 0003-block-building-warp-sync test - one more approach (#8974)
  [Staking] [AHM] Fixes insufficient slashing of nominators (and some other small issues). (#8937)
  chore: Bump bounded-collections dep (#9004)
  XCMP and DMP improvements (#8860)
  EPMB/unsigned: fixed multi-page winner computation (#8987)
  Always send full parent header, not only hash, part of collation response (#8939)
  revive: Precompiles should return dummy code when queried (#9001)
  Fix confusing log messages in network protocol behaviour (#8819)
  Fix pallet_migrations benchmark when FailedMigrationHandler emits events (#8694)
  ...
fellowship-merge-bot bot pushed a commit to polkadot-fellows/runtimes that referenced this pull request Aug 15, 2025
This brings in `unstable2507` Polkadot SDK, and integrates new features.

Integrated breaking changes to be verified by the original authors:

- [ ] paritytech/polkadot-sdk#7953 @kianenigma
@Ank4n acatangiu#13
- [x] paritytech/polkadot-sdk#8684 @nkpar
- [x] paritytech/polkadot-sdk#8693 @tiagobndr
@franciscoaguirre
- [x] paritytech/polkadot-sdk#9137
@franciscoaguirre

fixes #837

---------

Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: kianenigma <kian@parity.io>
Co-authored-by: Christian Langenbacher <clangenb+gh@protonmail.ch>
alvicsam pushed a commit that referenced this pull request Oct 17, 2025
Implemented an `on_idle` hook for automatic rebagging of accounts,
enabling incremental correction of account positions within the
bags-list during the idle phase of block execution. Introduced new
storages and configurable constants to support this functionality, along
with improvements in logging and internal helpers.

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ankan <10196091+Ank4n@users.noreply.github.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
alvicsam pushed a commit that referenced this pull request Oct 17, 2025
…9166)

quick follow-up to #8684,
ensuring all blocks don't have x events when the feature is enabled (as
it is now in WAH)

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T2-pallets This PR/Issue is related to a particular pallet.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

pallet-bags-list: Add optional auto-rebag within on-idle

6 participants