Skip to content

Commit

Permalink
Rename echo_message -> echo_broadcast for consistency with other code…
Browse files Browse the repository at this point in the history
… and type names
  • Loading branch information
fjarri committed Oct 25, 2024
1 parent 6aee9bf commit 794de35
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
32 changes: 16 additions & 16 deletions manul/src/session/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) enum EchoRoundError<Id> {

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EchoRoundMessage<SP: SessionParameters> {
pub(crate) echo_messages: SerializableMap<SP::Verifier, SignedMessage<EchoBroadcast>>,
pub(crate) echo_broadcasts: SerializableMap<SP::Verifier, SignedMessage<EchoBroadcast>>,
}

/// Each protocol round can contain one `EchoRound` with "echo messages" that are sent to all
Expand All @@ -40,7 +40,7 @@ pub struct EchoRoundMessage<SP: SessionParameters> {
#[derive(Debug)]
pub struct EchoRound<P, SP: SessionParameters> {
verifier: SP::Verifier,
echo_messages: BTreeMap<SP::Verifier, SignedMessage<EchoBroadcast>>,
echo_broadcasts: BTreeMap<SP::Verifier, SignedMessage<EchoBroadcast>>,
destinations: BTreeSet<SP::Verifier>,
expected_echos: BTreeSet<SP::Verifier>,
main_round: Box<dyn ObjectSafeRound<SP::Verifier, Protocol = P>>,
Expand All @@ -55,25 +55,25 @@ where
{
pub fn new(
verifier: SP::Verifier,
my_echo_message: SignedMessage<EchoBroadcast>,
echo_messages: BTreeMap<SP::Verifier, SignedMessage<EchoBroadcast>>,
my_echo_broadcast: SignedMessage<EchoBroadcast>,
echo_broadcasts: BTreeMap<SP::Verifier, SignedMessage<EchoBroadcast>>,
main_round: Box<dyn ObjectSafeRound<SP::Verifier, Protocol = P>>,
payloads: BTreeMap<SP::Verifier, Payload>,
artifacts: BTreeMap<SP::Verifier, Artifact>,
) -> Self {
let destinations = echo_messages.keys().cloned().collect::<BTreeSet<_>>();
let destinations = echo_broadcasts.keys().cloned().collect::<BTreeSet<_>>();

// Add our own echo message because we expect it to be sent back from other nodes.
let mut expected_echos = destinations.clone();
expected_echos.insert(verifier.clone());

let mut echo_messages = echo_messages;
echo_messages.insert(verifier.clone(), my_echo_message);
let mut echo_broadcasts = echo_broadcasts;
echo_broadcasts.insert(verifier.clone(), my_echo_broadcast);

debug!("{:?}: initialized echo round with {:?}", verifier, destinations);
Self {
verifier,
echo_messages,
echo_broadcasts,
destinations,
expected_echos,
main_round,
Expand Down Expand Up @@ -110,16 +110,16 @@ where
debug!("{:?}: making echo round message for {:?}", self.verifier, destination);

// Don't send our own message the second time
let mut echo_messages = self.echo_messages.clone();
if echo_messages.remove(&self.verifier).is_none() {
let mut echo_broadcasts = self.echo_broadcasts.clone();
if echo_broadcasts.remove(&self.verifier).is_none() {
return Err(LocalError::new(format!(
"Expected {:?} to be in the set of all echo messages",
self.verifier
)));
}

let message = EchoRoundMessage::<SP> {
echo_messages: echo_messages.into(),
echo_broadcasts: echo_broadcasts.into(),
};
let dm = DirectMessage::new::<P, _>(&message)?;
Ok((dm, Artifact::empty()))
Expand Down Expand Up @@ -150,7 +150,7 @@ where
self.destinations
)));
}
let message_keys = message.echo_messages.keys().cloned().collect::<BTreeSet<_>>();
let message_keys = message.echo_broadcasts.keys().cloned().collect::<BTreeSet<_>>();

let missing_keys = expected_keys.difference(&message_keys).collect::<Vec<_>>();
if !missing_keys.is_empty() {
Expand All @@ -172,12 +172,12 @@ where
// If there's a difference, it's a provable fault,
// since we have both messages signed by `from`.

for (sender, echo) in message.echo_messages.iter() {
for (sender, echo) in message.echo_broadcasts.iter() {
// We expect the key to be there since
// `message.echo_messages.keys()` is within `self.destinations`
// which was constructed as `self.echo_messages.keys()`.
// `message.echo_broadcasts.keys()` is within `self.destinations`
// which was constructed as `self.echo_broadcasts.keys()`.
let previously_received_echo = self
.echo_messages
.echo_broadcasts
.get(sender)
.expect("the key is present by construction");

Expand Down
6 changes: 3 additions & 3 deletions manul/src/session/evidence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ where
.map_err(|error| {
LocalError::new(format!("Failed to deserialize the given direct message: {:?}", error))
})?;
let echoed_to_us = deserialized.echo_messages.get(&from).ok_or_else(|| {
let echoed_to_us = deserialized.echo_broadcasts.get(&from).ok_or_else(|| {
LocalError::new(format!(
"The echo message from {from:?} is missing from the echo packet"
))
Expand Down Expand Up @@ -248,7 +248,7 @@ where
let verified = self.direct_message.clone().verify::<P, SP>(verifier)?;
let deserialized = verified.payload().deserialize::<P, EchoRoundMessage<SP>>()?;
let invalid_echo = deserialized
.echo_messages
.echo_broadcasts
.get(&self.invalid_echo_sender)
.ok_or_else(|| {
EvidenceError::InvalidEvidence(format!(
Expand Down Expand Up @@ -419,7 +419,7 @@ where
let echo_set = DirectMessage::deserialize::<P, EchoRoundMessage<SP>>(verified_combined_echo.payload())?;

let mut verified_echo_set = Vec::new();
for (other_verifier, echo_broadcast) in echo_set.echo_messages.iter() {
for (other_verifier, echo_broadcast) in echo_set.echo_broadcasts.iter() {
let verified_echo_broadcast = echo_broadcast.clone().verify::<P, SP>(other_verifier)?;
let metadata = verified_echo_broadcast.metadata();
if metadata.session_id() != session_id || metadata.round_id() != *round_id {
Expand Down
14 changes: 7 additions & 7 deletions manul/src/session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub struct Session<P: Protocol, SP: SessionParameters> {
verifier: SP::Verifier,
round: Box<dyn ObjectSafeRound<SP::Verifier, Protocol = P>>,
message_destinations: BTreeSet<SP::Verifier>,
echo_message: Option<SignedMessage<EchoBroadcast>>,
echo_broadcast: Option<SignedMessage<EchoBroadcast>>,
possible_next_rounds: BTreeSet<RoundId>,
transcript: Transcript<P, SP>,
}
Expand Down Expand Up @@ -159,14 +159,14 @@ where
transcript: Transcript<P, SP>,
) -> Result<Self, LocalError> {
let verifier = signer.verifying_key();
let echo_message = round
let echo_broadcast = round
.make_echo_broadcast(rng)
.transpose()?
.map(|echo| SignedMessage::new::<P, SP>(rng, &signer, &session_id, round.id(), echo))
.transpose()?;
let message_destinations = round.message_destinations().clone();

let possible_next_rounds = if echo_message.is_none() {
let possible_next_rounds = if echo_broadcast.is_none() {
round.possible_next_rounds()
} else {
BTreeSet::from([round.id().echo()])
Expand All @@ -177,7 +177,7 @@ where
signer,
verifier,
round,
echo_message,
echo_broadcast,
possible_next_rounds,
message_destinations,
transcript,
Expand Down Expand Up @@ -215,7 +215,7 @@ where
&self.session_id,
self.round.id(),
direct_message,
self.echo_message.clone(),
self.echo_broadcast.clone(),
)?;

Ok((
Expand Down Expand Up @@ -413,10 +413,10 @@ where
accum.still_have_not_sent_messages,
)?;

if let Some(echo_message) = self.echo_message {
if let Some(echo_broadcast) = self.echo_broadcast {
let round = Box::new(ObjectSafeRoundWrapper::new(EchoRound::<P, SP>::new(
verifier,
echo_message,
echo_broadcast,
transcript.echo_broadcasts(round_id)?,
self.round,
accum.payloads,
Expand Down

0 comments on commit 794de35

Please sign in to comment.