diff --git a/state-chain/pallets/cf-elections/src/electoral_system.rs b/state-chain/pallets/cf-elections/src/electoral_system.rs index 06a63ec2ef..6d510b1ac8 100644 --- a/state-chain/pallets/cf-elections/src/electoral_system.rs +++ b/state-chain/pallets/cf-elections/src/electoral_system.rs @@ -7,7 +7,7 @@ use sp_std::vec::Vec; use crate::{ vote_storage::{AuthorityVote, VoteStorage}, - CorruptStorageError, ElectionIdentifier, + CorruptStorageError, ElectionIdentifier, SharedDataHash, }; pub struct ConsensusVote { @@ -238,6 +238,7 @@ mod access { //! correct ElectoralSystem implementation. use super::{CorruptStorageError, ElectionIdentifierOf, ElectoralSystem}; + use crate::{vote_storage::VoteStorage, SharedDataHash}; /// Represents the current consensus, and how it has changed since it was last checked (i.e. /// 'check_consensus' was called). @@ -311,6 +312,12 @@ mod access { fn state( &self, ) -> Result<::ElectionState, CorruptStorageError>; + + fn shared_data_hash_of( + &self, + data: <::Vote as VoteStorage>::SharedData, + ) -> SharedDataHash; + #[cfg(test)] fn election_identifier( &self, diff --git a/state-chain/pallets/cf-elections/src/electoral_systems/composite.rs b/state-chain/pallets/cf-elections/src/electoral_systems/composite.rs index c2da030d6c..8dd6f90862 100644 --- a/state-chain/pallets/cf-elections/src/electoral_systems/composite.rs +++ b/state-chain/pallets/cf-elections/src/electoral_systems/composite.rs @@ -52,6 +52,7 @@ macro_rules! generate_electoral_system_tuple_impls { }; use crate::{ + SharedDataHash, CorruptStorageError, electoral_system::{ ElectoralSystem, @@ -72,7 +73,7 @@ macro_rules! generate_electoral_system_tuple_impls { }, ElectionIdentifier, }; - use crate::vote_storage::composite::$module::{CompositeVoteProperties, CompositeVote, CompositePartialVote}; + use crate::vote_storage::composite::$module::{CompositeVoteProperties, CompositeVote, CompositePartialVote, CompositeSharedData}; use frame_support::{Parameter, pallet_prelude::{Member, MaybeSerializeDeserialize}}; @@ -440,6 +441,12 @@ macro_rules! generate_electoral_system_tuple_impls { _ => Err(CorruptStorageError::new()) } } + + // TODO: Push this into lower level + fn shared_data_hash_of(&self, data: <::Vote as VoteStorage>::SharedData) -> SharedDataHash { + SharedDataHash::of(&CompositeSharedData::<$(<<$electoral_system as ElectoralSystem>::Vote as VoteStorage>::SharedData),*>::$current(data)) + } + #[cfg(test)] fn election_identifier(&self) -> Result, CorruptStorageError> { let composite_identifier = self.ea.borrow().election_identifier()?; diff --git a/state-chain/pallets/cf-elections/src/electoral_systems/monotonic_change.rs b/state-chain/pallets/cf-elections/src/electoral_systems/monotonic_change.rs index 7ab63e57b1..df77fe680b 100644 --- a/state-chain/pallets/cf-elections/src/electoral_systems/monotonic_change.rs +++ b/state-chain/pallets/cf-elections/src/electoral_systems/monotonic_change.rs @@ -115,7 +115,7 @@ impl< partial_vote: &::PartialVote, ) -> Result { let (_, previous_value, previous_slot) = election_access.properties()?; - Ok(partial_vote.value != SharedDataHash::of(&previous_value) && + Ok(partial_vote.value != election_access.shared_data_hash_of(previous_value) && partial_vote.block > previous_slot) } fn generate_vote_properties( diff --git a/state-chain/pallets/cf-elections/src/lib.rs b/state-chain/pallets/cf-elections/src/lib.rs index 12e8900a04..5b3c425ce9 100644 --- a/state-chain/pallets/cf-elections/src/lib.rs +++ b/state-chain/pallets/cf-elections/src/lib.rs @@ -637,6 +637,12 @@ pub mod pallet { ElectionState::::get(self.unique_monotonic_identifier()) .ok_or_else(CorruptStorageError::new) } + fn shared_data_hash_of( + &self, + shared_data: <::Vote as VoteStorage>::SharedData, + ) -> SharedDataHash { + todo!() + } #[cfg(test)] fn election_identifier( &self,