Skip to content

Commit

Permalink
Rename timeout-related variants for more clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Nov 1, 2023
1 parent d39d681 commit 10677dc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Code/consensus/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ where
NewRound(Round),
Proposal(Ctx::Proposal),
Vote(SignedVote<Ctx>),
Timeout(Timeout),
TimeoutElapsed(Timeout),
}

#[derive(Clone, Debug)]
Expand All @@ -49,7 +49,7 @@ where
Propose(Ctx::Proposal),
Vote(SignedVote<Ctx>),
Decide(Round, Ctx::Value),
SetTimeout(Timeout),
ScheduleTimeout(Timeout),
}

impl<Ctx> Executor<Ctx>
Expand Down Expand Up @@ -113,7 +113,7 @@ where
Some(Message::Vote(signed_vote))
}

RoundMessage::Timeout(timeout) => Some(Message::SetTimeout(timeout)),
RoundMessage::ScheduleTimeout(timeout) => Some(Message::ScheduleTimeout(timeout)),

RoundMessage::Decision(value) => {
// TODO: update the state
Expand All @@ -127,7 +127,7 @@ where
Event::NewRound(round) => self.apply_new_round(round),
Event::Proposal(proposal) => self.apply_proposal(proposal),
Event::Vote(signed_vote) => self.apply_vote(signed_vote),
Event::Timeout(timeout) => self.apply_timeout(timeout),
Event::TimeoutElapsed(timeout) => self.apply_timeout(timeout),
}
}

Expand Down
8 changes: 4 additions & 4 deletions Code/round/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ where
NewRound(Round), // Move to the new round.
Proposal(Ctx::Proposal), // Broadcast the proposal.
Vote(Ctx::Vote), // Broadcast the vote.
Timeout(Timeout), // Schedule the timeout.
ScheduleTimeout(Timeout), // Schedule the timeout.
Decision(RoundValue<Ctx::Value>), // Decide the value.
}

Expand All @@ -23,7 +23,7 @@ where
Message::NewRound(round) => Message::NewRound(*round),
Message::Proposal(proposal) => Message::Proposal(proposal.clone()),
Message::Vote(vote) => Message::Vote(vote.clone()),
Message::Timeout(timeout) => Message::Timeout(*timeout),
Message::ScheduleTimeout(timeout) => Message::ScheduleTimeout(*timeout),
Message::Decision(round_value) => Message::Decision(round_value.clone()),
}
}
Expand All @@ -50,8 +50,8 @@ where
Message::Vote(Ctx::new_precommit(round, value_id, address))
}

pub fn timeout(round: Round, step: TimeoutStep) -> Self {
Message::Timeout(Timeout { round, step })
pub fn schedule_timeout(round: Round, step: TimeoutStep) -> Self {
Message::ScheduleTimeout(Timeout { round, step })
}

pub fn decision(round: Round, value: Ctx::Value) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions Code/round/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub fn schedule_timeout_propose<Ctx>(state: State<Ctx>) -> Transition<Ctx>
where
Ctx: Context,
{
let timeout = Message::timeout(state.round, TimeoutStep::Propose);
let timeout = Message::schedule_timeout(state.round, TimeoutStep::Propose);
Transition::to(state.next_step()).with_message(timeout)
}

Expand All @@ -261,7 +261,7 @@ pub fn schedule_timeout_prevote<Ctx>(state: State<Ctx>) -> Transition<Ctx>
where
Ctx: Context,
{
let message = Message::timeout(state.round, TimeoutStep::Prevote);
let message = Message::schedule_timeout(state.round, TimeoutStep::Prevote);
Transition::to(state.next_step()).with_message(message)
}

Expand All @@ -272,7 +272,7 @@ pub fn schedule_timeout_precommit<Ctx>(state: State<Ctx>) -> Transition<Ctx>
where
Ctx: Context,
{
let message = Message::timeout(state.round, TimeoutStep::Precommit);
let message = Message::schedule_timeout(state.round, TimeoutStep::Precommit);
Transition::to(state.next_step()).with_message(message)
}

Expand Down
10 changes: 5 additions & 5 deletions Code/test/tests/consensus_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn to_input_msg(output: Message<TestContext>) -> Option<Event<TestContext>> {
Message::Propose(p) => Some(Event::Proposal(p)),
Message::Vote(v) => Some(Event::Vote(v)),
Message::Decide(_, _) => None,
Message::SetTimeout(_) => None,
Message::ScheduleTimeout(_) => None,
}
}

Expand Down Expand Up @@ -236,7 +236,7 @@ fn executor_steps_not_proposer() {
TestStep {
desc: "Start round 0, we are not the proposer",
input_event: Some(Event::NewRound(Round::new(0))),
expected_output: Some(Message::SetTimeout(Timeout::propose(Round::new(0)))),
expected_output: Some(Message::ScheduleTimeout(Timeout::propose(Round::new(0)))),
new_state: State {
round: Round::new(0),
step: Step::Propose,
Expand Down Expand Up @@ -416,7 +416,7 @@ fn executor_steps_not_proposer_timeout() {
TestStep {
desc: "Start round 0, we are not the proposer",
input_event: Some(Event::NewRound(Round::new(0))),
expected_output: Some(Message::SetTimeout(Timeout::propose(Round::new(0)))),
expected_output: Some(Message::ScheduleTimeout(Timeout::propose(Round::new(0)))),
new_state: State {
round: Round::new(0),
step: Step::Propose,
Expand All @@ -428,7 +428,7 @@ fn executor_steps_not_proposer_timeout() {
// Receive a propose timeout, prevote for nil (v1)
TestStep {
desc: "Receive a propose timeout, prevote for nil (v1)",
input_event: Some(Event::Timeout(Timeout::propose(Round::new(0)))),
input_event: Some(Event::TimeoutElapsed(Timeout::propose(Round::new(0)))),
expected_output: Some(Message::Vote(
Vote::new_prevote(Round::new(0), None, my_addr).signed(&my_sk),
)),
Expand Down Expand Up @@ -531,7 +531,7 @@ fn executor_steps_not_proposer_timeout() {
// we receive a precommit timeout, start a new round
TestStep {
desc: "we receive a precommit timeout, start a new round",
input_event: Some(Event::Timeout(Timeout::precommit(Round::new(0)))),
input_event: Some(Event::TimeoutElapsed(Timeout::precommit(Round::new(0)))),
expected_output: None,
new_state: State {
round: Round::new(1),
Expand Down
2 changes: 1 addition & 1 deletion Code/test/tests/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn test_prevote() {
assert_eq!(transition.next_state.step, Step::Propose);
assert_eq!(
transition.message.unwrap(),
Message::Timeout(Timeout {
Message::ScheduleTimeout(Timeout {
round: Round::new(1),
step: TimeoutStep::Propose
})
Expand Down

0 comments on commit 10677dc

Please sign in to comment.