Skip to content

Commit

Permalink
justification for round changes wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jking-aus committed Oct 15, 2024
1 parent f551f94 commit 840bb5d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 24 deletions.
2 changes: 1 addition & 1 deletion anchor/qbft/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<D: Clone + Debug + Hash + Eq + Default> Default for ConfigBuilder<DefaultLe
committee_size: 5,
committee_members: vec![0, 1, 2, 3, 4],
quorum_size: 4,
round: 0,
round: 1,
pr: 0,
pv: D::default(),
round_time: Duration::new(2, 0),
Expand Down
75 changes: 54 additions & 21 deletions anchor/qbft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,11 @@ where
debug!("The corresponding pv value is: {:?}", max_value.pv);
self.set_pr_pv(max_value.pr, max_value.pv.clone());
} else {
debug!("Max pr is 0 and/or data is none");
debug!("ID{}: Prepare consensus not reached previously and/or consensus data is none" , self.operator_id());
}
} else {
debug!("The hashmap is empty.");
warn!("RoundChange quorum was not met");
//TODO: exit here with error
}
}
}
Expand All @@ -405,10 +406,6 @@ where

//Round start function
fn start_round(&mut self) {
if matches!(self.config.state, InstanceState::SentRoundChange) {
self.check_round_change_quorum(self.current_round, self.config.quorum_size);
}
self.set_state(InstanceState::AwaitingProposal);
debug!(
"ID{}: Round {} starting",
self.operator_id(),
Expand All @@ -417,13 +414,28 @@ where

if self.check_leader(self.operator_id()) {
debug!("ID{}: believes they are the leader", self.operator_id());

self.send_message(OutMessage::GetData(GetData {
operator_id: self.operator_id(),
instance_height: self.instance_height,
round: self.current_round,
}));
if matches!(self.config.state, InstanceState::SentRoundChange) {
self.check_round_change_quorum(self.current_round, self.config.quorum_size);
}
if self.config.pr >= 1 && self.validate_data(self.config.pv.clone()).is_some() {
debug!(
"ID{}: pr: {} and pv: {:?} are set from previous round",
self.operator_id(),
self.config.pr,
self.config.pv
);
self.send_proposal(self.config.pv.clone());
self.send_prepare(self.config.pv.clone());
} else {
debug! {"ID{}: requesting data from client processor", self.operator_id()}
self.send_message(OutMessage::GetData(GetData {
operator_id: self.operator_id(),
instance_height: self.instance_height,
round: self.current_round,
}));
}
};
self.set_state(InstanceState::AwaitingProposal);
}

/// Received message functions
Expand Down Expand Up @@ -456,18 +468,39 @@ where
&& self.check_committee(&propose_message.operator_id)
&& matches!(self.config.state, InstanceState::AwaitingProposal)
{
let self_operator_id = self.operator_id();
debug!(
"ID {}: Proposal is from round leader with ID {}",
self_operator_id, propose_message.operator_id,
"ID{}: Proposal is from round leader with ID {}",
self.operator_id(),
propose_message.operator_id,
);
// Validate the proposal with a local function that is is passed in from the config
// similar to the leaderfunction for now return bool -> true
if let Some(data) = self.validate_data(propose_message.value) {
// If of valid type, set data locally then send prepare
self.set_data(data.clone());
self.send_prepare(data);
self.check_round_change_quorum(self.current_round, self.config.quorum_size);
if self.current_round == 1 || self.config.pr <= 1 {
if let Some(data) = self.validate_data(propose_message.value.clone()) {
// If of valid type, set data locally then send prepare
self.set_data(data.clone());
self.send_prepare(data);
} else {
warn!("ID{}: Received invalid data", self.operator_id());
}
} else if self.validate_data(self.config.pv.clone()).is_some() {
debug!(
"ID{}: pr: {} and pv: {:?} are set from previous round",
self.operator_id(),
self.config.pr,
self.config.pv
);
if propose_message.value == self.config.pv {
self.set_data(self.config.pv.clone());
self.send_prepare(self.config.pv.clone());
} else {
debug!(
"ID{}: Received data does not agree with stored pv",
self.operator_id()
);
}
}
} else {
warn!("ID{}: this shouldn't happen", self.operator_id());
}
}

Expand Down
4 changes: 2 additions & 2 deletions anchor/qbft/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ fn emulate_client_processor<D: Default + Debug + Clone + Send + Sync + 'static +
// Duplicate the message to the new channel
let _ = new_senders[index].send(message.clone());
if let OutMessage::GetData(request) = message.clone() {
if request.operator_id != 0 {
if request.operator_id != 1 {
let _ = senders[index].send(InMessage::RecvData(RecvData {
operator_id: request.operator_id,
round: request.round,
Expand All @@ -239,7 +239,7 @@ fn emulate_client_processor<D: Default + Debug + Clone + Send + Sync + 'static +

debug!("responding to GetData")
} else {
debug!("ignoring request from id 0 for testing")
debug!("ignoring request from id 1 for testing")
}
}
if let OutMessage::Completed(completed_message) = message.clone() {
Expand Down

0 comments on commit 840bb5d

Please sign in to comment.