diff --git a/Cargo.lock b/Cargo.lock index 04b678e4f8..f91b2f1022 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -973,7 +973,7 @@ dependencies = [ [[package]] name = "basilisk-runtime" -version = "122.0.0" +version = "123.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-parachain-system", @@ -11179,7 +11179,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.0.5" +version = "1.0.6" dependencies = [ "basilisk-runtime", "cumulus-pallet-aura-ext", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index ae74465358..70bf3d7d04 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.0.5" +version = "1.0.6" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/integration-tests/src/kusama_test_net.rs b/integration-tests/src/kusama_test_net.rs index 35111d42b0..117beebb05 100644 --- a/integration-tests/src/kusama_test_net.rs +++ b/integration-tests/src/kusama_test_net.rs @@ -307,6 +307,38 @@ pub mod basilisk { get_account_id_from_seed::("Bob"), get_from_seed::("Bob"), ), + ( + get_account_id_from_seed::("Charlie"), + get_from_seed::("Charlie"), + ), + ( + get_account_id_from_seed::("Collator4"), + get_from_seed::("Collator4"), + ), + ( + get_account_id_from_seed::("Collator5"), + get_from_seed::("Collator5"), + ), + ( + get_account_id_from_seed::("Collator6"), + get_from_seed::("Collator6"), + ), + ( + get_account_id_from_seed::("Collator7"), + get_from_seed::("Collator7"), + ), + ( + get_account_id_from_seed::("Collator8"), + get_from_seed::("Collator8"), + ), + ( + get_account_id_from_seed::("Collator9"), + get_from_seed::("Collator9"), + ), + ( + get_account_id_from_seed::("Collator10"), + get_from_seed::("Collator10"), + ), ] } diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 7ae33ebae0..cec3dbd118 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -10,6 +10,7 @@ mod nft_marketplace; mod non_native_fee; mod oracle; mod router; +mod sessions; mod transact_call_filter; mod vesting; mod xyk; diff --git a/integration-tests/src/sessions.rs b/integration-tests/src/sessions.rs new file mode 100644 index 0000000000..b436ab392f --- /dev/null +++ b/integration-tests/src/sessions.rs @@ -0,0 +1,95 @@ +#![cfg(test)] +use crate::kusama_test_net::*; +use basilisk_runtime::CollatorRewards; +use basilisk_runtime::Runtime; +use frame_support::traits::Contains; +use pallet_session::SessionManager; +use polkadot_xcm::v3::prelude::*; +use polkadot_xcm::VersionedXcm; +use pretty_assertions::assert_eq; +use xcm_emulator::TestExt; +#[test] +fn new_session_should_rotate_collators_list() { + TestNet::reset(); + + Basilisk::execute_with(|| { + let collator1 = basilisk::invulnerables()[0].0.clone(); //d435... + let collator2 = basilisk::invulnerables()[1].0.clone(); //8eaf... + let collator3 = basilisk::invulnerables()[2].0.clone(); //90b5... + let collator4 = basilisk::invulnerables()[3].0.clone(); //6ebe... + let collator5 = basilisk::invulnerables()[4].0.clone(); //ec5e... + let collator6 = basilisk::invulnerables()[5].0.clone(); //9c78... + let collator7 = basilisk::invulnerables()[6].0.clone(); //a678... + let collator8 = basilisk::invulnerables()[7].0.clone(); //2433... + let collator9 = basilisk::invulnerables()[8].0.clone(); //ee28... + let collator10 = basilisk::invulnerables()[9].0.clone(); //da53... + + let collators = CollatorRewards::new_session(0).unwrap(); + assert_eq!( + collators, + vec![ + collator8.clone(), + collator4.clone(), + collator2.clone(), + collator3.clone(), + collator6.clone(), + collator7.clone(), + collator1.clone(), + collator10.clone(), + collator5.clone(), + collator9.clone() + ] + ); + + let collators = CollatorRewards::new_session(1).unwrap(); + assert_eq!( + collators, + vec![ + collator4.clone(), + collator2.clone(), + collator3.clone(), + collator6.clone(), + collator7.clone(), + collator1.clone(), + collator10.clone(), + collator5.clone(), + collator9.clone(), + collator8.clone(), + ] + ); + + let collators = CollatorRewards::new_session(2).unwrap(); + assert_eq!( + collators, + vec![ + collator2.clone(), + collator3.clone(), + collator6.clone(), + collator7.clone(), + collator1.clone(), + collator10.clone(), + collator5.clone(), + collator9.clone(), + collator8.clone(), + collator4.clone(), + ] + ); + + let collators = CollatorRewards::new_session(3).unwrap(); + assert_eq!( + collators, + vec![ + collator3.clone(), + collator6.clone(), + collator7.clone(), + collator1.clone(), + collator10.clone(), + collator5.clone(), + collator9.clone(), + collator8.clone(), + collator4.clone(), + collator2.clone(), + ] + ); + }); +} diff --git a/runtime/basilisk/Cargo.toml b/runtime/basilisk/Cargo.toml index aa3b2d79ab..c620927474 100644 --- a/runtime/basilisk/Cargo.toml +++ b/runtime/basilisk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "basilisk-runtime" -version = "122.0.0" +version = "123.0.0" authors = ["GalacticCouncil"] edition = "2021" homepage = "https://github.com/galacticcouncil/Basilisk-node" diff --git a/runtime/basilisk/src/lib.rs b/runtime/basilisk/src/lib.rs index c7e2413505..5d02c03caf 100644 --- a/runtime/basilisk/src/lib.rs +++ b/runtime/basilisk/src/lib.rs @@ -101,7 +101,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("basilisk"), impl_name: create_runtime_str!("basilisk"), authoring_version: 1, - spec_version: 122, + spec_version: 123, impl_version: 0, apis: apis::RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/runtime/basilisk/src/system.rs b/runtime/basilisk/src/system.rs index e62c09abb5..4c2ad35485 100644 --- a/runtime/basilisk/src/system.rs +++ b/runtime/basilisk/src/system.rs @@ -540,12 +540,34 @@ impl pallet_collator_rewards::Config for Runtime { type RewardPerCollator = RewardPerCollator; type RewardCurrencyId = NativeAssetId; type ExcludedCollators = ExcludedCollators; - // We wrap the ` SessionManager` implementation of `CollatorSelection` to get the collatrs that - // we hand out rewards to. - type SessionManager = CollatorSelection; + type SessionManager = RotatingCollatorManager; type MaxCandidates = MaxInvulnerables; } +pub struct RotatingCollatorManager; +impl SessionManager for RotatingCollatorManager { + fn new_session(new_index: SessionIndex) -> Option> { + // We wrap the ` SessionManager` implementation of `CollatorSelection` to get the collators that + // we hand out rewards to, + // then we rotate the collators to have a regular distribution for block production + let mut collators = CollatorSelection::new_session(new_index)?; + + if let Some(rotation_amount) = (new_index as usize).checked_rem(collators.len()) { + collators.rotate_left(rotation_amount); + } + + Some(collators) + } + + fn end_session(end_index: SessionIndex) { + CollatorSelection::end_session(end_index) + } + + fn start_session(start_index: SessionIndex) { + CollatorSelection::start_session(start_index) + } +} + parameter_types! { pub const BasicDeposit: Balance = 5 * DOLLARS; pub const ByteDeposit: Balance = DOLLARS / 10; @@ -614,6 +636,8 @@ use frame_system::EnsureSigned; #[cfg(not(feature = "runtime-benchmarks"))] use frame_system::EnsureSignedBy; +use pallet_session::SessionManager; +use sp_staking::SessionIndex; impl pallet_state_trie_migration::Config for Runtime { type ControlOrigin = EnsureRoot;