Make BEEFY client keystore generic over BEEFY AuthorityId type (#2258)

This is the significant step to make BEEFY client able to handle both
ECDSA and (ECDSA, BLS) type signature. The idea is having BEEFY Client
generic on crypto types makes migration to new types smoother.

This makes the BEEFY Keystore generic over AuthorityId and extends its
tests to cover the case when the AuthorityId is of type (ECDSA,
BLS12-377)

---------

Co-authored-by: Davide Galassi <davxy@datawok.net>
Co-authored-by: Robert Hambrock <roberthambrock@gmail.com>
This commit is contained in:
drskalman
2024-02-08 11:08:51 -05:00
committed by GitHub
parent bc5a758c0c
commit 0a94124d24
22 changed files with 742 additions and 231 deletions
@@ -485,8 +485,8 @@ pub(crate) mod tests {
use sc_network_test::Block;
use sp_application_crypto::key_types::BEEFY as BEEFY_KEY_TYPE;
use sp_consensus_beefy::{
ecdsa_crypto::Signature, known_payloads, Commitment, Keyring, MmrRootHash, Payload,
SignedCommitment, VoteMessage,
ecdsa_crypto::Signature, known_payloads, test_utils::Keyring, Commitment, MmrRootHash,
Payload, SignedCommitment, VoteMessage,
};
use sp_keystore::{testing::MemoryKeystore, Keystore};
@@ -507,10 +507,13 @@ pub(crate) mod tests {
}
}
pub fn sign_commitment<BN: Encode>(who: &Keyring, commitment: &Commitment<BN>) -> Signature {
pub fn sign_commitment<BN: Encode>(
who: &Keyring<AuthorityId>,
commitment: &Commitment<BN>,
) -> Signature {
let store = MemoryKeystore::new();
store.ecdsa_generate_new(BEEFY_KEY_TYPE, Some(&who.to_seed())).unwrap();
let beefy_keystore: BeefyKeystore = Some(store.into()).into();
let beefy_keystore: BeefyKeystore<AuthorityId> = Some(store.into()).into();
beefy_keystore.sign(&who.public(), &commitment.encode()).unwrap()
}
@@ -538,7 +541,10 @@ pub(crate) mod tests {
.validators()
.iter()
.map(|validator: &AuthorityId| {
Some(sign_commitment(&Keyring::from_public(validator).unwrap(), &commitment))
Some(sign_commitment(
&Keyring::<AuthorityId>::from_public(validator).unwrap(),
&commitment,
))
})
.collect();
@@ -547,7 +553,7 @@ pub(crate) mod tests {
#[test]
fn should_validate_messages() {
let keys = vec![Keyring::Alice.public()];
let keys = vec![Keyring::<AuthorityId>::Alice.public()];
let validator_set = ValidatorSet::<AuthorityId>::new(keys.clone(), 0).unwrap();
let (gv, mut report_stream) =
GossipValidator::<Block>::new(Arc::new(Mutex::new(KnownPeers::new())));