2929 crate :: {
3030 account_info:: { AccountInfo , Offset , StorageLocation } ,
3131 account_storage:: {
32- meta:: StoredAccountMeta , stored_account_info:: StoredAccountInfo , AccountStorage ,
33- AccountStorageStatus , ShrinkInProgress ,
32+ meta:: StoredAccountMeta ,
33+ stored_account_info:: { StoredAccountInfo , StoredAccountInfoWithoutData } ,
34+ AccountStorage , AccountStorageStatus , ShrinkInProgress ,
3435 } ,
3536 accounts_cache:: { AccountsCache , CachedAccount , SlotCache } ,
3637 accounts_db:: stats:: {
@@ -173,6 +174,8 @@ impl StoreTo<'_> {
173174#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
174175pub ( crate ) enum ScanAccountStorageData {
175176 /// callback for accounts in storage will not include `data`
177+ // Note, currently only used in tests, but do not remove.
178+ #[ cfg_attr( not( test) , allow( dead_code) ) ]
176179 NoData ,
177180 /// return data (&[u8]) for each account.
178181 /// This can be expensive to get and is not necessary for many scan operations.
@@ -4924,20 +4927,32 @@ impl AccountsDb {
49244927 & self ,
49254928 slot : Slot ,
49264929 cache_map_func : impl Fn ( & LoadedAccount ) -> Option < R > + Sync ,
4927- storage_scan_func : impl Fn ( & B , & LoadedAccount , Option < & [ u8 ] > ) + Sync ,
4930+ storage_scan_func : impl for <' a , ' b , ' storage > Fn (
4931+ & ' b B ,
4932+ & ' a StoredAccountInfoWithoutData < ' storage > ,
4933+ Option < & ' storage [ u8 ] > , // account data
4934+ ) + Sync ,
49284935 scan_account_storage_data : ScanAccountStorageData ,
49294936 ) -> ScanStorageResult < R , B >
49304937 where
49314938 R : Send ,
49324939 B : Send + Default + Sync ,
49334940 {
49344941 self . scan_cache_storage_fallback ( slot, cache_map_func, |retval, storage| {
4935- storage. scan_accounts ( |account| {
4936- let loaded_account = LoadedAccount :: Stored ( account) ;
4937- let data = ( scan_account_storage_data == ScanAccountStorageData :: DataRefForStorage )
4938- . then_some ( loaded_account. data ( ) ) ;
4939- storage_scan_func ( retval, & loaded_account, data)
4940- } ) ;
4942+ match scan_account_storage_data {
4943+ ScanAccountStorageData :: NoData => {
4944+ storage. scan_accounts ( |account| {
4945+ let account_without_data = StoredAccountInfoWithoutData :: new_from ( & account) ;
4946+ storage_scan_func ( retval, & account_without_data, None ) ;
4947+ } ) ;
4948+ }
4949+ ScanAccountStorageData :: DataRefForStorage => {
4950+ storage. scan_accounts ( |account| {
4951+ let account_without_data = StoredAccountInfoWithoutData :: new_from ( & account) ;
4952+ storage_scan_func ( retval, & account_without_data, Some ( account. data ) ) ;
4953+ } ) ;
4954+ }
4955+ } ;
49414956 } )
49424957 }
49434958
@@ -7495,18 +7510,23 @@ impl AccountsDb {
74957510 let scan_result: ScanStorageResult < ( Pubkey , AccountHash ) , DashMap < Pubkey , AccountHash > > =
74967511 self . scan_account_storage (
74977512 slot,
7498- |loaded_account : & LoadedAccount | {
7513+ |loaded_account| {
74997514 // Cache only has one version per key, don't need to worry about versioning
75007515 Some ( ( * loaded_account. pubkey ( ) , loaded_account. loaded_hash ( ) ) )
75017516 } ,
7502- |accum : & DashMap < Pubkey , AccountHash > , loaded_account : & LoadedAccount , _data| {
7517+ |accum : & DashMap < _ , _ > , stored_account, data| {
7518+ // SAFETY: We called scan_account_storage() with
7519+ // ScanAccountStorageData::DataRefForStorage, so `data` must be Some.
7520+ let data = data. unwrap ( ) ;
7521+ let loaded_account =
7522+ LoadedAccount :: Stored ( StoredAccountInfo :: new_from ( stored_account, data) ) ;
75037523 let mut loaded_hash = loaded_account. loaded_hash ( ) ;
75047524 if loaded_hash == AccountHash ( Hash :: default ( ) ) {
7505- loaded_hash = Self :: hash_account ( loaded_account, loaded_account. pubkey ( ) )
7525+ loaded_hash = Self :: hash_account ( & loaded_account, loaded_account. pubkey ( ) )
75067526 }
75077527 accum. insert ( * loaded_account. pubkey ( ) , loaded_hash) ;
75087528 } ,
7509- ScanAccountStorageData :: NoData ,
7529+ ScanAccountStorageData :: DataRefForStorage ,
75107530 ) ;
75117531 scan. stop ( ) ;
75127532
@@ -7527,11 +7547,16 @@ impl AccountsDb {
75277547 // Cache only has one version per key, don't need to worry about versioning
75287548 Some ( ( * loaded_account. pubkey ( ) , loaded_account. take_account ( ) ) )
75297549 } ,
7530- |accum : & DashMap < _ , _ > , loaded_account, _data| {
7550+ |accum : & DashMap < _ , _ > , stored_account, data| {
7551+ // SAFETY: We called scan_account_storage() with
7552+ // ScanAccountStorageData::DataRefForStorage, so `data` must be Some.
7553+ let data = data. unwrap ( ) ;
7554+ let loaded_account =
7555+ LoadedAccount :: Stored ( StoredAccountInfo :: new_from ( stored_account, data) ) ;
75317556 // Storage may have duplicates so only keep the latest version for each key
75327557 accum. insert ( * loaded_account. pubkey ( ) , loaded_account. take_account ( ) ) ;
75337558 } ,
7534- ScanAccountStorageData :: NoData ,
7559+ ScanAccountStorageData :: DataRefForStorage ,
75357560 ) ;
75367561
75377562 match scan_result {
@@ -7546,27 +7571,30 @@ impl AccountsDb {
75467571 ScanStorageResult < PubkeyHashAccount , DashMap < Pubkey , ( AccountHash , AccountSharedData ) > > ;
75477572 let scan_result: ScanResult = self . scan_account_storage (
75487573 slot,
7549- |loaded_account : & LoadedAccount | {
7574+ |loaded_account| {
75507575 // Cache only has one version per key, don't need to worry about versioning
75517576 Some ( PubkeyHashAccount {
75527577 pubkey : * loaded_account. pubkey ( ) ,
75537578 hash : loaded_account. loaded_hash ( ) ,
75547579 account : loaded_account. take_account ( ) ,
75557580 } )
75567581 } ,
7557- |accum : & DashMap < Pubkey , ( AccountHash , AccountSharedData ) > ,
7558- loaded_account : & LoadedAccount ,
7559- _data| {
7560- // Storage may have duplicates so only keep the latest version for each key
7582+ |accum : & DashMap < _ , _ > , stored_account, data| {
7583+ // SAFETY: We called scan_account_storage() with
7584+ // ScanAccountStorageData::DataRefForStorage, so `data` must be Some.
7585+ let data = data. unwrap ( ) ;
7586+ let loaded_account =
7587+ LoadedAccount :: Stored ( StoredAccountInfo :: new_from ( stored_account, data) ) ;
75617588 let mut loaded_hash = loaded_account. loaded_hash ( ) ;
75627589 let key = * loaded_account. pubkey ( ) ;
75637590 let account = loaded_account. take_account ( ) ;
75647591 if loaded_hash == AccountHash ( Hash :: default ( ) ) {
75657592 loaded_hash = Self :: hash_account ( & account, & key)
75667593 }
7594+ // Storage may have duplicates so only keep the latest version for each key
75677595 accum. insert ( key, ( loaded_hash, account) ) ;
75687596 } ,
7569- ScanAccountStorageData :: NoData ,
7597+ ScanAccountStorageData :: DataRefForStorage ,
75707598 ) ;
75717599
75727600 match scan_result {
0 commit comments