Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

better way to resolve Phase::Emergency via governance #10663

Merged
merged 8 commits into from
Jan 27, 2022

Conversation

kianenigma
Copy link
Contributor

@kianenigma kianenigma commented Jan 14, 2022

This allows chain that are stuck in Phase::Emergency to resolve it more easily, without the need to rely on the (really hard to use staking-miner).

This also closes #8348, we can now have bounded on-chain election. Although, using it in a chain that does not have bags-list is kinda stupid, because you are basically relying on random order of nominators, if you pass Some to the call parameters.

Nonetheless, for most testnets, this is a big relief. When chain goes to Phase::emergency, call this new call with None and it should become unblocked by the next epoch.

As a side-note, I want to highly recommend to all test-nets to actually use type ElectionProvider = OnChainSeqPhragmen<_> in the first place, if their test-net is not expected to have thousands of nominators.

Polkadot companion: paritytech/polkadot#4757

@kianenigma kianenigma added A0-please_review Pull request needs code review. B7-runtimenoteworthy C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Jan 14, 2022
@@ -1010,6 +1028,37 @@ pub mod pallet {
});
Ok(())
}

/// Trigger the governance fallback.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is OnChainSeqPhragmen the only current option that we offer out of the box that would work here? If so might be good to mention that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but anyone can write a custom one as well.

type DataProvider = T::DataProvider;

fn elect() -> Result<Supports<T::AccountId>, Self::Error> {
Self::elect_with(None, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a dq, but why is it safe to not put a limit on the number of voters and targets? Do we assume that if you are using OnChainSequentialPhragmen as the election provider then DataProvider::{voters, target} will always return values that won't OOM? If so we should document

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is actually NOT safe, and you should NOT use this. I'll document it a bit better.

Copy link
Member

Choose a reason for hiding this comment

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

Huh? If this is not safe, can you document something right here?

Copy link
Contributor Author

@kianenigma kianenigma Jan 19, 2022

Choose a reason for hiding this comment

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

It is documented at the type, where it is much more visible than being an inline comment in the code:

/// Finally, the [`ElectionProvider`] implementation of this type does not impose any limits on the
/// number of voters and targets that are fetched. This could potentially make this unsuitable for
/// execution onchain. On the other hand, the [`InstantElectionProvider`] implementation does limit
/// these inputs.
///
/// It is advisable to use the former ([`ElectionProvider::elect`]) only at genesis, or for testing,
/// the latter [`InstantElectionProvider::instant_elect`] for onchain operations, with thoughtful
/// bounds.

Note that we never use this except at genesis, as recommended.

@emostov
Copy link
Contributor

emostov commented Jan 14, 2022

Overall looks good just want to make sure I understand #10663 (comment)

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>
@kianenigma kianenigma added this to In progress in Runtime via automation Jan 17, 2022
@kianenigma kianenigma moved this from In progress to Please Review in Runtime Jan 17, 2022
Runtime automation moved this from Please Review to Needs Audit Jan 19, 2022
Copy link
Member

@shawntabrizi shawntabrizi left a comment

Choose a reason for hiding this comment

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

Pretty sure this makes sense to me.

Basically, in a really bad situation, we just pick the first N people rather than doing any fancy calculation which may stall us.

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
@kianenigma kianenigma added D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited and removed D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Jan 19, 2022
@kianenigma
Copy link
Contributor Author

@georgesdib would you like to prepare the appropriate companions for this one as well? should be fairly understandable for you.

@georgesdib
Copy link
Contributor

@georgesdib would you like to prepare the appropriate companions for this one as well? should be fairly understandable for you.

I just created that under:

Polkadot companion: paritytech/polkadot#4757

cumulus seem to build fine.

@kianenigma kianenigma added A8-mergeoncegreen D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited and removed D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited A0-please_review Pull request needs code review. labels Jan 21, 2022
@jakoblell jakoblell added D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited and removed D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited labels Jan 25, 2022
@kianenigma
Copy link
Contributor Author

bot merge

@paritytech-processbot
Copy link

Error: Github API says paritytech/polkadot#4757 is not mergeable

@kianenigma
Copy link
Contributor Author

bot merge

@paritytech-processbot paritytech-processbot bot merged commit da534d7 into master Jan 27, 2022
@paritytech-processbot paritytech-processbot bot deleted the kiz-election-onchain-backup branch January 27, 2022 10:00
Runtime automation moved this from Needs Audit to Done Jan 27, 2022
@shawntabrizi shawntabrizi moved this from Done to Archive in Runtime Feb 3, 2022
Wizdave97 pushed a commit to ComposableFi/substrate that referenced this pull request Feb 4, 2022
…0663)

* better way to resolve Phase::Emergency via governance

* Update frame/election-provider-multi-phase/src/lib.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* review grumbles

* Update frame/election-provider-support/src/onchain.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* revert usize -> u32

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
grishasobol pushed a commit to gear-tech/substrate that referenced this pull request Mar 28, 2022
…0663)

* better way to resolve Phase::Emergency via governance

* Update frame/election-provider-multi-phase/src/lib.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* review grumbles

* Update frame/election-provider-support/src/onchain.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* revert usize -> u32

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
…0663)

* better way to resolve Phase::Emergency via governance

* Update frame/election-provider-multi-phase/src/lib.rs

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>

* review grumbles

* Update frame/election-provider-support/src/onchain.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* revert usize -> u32

Co-authored-by: Zeke Mostov <z.mostov@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C1-low PR touches the given topic and has a low impact on builders. D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Limit the execution time of on-chain sequential phragmen
5 participants