mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +00:00
VRF refactory (#13889)
* First iteration to encapsulate schnorrkel and merlin usage * Remove schnorkel direct dependency from BABE pallet * Remove schnorrkel direct dependency from BABE client * Trivial renaming for VrfTranscript data and value * Better errors * Expose a function to get a schnorrkel friendly transcript * Keep the vrf signature stuff together (preventing some clones around) * Fix tests * Remove vrf agnostic transcript and define it as an associated type for VrfSigner and VrfVerifier * Fix babe pallet mock * Inner types are required to be public for polkadot * Update client/consensus/babe/src/verification.rs Co-authored-by: Koute <koute@users.noreply.github.com> * Nit * Remove Deref implementations * make_bytes as a method * Trigger CI --------- Co-authored-by: Koute <koute@users.noreply.github.com>
This commit is contained in:
@@ -25,11 +25,12 @@ use frame_support::{
|
||||
};
|
||||
use mock::*;
|
||||
use pallet_session::ShouldEndSession;
|
||||
use sp_consensus_babe::{AllowedSlots, BabeEpochConfiguration, Slot};
|
||||
use sp_consensus_vrf::schnorrkel::{VRFOutput, VRFProof};
|
||||
use sp_consensus_babe::{
|
||||
AllowedSlots, BabeEpochConfiguration, Slot, VrfSignature, RANDOMNESS_LENGTH,
|
||||
};
|
||||
use sp_core::crypto::Pair;
|
||||
|
||||
const EMPTY_RANDOMNESS: [u8; 32] = [
|
||||
const EMPTY_RANDOMNESS: [u8; RANDOMNESS_LENGTH] = [
|
||||
74, 25, 49, 128, 53, 97, 244, 49, 222, 202, 176, 2, 231, 66, 95, 10, 133, 49, 213, 228, 86,
|
||||
161, 164, 127, 217, 153, 138, 37, 48, 192, 248, 0,
|
||||
];
|
||||
@@ -62,10 +63,9 @@ fn first_block_epoch_zero_start() {
|
||||
|
||||
ext.execute_with(|| {
|
||||
let genesis_slot = Slot::from(100);
|
||||
let (vrf_output, vrf_proof, vrf_randomness) = make_vrf_output(genesis_slot, &pairs[0]);
|
||||
let (vrf_signature, vrf_randomness) = make_vrf_output(genesis_slot, &pairs[0]);
|
||||
|
||||
let first_vrf = vrf_output;
|
||||
let pre_digest = make_primary_pre_digest(0, genesis_slot, first_vrf.clone(), vrf_proof);
|
||||
let pre_digest = make_primary_pre_digest(0, genesis_slot, vrf_signature);
|
||||
|
||||
assert_eq!(Babe::genesis_slot(), Slot::from(0));
|
||||
System::reset_events();
|
||||
@@ -111,8 +111,8 @@ fn current_slot_is_processed_on_initialization() {
|
||||
|
||||
ext.execute_with(|| {
|
||||
let genesis_slot = Slot::from(10);
|
||||
let (vrf_output, vrf_proof, vrf_randomness) = make_vrf_output(genesis_slot, &pairs[0]);
|
||||
let pre_digest = make_primary_pre_digest(0, genesis_slot, vrf_output, vrf_proof);
|
||||
let (vrf_signature, vrf_randomness) = make_vrf_output(genesis_slot, &pairs[0]);
|
||||
let pre_digest = make_primary_pre_digest(0, genesis_slot, vrf_signature);
|
||||
|
||||
System::reset_events();
|
||||
System::initialize(&1, &Default::default(), &pre_digest);
|
||||
@@ -134,14 +134,14 @@ fn current_slot_is_processed_on_initialization() {
|
||||
|
||||
fn test_author_vrf_output<F>(make_pre_digest: F)
|
||||
where
|
||||
F: Fn(sp_consensus_babe::AuthorityIndex, Slot, VRFOutput, VRFProof) -> sp_runtime::Digest,
|
||||
F: Fn(sp_consensus_babe::AuthorityIndex, Slot, VrfSignature) -> sp_runtime::Digest,
|
||||
{
|
||||
let (pairs, mut ext) = new_test_ext_with_pairs(1);
|
||||
|
||||
ext.execute_with(|| {
|
||||
let genesis_slot = Slot::from(10);
|
||||
let (vrf_output, vrf_proof, vrf_randomness) = make_vrf_output(genesis_slot, &pairs[0]);
|
||||
let pre_digest = make_pre_digest(0, genesis_slot, vrf_output, vrf_proof);
|
||||
let (vrf_signature, vrf_randomness) = make_vrf_output(genesis_slot, &pairs[0]);
|
||||
let pre_digest = make_pre_digest(0, genesis_slot, vrf_signature);
|
||||
|
||||
System::reset_events();
|
||||
System::initialize(&1, &Default::default(), &pre_digest);
|
||||
|
||||
Reference in New Issue
Block a user