Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions accounts-db/src/tiered_storage/byte_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ impl ByteBlockWriter {
if let Some(rent_epoch) = opt_fields.rent_epoch {
size += self.write_pod(&rent_epoch)?;
}
if let Some(lamports) = opt_fields.lamports {
size += self.write_pod(&lamports)?;
}

debug_assert_eq!(size, opt_fields.size());

Expand Down Expand Up @@ -341,6 +344,7 @@ mod tests {

fn write_optional_fields(format: AccountBlockFormat) {
let mut test_epoch = 5432312;
let mut test_lamports = 2314312321321;

let mut writer = ByteBlockWriter::new(format);
let mut opt_fields_vec = vec![];
Expand All @@ -349,10 +353,17 @@ mod tests {
// prepare a vector of optional fields that contains all combinations
// of Some and None.
for rent_epoch in [None, Some(test_epoch)] {
some_count += rent_epoch.iter().count();

opt_fields_vec.push(AccountMetaOptionalFields { rent_epoch });
test_epoch += 1;
for lamports in [None, Some(test_lamports)] {
some_count += rent_epoch.map_or(0, |_| 1);
some_count += lamports.map_or(0, |_| 1);

opt_fields_vec.push(AccountMetaOptionalFields {
rent_epoch,
lamports,
});
test_epoch += 1;
test_lamports += 1;
}
}

// write all the combinations of the optional fields
Expand Down Expand Up @@ -383,6 +394,12 @@ mod tests {
verified_count += 1;
offset += std::mem::size_of::<Epoch>();
}
if let Some(expected_lamports) = opt_fields.lamports {
let lamports = read_pod::<u64>(&decoded_buffer, offset).unwrap();
assert_eq!(*lamports, expected_lamports);
verified_count += 1;
offset += std::mem::size_of::<u64>();
}
}

// make sure the number of Some fields matches the number of fields we
Expand Down
3 changes: 3 additions & 0 deletions accounts-db/src/tiered_storage/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ pub enum TieredStorageError {

#[error("OffsetAlignmentError: offset {0} must be multiple of {1}")]
OffsetAlignmentError(usize, usize),

#[error("UnsupportedAccountMetaFormat: format is unsupported.")]
UnsupportedAccountMetaFormat,
}
5 changes: 2 additions & 3 deletions accounts-db/src/tiered_storage/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ impl Default for TieredStorageMagicNumber {
pub enum AccountMetaFormat {
#[default]
Hot = 0,
// Temporarily comment out to avoid unimplemented!() block
// Cold = 1,
HotPacked = 1,
}

#[repr(u16)]
Expand Down Expand Up @@ -336,7 +335,7 @@ mod tests {
fn test_footer() {
let path = get_append_vec_path("test_file_footer");
let expected_footer = TieredStorageFooter {
account_meta_format: AccountMetaFormat::Hot,
account_meta_format: AccountMetaFormat::HotPacked,
owners_block_format: OwnersBlockFormat::AddressesOnly,
index_block_format: IndexBlockFormat::AddressesThenOffsets,
account_block_format: AccountBlockFormat::AlignedRaw,
Expand Down
Loading