Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Migration is there, what's missing is to make this works with the other migrations regarding the election pallet. |
a0e44e2 to
60d48c3
Compare
1605655 to
54631ea
Compare
| SharedData::<T, I>::drain(); | ||
| BitmapComponents::<T, I>::drain(); | ||
| IndividualComponents::<T, I>::drain(); | ||
| ElectionConsensusHistory::<T, I>::drain(); |
There was a problem hiding this comment.
Shouldn't we also drain ElectionConsensusHistoryUpToDate? For example, it's cleared in clear_election_votes().
| type ElectionState = (); | ||
| type VoteStorage = | ||
| vote_storage::individual::Individual<(), vote_storage::individual::shared::Shared<Value>>; | ||
| type VoteStorage = vote_storage::bitmap_numerical::BitmapNoHash<Value>; |
There was a problem hiding this comment.
I'm not sure we want to change this vote storage - it's used for solana block height, where I think most of the validators are going to vote for different heights. Or is that not the case?
There was a problem hiding this comment.
From observation the span of these votes is ~10 different votes, which means we can do some deduplication here.
Currently we save the SharedDataHash for each validator but since the votes usually span across 10 blocks we end up not having the full vote for some of them which means consensus gets delayed since we need to retrieve the original vote. Using the new VoteStorage means we save a bitmap for each of those ~10 different values but no hash at all, meaning we always have access to the full vote.
TLDR: if we know the span of vote is limited like in this case it makes sense to use this new vote storage to obtain some deduplication without delaying consensus. Furthermore we also save some storage in this case since there is no need to save 150 Hashes.
If the span of vote is potentially 150 different votes, then it makes sense to use the Identity VoteStorage instead for numerical values since it will always be smaller than an hash
There was a problem hiding this comment.
Ah right, I see. Cool, then BitmapNoHash does sound like the best option.
| type ElectionState = (); | ||
| type VoteStorage = | ||
| vote_storage::individual::Individual<(), vote_storage::individual::shared::Shared<Value>>; | ||
| type VoteStorage = vote_storage::bitmap_numerical::BitmapNoHash<Value>; |
There was a problem hiding this comment.
Again, I'm not sure we should change this. This is currently only used in bitcoin fee tracking, and since we're going to do sampling we can't guarantee that the validators are going to vote with the same values. Of course, we could for example do some rounding on the voters' side to ensure that the votes fall into "a few buckets". But usually, computing a median implies that we have a bunch of different values, so I would leave this as individual storage.
There was a problem hiding this comment.
See answer above, I agree on this one though, if we switch to the new fee witnessing (which means it's very likely we will have 150 different values) we should then use the Identity VoteStorage
There was a problem hiding this comment.
we should then use the
IdentityVoteStorage
Yes, I'm then fine with keeping it currently as you have it, and switch over to identity in my later fee PR.
| } | ||
| } | ||
| pub type PalletMigration<T, I> = | ||
| (vote_storage_migration::VoteStorageMigration<T, I>, PlaceholderMigration<6, Pallet<T, I>>); |
There was a problem hiding this comment.
Yeah I think this is correct. Later on we do the migrations::bitcoin_elections::Migration which increases the storage version to 7.
state-chain/pallets/cf-elections/src/electoral_systems/tests/egress_success.rs
Outdated
Show resolved
Hide resolved
| #[extrinsic_call] | ||
| provide_shared_data(RawOrigin::Signed(validator_id), Box::new(shared_data_value.clone())); | ||
|
|
||
| assert!(SharedData::<T, I>::get(shared_data_hash).is_some()); |
There was a problem hiding this comment.
I think we could also check that the shared data we get is the one we provided, as we did previously, no?
| SharedDataReferenceCount::<T, I>::insert( | ||
| shared_data_hash, | ||
| UniqueMonotonicIdentifier::from(0), | ||
| ReferenceDetails::<BlockNumberFor<T>> { | ||
| count: 1u32, | ||
| created: BlockNumberFor::<T>::from(1u32), | ||
| expires: BlockNumberFor::<T>::from(10u32), | ||
| }, | ||
| ); |
There was a problem hiding this comment.
Just for clarification, why did calling the vote() function break?
There was a problem hiding this comment.
It doesn't, vote() works fine here but since we don't use SharedData nothing get's inserted in the SharedDataReferenceCount which then causes provide_shared_data to return UnreferencedSharedData
There was a problem hiding this comment.
I'll also add a comment here to explain
There was a problem hiding this comment.
I'll also add a comment here to explain
Perfect, a comment like what you wrote above would be already very helpful.
| // Setup a validator set of 150 as in the case of Mainnet. | ||
| let election_identifier = | ||
| setup_validators_and_vote::<T, I>(150, BenchmarkValue::benchmark_value()); | ||
| setup_validators_and_vote::<T, I>(3, BenchmarkValue::benchmark_value()); |
There was a problem hiding this comment.
The comment should also say 3. And I think it would be useful to explain to future readers why using 150 doesn't work.
There was a problem hiding this comment.
I'll update the comment.
Same as the epoch index, I didn't investigate why 150 doesn't work, but I tested it and the authority set size get set to 3 max.
There was a problem hiding this comment.
Would be good to know and understand I think. What error does it fail with?
There was a problem hiding this comment.
What happens is that the epoch authority size ends up being 3.
When a validator with authority index >= 3 votes the index is out of bound when accessing the bitmap causing CorruptedStorage, thinking about this the check ensure_can_vote in vote() should prevent this to happen though! I'll investigate this a bit further.
There was a problem hiding this comment.
the index is out of bound when accessing the bitmap causing CorruptedStorage
And previously we only didn't notice this because we ran the benchmarks with a different votestorage, right?
| // Setup a validator set of 150 and reach consensus | ||
| let election_identifier = | ||
| setup_validators_and_vote::<T, I>(150, BenchmarkValue::benchmark_value()); | ||
| setup_validators_and_vote::<T, I>(3, BenchmarkValue::benchmark_value()); |
| #[block] | ||
| {} |
There was a problem hiding this comment.
This looks strange, what is this?
There was a problem hiding this comment.
we need either a #[block] or #[extrinsic] in the benchmarks.
Since we don't really care about measuring the weights here but it is more a test we just run an empty block just to make it compile. This could be moved into the tests but then we would have to mock another ES since the MockESRunner is a composite of 1 ES only.
There was a problem hiding this comment.
I see, I wasn't aware of that 👍
| } | ||
|
|
||
| #[benchmark] | ||
| fn test_mismatch<T: crate::pallet::Config<I>, I: 'static>() { |
state-chain/pallets/cf-elections/src/electoral_systems/composite.rs
Outdated
Show resolved
Hide resolved
| ) -> Result<(), sp_runtime::DispatchError> { | ||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
Does this need a default implementation?
There was a problem hiding this comment.
🤔 this is the mock impl
…te.rs Co-authored-by: Maxim Urschumzew <MxmUrw@users.noreply.github.com>
* add new vote storage * add migration * fix migrations * fix benchmarks * address comments * last fix for benchmarks * add check to prevent vote mismatch * remove from test * Update state-chain/pallets/cf-elections/src/electoral_systems/composite.rs Co-authored-by: Maxim Urschumzew <MxmUrw@users.noreply.github.com> --------- Co-authored-by: Maxim Urschumzew <MxmUrw@users.noreply.github.com>
Pull Request
Closes: PRO-2400
Checklist
Please conduct a thorough self-review before opening the PR.
Summary
Add new
VoteStorageto avoid usingSharedDataHashin case the Value voted on is smaller than an Hash (32 bytes),this makes less likely to delay consensus cause we don't have the full vote for some of the available hashes and vote extrinsics more readable since validators will always vote with the full vote.