@@ -165,8 +165,6 @@ impl IsZeroLamport for IndexInfo {
165
165
struct AccountOffsets {
166
166
/// offset to the end of the &[u8] data
167
167
offset_to_end_of_data : usize ,
168
- /// # of bytes (aligned) to store this account, including variable sized data
169
- stored_size_aligned : usize ,
170
168
}
171
169
172
170
#[ cfg_attr( feature = "frozen-abi" , derive( AbiExample ) ) ]
@@ -889,14 +887,15 @@ impl AppendVec {
889
887
& self ,
890
888
offset : usize ,
891
889
) -> Option < ( StoredMeta , solana_account:: AccountSharedData ) > {
892
- let sizes = self . get_account_sizes ( & [ offset] ) ;
890
+ let data_len = self . get_account_data_lens ( & [ offset] ) ;
891
+ let sizes = self . calculate_storage_size ( & data_len) ;
893
892
let result = self . get_stored_account_meta_callback ( offset, |r_callback| {
894
893
let r2 = self . get_account_shared_data ( offset) ;
895
894
assert ! ( solana_account:: accounts_equal(
896
895
& r_callback,
897
896
r2. as_ref( ) . unwrap( )
898
897
) ) ;
899
- assert_eq ! ( sizes, vec! [ r_callback. stored_size( ) ] ) ;
898
+ assert_eq ! ( sizes, r_callback. stored_size( ) ) ;
900
899
let meta = r_callback. meta ( ) . clone ( ) ;
901
900
Some ( ( meta, r_callback. to_account_shared_data ( ) ) )
902
901
} ) ;
@@ -906,7 +905,7 @@ impl AppendVec {
906
905
. is_none( ) ) ;
907
906
assert ! ( self . get_account_shared_data( offset) . is_none( ) ) ;
908
907
// it has different rules for checking len and returning None
909
- assert ! ( sizes. is_empty ( ) ) ;
908
+ assert ! ( sizes == 0 ) ;
910
909
}
911
910
result. flatten ( )
912
911
}
@@ -926,12 +925,10 @@ impl AppendVec {
926
925
let stored_size_unaligned = STORE_META_OVERHEAD
927
926
. checked_add ( stored_meta. data_len as usize )
928
927
. expect ( "stored size cannot overflow" ) ;
929
- let stored_size_aligned = u64_align ! ( stored_size_unaligned) ;
930
928
let offset_to_end_of_data = start_offset + stored_size_unaligned;
931
929
932
930
AccountOffsets {
933
931
offset_to_end_of_data,
934
- stored_size_aligned,
935
932
}
936
933
}
937
934
@@ -1098,8 +1095,13 @@ impl AppendVec {
1098
1095
}
1099
1096
}
1100
1097
1101
- /// for each offset in `sorted_offsets`, get the size of the account. No other information is needed for the account.
1102
- pub ( crate ) fn get_account_sizes ( & self , sorted_offsets : & [ usize ] ) -> Vec < usize > {
1098
+ /// Estimate the amount of storage required for the passed in data lengths
1099
+ pub ( crate ) fn calculate_storage_size ( & self , data_len : & [ usize ] ) -> usize {
1100
+ data_len. iter ( ) . map ( |len| aligned_stored_size ( * len) ) . sum ( )
1101
+ }
1102
+
1103
+ /// for each offset in `sorted_offsets`, get the the amount of data stored in the account.
1104
+ pub ( crate ) fn get_account_data_lens ( & self , sorted_offsets : & [ usize ] ) -> Vec < usize > {
1103
1105
// self.len() is an atomic load, so only do it once
1104
1106
let self_len = self . len ( ) ;
1105
1107
let mut account_sizes = Vec :: with_capacity ( sorted_offsets. len ( ) ) ;
@@ -1115,7 +1117,7 @@ impl AppendVec {
1115
1117
// data doesn't fit, so don't include
1116
1118
break ;
1117
1119
}
1118
- account_sizes. push ( next . stored_size_aligned ) ;
1120
+ account_sizes. push ( stored_meta . data_len as usize ) ;
1119
1121
}
1120
1122
}
1121
1123
AppendVecFileBacking :: File ( file) => {
@@ -1143,7 +1145,7 @@ impl AppendVec {
1143
1145
// data doesn't fit, so don't include
1144
1146
break ;
1145
1147
}
1146
- account_sizes. push ( next . stored_size_aligned ) ;
1148
+ account_sizes. push ( stored_meta . data_len as usize ) ;
1147
1149
}
1148
1150
}
1149
1151
}
@@ -1699,7 +1701,7 @@ pub mod tests {
1699
1701
let size = 1000 ;
1700
1702
let mut indexes = vec ! [ ] ;
1701
1703
let now = Instant :: now ( ) ;
1702
- let mut sizes = vec ! [ ] ;
1704
+ let mut sizes: Vec < usize > = vec ! [ ] ;
1703
1705
for sample in 0 ..size {
1704
1706
// sample + 1 is so sample = 0 won't be used.
1705
1707
// sample = 0 produces default account with default pubkey
@@ -1708,7 +1710,10 @@ pub mod tests {
1708
1710
let pos = av. append_account_test ( & account) . unwrap ( ) ;
1709
1711
assert_eq ! ( av. get_account_test( pos) . unwrap( ) , account) ;
1710
1712
indexes. push ( pos) ;
1711
- assert_eq ! ( sizes, av. get_account_sizes( & indexes) ) ;
1713
+ assert_eq ! (
1714
+ sizes. iter( ) . sum:: <usize >( ) ,
1715
+ av. calculate_storage_size( & av. get_account_data_lens( indexes. as_slice( ) ) )
1716
+ ) ;
1712
1717
}
1713
1718
trace ! ( "append time: {} ms" , now. elapsed( ) . as_millis( ) ) ;
1714
1719
@@ -2071,8 +2076,9 @@ pub mod tests {
2071
2076
let ( append_vec, _) =
2072
2077
AppendVec :: new_from_file ( & temp_file. path , total_stored_size, storage_access) . unwrap ( ) ;
2073
2078
2074
- let account_sizes = append_vec. get_account_sizes ( account_offsets. as_slice ( ) ) ;
2075
- assert_eq ! ( account_sizes, stored_sizes) ;
2079
+ let account_sizes = append_vec
2080
+ . calculate_storage_size ( & append_vec. get_account_data_lens ( account_offsets. as_slice ( ) ) ) ;
2081
+ assert_eq ! ( account_sizes, total_stored_size) ;
2076
2082
}
2077
2083
2078
2084
/// A helper function for testing different scenario for scan_*.
0 commit comments