paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.com/
1.89k stars 696 forks source link

Implements a mechanism to lock/unlock the `SortedListProvider` and bags-list iter #6510

Open gpestana opened 7 hours ago

gpestana commented 7 hours ago

Implements a mechanism to lock/unlock the SortedListProvider and bags-list iter.

WIP and currently implementing Option 1.

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.

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:

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.