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:
Rakan Alhneiti
2020-06-18 20:37:49 +02:00
committed by GitHub
parent 4b5a0680e3
commit d25f460b63
15 changed files with 394 additions and 94 deletions
@@ -17,6 +17,7 @@ codec = { package = "parity-scale-codec", version = "1.3.0", default-features =
merlin = { version = "2.0", default-features = false }
sp-std = { version = "2.0.0-rc3", default-features = false, path = "../../std" }
sp-api = { version = "2.0.0-rc3", default-features = false, path = "../../api" }
sp-core = { version = "2.0.0-rc3", default-features = false, path = "../../core" }
sp-consensus = { version = "0.8.0-rc3", optional = true, path = "../common" }
sp-consensus-vrf = { version = "0.8.0-rc3", path = "../vrf", default-features = false }
sp-inherents = { version = "2.0.0-rc3", default-features = false, path = "../../inherents" }
@@ -26,6 +27,7 @@ sp-timestamp = { version = "2.0.0-rc3", default-features = false, path = "../../
[features]
default = ["std"]
std = [
"sp-core/std",
"sp-application-crypto/std",
"codec/std",
"merlin/std",
@@ -31,6 +31,8 @@ pub use merlin::Transcript;
use codec::{Encode, Decode};
use sp_std::vec::Vec;
use sp_runtime::{ConsensusEngineId, RuntimeDebug};
#[cfg(feature = "std")]
use sp_core::vrf::{VRFTranscriptData, VRFTranscriptValue};
use crate::digests::{NextEpochDescriptor, NextConfigDescriptor};
mod app {
@@ -94,6 +96,23 @@ pub fn make_transcript(
transcript
}
/// Make a VRF transcript data container
#[cfg(feature = "std")]
pub fn make_transcript_data(
randomness: &Randomness,
slot_number: u64,
epoch: u64,
) -> VRFTranscriptData {
VRFTranscriptData {
label: &BABE_ENGINE_ID,
items: vec![
("slot number", VRFTranscriptValue::U64(slot_number)),
("current epoch", VRFTranscriptValue::U64(epoch)),
("chain randomness", VRFTranscriptValue::Bytes(&randomness[..])),
]
}
}
/// An consensus log item for BABE.
#[derive(Decode, Encode, Clone, PartialEq, Eq)]
pub enum ConsensusLog {