Skip to content

Commit

Permalink
fix: correct shared data hash
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezs committed Oct 29, 2024
1 parent d4eff08 commit e019a0b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
9 changes: 8 additions & 1 deletion state-chain/pallets/cf-elections/src/electoral_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use sp_std::vec::Vec;

use crate::{
vote_storage::{AuthorityVote, VoteStorage},
CorruptStorageError, ElectionIdentifier,
CorruptStorageError, ElectionIdentifier, SharedDataHash,
};

pub struct ConsensusVote<ES: ElectoralSystem> {
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -311,6 +312,12 @@ mod access {
fn state(
&self,
) -> Result<<Self::ElectoralSystem as ElectoralSystem>::ElectionState, CorruptStorageError>;

fn shared_data_hash_of(
&self,
data: <<Self::ElectoralSystem as ElectoralSystem>::Vote as VoteStorage>::SharedData,
) -> SharedDataHash;

#[cfg(test)]
fn election_identifier(
&self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ macro_rules! generate_electoral_system_tuple_impls {
};

use crate::{
SharedDataHash,
CorruptStorageError,
electoral_system::{
ElectoralSystem,
Expand All @@ -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}};

Expand Down Expand Up @@ -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: <<Self::ElectoralSystem as ElectoralSystem>::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<ElectionIdentifierOf<Self::ElectoralSystem>, CorruptStorageError> {
let composite_identifier = self.ea.borrow().election_identifier()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<
partial_vote: &<Self::Vote as VoteStorage>::PartialVote,
) -> Result<bool, CorruptStorageError> {
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(
Expand Down
6 changes: 6 additions & 0 deletions state-chain/pallets/cf-elections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,12 @@ pub mod pallet {
ElectionState::<T, I>::get(self.unique_monotonic_identifier())
.ok_or_else(CorruptStorageError::new)
}
fn shared_data_hash_of(
&self,
shared_data: <<T::ElectoralSystem as ElectoralSystem>::Vote as VoteStorage>::SharedData,
) -> SharedDataHash {
todo!()
}
#[cfg(test)]
fn election_identifier(
&self,
Expand Down

0 comments on commit e019a0b

Please sign in to comment.