3030
3131// Re-export since this is necessary for `impl_apis` in runtime.
3232pub use sp_consensus_grandpa:: {
33- self as fg_primitives, AuthorityId , AuthorityList , AuthorityWeight , VersionedAuthorityList ,
33+ self as fg_primitives, AuthorityId , AuthorityList , AuthorityWeight ,
3434} ;
3535
36- use codec:: { self as codec , Decode , Encode , MaxEncodedLen } ;
36+ use codec:: { Decode , Encode , MaxEncodedLen } ;
3737use frame_support:: {
3838 dispatch:: { DispatchResultWithPostInfo , Pays } ,
3939 pallet_prelude:: Get ,
40- storage,
4140 traits:: OneSessionHandler ,
4241 weights:: Weight ,
4342 WeakBoundedVec ,
4443} ;
4544use frame_system:: pallet_prelude:: BlockNumberFor ;
4645use scale_info:: TypeInfo ;
4746use sp_consensus_grandpa:: {
48- ConsensusLog , EquivocationProof , ScheduledChange , SetId , GRANDPA_AUTHORITIES_KEY ,
49- GRANDPA_ENGINE_ID , RUNTIME_LOG_TARGET as LOG_TARGET ,
47+ ConsensusLog , EquivocationProof , ScheduledChange , SetId , GRANDPA_ENGINE_ID ,
48+ RUNTIME_LOG_TARGET as LOG_TARGET ,
5049} ;
5150use sp_runtime:: { generic:: DigestItem , traits:: Zero , DispatchResult } ;
5251use sp_session:: { GetSessionNumber , GetValidatorCount } ;
@@ -75,7 +74,7 @@ pub mod pallet {
7574 use frame_system:: pallet_prelude:: * ;
7675
7776 /// The current storage version.
78- const STORAGE_VERSION : StorageVersion = StorageVersion :: new ( 4 ) ;
77+ const STORAGE_VERSION : StorageVersion = StorageVersion :: new ( 5 ) ;
7978
8079 #[ pallet:: pallet]
8180 #[ pallet:: storage_version( STORAGE_VERSION ) ]
@@ -145,7 +144,7 @@ pub mod pallet {
145144
146145 // enact the change if we've reached the enacting block
147146 if block_number == pending_change. scheduled_at + pending_change. delay {
148- Self :: set_grandpa_authorities ( & pending_change. next_authorities ) ;
147+ Authorities :: < T > :: put ( & pending_change. next_authorities ) ;
149148 Self :: deposit_event ( Event :: NewAuthorities {
150149 authority_set : pending_change. next_authorities . into_inner ( ) ,
151150 } ) ;
@@ -342,6 +341,11 @@ pub mod pallet {
342341 #[ pallet:: getter( fn session_for_set) ]
343342 pub ( super ) type SetIdSession < T : Config > = StorageMap < _ , Twox64Concat , SetId , SessionIndex > ;
344343
344+ /// The current list of authorities.
345+ #[ pallet:: storage]
346+ pub ( crate ) type Authorities < T : Config > =
347+ StorageValue < _ , BoundedAuthorityList < T :: MaxAuthorities > , ValueQuery > ;
348+
345349 #[ derive( frame_support:: DefaultNoBound ) ]
346350 #[ pallet:: genesis_config]
347351 pub struct GenesisConfig < T : Config > {
@@ -354,7 +358,7 @@ pub mod pallet {
354358 impl < T : Config > BuildGenesisConfig for GenesisConfig < T > {
355359 fn build ( & self ) {
356360 CurrentSetId :: < T > :: put ( SetId :: default ( ) ) ;
357- Pallet :: < T > :: initialize ( & self . authorities )
361+ Pallet :: < T > :: initialize ( self . authorities . clone ( ) )
358362 }
359363 }
360364
@@ -428,12 +432,7 @@ pub enum StoredState<N> {
428432impl < T : Config > Pallet < T > {
429433 /// Get the current set of authorities, along with their respective weights.
430434 pub fn grandpa_authorities ( ) -> AuthorityList {
431- storage:: unhashed:: get_or_default :: < VersionedAuthorityList > ( GRANDPA_AUTHORITIES_KEY ) . into ( )
432- }
433-
434- /// Set the current set of authorities, along with their respective weights.
435- fn set_grandpa_authorities ( authorities : & AuthorityList ) {
436- storage:: unhashed:: put ( GRANDPA_AUTHORITIES_KEY , & VersionedAuthorityList :: from ( authorities) ) ;
435+ Authorities :: < T > :: get ( ) . into_inner ( )
437436 }
438437
439438 /// Schedule GRANDPA to pause starting in the given number of blocks.
@@ -522,10 +521,14 @@ impl<T: Config> Pallet<T> {
522521
523522 // Perform module initialization, abstracted so that it can be called either through genesis
524523 // config builder or through `on_genesis_session`.
525- fn initialize ( authorities : & AuthorityList ) {
524+ fn initialize ( authorities : AuthorityList ) {
526525 if !authorities. is_empty ( ) {
527526 assert ! ( Self :: grandpa_authorities( ) . is_empty( ) , "Authorities are already initialized!" ) ;
528- Self :: set_grandpa_authorities ( authorities) ;
527+ Authorities :: < T > :: put (
528+ & BoundedAuthorityList :: < T :: MaxAuthorities > :: try_from ( authorities) . expect (
529+ "Grandpa: `Config::MaxAuthorities` is smaller than the number of genesis authorities!" ,
530+ ) ,
531+ ) ;
529532 }
530533
531534 // NOTE: initialize first session of first set. this is necessary for
@@ -568,7 +571,7 @@ where
568571 I : Iterator < Item = ( & ' a T :: AccountId , AuthorityId ) > ,
569572 {
570573 let authorities = validators. map ( |( _, k) | ( k, 1 ) ) . collect :: < Vec < _ > > ( ) ;
571- Self :: initialize ( & authorities) ;
574+ Self :: initialize ( authorities) ;
572575 }
573576
574577 fn on_new_session < ' a , I : ' a > ( changed : bool , validators : I , _queued_validators : I )
0 commit comments