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
+11 -10
View File
@@ -57,9 +57,10 @@ use sp_consensus_beefy::{
ecdsa_crypto::{AuthorityId, Signature},
known_payloads,
mmr::{find_mmr_root_digest, MmrRootProvider},
BeefyApi, Commitment, ConsensusLog, EquivocationProof, Keyring as BeefyKeyring, MmrRootHash,
OpaqueKeyOwnershipProof, Payload, SignedCommitment, ValidatorSet, ValidatorSetId,
VersionedFinalityProof, VoteMessage, BEEFY_ENGINE_ID,
test_utils::Keyring as BeefyKeyring,
BeefyApi, Commitment, ConsensusLog, EquivocationProof, MmrRootHash, OpaqueKeyOwnershipProof,
Payload, SignedCommitment, ValidatorSet, ValidatorSetId, VersionedFinalityProof, VoteMessage,
BEEFY_ENGINE_ID,
};
use sp_core::H256;
use sp_keystore::{testing::MemoryKeystore, Keystore, KeystorePtr};
@@ -349,11 +350,11 @@ fn add_auth_change_digest(builder: &mut impl BlockBuilderExt, new_auth_set: Beef
.unwrap();
}
pub(crate) fn make_beefy_ids(keys: &[BeefyKeyring]) -> Vec<AuthorityId> {
keys.iter().map(|&key| key.public().into()).collect()
pub(crate) fn make_beefy_ids(keys: &[BeefyKeyring<AuthorityId>]) -> Vec<AuthorityId> {
keys.iter().map(|key| key.public().into()).collect()
}
pub(crate) fn create_beefy_keystore(authority: BeefyKeyring) -> KeystorePtr {
pub(crate) fn create_beefy_keystore(authority: &BeefyKeyring<AuthorityId>) -> KeystorePtr {
let keystore = MemoryKeystore::new();
keystore
.ecdsa_generate_new(BEEFY_KEY_TYPE, Some(&authority.to_seed()))
@@ -393,7 +394,7 @@ async fn voter_init_setup(
// Spawns beefy voters. Returns a future to spawn on the runtime.
fn initialize_beefy<API>(
net: &mut BeefyTestNet,
peers: Vec<(usize, &BeefyKeyring, Arc<API>)>,
peers: Vec<(usize, &BeefyKeyring<AuthorityId>, Arc<API>)>,
min_block_delta: u32,
) -> impl Future<Output = ()>
where
@@ -413,7 +414,7 @@ where
for (peer_id, key, api) in peers.into_iter() {
let peer = &net.peers[peer_id];
let keystore = create_beefy_keystore(*key);
let keystore = create_beefy_keystore(key);
let (_, _, peer_data) = net.make_block_import(peer.client().clone());
let PeerData { beefy_rpc_links, beefy_voter_links, .. } = peer_data;
@@ -471,7 +472,7 @@ async fn run_for(duration: Duration, net: &Arc<Mutex<BeefyTestNet>>) {
pub(crate) fn get_beefy_streams(
net: &mut BeefyTestNet,
// peer index and key
peers: impl Iterator<Item = (usize, BeefyKeyring)>,
peers: impl Iterator<Item = (usize, BeefyKeyring<AuthorityId>)>,
) -> (Vec<NotificationReceiver<H256>>, Vec<NotificationReceiver<BeefyVersionedFinalityProof<Block>>>)
{
let mut best_block_streams = Vec::new();
@@ -569,7 +570,7 @@ async fn streams_empty_after_timeout<T>(
async fn finalize_block_and_wait_for_beefy(
net: &Arc<Mutex<BeefyTestNet>>,
// peer index and key
peers: impl Iterator<Item = (usize, BeefyKeyring)> + Clone,
peers: impl Iterator<Item = (usize, BeefyKeyring<AuthorityId>)> + Clone,
finalize_target: &H256,
expected_beefy: &[u64],
) {