Skip to content

Commit

Permalink
notify that the voter proposed through Environment
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilva committed Mar 29, 2019
1 parent b40c014 commit 33cde87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use tokio::timer::Delay;
use parking_lot::Mutex;
use futures::prelude::*;
use futures::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use super::{Chain, Commit, Error, Equivocation, Message, Prevote, Precommit, SignedMessage};
use super::{Chain, Commit, Error, Equivocation, Message, Prevote, Precommit, PrimaryPropose, SignedMessage};

pub const GENESIS_HASH: &str = "genesis";
const NULL_HASH: &str = "NULL";
Expand Down Expand Up @@ -236,6 +236,10 @@ impl crate::voter::Environment<&'static str, u32> for Environment {
Ok(())
}

fn proposed(&self, _round: u64, _propose: PrimaryPropose<&'static str, u32>) -> Result<(), Self::Error> {
Ok(())
}

fn prevoted(&self, _round: u64, _prevote: Prevote<&'static str, u32>) -> Result<(), Self::Error> {
Ok(())
}
Expand Down
7 changes: 5 additions & 2 deletions src/voter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ use std::sync::Arc;

use crate::round::State as RoundState;
use crate::{
Chain, Commit, CompactCommit, Equivocation, Message, Prevote, Precommit, SignedMessage,
BlockNumberOps, validate_commit
Chain, Commit, CompactCommit, Equivocation, Message, Prevote, Precommit, PrimaryPropose,
SignedMessage, BlockNumberOps, validate_commit
};
use crate::voter_set::VoterSet;
use past_rounds::PastRounds;
Expand Down Expand Up @@ -87,6 +87,9 @@ pub trait Environment<H: Eq, N: BlockNumberOps>: Chain<H, N> {
/// commit messages that are sent (e.g. random value in [0, 1] seconds).
fn round_commit_timer(&self) -> Self::Timer;

/// Note that we've done a primary proposal in the given round.
fn proposed(&self, round: u64, propose: PrimaryPropose<H, N>) -> Result<(), Self::Error>;

/// Note that we have prevoted in the given round.
fn prevoted(&self, round: u64, prevote: Prevote<H, N>) -> Result<(), Self::Error>;

Expand Down
12 changes: 6 additions & 6 deletions src/voter/voting_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ impl<H, N, E: Environment<H, N>> VotingRound<H, N, E> where
let should_send_primary = maybe_finalized.map_or(true, |f| last_round_estimate.1 < f.1);
if should_send_primary {
debug!(target: "afg", "Sending primary block hint for round {}", self.votes.number());
self.outgoing.push(Message::PrimaryPropose(
PrimaryPropose {
target_hash: last_round_estimate.0,
target_number: last_round_estimate.1,
})
);
let primary = PrimaryPropose {
target_hash: last_round_estimate.0,
target_number: last_round_estimate.1,
};
self.env.proposed(self.round_number(), primary.clone())?;
self.outgoing.push(Message::PrimaryPropose(primary));
self.state = Some(State::Proposed(prevote_timer, precommit_timer));

return Ok(());
Expand Down

0 comments on commit 33cde87

Please sign in to comment.