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

Move sp-npos-elections-solution-type to frame-election-provider-support #10866

Closed
kianenigma opened this issue Feb 16, 2022 · 1 comment · Fixed by #11032
Closed

Move sp-npos-elections-solution-type to frame-election-provider-support #10866

kianenigma opened this issue Feb 16, 2022 · 1 comment · Fixed by #11032
Labels
I7-refactor Code needs refactoring. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder Z6-mentor An easy task where a mentor is available. Please indicate in the issue who the mentor could be.

Comments

@kianenigma
Copy link
Contributor

... and derive MaxEncodedLen for it. Deriving MaxEncodedLen should be rather tricky. The final struct for which we want to derive it looks like this:

pub struct Foo {
  votes1: Vec<T1>,
  votes2: Vec<T2>,
  votes3: Vec<T2>,
  ...
  votes16: Vec<T16>,
}

And while the inner types (T1 to T16) are all bounded, Vec is simply not MaxEncodedLen.

One option would be to try and move all of the Vecs to BoundedVec. I strongly advice against that, mainly because I speculate that we want to re-think generate_npos_solution! macro overall and not generate it at compile-time.

What I recommend instead is to take a simpler approach, and accept that our MaxEncodedLen estimate for this type will be slightly pessimistic for now. We leverage the known fact that T1 < T2 < ... < T16. Also, we leverage the fact that we could know sum{votes1.len(), votes2.len(), ..., votes16.len()} at compile time (hint: this is essentially the same as VoterSnapshotPerBlock ;) ).

So all in all, the macro will be given one bound, named b (either as an expression or a type that is Get<u32>), which is essentially the total number of possible voters that this solution could represent. Then, the MaxEncodedLen will assume that votes16 (or whatever is the maximum) has b items and all the rest are empty.

Of course, this needs to be rethink-ed before this type is efficiently usable in a parachain, but for relay chains it is fine.

@kianenigma kianenigma added I7-refactor Code needs refactoring. Z6-mentor An easy task where a mentor is available. Please indicate in the issue who the mentor could be. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder labels Feb 16, 2022
@kianenigma kianenigma added this to Backlog in Runtime via automation Feb 16, 2022
@kianenigma
Copy link
Contributor Author

closed by the linked PR.

Runtime automation moved this from Backlog to Done Mar 20, 2022
@shawntabrizi shawntabrizi moved this from Done to Archive in Runtime May 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I7-refactor Code needs refactoring. Z1-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder Z6-mentor An easy task where a mentor is available. Please indicate in the issue who the mentor could be.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant