Skip to content

Commit

Permalink
Use different types for the executors inputs and outputs (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
romac authored Oct 27, 2023
1 parent 4968797 commit 5e5d175
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 56 deletions.
4 changes: 2 additions & 2 deletions Code/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ publish = false

[dependencies]
malachite-common = { version = "0.1.0", path = "../common" }
malachite-round = { version = "0.1.0", path = "../round" }
malachite-vote = { version = "0.1.0", path = "../vote" }
malachite-round = { version = "0.1.0", path = "../round" }
malachite-vote = { version = "0.1.0", path = "../vote" }
30 changes: 19 additions & 11 deletions Code/consensus/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ where
Timeout(Timeout),
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Output<C>
where
C: Consensus,
{
Propose(C::Proposal),
Vote(C::Vote),
Decide(Round, C::Value),
SetTimeout(Timeout),
}

impl<C> Executor<C>
where
C: Consensus,
Expand All @@ -60,7 +71,7 @@ where
C::DUMMY_VALUE
}

pub fn execute(&mut self, msg: Message<C>) -> Option<Message<C>> {
pub fn execute(&mut self, msg: Message<C>) -> Option<Output<C>> {
let round_msg = match self.apply(msg) {
Some(msg) => msg,
None => return None,
Expand All @@ -76,9 +87,9 @@ where
None
}

RoundMessage::Proposal(p) => {
RoundMessage::Proposal(proposal) => {
// sign the proposal
Some(Message::Proposal(p))
Some(Output::Propose(proposal))
}

RoundMessage::Vote(mut v) => {
Expand All @@ -93,17 +104,14 @@ where

v.set_address(address);

Some(Message::Vote(v))
Some(Output::Vote(v))
}

RoundMessage::Timeout(_) => {
// schedule the timeout
None
}
RoundMessage::Timeout(timeout) => Some(Output::SetTimeout(timeout)),

RoundMessage::Decision(_) => {
// update the state
None
RoundMessage::Decision(value) => {
// TODO: update the state
Some(Output::Decide(value.round, value.value))
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion Code/round/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use malachite_common::{Consensus, Round, Timeout, TimeoutStep, ValueId};
use crate::state::RoundValue;

#[derive(Debug, PartialEq, Eq)]
pub enum Message<C: Consensus> {
pub enum Message<C>
where
C: Consensus,
{
NewRound(Round), // Move to the new round.
Proposal(C::Proposal), // Broadcast the proposal.
Vote(C::Vote), // Broadcast the vote.
Expand Down
5 changes: 2 additions & 3 deletions Code/test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[package]
name = "malachite-test"
name = "malachite-test"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
publish = false

[dependencies]
malachite-common = { version = "0.1.0", path = "../common" }
Expand Down
Loading

0 comments on commit 5e5d175

Please sign in to comment.