@@ -118,6 +118,7 @@ pub use self::{
118
118
#[ frame_support:: pallet]
119
119
pub mod pallet {
120
120
use super :: * ;
121
+ use cumulus_primitives_storage_weight_reclaim:: get_proof_size;
121
122
use frame_support:: pallet_prelude:: * ;
122
123
use frame_system:: pallet_prelude:: * ;
123
124
@@ -684,6 +685,35 @@ pub mod pallet {
684
685
#[ pallet:: storage]
685
686
pub type AccountStorages < T : Config > =
686
687
StorageDoubleMap < _ , Blake2_128Concat , H160 , Blake2_128Concat , H256 , H256 , ValueQuery > ;
688
+
689
+ #[ pallet:: hooks]
690
+ impl < T : Config > Hooks < BlockNumberFor < T > > for Pallet < T > {
691
+ fn on_initialize ( _: BlockNumberFor < T > ) -> Weight {
692
+ let mut total_weight = Weight :: zero ( ) ;
693
+
694
+ // Do dummy read to populate the pov with the intermediates nodes,
695
+ // only when proof size recording is enabled.
696
+ if let Some ( pov_before) = get_proof_size ( ) {
697
+ const ZERO_ACCOUNT : H160 = H160 :: zero ( ) ;
698
+
699
+ // just a dummy read to populate the pov with the intermediates nodes
700
+ let _ = AccountCodesMetadata :: < T > :: get ( ZERO_ACCOUNT . clone ( ) ) ;
701
+ let ( _, min_gas_weight) = T :: FeeCalculator :: min_gas_price ( ) ;
702
+ let ( _, account_basic_weight) = Pallet :: < T > :: account_basic ( & ZERO_ACCOUNT ) ;
703
+
704
+ let pov = get_proof_size ( ) . unwrap_or_default ( ) - pov_before;
705
+
706
+ total_weight = total_weight
707
+ . saturating_add ( Weight :: from_parts ( 0 , pov) )
708
+ . saturating_add ( T :: DbWeight :: get ( ) . reads ( 1 ) )
709
+ . saturating_add ( account_basic_weight)
710
+ . saturating_add ( min_gas_weight) ;
711
+
712
+ }
713
+
714
+ total_weight
715
+ }
716
+ }
687
717
}
688
718
689
719
/// Utility alias for easy access to the [`AccountProvider::AccountId`] type from a given config.
0 commit comments