Skip to content

Commit

Permalink
Use a private enum to get rid of unreachable!() in `preprocess_mess…
Browse files Browse the repository at this point in the history
…age()`
  • Loading branch information
fjarri committed Oct 30, 2024
1 parent 24b0914 commit 174ec69
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions manul/src/session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,26 +313,33 @@ where
return Ok(None);
}

if message_round_id == self.round_id() {
enum MessageFor {
ThisRound,
NextRound,
}

let message_for = if message_round_id == self.round_id() {
if accum.message_is_being_processed(from) {
let err = "Message from this party is already being processed";
accum.register_unprovable_error(from, RemoteError::new(err))?;
trace!("{key:?} {err}");
return Ok(None);
}
MessageFor::ThisRound
} else if self.possible_next_rounds.contains(&message_round_id) {
if accum.message_is_cached(from, message_round_id) {
let err = format!("Message for {:?} is already cached", message_round_id);
accum.register_unprovable_error(from, RemoteError::new(&err))?;
trace!("{key:?} {err}");
return Ok(None);
}
MessageFor::NextRound
} else {
let err = format!("Unexpected message round ID: {:?}", message_round_id);
accum.register_unprovable_error(from, RemoteError::new(&err))?;
trace!("{key:?} {err}");
return Ok(None);
}
};

// Verify the signature now

Expand All @@ -352,27 +359,20 @@ where
}
Err(MessageVerificationError::Local(error)) => return Err(error),
};
debug!(
"{key:?}: Received {:?} message from {:?}",
verified_message.metadata().round_id(),
from
);
debug!("{key:?}: Received {message_round_id:?} message from {from:?}");

if message_round_id == self.round_id() {
accum.mark_processing(&verified_message)?;
Ok(Some(verified_message))
} else if self.possible_next_rounds.contains(&message_round_id) {
debug!(
"{key:?}: Caching message from {:?} for {:?}",
verified_message.from(),
verified_message.metadata().round_id()
);
accum.cache_message(verified_message)?;
// TODO(dp): this is a bit awkward. It means "all good, but nothing to do here right
// now".
Ok(None)
} else {
unreachable!()
match message_for {
MessageFor::ThisRound => {
accum.mark_processing(&verified_message)?;
Ok(Some(verified_message))
}
MessageFor::NextRound => {
debug!("{key:?}: Caching message from {from:?} for {message_round_id:?}");
accum.cache_message(verified_message)?;
// TODO(dp): this is a bit awkward. It means "all good, but nothing to do here right
// now".
Ok(None)
}
}
}

Expand Down

0 comments on commit 174ec69

Please sign in to comment.