substrate icon indicating copy to clipboard operation
substrate copied to clipboard

make MAX_VOTERS and MAX_CANDIDATES in elections-phragmen configurable. Fix: #11092

Open sudipghimire533 opened this issue 2 years ago • 24 comments

Closes: #11902 Polkadot companion: https://github.com/paritytech/polkadot/pull/5815

Update

  • Allow max_voters & max_candidates to be configurable from Config trait of pallet_elections_phragmen
  • Put value 1000 (for max_candidates) & 10_000 (for max_voters) while creating runtime from /bin/node/runtime. Value taken as was in PR #11790

sudipghimire533 avatar Jul 25 '22 15:07 sudipghimire533

User @sudipghimire533, please sign the CLA here.

cla-bot-2021[bot] avatar Jul 25 '22 15:07 cla-bot-2021[bot]

Looks mostly good, need to make companions.

kianenigma avatar Jul 25 '22 16:07 kianenigma

Polkadot companion: https://github.com/paritytech/polkadot/pull/5815

sudipghimire533 avatar Jul 25 '22 17:07 sudipghimire533

@sudipghimire533 Note that you have to update the benchmarking.rs file also.

Szegoo avatar Jul 26 '22 07:07 Szegoo

@Szegoo maybe you can help me here:

error: expected one of `:`, `;`, `=`, `@`, or `|`, found keyword `in`
   --> frame/elections-phragmen/src/benchmarking.rs:394:9
    |
394 |         let e in T::MaxVoters::get() .. T::MaxVoters * MAXIMUM_VOTE as u32;
    |               ^^ expected one of `:`, `;`, `=`, `@`, or `|`

error: expected one of `:`, `;`, `=`, `@`, or `|`, found keyword `in`
   --> frame/elections-phragmen/src/benchmarking.rs:429:9
    |
429 |         let e in T::MaxVoters::get() .. T::MaxVoters::get() * MAXIMUM_VOTE as u32;
    |               ^^ expected one of `:`, `;`, `=`, `@`, or `|`

sudipghimire533 avatar Jul 26 '22 09:07 sudipghimire533

@Szegoo maybe you can help me here:

error: expected one of `:`, `;`, `=`, `@`, or `|`, found keyword `in`
   --> frame/elections-phragmen/src/benchmarking.rs:394:9
    |
394 |         let e in T::MaxVoters::get() .. T::MaxVoters * MAXIMUM_VOTE as u32;
    |               ^^ expected one of `:`, `;`, `=`, `@`, or `|`

error: expected one of `:`, `;`, `=`, `@`, or `|`, found keyword `in`
   --> frame/elections-phragmen/src/benchmarking.rs:429:9
    |
429 |         let e in T::MaxVoters::get() .. T::MaxVoters::get() * MAXIMUM_VOTE as u32;
    |               ^^ expected one of `:`, `;`, `=`, `@`, or `|`

I think you need to wrap it in a parenthesis: https://github.com/paritytech/substrate/blob/54d6f2cbae12fa314f2bcaf6d57fba585162438f/frame/staking/src/benchmarking.rs#L815

kianenigma avatar Jul 26 '22 13:07 kianenigma

Not working same error and neither can I assign it as variable and re-use. @kianenigma do you think you can help me with benchmarking.rs ?

sudipghimire533 avatar Jul 26 '22 13:07 sudipghimire533

Not working same error and neither can I assign it as variable and re-use. @kianenigma do you think you can help me with benchmarking.rs ?

I have run into the same issue when working on this, the suggested solution from @kianenigma should work. Could you give me access to your branch, so maybe I manage to get it working?

Szegoo avatar Jul 26 '22 13:07 Szegoo

Not working same error and neither can I assign it as variable and re-use. @kianenigma do you think you can help me with benchmarking.rs ?

I have run into the same issue when working on this, the suggested solution from @kianenigma should work. Could you give me access to your branch, so maybe I manage to get it working?

@Szegoo I have invited you to my fork. Also I tried adding () as well. Not good from my side. Let's see

sudipghimire533 avatar Jul 26 '22 13:07 sudipghimire533

Not working same error and neither can I assign it as variable and re-use. @kianenigma do you think you can help me with benchmarking.rs ?

I have run into the same issue when working on this, the suggested solution from @kianenigma should work. Could you give me access to your branch, so maybe I manage to get it working?

@Szegoo I have invited you to my fork. Also I tried adding () as well. Not good from my side. Let's see

Ahh you guys meant to only wrap the get. Gotcha but looks like benchmark verification failing no?

Jul 26 20:05:52.022 ERROR runtime::elections-phragmen: Failed to run election. Number of voters exceeded    

sudipghimire533 avatar Jul 26 '22 14:07 sudipghimire533

@sudipghimire533 The errors are now fixed :)

Szegoo avatar Jul 28 '22 13:07 Szegoo

@sudipghimire533 The errors are now fixed :)

Indeed, a smart wizard named Szegoo same and fixed everything.. Thanks a lot for helping out mate :)

sudipghimire533 avatar Jul 28 '22 13:07 sudipghimire533

@sudipghimire533 The errors are now fixed :)

Indeed, a smart wizard named Szegoo same and fixed everything.. Thanks a lot for helping out mate :)

NP, note that you should put the polkadot companion in the PR description so that the companion CI checks pass. It should look like this: polkadot companion: https://github.com/paritytech/polkadot/pull/5815

Szegoo avatar Jul 28 '22 13:07 Szegoo

@sudipghimire533 The errors are now fixed :)

Indeed, a smart wizard named Szegoo same and fixed everything.. Thanks a lot for helping out mate :)

NP, note that you should put the polkadot companion in the PR description so that the companion CI checks pass. It should look like this: polkadot companion: paritytech/polkadot#5815

https://github.com/paritytech/polkadot/pull/5815

This looks ok?

sudipghimire533 avatar Jul 28 '22 13:07 sudipghimire533

@sudipghimire533 The errors are now fixed :)

Indeed, a smart wizard named Szegoo same and fixed everything.. Thanks a lot for helping out mate :)

NP, note that you should put the polkadot companion in the PR description so that the companion CI checks pass. It should look like this: polkadot companion: paritytech/polkadot#5815

paritytech/polkadot#5815

This looks ok?

You should put it inside the PR description, but don't put it in a list as you did. Here is an example: # 11831

Szegoo avatar Jul 28 '22 13:07 Szegoo

@sudipghimire533 Are you working on this, or may I finish this?

Szegoo avatar Aug 02 '22 07:08 Szegoo

@sudipghimire533 Are you working on this, or may I finish this?

I seems quite busy on my office work. You can take over. Thanks @Szegoo

sudipghimire533 avatar Aug 02 '22 07:08 sudipghimire533

Needs to be able to set smaller values for testing, otherwise running tests and benchmarks of this pallet would take ages.

You can try yourself by doing cargo test -p pallet-elections-phragmen --features runtime-benchmarks

@kianenigma I don't think that is right. Please correct me if I am wrong, but in the code, the TEST_MAX_VOTERS and TEST_MAX_CANDIDATES constants are removed, so for the tests and benchmarks the values are used from the Test implementation of Config. I have put the values in the Test configuration to be the same as the deleted test constants. So the benchmarks don't take a long time to execute. The non-test values are specified in the runtime config and don't impact the benchmarks.

Szegoo avatar Aug 02 '22 08:08 Szegoo

@kianenigma I have updated the docs.

Szegoo avatar Aug 05 '22 12:08 Szegoo

companion needs an update too.

kianenigma avatar Aug 07 '22 09:08 kianenigma

companion needs an update too.

Can you mention what needed to me updated

sudipghimire533 avatar Aug 07 '22 09:08 sudipghimire533

/cmd queue -c bench-bot $ pallet dev pallet_elections_phragmen

ggwpez avatar Aug 08 '22 09:08 ggwpez

@ggwpez https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1726285 was started for your command "$PIPELINE_SCRIPTS_DIR/bench-bot.sh" pallet dev pallet_elections_phragmen. Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment /cmd cancel 10-705eccf4-9bf2-4e1f-aed1-46615cdc9dbf to cancel this command or /cmd cancel to cancel all commands in this pull request.

command-bot[bot] avatar Aug 08 '22 09:08 command-bot[bot]

@ggwpez Command "$PIPELINE_SCRIPTS_DIR/bench-bot.sh" pallet dev pallet_elections_phragmen has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1726285 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1726285/artifacts/download.

command-bot[bot] avatar Aug 08 '22 13:08 command-bot[bot]

bot rebase

kianenigma avatar Aug 14 '22 17:08 kianenigma

Rebased

bot merge

kianenigma avatar Aug 14 '22 18:08 kianenigma

https://github.com/sudipghimire533 @Szegoo can you both paste your Polkadot address for a tip here?

kianenigma avatar Aug 14 '22 18:08 kianenigma

https://github.com/sudipghimire533 @Szegoo can you both paste your Polkadot address for a tip here?

I can't edit the PR description, should I provide it somehow else?

Szegoo avatar Aug 14 '22 18:08 Szegoo

https://github.com/sudipghimire533 @Szegoo can you both paste your Polkadot address for a tip here?

I can't edit the PR description, should I provide it somehow else?

If it need to be in PR description you can put it here and I will put in the Description

sudipghimire533 avatar Aug 15 '22 02:08 sudipghimire533