authority_selection_inherents/
lib.rs

1//! This crate provides inherents for authority selection.
2#![cfg_attr(not(feature = "std"), no_std)]
3#![deny(missing_docs)]
4
5extern crate alloc;
6
7use scale_info::TypeInfo;
8use serde::{Deserialize, Serialize};
9use sidechain_domain::StakePoolPublicKey;
10use sp_core::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
11use sp_session_validator_management::CommitteeMember as CommitteeMemberT;
12
13pub mod ariadne_inherent_data_provider;
14pub mod authority_selection_inputs;
15pub mod filter_invalid_candidates;
16pub mod select_authorities;
17
18#[cfg(test)]
19mod runtime_api_mock;
20#[cfg(test)]
21mod tests;
22
23#[cfg(any(test, feature = "mock"))]
24pub mod mock;
25
26#[derive(
27	Serialize,
28	Deserialize,
29	Clone,
30	Encode,
31	Decode,
32	DecodeWithMemTracking,
33	TypeInfo,
34	MaxEncodedLen,
35	Debug,
36	PartialEq,
37	Eq,
38)]
39/// Type representing committee members, either permissioned or registered
40pub enum CommitteeMember<AuthorityId, AuthorityKeys> {
41	/// A permissioned candidate
42	Permissioned {
43		/// Authority id of the candidate
44		id: AuthorityId,
45		/// Authority keys of the candidate
46		keys: AuthorityKeys,
47	},
48	/// A registered candidate
49	Registered {
50		/// Authority id of the candidate
51		id: AuthorityId,
52		/// Authority keys of the candidate
53		keys: AuthorityKeys,
54		/// Stake pool pub key of the candidate
55		stake_pool_pub_key: StakePoolPublicKey,
56	},
57}
58
59impl<AuthorityId, AuthorityKeys> From<(AuthorityId, AuthorityKeys)>
60	for CommitteeMember<AuthorityId, AuthorityKeys>
61{
62	fn from((id, keys): (AuthorityId, AuthorityKeys)) -> Self {
63		Self::Permissioned { id, keys }
64	}
65}
66
67impl<AuthorityId, AuthorityKeys> CommitteeMember<AuthorityId, AuthorityKeys> {
68	/// Constructs new permissioned candidate
69	pub fn permissioned(id: AuthorityId, keys: AuthorityKeys) -> Self {
70		Self::Permissioned { id, keys }
71	}
72}
73
74impl<AuthorityId: Clone, AuthorityKeys: Clone> CommitteeMemberT
75	for CommitteeMember<AuthorityId, AuthorityKeys>
76{
77	type AuthorityId = AuthorityId;
78	type AuthorityKeys = AuthorityKeys;
79
80	fn authority_id(&self) -> AuthorityId {
81		match self {
82			Self::Permissioned { id, .. } => id.clone(),
83			Self::Registered { id, .. } => id.clone(),
84		}
85	}
86
87	fn authority_keys(&self) -> AuthorityKeys {
88		match self {
89			Self::Permissioned { keys, .. } => keys.clone(),
90			Self::Registered { keys, .. } => keys.clone(),
91		}
92	}
93}