From 314fa206c2a9b8df66f1e63867fa8d4f1a106e89 Mon Sep 17 00:00:00 2001 From: Andreas Doerr Date: Thu, 4 Mar 2021 06:38:55 +0100 Subject: [PATCH] Ad 92 (#97) * sign_commitment() * Error handling todo --- client/beefy/src/lib.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/client/beefy/src/lib.rs b/client/beefy/src/lib.rs index 0722f00d0797b..4cd2aa6e67a1e 100644 --- a/client/beefy/src/lib.rs +++ b/client/beefy/src/lib.rs @@ -264,6 +264,17 @@ where number == next_block_to_vote_on } + fn sign_commitment(&self, id: &Id, commitment: &[u8]) -> Option { + let sig = SyncCryptoStore::sign_with(&*self.key_store, KEY_TYPE, &id.to_public_crypto_pair(), &commitment) + .ok() + .flatten()? + .try_into() + .ok()?; + + // TODO #98 - return errors as well + Some(sig) + } + fn handle_finality_notification(&mut self, notification: FinalityNotification) { debug!(target: "beefy", "🥩 Finality notification: {:?}", notification); @@ -300,22 +311,10 @@ where validator_set_id: current_set_id, }; - // TODO #92 - let signature = match SyncCryptoStore::sign_with( - &*self.key_store, - KEY_TYPE, - &local_id.to_public_crypto_pair(), - &commitment.encode(), - ) - .map_err(|_| ()) - .and_then(|res| { - res.expect("closure won't be called in case of an error; qed") - .try_into() - .map_err(|_| ()) - }) { - Ok(sig) => sig, - Err(err) => { - warn!(target: "beefy", "🥩 Error signing: {:?}", err); + let signature = match self.sign_commitment(local_id, commitment.encode().as_ref()) { + Some(sig) => sig, + None => { + warn!(target: "beefy", "🥩 Error signing commitment: {:?}", commitment); return; } };