move seal into commit

This commit is contained in:
keorn 2016-08-29 14:32:37 +02:00
parent 4025645188
commit d7499044e3

View File

@ -17,6 +17,7 @@
//! Tendermint BFT consensus engine with round robin proof-of-authority. //! Tendermint BFT consensus engine with round robin proof-of-authority.
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering}; use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
use std::time::Duration;
use common::*; use common::*;
use account_provider::AccountProvider; use account_provider::AccountProvider;
use block::*; use block::*;
@ -36,24 +37,36 @@ pub struct TendermintParams {
pub validators: Vec<Address>, pub validators: Vec<Address>,
/// Number of validators. /// Number of validators.
pub validator_n: usize, pub validator_n: usize,
/// Timeout durations for different steps.
timeouts: Timeouts,
/// Consensus round. /// Consensus round.
r: u64, r: u64,
/// Consensus step. /// Consensus step.
s: RwLock<Step>, s: RwLock<Step>,
/// Used to swith proposer. /// Used to swith proposer.
proposer_nonce: AtomicUsize, proposer_nonce: AtomicUsize,
/// Seal collection.
seal: Vec<Bytes>
} }
#[derive(Debug)] #[derive(Debug)]
enum Step { enum Step {
Propose, Propose,
Prevote(ProposeCollect), Prevote(ProposeCollect),
Precommit(ProposeCollect, Vec<Bytes>), /// Precommit step storing the precommit vote and accumulating seal.
Commit 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<Bytes>;
impl From<ethjson::spec::TendermintParams> for TendermintParams { impl From<ethjson::spec::TendermintParams> for TendermintParams {
fn from(p: ethjson::spec::TendermintParams) -> Self { fn from(p: ethjson::spec::TendermintParams) -> Self {
let val: Vec<_> = p.validators.into_iter().map(Into::into).collect(); let val: Vec<_> = p.validators.into_iter().map(Into::into).collect();
@ -63,10 +76,10 @@ impl From<ethjson::spec::TendermintParams> for TendermintParams {
duration_limit: p.duration_limit.into(), duration_limit: p.duration_limit.into(),
validators: val, validators: val,
validator_n: val_n, 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, r: 0,
s: RwLock::new(Step::Propose), s: RwLock::new(Step::Propose),
proposer_nonce: AtomicUsize::new(0), proposer_nonce: AtomicUsize::new(0)
seal: Vec::new()
} }
} }
} }
@ -154,7 +167,7 @@ impl Tendermint {
// Commit if precommit is won. // Commit if precommit is won.
if vote.is_won() { if vote.is_won() {
let mut guard = self.our_params.s.write(); let mut guard = self.our_params.s.write();
*guard = Step::Commit; *guard = Step::Commit(seal.clone());
Ok(message.as_raw().to_vec()) Ok(message.as_raw().to_vec())
} else { } else {
Ok(message.as_raw().to_vec()) Ok(message.as_raw().to_vec())
@ -245,7 +258,7 @@ impl Engine for Tendermint {
Ok(()) 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(()) Ok(())
} }