diff --git a/ethcore/src/engines/tendermint.rs b/ethcore/src/engines/tendermint.rs index d1bfe26ce..116a0ce16 100644 --- a/ethcore/src/engines/tendermint.rs +++ b/ethcore/src/engines/tendermint.rs @@ -17,6 +17,7 @@ //! Tendermint BFT consensus engine with round robin proof-of-authority. use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering}; +use std::time::Duration; use common::*; use account_provider::AccountProvider; use block::*; @@ -36,24 +37,36 @@ pub struct TendermintParams { pub validators: Vec
, /// Number of validators. pub validator_n: usize, + /// Timeout durations for different steps. + timeouts: Timeouts, /// Consensus round. r: u64, /// Consensus step. s: RwLock, /// Used to swith proposer. proposer_nonce: AtomicUsize, - /// Seal collection. - seal: Vec } #[derive(Debug)] enum Step { Propose, Prevote(ProposeCollect), - Precommit(ProposeCollect, Vec), - Commit + /// Precommit step storing the precommit vote and accumulating seal. + Precommit(ProposeCollect, Seal), + /// Commit step storing a complete valid seal. + Commit(Seal) } +#[derive(Debug)] +struct Timeouts { + propose: Duration, + prevote: Duration, + precommit: Duration, + commit: Duration +} + +type Seal = Vec; + impl From for TendermintParams { fn from(p: ethjson::spec::TendermintParams) -> Self { let val: Vec<_> = p.validators.into_iter().map(Into::into).collect(); @@ -63,10 +76,10 @@ impl From for TendermintParams { duration_limit: p.duration_limit.into(), validators: val, validator_n: val_n, + timeouts: Timeouts { propose: Duration::from_secs(3), prevote: Duration::from_secs(3), precommit: Duration::from_secs(3), commit: Duration::from_secs(3) }, r: 0, s: RwLock::new(Step::Propose), - proposer_nonce: AtomicUsize::new(0), - seal: Vec::new() + proposer_nonce: AtomicUsize::new(0) } } } @@ -154,7 +167,7 @@ impl Tendermint { // Commit if precommit is won. if vote.is_won() { let mut guard = self.our_params.s.write(); - *guard = Step::Commit; + *guard = Step::Commit(seal.clone()); Ok(message.as_raw().to_vec()) } else { Ok(message.as_raw().to_vec()) @@ -245,7 +258,7 @@ impl Engine for Tendermint { Ok(()) } - fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> { + fn verify_block_unordered(&self, _header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> { Ok(()) }