Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AgeManning committed Oct 18, 2024
1 parent a61188c commit d0705cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
19 changes: 5 additions & 14 deletions anchor/qbft/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use config::Config;
pub use config::{Config, ConfigBuilder};
use std::cmp::Eq;
use std::collections::{HashMap, HashSet};
use std::fmt::Debug;
Expand Down Expand Up @@ -113,13 +113,7 @@ where
// When a RoundChange message is received, run the received_roundChange function
Some(InMessage::RoundChange(operator_id, round, maybe_past_consensus_data)) => self.received_round_change(operator_id, round, maybe_past_consensus_data),
// When a CloseRequest is received, close the instance
Some(InMessage::RequestClose) => {
// stub function in case we want to do anything pre-close
self.received_request_close();
break;
}

None => { }// Channel is closed
None => { } // Channel is closed
}

}
Expand Down Expand Up @@ -368,7 +362,7 @@ where
}

// Store the prepare message
if self
if !self
.prepare_messages
.entry(consensus_data.round)
.or_default()
Expand Down Expand Up @@ -426,7 +420,7 @@ where
}

// Store the received commit message
if self
if !self
.commit_messages
.entry(self.current_round)
.or_default()
Expand All @@ -448,6 +442,7 @@ where
&& matches!(self.state, InstanceState::Commit)
{
self.send_completed(Completed::Success(data.clone()));
self.state = InstanceState::Terminating;
}
}
}
Expand Down Expand Up @@ -515,10 +510,6 @@ where
}
}

fn received_request_close(&self) {
debug!(?self.state, "Received close request");
}

// Send message functions
fn send_proposal(&mut self, data: D) {
self.send_message(OutMessage::Propose(ConsensusData {
Expand Down
29 changes: 12 additions & 17 deletions anchor/qbft/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,18 @@ fn emulate_client_processor<D: Default + Debug + Clone + Send + Sync + 'static +
senders: &mut HashMap<OperatorId, UnboundedSender<InMessage<D>>>,
new_senders: &mut HashMap<OperatorId, UnboundedSender<OutMessage<D>>>| {
// Duplicate the message to the new channel
let _ = new_senders.get(&operator_id).unwrap().send(message.clone());
let _ = new_senders.get(operator_id).unwrap().send(message.clone());
if let OutMessage::GetData(round) = message.clone() {
let _ =
senders
.get(&operator_id)
.get(operator_id)
.unwrap()
.send(InMessage::RecvData(ConsensusData {
round,
data: data.clone(),
}));
}
if let OutMessage::Completed(_completed_message) = message.clone() {
let _ = senders
.get(&operator_id)
.unwrap()
.send(InMessage::RequestClose);
}
if let OutMessage::Completed(_completed_message) = message.clone() {}
};

// Get messages from each instance, apply the function above and return the resulting channels
Expand Down Expand Up @@ -276,10 +271,8 @@ fn emulate_broadcast_network<D: Default + Debug + Clone + Send + Sync + 'static
.iter_mut()
.for_each(|(current_operator_id, sender)| {
if current_operator_id != operator_id {
let _ = sender.send(InMessage::Propose(
operator_id.clone(),
consensus_data.clone(),
));
let _ = sender
.send(InMessage::Propose(*operator_id, consensus_data.clone()));
}
});
}
Expand Down Expand Up @@ -380,11 +373,13 @@ where
));

while let Some((operator_id, out_message)) = grouped_receivers.next().await {
debug!(
?out_message,
operator = *operator_id,
"Handling message from instance"
);
/*
debug!(
?out_message,
operator = *operator_id,
"Handling message from instance"
);
*/
// Custom handling of the out message
message_handling(out_message, &operator_id, &mut senders, &mut new_senders);
// Add back a new future to await for the next message
Expand Down
2 changes: 0 additions & 2 deletions anchor/qbft/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ pub enum InMessage<D: Debug + Clone + Eq + Hash> {
Commit(OperatorId, ConsensusData<D>),
/// Round change message received from network
RoundChange(OperatorId, Round, Option<ConsensusData<D>>),
/// Close instance message received from the client processor
RequestClose,
}

/// Messages that may be sent to the message_out channel from the instance to the client processor
Expand Down

0 comments on commit d0705cf

Please sign in to comment.