Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sort pause in bags list and trait SortedListProvider #6328

Open
Tracked by #6498
gpestana opened this issue Nov 1, 2024 · 0 comments
Open
Tracked by #6498

Add sort pause in bags list and trait SortedListProvider #6328

gpestana opened this issue Nov 1, 2024 · 0 comments
Labels
T2-pallets This PR/Issue is related to a particular pallet.

Comments

@gpestana
Copy link
Contributor

gpestana commented Nov 1, 2024

In the multi-block election context, the snapshot creation takes multiple blocks. As the snapshot is ongoing, all the implicit and explicit rebags/put-in-front-of of the voter and target snapshot should be paused.

Currently and in #6034, the bags list and the SortedListProvider trait does not expose a way to pause moving IDs which is OK to run the election in a single-page context.

Implement the sorted list sorting pause before the multi-page election is rolled out.


Goals:

  1. Add a new method to trait SortedListProvider to allow locking and unlocking the ordering of the list's elements.
  2. Implement a mechanism to lock and unlock the ordering of the list iterator returned by SortedListProvider::iter() implementation of the bags-list.
  3. When the lock is set, allow all the bags list mutations that do not change the order of the iterator.

Option 1.

wip implementation at #6510

Return err List::ReorderingNotAllowed whenever a bags-list extrinsic or SortedListProvider method is called that may affect the iterator ordering while the lock is set, ie:

  • SortedListProvider::on_insert (inserting ID in the list will change the iter)
  • SortedListProvider::on_update (updating an ID score may cause a rebag)
  • SortedListProvider::on_remove (removing an ID in the list will change the iter)
  • BagsList::call::rebag
  • BagsList::call::put_in_front_of
  • BagsList::call::put_in_front_of_other

Even tough this approach is simple to implement and can be implemented all at the bags-list level, it may be too strict as some of the sorted list provider method calls may not affect the iter ordering or their implementation could be refactored to apply score mutations without changing the iter ordering e.g. on_update scores without rebag, on_remove do not remove the node from the list, etc.

Option 2.

Same as option 1, but refactor the sorted list provider implementation to ensure that all list mutations happen but ensure the list ordering does not change if the lock is set.

The explicit re-ordering implemented by the bags lists should fail if the lock is set.

  • BagsList::call::rebag
  • BagsList::call::put_in_front_of
  • BagsList::call::put_in_front_of_other

The implicit re-ordering implemented by the sorted list provider should mutate much as possible without changing the iterator ordering:

  • SortedListProvider::on_insert: inserts a new ID but at the end of the list.
  • SortedListProvider::on_update: updates the ID score but do not rebag/put_in_front_of
  • SortedListProvider::on_remove: sets the ID score to zero/taint it but keep it in the list
@gpestana gpestana added the T2-pallets This PR/Issue is related to a particular pallet. label Nov 1, 2024
@gpestana gpestana added this to AHM Nov 1, 2024
@gpestana gpestana moved this to Backlog in AHM Nov 1, 2024
@gpestana gpestana changed the title Design and implement the lockable election provider for multi-block election Add sort pause in bags list and trait SortedListProvider Nov 12, 2024
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: Backlog
Development

No branches or pull requests

1 participant