mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 03:27:58 +00:00
Babe VRF Signing in keystore (#6225)
* Introduce trait * Implement VRFSigner in keystore * Use vrf_sign from keystore * Convert output to VRFInOut * Simplify conversion * vrf_sign secondary slot using keystore * Fix RPC call to claim_slot * Use Public instead of Pair * Check primary threshold in signer * Fix interface to return error * Move vrf_sign to BareCryptoStore * Fix authorship_works test * Fix BABE logic leaks * Acquire a read lock once * Also fix RPC acquiring the read lock once * Implement a generic way to construct VRF Transcript * Use make_transcript_data to call sr25519_vrf_sign * Make sure VRFTranscriptData is serializable * Cleanup * Move VRF to it's own module * Implement & test VRF signing in testing module * Remove leftover * Fix feature requirements * Revert removing vec macro * Drop keystore pointer to prevent deadlock * Nitpicks * Add test to make sure make_transcript works * Fix mismatch in VRF transcript * Add a test to verify transcripts match in babe * Return VRFOutput and VRFProof from keystore
This commit is contained in:
@@ -32,6 +32,11 @@ use sp_consensus_babe::{
|
||||
digests::PreDigest,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sp_core::{
|
||||
crypto::Public,
|
||||
traits::BareCryptoStore,
|
||||
};
|
||||
use sp_application_crypto::AppKey;
|
||||
use sc_keystore::KeyStorePtr;
|
||||
use sc_rpc_api::DenyUnsafe;
|
||||
use sp_api::{ProvideRuntimeApi, BlockId};
|
||||
@@ -125,22 +130,23 @@ impl<B, C, SC> BabeApi for BabeRpcHandler<B, C, SC>
|
||||
|
||||
let mut claims: HashMap<AuthorityId, EpochAuthorship> = HashMap::new();
|
||||
|
||||
let key_pairs = {
|
||||
let keystore = keystore.read();
|
||||
let keys = {
|
||||
let ks = keystore.read();
|
||||
epoch.authorities.iter()
|
||||
.enumerate()
|
||||
.flat_map(|(i, a)| {
|
||||
keystore
|
||||
.key_pair::<sp_consensus_babe::AuthorityPair>(&a.0)
|
||||
.ok()
|
||||
.map(|kp| (kp, i))
|
||||
.filter_map(|(i, a)| {
|
||||
if ks.has_keys(&[(a.0.to_raw_vec(), AuthorityId::ID)]) {
|
||||
Some((a.0.clone(), i))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
for slot_number in epoch_start..epoch_end {
|
||||
if let Some((claim, key)) =
|
||||
authorship::claim_slot_using_key_pairs(slot_number, &epoch, &key_pairs)
|
||||
authorship::claim_slot_using_keys(slot_number, &epoch, &keystore, &keys)
|
||||
{
|
||||
match claim {
|
||||
PreDigest::Primary { .. } => {
|
||||
|
||||
Reference in New Issue
Block a user