From c156c484cde9c3b5876d36ecc864a2b501e47db3 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 4 Dec 2024 18:21:19 +0100 Subject: [PATCH] change rotation to use module and add test with 10 collators --- integration-tests/src/kusama_test_net.rs | 28 +++++++ integration-tests/src/sessions.rs | 94 +++++++++++++++++------- runtime/basilisk/src/system.rs | 4 +- 3 files changed, 98 insertions(+), 28 deletions(-) diff --git a/integration-tests/src/kusama_test_net.rs b/integration-tests/src/kusama_test_net.rs index d2a3b3bd73..117beebb05 100644 --- a/integration-tests/src/kusama_test_net.rs +++ b/integration-tests/src/kusama_test_net.rs @@ -311,6 +311,34 @@ pub mod basilisk { 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/sessions.rs b/integration-tests/src/sessions.rs index d078598450..b436ab392f 100644 --- a/integration-tests/src/sessions.rs +++ b/integration-tests/src/sessions.rs @@ -6,8 +6,8 @@ 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(); @@ -16,38 +16,80 @@ fn new_session_should_rotate_collators_list() { 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![collator2.clone(), collator3.clone(), collator1.clone()]); + 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![collator2.clone(), collator3.clone(), collator1.clone()]); + 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(), collator1.clone()]); + 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(), collator1.clone(), collator2.clone()]); - - let collators = CollatorRewards::new_session(4).unwrap(); - assert_eq!(collators, vec![collator3.clone(), collator1.clone(), collator2.clone()]); - - let collators = CollatorRewards::new_session(5).unwrap(); - assert_eq!(collators, vec![collator3.clone(), collator1.clone(), collator2.clone()]); - - let collators = CollatorRewards::new_session(6).unwrap(); - assert_eq!(collators, vec![collator1.clone(), collator2.clone(), collator3.clone()]); - - let collators = CollatorRewards::new_session(7).unwrap(); - assert_eq!(collators, vec![collator1.clone(), collator2.clone(), collator3.clone()]); - - let collators = CollatorRewards::new_session(8).unwrap(); - assert_eq!(collators, vec![collator1.clone(), collator2.clone(), collator3.clone()]); - - let collators = CollatorRewards::new_session(9).unwrap(); - assert_eq!(collators, vec![collator2.clone(), collator3.clone(), collator1.clone()]); - - let collators = CollatorRewards::new_session(10).unwrap(); - assert_eq!(collators, vec![collator2.clone(), collator3.clone(), collator1.clone()]); + 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/src/system.rs b/runtime/basilisk/src/system.rs index e6f9d7fb03..4c2ad35485 100644 --- a/runtime/basilisk/src/system.rs +++ b/runtime/basilisk/src/system.rs @@ -552,8 +552,8 @@ impl SessionManager for RotatingCollatorManager { // then we rotate the collators to have a regular distribution for block production let mut collators = CollatorSelection::new_session(new_index)?; - if let Some(amount) = (new_index as usize).checked_div(collators.len()) { - collators.rotate_left(amount); + if let Some(rotation_amount) = (new_index as usize).checked_rem(collators.len()) { + collators.rotate_left(rotation_amount); } Some(collators)