Skip to content
Permalink
Browse files

update the BFT state leader selection as it does not need the update …

…system anymore
  • Loading branch information...
NicolasDP committed Mar 12, 2019
1 parent a7b1a39 commit dc5e5aa10352a3d6a21d3f878d357f459b994a9d
Showing with 0 additions and 58 deletions.
  1. +0 −58 chain-impl-mockchain/src/leadership/bft.rs
@@ -49,68 +49,10 @@ impl BftLeaderSelection {
}

impl LeaderSelection for BftLeaderSelection {
type Update = Update;
type Block = Block;
type Error = Error;
type LeaderId = PublicLeader;

fn diff(&self, input: &Self::Block) -> Result<Self::Update, Self::Error> {
if input.version() != BLOCK_VERSION_CONSENSUS_BFT {
return Err(Error {
kind: ErrorKind::IncompatibleBlockVersion,
cause: None,
});
}
let mut update = <Self::Update as property::Update>::empty();

let new_leader = self.get_leader_at(input.date())?;

match &input.header.proof() {
Proof::Bft(bft_proof) => {
let input_leader = PublicLeader::Bft(bft_proof.leader_id.clone());
if input_leader != new_leader {
return Err(Error {
kind: ErrorKind::InvalidLeader,
cause: Some(Box::new(BftError::BlockHasInvalidLeader(
new_leader,
input_leader,
))),
});
}
update.previous_leader = PublicLeader::Bft(self.current_leader.clone());
update.next_leader = input_leader;
}
_ => {
return Err(Error {
kind: ErrorKind::IncompatibleLeadershipMode,
cause: Some(Box::new(BftError::BlockProofIsDifferent)),
});
}
}

if !input.verify() {
return Err(Error {
kind: ErrorKind::InvalidLeader,
cause: Some(Box::new(BftError::BlockSignatureIsInvalid)),
});
}

Ok(update)
}
fn apply(&mut self, update: Self::Update) -> Result<(), Self::Error> {
let current_leader = PublicLeader::Bft(self.current_leader.clone());
if update.previous_leader != current_leader {
return Err(Error {
kind: ErrorKind::InvalidLeader,
cause: Some(Box::new(BftError::UpdateHasInvalidCurrentLeader(
current_leader,
update.previous_leader.clone(),
))),
});
}
Ok(())
}

#[inline]
fn get_leader_at(
&self,

0 comments on commit dc5e5aa

Please sign in to comment.
You can’t perform that action at this time.