diff --git a/src/consensus/metadata.rs b/src/consensus/metadata.rs index 53f94e12f..03c62b814 100644 --- a/src/consensus/metadata.rs +++ b/src/consensus/metadata.rs @@ -80,7 +80,7 @@ impl MetadataStore { } /// Insert metadata into the metadatastore. - /// The block hash for the madatad is used as the key, where value is the serialized metadata. + /// The block hash for the metadata is used as the key, where value is the serialized metadata. pub fn insert(&self, metadata: &Metadata, block: blake3::Hash) -> Result<()> { self.0.insert(block.as_bytes(), serialize(metadata))?; Ok(()) diff --git a/src/consensus/state.rs b/src/consensus/state.rs index b4f851e3d..1582d3836 100644 --- a/src/consensus/state.rs +++ b/src/consensus/state.rs @@ -356,6 +356,20 @@ impl ValidatorState { let nodes_count = self.consensus.participants.len(); self.zero_participants_check(); + // Checking that the voter can actually vote. + match self.consensus.participants.get(&vote.id) { + Some(participant) => { + if self.current_epoch() <= participant.joined { + debug!("Voter joined after current epoch. Voter: {:?}", vote.id); + return Ok(false) + } + } + None => { + debug!("Voter is not a participant. Voter: {:?}", vote.id); + return Ok(false) + } + } + let proposal = self.find_proposal(&vote.proposal).unwrap(); if proposal == None { debug!("Received vote for unknown proposal."); @@ -382,7 +396,16 @@ impl ValidatorState { Some(p) => p.clone(), None => Participant::new(vote.id, vote.sl), }; - participant.voted = Some(vote.sl); + + match participant.voted { + Some(voted) => { + if vote.sl > voted { + participant.voted = Some(vote.sl); + } + } + None => participant.voted = Some(vote.sl), + } + self.consensus.participants.insert(participant.id, participant); return Ok(true)