mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
src/consensus: misc vote validations
This commit is contained in:
@@ -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(())
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user