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

Commit 8f7f4e2

Browse files
authored
Make KeyStore optional (#173)
1 parent 5fb0be3 commit 8f7f4e2

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

client/beefy/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ where
9090
/// This is a thin shim around running and awaiting a BEEFY worker.
9191
pub async fn start_beefy_gadget<B, P, BE, C, N, SO>(
9292
client: Arc<C>,
93-
key_store: SyncCryptoStorePtr,
93+
key_store: Option<SyncCryptoStorePtr>,
9494
network: N,
9595
signed_commitment_sender: notification::BeefySignedCommitmentSender<B, P::Signature>,
9696
_sync_oracle: SO,

client/beefy/src/worker.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ where
6565
C: Client<B, BE, P>,
6666
{
6767
client: Arc<C>,
68-
key_store: SyncCryptoStorePtr,
68+
key_store: Option<SyncCryptoStorePtr>,
6969
signed_commitment_sender: notification::BeefySignedCommitmentSender<B, P::Signature>,
7070
gossip_engine: Arc<Mutex<GossipEngine<B>>>,
7171
gossip_validator: Arc<BeefyGossipValidator<B, P>>,
@@ -103,7 +103,7 @@ where
103103
/// The BEEFY pallet is needed in order to keep track of the BEEFY authority set.
104104
pub(crate) fn new(
105105
client: Arc<C>,
106-
key_store: SyncCryptoStorePtr,
106+
key_store: Option<SyncCryptoStorePtr>,
107107
signed_commitment_sender: notification::BeefySignedCommitmentSender<B, P::Signature>,
108108
gossip_engine: GossipEngine<B>,
109109
gossip_validator: Arc<BeefyGossipValidator<B, P>>,
@@ -158,7 +158,12 @@ where
158158
}
159159

160160
fn sign_commitment(&self, id: &P::Public, commitment: &[u8]) -> Result<P::Signature, error::Crypto<P::Public>> {
161-
let sig = SyncCryptoStore::sign_with(&*self.key_store, KEY_TYPE, &id.to_public_crypto_pair(), &commitment)
161+
let key_store = self
162+
.key_store
163+
.clone()
164+
.ok_or_else(|| error::Crypto::CannotSign((*id).clone(), "Missing KeyStore".into()))?;
165+
166+
let sig = SyncCryptoStore::sign_with(&*key_store, KEY_TYPE, &id.to_public_crypto_pair(), &commitment)
162167
.map_err(|e| error::Crypto::CannotSign((*id).clone(), e.to_string()))?
163168
.ok_or_else(|| error::Crypto::CannotSign((*id).clone(), "No key in KeyStore found".into()))?;
164169

@@ -190,10 +195,12 @@ where
190195
///
191196
/// `None` is returned, if we are not permitted to vote
192197
fn local_id(&self) -> Option<P::Public> {
198+
let key_store = self.key_store.clone()?;
199+
193200
self.rounds
194201
.validators()
195202
.iter()
196-
.find(|id| SyncCryptoStore::has_keys(&*self.key_store, &[(id.to_raw_vec(), KEY_TYPE)]))
203+
.find(|id| SyncCryptoStore::has_keys(&*key_store, &[(id.to_raw_vec(), KEY_TYPE)]))
197204
.cloned()
198205
}
199206

0 commit comments

Comments
 (0)