Skip to content

Commit 2b4321a

Browse files
authored
change: ETCM-12427 use concrete type for CommitteeMember (#1080)
1 parent 4a18c38 commit 2b4321a

File tree

30 files changed

+278
-288
lines changed

30 files changed

+278
-288
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ current `moment: Moment` as input instead of slot.
2727
*Important:* for backward compatibiliyt, chains that used the slot-based version should pass the
2828
*starting timestamp of the slot* to the new IDP instead of the actual timestamp. See the implementation
2929
of the demo node for reference.
30+
* `pallet-session-validator-management` is no longer configured with a `CommitteeMember` type and instead
31+
uses `sp_session_validator_management::CommitteeMember` type directly. As this type was the only type
32+
supported by the toolkit, this change is backwards compatible for existing chains.
3033

3134
## Removed
3235

demo/node/src/command/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub fn run() -> sc_cli::Result<()> {
7171
_,
7272
_,
7373
_,
74+
_,
7475
BlockProducerMetadataType,
7576
WizardBindings,
7677
AccountId32,

demo/node/src/inherent_data.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use authority_selection_inherents::{
22
AriadneInherentDataProvider as AriadneIDP, AuthoritySelectionDataSource,
3-
AuthoritySelectionInputs, CommitteeMember,
3+
AuthoritySelectionInputs,
44
};
55
use derive_new::new;
66
use jsonrpsee::core::async_trait;
@@ -56,7 +56,8 @@ where
5656
T: HeaderBackend<Block>,
5757
T::Api: SessionValidatorManagementApi<
5858
Block,
59-
CommitteeMember<CrossChainPublic, SessionKeys>,
59+
CrossChainPublic,
60+
SessionKeys,
6061
AuthoritySelectionInputs,
6162
ScEpochNumber,
6263
>,
@@ -182,7 +183,8 @@ where
182183
T: ProvideRuntimeApi<Block> + Send + Sync + HeaderBackend<Block>,
183184
T::Api: SessionValidatorManagementApi<
184185
Block,
185-
CommitteeMember<CrossChainPublic, SessionKeys>,
186+
CrossChainPublic,
187+
SessionKeys,
186188
AuthoritySelectionInputs,
187189
ScEpochNumber,
188190
>,

demo/node/src/rpc.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#![warn(missing_docs)]
77

88
use crate::data_sources::DataSources;
9-
use authority_selection_inherents::{
10-
AuthoritySelectionInputs, CandidateValidationApi, CommitteeMember,
11-
};
9+
use authority_selection_inherents::{AuthoritySelectionInputs, CandidateValidationApi};
1210
use jsonrpsee::RpcModule;
1311
use pallet_block_producer_fees_rpc::*;
1412
use pallet_block_producer_metadata_rpc::*;
@@ -81,7 +79,8 @@ where
8179
C::Api: sp_block_producer_metadata::BlockProducerMetadataApi<Block, BlockProducerMetadataType>,
8280
C::Api: sp_session_validator_management::SessionValidatorManagementApi<
8381
Block,
84-
CommitteeMember<CrossChainPublic, SessionKeys>,
82+
CrossChainPublic,
83+
SessionKeys,
8584
AuthoritySelectionInputs,
8685
ScEpochNumber,
8786
>,

demo/node/src/staging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::chain_spec::get_account_id_from_seed;
22
use crate::chain_spec::*;
3-
use authority_selection_inherents::CommitteeMember;
43
use partner_chains_demo_runtime::{
54
AccountId, AuraConfig, BalancesConfig, BridgeConfig, GovernedMapConfig, GrandpaConfig,
65
RuntimeGenesisConfig, SessionCommitteeManagementConfig, SessionConfig, SidechainConfig,
@@ -10,6 +9,7 @@ use sc_service::{ChainType, Properties};
109
use sidechain_domain::*;
1110
use sp_core::bytes::from_hex;
1211
use sp_core::{ed25519, sr25519};
12+
use sp_session_validator_management::CommitteeMember;
1313
use std::str::FromStr;
1414

1515
pub fn authority_keys(

demo/node/src/testnet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::chain_spec::*;
2-
use authority_selection_inherents::CommitteeMember;
32
use partner_chains_demo_runtime::{
43
AccountId, AuraConfig, BalancesConfig, BridgeConfig, GovernedMapConfig, GrandpaConfig,
54
RuntimeGenesisConfig, SessionCommitteeManagementConfig, SessionConfig, SidechainConfig,
@@ -10,6 +9,7 @@ use sidechain_domain::*;
109
use sidechain_slots::SlotsPerEpoch;
1110
use sp_core::bytes::from_hex;
1211
use sp_core::{ed25519, sr25519};
12+
use sp_session_validator_management::CommitteeMember;
1313
use std::str::FromStr;
1414

1515
pub fn authority_keys(

demo/node/src/tests/runtime_api_mock.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::mock::mock_genesis_utxo;
2-
use authority_selection_inherents::{AuthoritySelectionInputs, CommitteeMember};
2+
use authority_selection_inherents::AuthoritySelectionInputs;
33
use hex_literal::hex;
44
use partner_chains_demo_runtime::opaque::SessionKeys;
55
use partner_chains_demo_runtime::{BlockAuthor, CrossChainPublic};
@@ -14,6 +14,7 @@ use sp_inherents::InherentIdentifier;
1414
use sp_runtime::Digest;
1515
use sp_runtime::key_types::{AURA, GRANDPA};
1616
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};
17+
use sp_session_validator_management::CommitteeMember;
1718
use sp_sidechain::GetGenesisUtxo;
1819
use std::collections::HashMap;
1920

@@ -70,7 +71,7 @@ sp_api::mock_impl_runtime_apis! {
7071
fn genesis_utxo() -> UtxoId { mock_genesis_utxo() }
7172
}
7273

73-
impl sp_session_validator_management::SessionValidatorManagementApi<Block, CommitteeMember<CrossChainPublic, SessionKeys>, AuthoritySelectionInputs, ScEpochNumber> for TestApi {
74+
impl sp_session_validator_management::SessionValidatorManagementApi<Block, CrossChainPublic, SessionKeys, AuthoritySelectionInputs, ScEpochNumber> for TestApi {
7475
fn get_current_committee() -> (ScEpochNumber, Vec<CommitteeMember<CrossChainPublic, SessionKeys>>) {
7576
unimplemented!()
7677
}

demo/runtime/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ extern crate alloc;
1212
use alloc::collections::BTreeMap;
1313
use alloc::string::String;
1414
use authority_selection_inherents::{
15-
AuthoritySelectionInputs, CommitteeMember, PermissionedCandidateDataError,
16-
RegistrationDataError, StakeError, select_authorities, validate_permissioned_candidate_data,
15+
AuthoritySelectionInputs, PermissionedCandidateDataError, RegistrationDataError, StakeError,
16+
select_authorities, validate_permissioned_candidate_data,
1717
};
1818
use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params};
1919
use frame_support::genesis_builder_helper::{build_state, get_preset};
@@ -30,6 +30,7 @@ use frame_system::EnsureRoot;
3030
use opaque::SessionKeys;
3131
use pallet_block_producer_metadata;
3232
use pallet_grandpa::AuthorityId as GrandpaId;
33+
use pallet_session_validator_management::CommitteeMemberOf;
3334
use pallet_transaction_payment::{ConstFeeMultiplier, FungibleAdapter, Multiplier};
3435
use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
3536
use scale_info::TypeInfo;
@@ -58,6 +59,7 @@ use sp_runtime::{
5859
},
5960
transaction_validity::{TransactionSource, TransactionValidity},
6061
};
62+
use sp_session_validator_management::CommitteeMember;
6163
use sp_sidechain::SidechainStatus;
6264
use sp_std::prelude::*;
6365
use sp_version::RuntimeVersion;
@@ -351,13 +353,12 @@ impl pallet_session_validator_management::Config for Runtime {
351353
type AuthorityKeys = SessionKeys;
352354
type AuthoritySelectionInputs = AuthoritySelectionInputs;
353355
type WeightInfo = pallet_session_validator_management::weights::SubstrateWeight<Runtime>;
354-
type CommitteeMember = CommitteeMember<CrossChainPublic, SessionKeys>;
355356
type MainChainScriptsOrigin = EnsureRoot<Self::AccountId>;
356357

357358
fn select_authorities(
358359
input: AuthoritySelectionInputs,
359360
sidechain_epoch: ScEpochNumber,
360-
) -> Option<BoundedVec<Self::CommitteeMember, Self::MaxValidators>> {
361+
) -> Option<BoundedVec<CommitteeMemberOf<Self>, Self::MaxValidators>> {
361362
select_authorities::<sidechain_domain::cross_chain_app::Public, SessionKeys, MaxValidators>(
362363
Sidechain::genesis_utxo(),
363364
input,
@@ -1088,10 +1089,11 @@ impl_runtime_apis! {
10881089
}
10891090
}
10901091

1091-
#[api_version(2)]
1092+
#[api_version(3)]
10921093
impl sp_session_validator_management::SessionValidatorManagementApi<
10931094
Block,
1094-
CommitteeMember<CrossChainPublic, SessionKeys>,
1095+
CrossChainPublic,
1096+
SessionKeys,
10951097
AuthoritySelectionInputs,
10961098
sidechain_domain::ScEpochNumber
10971099
> for Runtime {

demo/runtime/src/mock.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use frame_support::{
1010
};
1111
use frame_system::EnsureRoot;
1212
use hex_literal::hex;
13+
use pallet_session_validator_management::CommitteeMemberOf;
1314
use plutus::ToDatum;
1415
use sidechain_domain::*;
1516
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
@@ -165,20 +166,19 @@ impl pallet_session_validator_management::Config for Test {
165166
type AuthorityId = CrossChainPublic;
166167
type AuthorityKeys = TestSessionKeys;
167168
type AuthoritySelectionInputs = AuthoritySelectionInputs;
168-
type CommitteeMember = (Self::AuthorityId, Self::AuthorityKeys);
169169
type MainChainScriptsOrigin = EnsureRoot<Self::AccountId>;
170170

171171
/// Mock simply selects all valid registered candidates as validators.
172172
fn select_authorities(
173173
input: AuthoritySelectionInputs,
174174
_sidechain_epoch: ScEpochNumber,
175-
) -> Option<BoundedVec<(Self::AuthorityId, Self::AuthorityKeys), Self::MaxValidators>> {
175+
) -> Option<BoundedVec<CommitteeMemberOf<Self>, Self::MaxValidators>> {
176176
let candidates: Vec<_> = filter_trustless_candidates_registrations::<
177177
Self::AuthorityId,
178178
Self::AuthorityKeys,
179179
>(input.registered_candidates, Sidechain::genesis_utxo())
180180
.into_iter()
181-
.map(|(c, _)| (c.account_id().clone(), c.account_keys().clone()))
181+
.map(|(c, _)| c.into())
182182
.collect();
183183
if candidates.is_empty() { None } else { Some(BoundedVec::truncate_from(candidates)) }
184184
}
@@ -225,10 +225,7 @@ impl pallet_grandpa::Config for Test {
225225
pub fn new_test_ext() -> sp_io::TestExternalities {
226226
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
227227

228-
let initial_authorities: Vec<_> = vec![
229-
(alice().cross_chain.public(), alice().session()),
230-
(bob().cross_chain.public(), bob().session()),
231-
];
228+
let initial_authorities: Vec<_> = vec![alice().as_permissioned(), bob().as_permissioned()];
232229

233230
let session_keys: Vec<_> =
234231
vec![(alice().account(), alice().session()), (bob().account(), bob().session())];
@@ -423,6 +420,9 @@ impl TestKeys {
423420
.collect(),
424421
)
425422
}
423+
pub fn as_permissioned(&self) -> CommitteeMemberOf<Test> {
424+
CommitteeMember::permissioned(self.cross_chain.public(), self.session())
425+
}
426426
}
427427

428428
pub fn pair_from_seed<P: Pair>(seed: &str) -> P {
@@ -482,6 +482,6 @@ macro_rules! assert_aura_authorities {
482482
}
483483
pub(crate) use assert_aura_authorities;
484484
use sidechain_slots::SlotsPerEpoch;
485-
use sp_session_validator_management::MainChainScripts;
485+
use sp_session_validator_management::{CommitteeMember, MainChainScripts};
486486

487487
use crate::CrossChainPublic;

toolkit/cli/node-commands/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use sp_runtime::AccountId32;
2323
use sp_runtime::DeserializeOwned;
2424
use sp_runtime::Serialize;
2525
use sp_runtime::traits::Block as BlockT;
26-
use sp_session_validator_management::CommitteeMember as CommitteeMemberT;
2726
use sp_session_validator_management::SessionValidatorManagementApi;
2827
use sp_session_validator_management_query::SessionValidatorManagementQuery;
2928
use sp_session_validator_management_query::commands::*;
@@ -148,7 +147,8 @@ pub enum PartnerChainsSubcommand<
148147
pub fn run<
149148
Cli,
150149
Block,
151-
CommitteeMember,
150+
AuthorityId,
151+
AuthorityKeys,
152152
Client,
153153
BlockProducerMetadata,
154154
RuntimeBindings: PartnerChainRuntime + Send + Sync,
@@ -170,15 +170,15 @@ where
170170
+ GetSidechainStatus<Block>
171171
+ SessionValidatorManagementApi<
172172
Block,
173-
CommitteeMember,
173+
AuthorityId,
174+
AuthorityKeys,
174175
AuthoritySelectionInputs,
175176
ScEpochNumber,
176177
> + CandidateValidationApi<Block>,
177178
Block: BlockT,
178179
NumberFor<Block>: From<u32> + Into<u32>,
179-
CommitteeMember: CommitteeMemberT + Encode + Decode + Send + Sync + 'static,
180-
CommitteeMember::AuthorityId: Decode + Encode + AsRef<[u8]> + Send + Sync + 'static,
181-
CommitteeMember::AuthorityKeys: Decode + Encode,
180+
AuthorityId: Decode + Encode + AsRef<[u8]> + Send + Sync + Clone + 'static,
181+
AuthorityKeys: Decode + Encode + Send + Sync + Clone + 'static,
182182
BlockProducerMetadata: DeserializeOwned + Encode + Send + Sync,
183183
PartnerchainAddress: Serialize + Clone + Sync + Send + FromStrStdErr + Encode + 'static,
184184
{

0 commit comments

Comments
 (0)