Cleanup `handle_part` function.

This commit is contained in:
Marc Brinkmann 2018-10-03 13:21:59 +02:00 committed by Andreas Fackler
parent d2627272fe
commit 284b5088b3
1 changed files with 6 additions and 9 deletions

View File

@ -362,17 +362,14 @@ where
/// Handles a `Part` message that was output by Honey Badger.
fn handle_part(&mut self, sender_id: &N, part: Part) -> Result<Step<C, N>> {
// Awkward construction due to borrowck shortcomings; we need to borrow two struct fields
// mutably and have the borrow end early enough for us to call `send_transaction`.
// FIXME: This part should be cleaned up and restructured.
let res = {
let kgs = self.key_gen_state.as_mut();
let rng = &mut self.rng;
let handle = |kgs: &mut KeyGenState<N>| kgs.key_gen.handle_part(rng, &sender_id, part);
kgs.and_then(handle)
let outcome = if let Some(kgs) = self.key_gen_state.as_mut() {
kgs.key_gen.handle_part(&mut self.rng, &sender_id, part)
} else {
// No key generation ongoing. Return early.
return Ok(Step::default());
};
match res {
match outcome {
Some(PartOutcome::Valid(ack)) => self.send_transaction(KeyGenMessage::Ack(ack)),
Some(PartOutcome::Invalid(fault_log)) => Ok(fault_log.into()),
None => Ok(Step::default()),