Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bkchr committed Sep 25, 2023
1 parent 7f9a455 commit 2ecdeb3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
10 changes: 8 additions & 2 deletions cumulus/pallets/collator-selection/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@

use crate as collator_selection;
use crate::{mock::*, CandidateInfo, Error};
use codec::Encode;
use frame_support::{
assert_noop, assert_ok,
traits::{Currency, OnInitialize},
};
use pallet_balances::Error as BalancesError;
use sp_runtime::{testing::UintAuthorityId, traits::BadOrigin, BuildStorage};
use sp_runtime::{testing::UintAuthorityId, traits::BadOrigin, BuildStorage, RuntimeAppPublic};

#[test]
fn basic_setup_works() {
Expand Down Expand Up @@ -121,7 +122,12 @@ fn invulnerable_limit_works() {
if ii > 5 {
Balances::make_free_balance_be(&ii, 100);
let key = MockSessionKeys { aura: UintAuthorityId(ii) };
Session::set_keys(RuntimeOrigin::signed(ii).into(), key, Vec::new()).unwrap();
Session::set_keys(
RuntimeOrigin::signed(ii).into(),
key.clone(),
key.create_ownership_proof(&ii.encode()).unwrap(),
)
.unwrap();
}
assert_eq!(Balances::free_balance(ii), 100);
if ii < 21 {
Expand Down
22 changes: 18 additions & 4 deletions substrate/primitives/runtime/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2033,10 +2033,8 @@ macro_rules! impl_opaque_keys_inner {
)*
};

let proof = $crate::codec::Encode::encode(&($(
$crate::RuntimeAppPublic::sign(&keys.$field, &owner)
.expect("Private key that was generated a moment ago, should exist; qed")
),*));
let proof = keys.create_ownership_proof(owner)
.expect("Private key that was generated a moment ago, should exist; qed");

let keys = $crate::codec::Encode::encode(&keys);

Expand Down Expand Up @@ -2078,6 +2076,22 @@ macro_rules! impl_opaque_keys_inner {
.ok()
.map(|s| s.into_raw_public_keys())
}

/// Create the ownership proof.
///
/// - `owner`: Some bytes that will be signed by the private keys associated to the
/// public keys in this session key object. These signatures are put into a tuple in
/// the same order as the public keys. The SCALE encoded signature tuple corresponds
/// to the `proof` returned by this function.
///
/// Returns the SCALE encoded proof that will proof the ownership of the keys for `user`.
/// An error is returned if the signing of `user` failed, e.g. a private key isn't present in the keystore.
#[allow(dead_code)]
pub fn create_ownership_proof(&self, owner: &[u8]) -> $crate::sp_std::result::Result<Vec<u8>, ()> {
Ok($crate::codec::Encode::encode(&($(
$crate::RuntimeAppPublic::sign(&self.$field, &owner).ok_or(())?
),*)))
}
}

impl $crate::traits::OpaqueKeys for $name {
Expand Down

0 comments on commit 2ecdeb3

Please sign in to comment.