Skip to content

Commit b351792

Browse files
authored
fix(accountsdb): cast block size and block count to u64 before comput… (#341)
…ing db size <!-- greptile_comment --> ## Greptile Summary This change refines the database size calculation in the storage module to prevent overflow issues when handling large sizes. - In `/magicblock-accounts-db/src/storage.rs`, both `meta.total_blocks` and `meta.block_size` are now cast to `u64` before multiplication. - The addition of `METADATA_STORAGE_SIZE` is safely handled to ensure accurate sizing. - These casts protect against overflow when using near-maximum `u32` values for block metadata. - Overall, the fix enhances the integrity of the database size computation for large account databases. <!-- /greptile_comment -->
1 parent 179e2a5 commit b351792

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

magicblock-accounts-db/src/storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl AccountsStorage {
269269

270270
/// total number of bytes occupied by storage
271271
pub(crate) fn size(&self) -> u64 {
272-
(self.meta.total_blocks * self.meta.block_size) as u64
272+
(self.meta.total_blocks as u64 * self.meta.block_size as u64)
273273
+ METADATA_STORAGE_SIZE as u64
274274
}
275275

0 commit comments

Comments
 (0)