Skip to content

Commit

Permalink
AccountAddressRange is byval (solana-labs#807)
Browse files Browse the repository at this point in the history
jeffwashington authored Apr 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 7138ea7 commit aed1a5e
Showing 2 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions accounts-db/src/tiered_storage/hot.rs
Original file line number Diff line number Diff line change
@@ -819,8 +819,8 @@ impl HotStorageWriter {
footer
.owners_block_format
.write_owners_block(&mut self.storage, &owners_table)?;
footer.min_account_address = *address_range.min;
footer.max_account_address = *address_range.max;
footer.min_account_address = address_range.min;
footer.max_account_address = address_range.max;
footer.write_footer_block(&mut self.storage)?;

Ok(stored_infos)
32 changes: 16 additions & 16 deletions accounts-db/src/tiered_storage/meta.rs
Original file line number Diff line number Diff line change
@@ -137,29 +137,29 @@ const MAX_ACCOUNT_ADDRESS: Pubkey = Pubkey::new_from_array([0xFFu8; 32]);

#[derive(Debug)]
/// A struct that maintains an address-range using its min and max fields.
pub struct AccountAddressRange<'a> {
pub struct AccountAddressRange {
/// The minimum address observed via update()
pub min: &'a Pubkey,
pub min: Pubkey,
/// The maximum address observed via update()
pub max: &'a Pubkey,
pub max: Pubkey,
}

impl Default for AccountAddressRange<'_> {
impl Default for AccountAddressRange {
fn default() -> Self {
Self {
min: &MAX_ACCOUNT_ADDRESS,
max: &MIN_ACCOUNT_ADDRESS,
min: MAX_ACCOUNT_ADDRESS,
max: MIN_ACCOUNT_ADDRESS,
}
}
}

impl<'a> AccountAddressRange<'a> {
pub fn update(&mut self, address: &'a Pubkey) {
if *self.min > *address {
self.min = address;
impl AccountAddressRange {
pub fn update(&mut self, address: &Pubkey) {
if self.min > *address {
self.min = *address;
}
if *self.max < *address {
self.max = address;
if self.max < *address {
self.max = *address;
}
}
}
@@ -269,8 +269,8 @@ pub mod tests {

address_range.update(&address);
// For a single update, the min and max should equal to the address
assert_eq!(*address_range.min, address);
assert_eq!(*address_range.max, address);
assert_eq!(address_range.min, address);
assert_eq!(address_range.max, address);
}

#[test]
@@ -301,7 +301,7 @@ pub mod tests {
.iter()
.for_each(|address| address_range.update(address));

assert_eq!(*address_range.min, addresses[min_index]);
assert_eq!(*address_range.max, addresses[max_index]);
assert_eq!(address_range.min, addresses[min_index]);
assert_eq!(address_range.max, addresses[max_index]);
}
}

0 comments on commit aed1a5e

Please sign in to comment.