Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: Include candidate type and MC pubkey in committee data in the storage #506

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ WARNING: Benchmarking command has been removed, because `frame-benchmarking-cli`
mainnet or one of the official testnets, you don't need to change anything. Otherwise, the duration can
be set through `MC__SLOT_DURATION_MILLIS` environment variable.
* e2e-tests: updated python to 3.12 and libs versions.
* Committee member data stored by the Session Validator Management Pallet is now fullly generic. To migrate to this version,
define your own `CommitteeMember` type and implement the trait `CommitteeMember` for it. See the `CommitteeMember`
type implemented in `node/runtime/src/lib.rs` for reference using Ariadne.

## Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,28 +174,34 @@ jq '.genesis.runtimeGenesis.config.session.initialValidators = [

echo "Configuring Initial Authorities..."
jq '.genesis.runtimeGenesis.config.sessionCommitteeManagement.initialAuthorities = [
[
"KW39r9CJjAVzmkf9zQ4YDb2hqfAVGdRqn53eRqyruqpxAP5YL",
{
"aura": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"grandpa": "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu"
}
],
[
"KWByAN7WfZABWS5AoWqxriRmF5f2jnDqy3rB5pfHLGkY93ibN",
{
"aura": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
"grandpa": "5GoNkf6WdbxCFnPdAnYYQyCjAKPJgLNxXwPjwTh6DGg6gN3E"
}
],
[
"KWBpGtyJLBkJERdZT1a1uu19c2uPpZm9nFd8SGtCfRUAT3Y4w",
{
"aura": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
"grandpa": "5DbKjhNLpqX3zqZdNBc9BGb4fHU1cRBaDhJUskrvkwfraDi6"
}
]
]' chain-spec.json > tmp.json && mv tmp.json chain-spec.json
{
"Permissioned": {
"id": "KW39r9CJjAVzmkf9zQ4YDb2hqfAVGdRqn53eRqyruqpxAP5YL",
"keys": {
"aura": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"grandpa": "5FA9nQDVg267DEd8m1ZypXLBnvN7SFxYwV7ndqSYGiN9TTpu"
}
}
},
{
"Permissioned": {
"id": "KWByAN7WfZABWS5AoWqxriRmF5f2jnDqy3rB5pfHLGkY93ibN",
"keys": {
"aura": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
"grandpa": "5GoNkf6WdbxCFnPdAnYYQyCjAKPJgLNxXwPjwTh6DGg6gN3E"
}
}
},
{
"Permissioned": {
"id": "KWBpGtyJLBkJERdZT1a1uu19c2uPpZm9nFd8SGtCfRUAT3Y4w",
"keys": {
"aura": "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
"grandpa": "5DbKjhNLpqX3zqZdNBc9BGb4fHU1cRBaDhJUskrvkwfraDi6"
}
}
}
]' chain-spec.json > tmp.json && mv tmp.json chain-spec.json

echo "Set initial funds to Alice (ecdsa), ?, and Alice (sr25519)"
jq '.genesis.runtimeGenesis.config.balances.balances = [
Expand Down
3 changes: 2 additions & 1 deletion node/node/src/staging.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::chain_spec::get_account_id_from_seed;
use crate::chain_spec::*;
use authority_selection_inherents::CommitteeMember;
use sc_service::ChainType;
use sidechain_domain::*;
use sidechain_runtime::{
Expand Down Expand Up @@ -143,7 +144,7 @@ pub fn staging_genesis(
session_committee_management: SessionCommitteeManagementConfig {
initial_authorities: initial_authorities
.into_iter()
.map(|keys| (keys.cross_chain, keys.session))
.map(|keys| CommitteeMember::permissioned(keys.cross_chain, keys.session))
.collect(),
main_chain_scripts: sp_session_validator_management::MainChainScripts::read_from_env()?,
},
Expand Down
3 changes: 2 additions & 1 deletion node/node/src/testnet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::chain_spec::*;
use authority_selection_inherents::CommitteeMember;
use sc_service::ChainType;
use sidechain_domain::*;
use sidechain_runtime::{
Expand Down Expand Up @@ -195,7 +196,7 @@ pub fn testnet_genesis(
session_committee_management: SessionCommitteeManagementConfig {
initial_authorities: initial_authorities
.into_iter()
.map(|keys| (keys.cross_chain, keys.session))
.map(|keys| CommitteeMember::permissioned(keys.cross_chain, keys.session))
.collect(),
main_chain_scripts: sp_session_validator_management::MainChainScripts::read_from_env()?,
},
Expand Down
1 change: 1 addition & 0 deletions node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ log = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
derive-new = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true, default-features = false, features = [
"alloc",
] }
Expand Down
60 changes: 27 additions & 33 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ extern crate frame_benchmarking;

extern crate alloc;

// A few exports that help ease life for downstream crates.
use authority_selection_inherents::authority_selection_inputs::AuthoritySelectionInputs;
use authority_selection_inherents::filter_invalid_candidates::{
validate_permissioned_candidate_data, PermissionedCandidateDataError, RegistrationDataError,
Expand All @@ -18,24 +17,14 @@ use authority_selection_inherents::select_authorities::select_authorities;
use frame_support::genesis_builder_helper::{build_state, get_preset};
use frame_support::weights::constants::RocksDbWeight as RuntimeDbWeight;
use frame_support::BoundedVec;
pub use frame_support::{
use frame_support::{
construct_runtime, parameter_types,
traits::{
ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, Randomness,
StorageInfo,
},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_REF_TIME_PER_SECOND},
IdentityFee,
},
PalletId, StorageValue,
traits::{ConstBool, ConstU128, ConstU32, ConstU64, ConstU8},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, IdentityFee},
};
pub use frame_system::Call as SystemCall;
use opaque::SessionKeys;
pub use pallet_balances::Call as BalancesCall;
use pallet_grandpa::AuthorityId as GrandpaId;
pub use pallet_session_validator_management;
pub use pallet_timestamp::Call as TimestampCall;
use pallet_session_validator_management;
use pallet_transaction_payment::{ConstFeeMultiplier, FungibleAdapter, Multiplier};
use session_manager::ValidatorManagementSessionManager;
use sidechain_domain::{
Expand All @@ -44,21 +33,17 @@ use sidechain_domain::{
};
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::hexdisplay::HexDisplay;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
use sp_runtime::DispatchResult;
use sp_core::{crypto::KeyTypeId, hexdisplay::HexDisplay, OpaqueMetadata};
use sp_runtime::{
generic, impl_opaque_keys,
traits::{
AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, One, OpaqueKeys,
Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
ApplyExtrinsicResult, DispatchResult, MultiSignature, Perbill,
};
pub use sp_runtime::{Perbill, Permill};
use sp_session_validator_management::CommitteeMember;
use sp_sidechain::SidechainStatus;
use sp_std::prelude::*;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -413,20 +398,19 @@ impl pallet_session_validator_management::Config for Runtime {
type AuthoritySelectionInputs = AuthoritySelectionInputs;
type ScEpochNumber = ScEpochNumber;
type WeightInfo = pallet_session_validator_management::weights::SubstrateWeight<Runtime>;
type CommitteeMember =
authority_selection_inherents::CommitteeMember<CrossChainPublic, SessionKeys>;

fn select_authorities(
input: AuthoritySelectionInputs,
sidechain_epoch: ScEpochNumber,
) -> Option<BoundedVec<(Self::AuthorityId, Self::AuthorityKeys), Self::MaxValidators>> {
let committee = select_authorities::<Self::AuthorityId, Self::AuthorityKeys>(
Sidechain::genesis_utxo(),
input,
sidechain_epoch,
)?
.into_iter()
.map(|member| (member.account_id().clone(), member.account_keys().clone()))
.collect();
Some(BoundedVec::truncate_from(committee))
) -> Option<BoundedVec<Self::CommitteeMember, Self::MaxValidators>> {
Some(BoundedVec::truncate_from(
select_authorities(Sidechain::genesis_utxo(), input, sidechain_epoch)?
.into_iter()
.map(|member| member.into())
.collect(),
))
}

fn current_epoch_number() -> ScEpochNumber {
Expand Down Expand Up @@ -543,13 +527,18 @@ pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
pub type Migrations = (
pallet_session_validator_management::migrations::v1::LegacyToV1Migration<Runtime>,
// More migrations can be added here
);
/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
Migrations,
>;

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -850,7 +839,12 @@ impl_runtime_apis! {
SessionCommitteeManagement::get_next_unset_epoch_number()
}
fn calculate_committee(authority_selection_inputs: AuthoritySelectionInputs, sidechain_epoch: ScEpochNumber) -> Option<Vec<(CrossChainPublic, SessionKeys)>> {
SessionCommitteeManagement::calculate_committee(authority_selection_inputs, sidechain_epoch)
Some(
SessionCommitteeManagement::calculate_committee(authority_selection_inputs, sidechain_epoch)?
.into_iter()
.map(|member| (member.authority_id(), member.authority_keys()))
.collect()
)
}
fn get_main_chain_scripts() -> sp_session_validator_management::MainChainScripts {
SessionCommitteeManagement::get_main_chain_scripts()
Expand Down
1 change: 1 addition & 0 deletions node/runtime/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl pallet_session_validator_management::Config for Test {
type AuthorityKeys = TestSessionKeys;
type AuthoritySelectionInputs = AuthoritySelectionInputs;
type ScEpochNumber = ScEpochNumber;
type CommitteeMember = (Self::AuthorityId, Self::AuthorityKeys);

/// Mock simply selects all valid registered candidates as validators.
fn select_authorities(
Expand Down
9 changes: 9 additions & 0 deletions toolkit/pallets/session-validator-management/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Session Validator Management Pallet

This pallet provides a way to rotate session validators based on arbitrary
inputs and selection algorithm.

## Migrations

This pallet's storage has changed compared to its legacy version. See
[src/migrations/README.md] for more information.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn set_epoch_number<T: Config>(epoch: u64) {
}

use pallet_session_validator_management::Call;
#[benchmarks]
#[benchmarks(where <T as pallet_session_validator_management::Config>::CommitteeMember: From<(<T as pallet_session_validator_management::Config>::AuthorityId, <T as pallet_session_validator_management::Config>::AuthorityKeys)>)]
pub mod benchmarks {
use super::*;

Expand Down Expand Up @@ -66,15 +66,15 @@ pub mod benchmarks {
})
.collect();
let validators: BoundedVec<
(<T as pallet_session_validator_management::Config>::AuthorityId, T::AuthorityKeys),
<T as pallet_session_validator_management::Config>::CommitteeMember,
T::MaxValidators,
> = validators.try_into().unwrap();
> = BoundedVec::truncate_from(validators.into_iter().map(|member| member.into()).collect());

let for_epoch_number = T::current_epoch_number() + One::one();
set_epoch_number::<T>(for_epoch_number.into());

#[extrinsic_call]
_(RawOrigin::None, validators.clone(), for_epoch_number, Default::default());
_(RawOrigin::None, validators, for_epoch_number, Default::default());
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ impl pallet::Config for Test {
type AuthorityKeys = SessionKeys;
type AuthoritySelectionInputs = ();
type ScEpochNumber = ScEpochNumber;
type CommitteeMember = (Self::AuthorityId, Self::AuthorityKeys);

fn select_authorities(
_: Self::AuthoritySelectionInputs,
_: ScEpochNumber,
) -> Option<BoundedVec<(Self::AuthorityId, Self::AuthorityKeys), Self::MaxValidators>> {
) -> Option<BoundedVec<Self::CommitteeMember, Self::MaxValidators>> {
todo!("not used in benchmarks")
}

Expand Down
Loading
Loading