44//! distributing the rest of rewards to his stakers. Precision of the margin fee setting is bounded
55//! to 1/100 of a percent.
66//!
7- //! The margin fees are stored together with the slot at which change occurred, so this data can be
7+ //! The margin fees are stored together with the time at which change occurred, so this data can be
88//! exposed to rewards calculation.
99//!
1010//! Log of changes per account is bounded. The oldest entries are dropped when new ones are added.
@@ -31,7 +31,6 @@ pub mod pallet {
3131 use frame_support:: pallet_prelude:: * ;
3232 use frame_system:: pallet_prelude:: * ;
3333 use sp_block_producer_fees:: PerTenThousands ;
34- use sp_consensus_slots:: Slot ;
3534 use sp_std:: collections:: vec_deque:: VecDeque ;
3635
3736 /// Current version of the pallet
@@ -49,23 +48,26 @@ pub mod pallet {
4948 /// Weight information on extrinsic in the pallet. For convenience weights in [weights] module can be used.
5049 type WeightInfo : WeightInfo ;
5150
52- /// Should provide the slot number of the current block.
53- fn current_slot ( ) -> Slot ;
51+ /// Moment in time when a change in fees occured
52+ type Moment : Parameter + Default + MaxEncodedLen + PartialOrd ;
53+
54+ /// Should provide the moment for the current block.
55+ fn current_moment ( ) -> Self :: Moment ;
5456
5557 #[ cfg( feature = "runtime-benchmarks" ) ]
5658 /// Benchmark helper type used for running benchmarks
5759 type BenchmarkHelper : benchmarking:: BenchmarkHelper < Self :: AccountId > ;
5860 }
5961
60- type FeeChange = ( Slot , PerTenThousands ) ;
62+ type FeeChangeOf < T > = ( < T as Config > :: Moment , PerTenThousands ) ;
6163
6264 /// Stores bounded amount of fee changes per account
6365 #[ pallet:: storage]
6466 #[ pallet:: unbounded]
6567 pub type FeesChanges < T : Config > = StorageMap <
6668 Hasher = Twox64Concat ,
6769 Key = T :: AccountId ,
68- Value = VecDeque < FeeChange > ,
70+ Value = VecDeque < FeeChangeOf < T > > ,
6971 QueryKind = ValueQuery ,
7072 > ;
7173
@@ -83,7 +85,7 @@ pub mod pallet {
8385 if fees_log. len ( ) > T :: HistoricalChangesPerProducer :: get ( ) . into ( ) {
8486 let _ = fees_log. pop_back ( ) ;
8587 }
86- fees_log. push_front ( ( T :: current_slot ( ) , fee_numerator) ) ;
88+ fees_log. push_front ( ( T :: current_moment ( ) , fee_numerator) ) ;
8789 } ) ;
8890 Ok ( ( ) )
8991 }
@@ -96,25 +98,28 @@ pub mod pallet {
9698 }
9799
98100 /// Retrieves all stored block producer fees settings. The most recent fees are in front of vecdeque.
99- pub fn get_all ( ) -> impl Iterator < Item = ( T :: AccountId , VecDeque < FeeChange > ) > {
101+ pub fn get_all ( ) -> impl Iterator < Item = ( T :: AccountId , VecDeque < FeeChangeOf < T > > ) > {
100102 FeesChanges :: < T > :: iter ( )
101103 }
102104
103105 /// Retrieves the latest fee settings for all accounts.
104- pub fn get_all_latest ( ) -> impl Iterator < Item = ( T :: AccountId , FeeChange ) > {
106+ pub fn get_all_latest ( ) -> impl Iterator < Item = ( T :: AccountId , FeeChangeOf < T > ) > {
105107 Self :: get_all ( ) . map ( |( account_id, changes) | {
106- ( account_id, * changes. front ( ) . expect ( "There are no empty collections in storage" ) )
108+ (
109+ account_id,
110+ changes. front ( ) . expect ( "There are no empty collections in storage" ) . clone ( ) ,
111+ )
107112 } )
108113 }
109114
110115 /// Retrieves fees settings for the given account id.
111116 /// Empty collection is returned if there are no settings stored for given id.
112- pub fn get ( id : T :: AccountId ) -> VecDeque < FeeChange > {
117+ pub fn get ( id : T :: AccountId ) -> VecDeque < FeeChangeOf < T > > {
113118 FeesChanges :: < T > :: get ( id)
114119 }
115120
116121 /// Gets the latest fee setting for the given account.
117- pub fn get_latest ( id : T :: AccountId ) -> Option < FeeChange > {
122+ pub fn get_latest ( id : T :: AccountId ) -> Option < FeeChangeOf < T > > {
118123 FeesChanges :: < T > :: get ( id) . front ( ) . cloned ( )
119124 }
120125 }
0 commit comments