Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 314fa20

Browse files
authored
Ad 92 (#97)
* sign_commitment() * Error handling todo
1 parent 639790a commit 314fa20

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

client/beefy/src/lib.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,17 @@ where
264264
number == next_block_to_vote_on
265265
}
266266

267+
fn sign_commitment(&self, id: &Id, commitment: &[u8]) -> Option<Signature> {
268+
let sig = SyncCryptoStore::sign_with(&*self.key_store, KEY_TYPE, &id.to_public_crypto_pair(), &commitment)
269+
.ok()
270+
.flatten()?
271+
.try_into()
272+
.ok()?;
273+
274+
// TODO #98 - return errors as well
275+
Some(sig)
276+
}
277+
267278
fn handle_finality_notification(&mut self, notification: FinalityNotification<Block>) {
268279
debug!(target: "beefy", "🥩 Finality notification: {:?}", notification);
269280

@@ -300,22 +311,10 @@ where
300311
validator_set_id: current_set_id,
301312
};
302313

303-
// TODO #92
304-
let signature = match SyncCryptoStore::sign_with(
305-
&*self.key_store,
306-
KEY_TYPE,
307-
&local_id.to_public_crypto_pair(),
308-
&commitment.encode(),
309-
)
310-
.map_err(|_| ())
311-
.and_then(|res| {
312-
res.expect("closure won't be called in case of an error; qed")
313-
.try_into()
314-
.map_err(|_| ())
315-
}) {
316-
Ok(sig) => sig,
317-
Err(err) => {
318-
warn!(target: "beefy", "🥩 Error signing: {:?}", err);
314+
let signature = match self.sign_commitment(local_id, commitment.encode().as_ref()) {
315+
Some(sig) => sig,
316+
None => {
317+
warn!(target: "beefy", "🥩 Error signing commitment: {:?}", commitment);
319318
return;
320319
}
321320
};

0 commit comments

Comments
 (0)