diff --git a/runtime/src/tiered_storage/meta.rs b/runtime/src/tiered_storage/meta.rs index fb67a3a8f..a402d79e5 100644 --- a/runtime/src/tiered_storage/meta.rs +++ b/runtime/src/tiered_storage/meta.rs @@ -103,6 +103,23 @@ impl AccountMetaOptionalFields { .write_version .map_or(0, |_| std::mem::size_of::()) } + + /// Given the specified AccountMetaFlags, returns the size of its + /// associated AccountMetaOptionalFields. + pub fn size_from_flags(flags: &AccountMetaFlags) -> usize { + let mut fields_size = 0; + if flags.has_rent_epoch() { + fields_size += std::mem::size_of::(); + } + if flags.has_account_hash() { + fields_size += std::mem::size_of::(); + } + if flags.has_write_version() { + fields_size += std::mem::size_of::(); + } + + fields_size + } } #[cfg(test)] @@ -206,6 +223,12 @@ pub mod tests { + write_version .map_or(0, |_| std::mem::size_of::()) ); + assert_eq!( + opt_fields.size(), + AccountMetaOptionalFields::size_from_flags(&AccountMetaFlags::new_from( + &opt_fields + )) + ); } } }