Unverified Commit 70e53b30 authored by André Silva's avatar André Silva Committed by GitHub
Browse files

runtime: fix the session keys migration that includes the beefy key type (#2855)


Co-authored-by: Andronik Ordian's avatarAndronik Ordian <write@reusable.software>
parent 8454d7c4
Pipeline #133448 canceled with stages
in 5 minutes and 33 seconds
......@@ -36,7 +36,8 @@ mod mock;
#[cfg(test)]
mod integration_tests;
use primitives::v1::{BlockNumber, ValidatorId, AssignmentId};
use beefy_primitives::ecdsa::AuthorityId as BeefyId;
use primitives::v1::{AccountId, AssignmentId, BlockNumber, ValidatorId};
use sp_runtime::{Perquintill, Perbill, FixedPointNumber};
use frame_system::limits;
use frame_support::{
......@@ -190,6 +191,20 @@ impl<T: pallet_session::Config> OneSessionHandler<T::AccountId> for AssignmentSe
fn on_disabled(_: usize) { }
}
/// Generates a `BeefyId` from the given `AccountId`. The resulting `BeefyId` is
/// a dummy value and this is a utility function meant to be used when migration
/// session keys.
pub fn dummy_beefy_id_from_account_id(a: AccountId) -> BeefyId {
let mut id = BeefyId::default();
let id_raw: &mut [u8] = id.as_mut();
// NOTE: AccountId is 32 bytes, whereas BeefyId is 33 bytes.
id_raw[1..].copy_from_slice(a.as_ref());
id_raw[0..4].copy_from_slice(b"beef");
id
}
#[cfg(test)]
mod multiplier_tests {
use super::*;
......@@ -292,4 +307,15 @@ mod multiplier_tests {
println!("block = {} multiplier {:?}", blocks, multiplier);
}
}
#[test]
fn generate_dummy_unique_beefy_id_from_account_id() {
let acc1 = AccountId::new([0; 32]);
let acc2 = AccountId::new([1; 32]);
let beefy_id1 = dummy_beefy_id_from_account_id(acc1);
let beefy_id2 = dummy_beefy_id_from_account_id(acc2);
assert_ne!(beefy_id1, beefy_id2);
}
}
......@@ -197,14 +197,7 @@ fn transform_session_keys(v: AccountId, old: OldSessionKeys) -> SessionKeys {
para_validator: old.para_validator,
para_assignment: old.para_assignment,
authority_discovery: old.authority_discovery,
beefy: {
// We need to produce a dummy value that's unique for the validator.
let mut id = BeefyId::default();
let id_raw: &mut [u8] = id.as_mut();
id_raw.copy_from_slice(v.as_ref());
id_raw[0..4].copy_from_slice(b"beef");
id
},
beefy: runtime_common::dummy_beefy_id_from_account_id(v),
}
}
......
......@@ -299,14 +299,7 @@ fn transform_session_keys(v: AccountId, old: OldSessionKeys) -> SessionKeys {
para_validator: old.para_validator,
para_assignment: old.para_assignment,
authority_discovery: old.authority_discovery,
beefy: {
// We need to produce a dummy value that's unique for the validator.
let mut id = BeefyId::default();
let id_raw: &mut [u8] = id.as_mut();
id_raw.copy_from_slice(v.as_ref());
id_raw[0..4].copy_from_slice(b"beef");
id
},
beefy: runtime_common::dummy_beefy_id_from_account_id(v),
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment