-
Notifications
You must be signed in to change notification settings - Fork 2.7k
WIP Make ChangeMembers trait fallible #5985
Conversation
It looks like @apopiak signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
frame/scored-pool/src/lib.rs
Outdated
@@ -407,16 +407,20 @@ impl<T: Trait<I>, I: Instance> Module<T, I> { | |||
new_members.sort(); | |||
|
|||
let old_members = <Members<T, I>>::get(); | |||
// TODO: What to do in case of error? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
regarding changes to this pallet. If you look more closely at the pallet code, you will see there is a storage item MemberCount
which determines the number of members selected from the pool.
If I understand the end goals here correctly, you will make it so there is an upper limit to the number of members that can exist in a collective. So you should probably bring that information about the collective upper limit into this pallet, and choose the smaller of the two numbers when creating a membership group... or just make sure that if you send N members from this pallet to membership, that the top M members are selected or something like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will have to expose MaxMembers
through ChangeMembers
.
And while looking into this I also found that we need to adjust InitializeMembers
.
This is snowballing 🏔️
frame/scored-pool/src/lib.rs
Outdated
ChangeReceiver::MembershipChanged => | ||
T::MembershipChanged::set_members_sorted( | ||
ChangeReceiver::MembershipChanged => { | ||
// TODO: Is this safe? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not safe as is because members here are sorted by account id, not score. So if there is truncation happening downstream, it will pick the wrong set of members.
It seems like this PR should also introduce the member limit to collective |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not make any sense to write let _ =
for all these lengths. They are dropped automatically.
I added the member limit. |
It would be great to get some feedback on the API design here. 2 key questions:
|
@apopiak my take on your questions:
|
Co-authored-by: Bastian Köcher <[email protected]>
/// | ||
/// If this returns `Err`, calls to `change_members`, `change_members_sorted` and | ||
/// `set_members_sorted` are not guaranteed to have the desired effect. | ||
fn ensure_can_change_members(_new: &[AccountId], _old: &[AccountId]) -> DispatchResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have much to say agains the core of the change itself, but enforcing this trait, which by itself has nothing to do with dispatches, to return a DispatchResult
is a mistake. While I can guess that it makes the code on the pallets slightly easier, I think it makes a whole lot more sense if this returns normal Result
, or anything else which is generic, and then you can do a simple map_err()
on your pallet.
I guess we might use the same approach for other traits in support
as well.. which is also wrong IMO. Either way, take it with a grain of salt, but I think it is a valid point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good point, thanks.
Co-authored-by: Kian Paimani <[email protected]>
This is out of scope for the polkadot release and will be de-prioritized to ship the weights stuff. |
…ate into apopiak-change-members
What is the status of this pr? |
It is basically defunct. I split it off because it was out of scope of the PR that spawned it (the collective weights stuff) and figured that we would want to come back to it (the topic of how to adjust I'm busy with the Edgeware migration at the moment and won't be working on it, so feel free to close. I think it might be good to keep the branch, but up to how we handle stale branches at Parity (which I don't know). |
This PR changes the
ChangeMembers
trait to be fallible.change_members
,change_members_sorted
andset_members_sorted
are no longer guaranteed to set all members successfully.Instead they return the new number of members after the operation. There is also a new
ensure_can_change_members
function that is meant to allow checking whether a member change will execute without errors.Preparation for #5802 as it uses the member limit to estimate weights in
pallet-collective
(an implementor ofChangeMembers
).✄ -----------------------------------------------------------------------------
Fixes #228
orRelated #1337
.