File tree Expand file tree Collapse file tree 4 files changed +47
-3
lines changed
Expand file tree Collapse file tree 4 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -430,7 +430,7 @@ fn submit_new_message_root_signature() {
430430 // Case 3.
431431 let s_3 = sign ( & k_3, & message. 0 ) ;
432432 assert_noop ! (
433- EcdsaAuthority :: submit_new_message_root_signature( RuntimeOrigin :: signed( a_3) , s_3, ) ,
433+ EcdsaAuthority :: submit_new_message_root_signature( RuntimeOrigin :: signed( a_3) , s_3) ,
434434 <Error <Runtime >>:: NotAuthority
435435 ) ;
436436
Original file line number Diff line number Diff line change @@ -245,6 +245,8 @@ pub mod pallet {
245245 NotStaker ,
246246 /// Target is not a collator.
247247 TargetNotCollator ,
248+ /// Collator count mustn't be zero.
249+ ZeroCollatorCount ,
248250 }
249251
250252 /// All staking ledgers.
@@ -327,6 +329,10 @@ pub mod pallet {
327329 #[ pallet:: genesis_build]
328330 impl < T : Config > GenesisBuild < T > for GenesisConfig < T > {
329331 fn build ( & self ) {
332+ if self . collator_count == 0 {
333+ panic ! ( "[pallet::staking] collator count mustn't be 0" ) ;
334+ }
335+
330336 <SessionStartTime < T > >:: put ( self . now ) ;
331337 <ElapsedTime < T > >:: put ( self . elapsed_time ) ;
332338 <CollatorCount < T > >:: put ( self . collator_count ) ;
@@ -570,6 +576,25 @@ pub mod pallet {
570576
571577 Ok ( ( ) )
572578 }
579+
580+ /// Set collator count.
581+ ///
582+ /// This will apply to the incoming session.
583+ ///
584+ /// Require root origin.
585+ #[ pallet:: call_index( 7 ) ]
586+ #[ pallet:: weight( 0 ) ]
587+ pub fn set_collator_count ( origin : OriginFor < T > , count : u32 ) -> DispatchResult {
588+ ensure_root ( origin) ?;
589+
590+ if count == 0 {
591+ return Err ( <Error < T > >:: ZeroCollatorCount ) ?;
592+ }
593+
594+ <CollatorCount < T > >:: put ( count) ;
595+
596+ Ok ( ( ) )
597+ }
573598 }
574599 impl < T > Pallet < T >
575600 where
Original file line number Diff line number Diff line change @@ -290,7 +290,6 @@ fn initialize_block(number: u64) {
290290 <AllPalletsWithSystem as OnInitialize < u64 > >:: on_initialize ( number) ;
291291}
292292
293- #[ derive( Default ) ]
294293pub struct ExtBuilder {
295294 collator_count : u32 ,
296295}
@@ -332,3 +331,8 @@ impl ExtBuilder {
332331 ext
333332 }
334333}
334+ impl Default for ExtBuilder {
335+ fn default ( ) -> Self {
336+ Self { collator_count : 1 }
337+ }
338+ }
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ use darwinia_staking::*;
2727use dc_types:: { Balance , UNIT } ;
2828// substrate
2929use frame_support:: { assert_noop, assert_ok, BoundedVec } ;
30- use sp_runtime:: { assert_eq_error_rate, Perbill } ;
30+ use sp_runtime:: { assert_eq_error_rate, DispatchError , Perbill } ;
3131
3232#[ test]
3333fn stake_should_work ( ) {
@@ -403,6 +403,21 @@ fn chill_should_work() {
403403 } ) ;
404404}
405405
406+ #[ test]
407+ fn set_collator_count_should_work ( ) {
408+ ExtBuilder :: default ( ) . build ( ) . execute_with ( || {
409+ assert_noop ! (
410+ Staking :: set_collator_count( RuntimeOrigin :: signed( 1 ) , 1 ) ,
411+ DispatchError :: BadOrigin
412+ ) ;
413+ assert_noop ! (
414+ Staking :: set_collator_count( RuntimeOrigin :: root( ) , 0 ) ,
415+ <Error <Runtime >>:: ZeroCollatorCount
416+ ) ;
417+ assert_ok ! ( Staking :: set_collator_count( RuntimeOrigin :: root( ) , 1 ) ) ;
418+ } ) ;
419+ }
420+
406421#[ test]
407422fn power_should_work ( ) {
408423 ExtBuilder :: default ( ) . build ( ) . execute_with ( || {
You can’t perform that action at this time.
0 commit comments