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

Commit

Permalink
Ad 92 (#97)
Browse files Browse the repository at this point in the history
* sign_commitment()

* Error handling todo
  • Loading branch information
adoerr authored Mar 4, 2021
1 parent 639790a commit 314fa20
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions client/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ where
number == next_block_to_vote_on
}

fn sign_commitment(&self, id: &Id, commitment: &[u8]) -> Option<Signature> {
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<Block>) {
debug!(target: "beefy", "🥩 Finality notification: {:?}", notification);

Expand Down Expand Up @@ -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;
}
};
Expand Down

0 comments on commit 314fa20

Please sign in to comment.