66//!
77//! Based on https://github.com/srlabs/substrate-runtime-fuzzer/blob/2a42a8b750aff0e12eb0e09b33aea9825a40595a/runtimes/kusama/src/main.rs
88
9- use dancelight_runtime:: ExternalValidators ;
10- use dancelight_runtime:: CollatorsInflationRatePerBlock ;
11- use dancelight_runtime:: ValidatorsInflationRatePerEra ;
12- use dancelight_runtime:: ContainerRegistrar ;
13- use frame_support:: traits:: Currency ;
14- use dancelight_runtime:: InflationRewards ;
15- use sp_trie:: GenericMemoryDB ;
16- use sp_trie:: cache:: { CacheSize , SharedTrieCache } ;
17- use sp_state_machine:: MemoryDB ;
18- use sp_runtime:: traits:: BlakeTwo256 ;
19- use sp_storage:: StateVersion ;
20- use sp_state_machine:: LayoutV1 ;
21- use sp_state_machine:: TrieBackend ;
22- use sp_state_machine:: TrieBackendBuilder ;
23- use sp_state_machine:: Ext ;
24- use frame_support:: storage:: unhashed;
25- use std:: sync:: atomic:: AtomicBool ;
269use {
2710 cumulus_primitives_core:: ParaId ,
2811 dancelight_runtime:: {
2912 genesis_config_presets:: get_authority_keys_from_seed, AccountId , AllPalletsWithSystem ,
30- Balance , Balances , Executive , Header , ParaInherent , Runtime , RuntimeCall , RuntimeOrigin ,
31- Timestamp , UncheckedExtrinsic ,
13+ Balance , Balances , CollatorsInflationRatePerBlock , ContainerRegistrar , Executive ,
14+ ExternalValidators , Header , InflationRewards , ParaInherent , Runtime , RuntimeCall ,
15+ RuntimeOrigin , Timestamp , UncheckedExtrinsic , ValidatorsInflationRatePerEra ,
3216 } ,
3317 dancelight_runtime_constants:: time:: SLOT_DURATION ,
3418 dp_container_chain_genesis_data:: ContainerChainGenesisData ,
3721 frame_support:: {
3822 dispatch:: GetDispatchInfo ,
3923 pallet_prelude:: Weight ,
40- traits:: { IntegrityTest , OriginTrait , TryState , TryStateSelect } ,
24+ storage:: unhashed,
25+ traits:: { Currency , IntegrityTest , OriginTrait , TryState , TryStateSelect } ,
4126 weights:: constants:: WEIGHT_REF_TIME_PER_SECOND ,
4227 Hashable ,
4328 } ,
@@ -56,18 +41,25 @@ use {
5641 sp_core:: { sr25519, Decode , Get , Pair , Public , H256 } ,
5742 sp_inherents:: InherentDataProvider ,
5843 sp_runtime:: {
59- traits:: { Dispatchable , Header as HeaderT , IdentifyAccount , Verify } ,
44+ traits:: { BlakeTwo256 , Dispatchable , Header as HeaderT , IdentifyAccount , Verify } ,
6045 Digest , DigestItem , Perbill , Saturating , Storage ,
6146 } ,
62- sp_state_machine:: BasicExternalities ,
47+ sp_state_machine:: {
48+ BasicExternalities , Ext , LayoutV1 , MemoryDB , TrieBackend , TrieBackendBuilder ,
49+ } ,
50+ sp_storage:: StateVersion ,
51+ sp_trie:: {
52+ cache:: { CacheSize , SharedTrieCache } ,
53+ GenericMemoryDB ,
54+ } ,
6355 std:: {
6456 any:: TypeId ,
65- sync:: Arc ,
6657 cell:: Cell ,
6758 cmp:: max,
6859 collections:: BTreeMap ,
6960 iter,
7061 marker:: PhantomData ,
62+ sync:: { atomic:: AtomicBool , Arc } ,
7163 time:: { Duration , Instant } ,
7264 } ,
7365} ;
@@ -405,20 +397,30 @@ fn get_origin(origin: usize) -> &'static AccountId {
405397
406398use create_storage:: create_storage;
407399mod create_storage {
408- use super :: * ;
409- use trie_db :: TrieDBMut ;
410- use trie_db :: TrieDBMutBuilder ;
411- use sp_state_machine :: TrieMut ;
412- use sp_state_machine :: OverlayedChanges ;
400+ use {
401+ super :: * ,
402+ sp_state_machine :: { OverlayedChanges , TrieMut } ,
403+ trie_db :: { TrieDBMut , TrieDBMutBuilder } ,
404+ } ;
413405
414- pub fn create_storage ( mut overlay : OverlayedChanges < BlakeTwo256 > , backend : TrieBackend < MemoryDB < BlakeTwo256 > , BlakeTwo256 > , root : H256 , shared_cache : SharedTrieCache < BlakeTwo256 > ) -> ( MemoryDB < BlakeTwo256 > , H256 , SharedTrieCache < BlakeTwo256 > ) {
415- let changes = overlay. drain_storage_changes ( & backend, StateVersion :: V1 ) . unwrap ( ) ;
406+ pub fn create_storage (
407+ mut overlay : OverlayedChanges < BlakeTwo256 > ,
408+ backend : TrieBackend < MemoryDB < BlakeTwo256 > , BlakeTwo256 > ,
409+ root : H256 ,
410+ shared_cache : SharedTrieCache < BlakeTwo256 > ,
411+ ) -> ( MemoryDB < BlakeTwo256 > , H256 , SharedTrieCache < BlakeTwo256 > ) {
412+ let changes = overlay
413+ . drain_storage_changes ( & backend, StateVersion :: V1 )
414+ . unwrap ( ) ;
416415
417416 let mut storage = backend. into_storage ( ) ;
418417 let mut cache2 = shared_cache. local_cache ( ) ;
419418 //let mut root_decoded: H256 = Decode::decode(&mut root1.as_slice()).unwrap();
420419 let mut root_mut = root. clone ( ) ;
421- let mut triedbmut: TrieDBMut < LayoutV1 < BlakeTwo256 > > = TrieDBMutBuilder :: from_existing ( & mut storage, & mut root_mut) . with_optional_cache ( None ) . build ( ) ;
420+ let mut triedbmut: TrieDBMut < LayoutV1 < BlakeTwo256 > > =
421+ TrieDBMutBuilder :: from_existing ( & mut storage, & mut root_mut)
422+ . with_optional_cache ( None )
423+ . build ( ) ;
422424
423425 for ( k, v) in changes. main_storage_changes {
424426 if let Some ( v) = v {
@@ -675,7 +677,8 @@ fn fuzz_main(data: &[u8]) {
675677
676678 let validators = dancelight_runtime:: Session :: validators ( ) ;
677679 let slot = Slot :: from ( u64:: from ( block + 350000000 ) ) ;
678- let authority_index = u32:: try_from ( u64:: from ( slot) % u64:: try_from ( validators. len ( ) ) . unwrap ( ) ) . unwrap ( ) ;
680+ let authority_index =
681+ u32:: try_from ( u64:: from ( slot) % u64:: try_from ( validators. len ( ) ) . unwrap ( ) ) . unwrap ( ) ;
679682 let pre_digest = Digest {
680683 logs : vec ! [ DigestItem :: PreRuntime (
681684 BABE_ENGINE_ID ,
@@ -722,14 +725,19 @@ fn fuzz_main(data: &[u8]) {
722725 new_era = true ;
723726 }
724727 if new_era {
725- let new_supply_validators = ValidatorsInflationRatePerEra :: get ( ) * Balances :: total_issuance ( ) ;
728+ let new_supply_validators =
729+ ValidatorsInflationRatePerEra :: get ( ) * Balances :: total_issuance ( ) ;
726730 block_rewards. set ( block_rewards. get ( ) + new_supply_validators) ;
727731 }
728732 }
729733
730734 Executive :: initialize_block ( & parent_header) ;
731735
732- Timestamp :: set ( RuntimeOrigin :: none ( ) , u64:: from ( block) * SLOT_DURATION + 2_100_000_000_000 ) . unwrap ( ) ;
736+ Timestamp :: set (
737+ RuntimeOrigin :: none ( ) ,
738+ u64:: from ( block) * SLOT_DURATION + 2_100_000_000_000 ,
739+ )
740+ . unwrap ( ) ;
733741
734742 Executive :: apply_extrinsic ( UncheckedExtrinsic :: new_unsigned ( RuntimeCall :: AuthorNoting (
735743 pallet_author_noting:: Call :: set_latest_author_data { data : ( ) } ,
@@ -759,14 +767,13 @@ fn fuzz_main(data: &[u8]) {
759767
760768 use sp_runtime:: traits:: BlakeTwo256 ;
761769
762- use sp_state_machine:: OverlayedChanges ;
763- use sp_state_machine:: TrieBackendBuilder ;
764- use sp_state_machine:: Ext ;
770+ use sp_state_machine:: { Ext , OverlayedChanges , TrieBackendBuilder } ;
765771 let mut overlay = OverlayedChanges :: default ( ) ;
766772 let ( storage, root, shared_cache) = & * GENESIS_STORAGE ;
767773 let root = * root;
768774 let cache = shared_cache. local_cache ( ) ;
769- let mut backend: TrieBackend < _ , BlakeTwo256 > = TrieBackendBuilder :: new_with_cache ( storage, root, cache) . build ( ) ;
775+ let mut backend: TrieBackend < _ , BlakeTwo256 > =
776+ TrieBackendBuilder :: new_with_cache ( storage, root, cache) . build ( ) ;
770777 let extensions = None ;
771778 let mut ext = Ext :: new ( & mut overlay, & backend, extensions) ;
772779 sp_externalities:: set_and_run_with_externalities ( & mut ext, || {
0 commit comments