AccountInfo: construct with new() (#21788)
This commit is contained in:
committed by
GitHub
parent
825f8bcea4
commit
025a5a3b9c
@ -22,3 +22,14 @@ impl ZeroLamport for AccountInfo {
|
|||||||
self.lamports == 0
|
self.lamports == 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AccountInfo {
|
||||||
|
pub fn new(store_id: AppendVecId, offset: usize, stored_size: usize, lamports: u64) -> Self {
|
||||||
|
Self {
|
||||||
|
store_id,
|
||||||
|
offset,
|
||||||
|
stored_size,
|
||||||
|
lamports,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4459,14 +4459,14 @@ impl AccountsDb {
|
|||||||
let stored_size = offsets[1] - offsets[0];
|
let stored_size = offsets[1] - offsets[0];
|
||||||
storage.add_account(stored_size);
|
storage.add_account(stored_size);
|
||||||
|
|
||||||
infos.push(AccountInfo {
|
infos.push(AccountInfo::new(
|
||||||
store_id: storage.append_vec_id(),
|
storage.append_vec_id(),
|
||||||
offset: offsets[0],
|
offsets[0],
|
||||||
stored_size,
|
stored_size,
|
||||||
lamports: account
|
account
|
||||||
.map(|account| account.lamports())
|
.map(|account| account.lamports())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
});
|
));
|
||||||
}
|
}
|
||||||
// restore the state to available
|
// restore the state to available
|
||||||
storage.set_status(AccountStorageStatus::Available);
|
storage.set_status(AccountStorageStatus::Available);
|
||||||
@ -4878,12 +4878,12 @@ impl AccountsDb {
|
|||||||
let account = account
|
let account = account
|
||||||
.map(|account| account.to_account_shared_data())
|
.map(|account| account.to_account_shared_data())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let account_info = AccountInfo {
|
let account_info = AccountInfo::new(
|
||||||
store_id: CACHE_VIRTUAL_STORAGE_ID,
|
CACHE_VIRTUAL_STORAGE_ID,
|
||||||
offset: CACHE_VIRTUAL_OFFSET,
|
CACHE_VIRTUAL_OFFSET,
|
||||||
stored_size: CACHE_VIRTUAL_STORED_SIZE,
|
CACHE_VIRTUAL_STORED_SIZE,
|
||||||
lamports: account.lamports(),
|
account.lamports(),
|
||||||
};
|
);
|
||||||
|
|
||||||
self.notify_account_at_accounts_update(slot, meta, &account);
|
self.notify_account_at_accounts_update(slot, meta, &account);
|
||||||
|
|
||||||
@ -6699,12 +6699,12 @@ impl AccountsDb {
|
|||||||
|
|
||||||
(
|
(
|
||||||
pubkey,
|
pubkey,
|
||||||
AccountInfo {
|
AccountInfo::new(
|
||||||
store_id,
|
store_id,
|
||||||
offset: stored_account.offset,
|
stored_account.offset,
|
||||||
stored_size: stored_account.stored_size,
|
stored_account.stored_size,
|
||||||
lamports: stored_account.account_meta.lamports,
|
stored_account.account_meta.lamports,
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -6950,15 +6950,12 @@ impl AccountsDb {
|
|||||||
for (slot2, account_info2) in sl.iter() {
|
for (slot2, account_info2) in sl.iter() {
|
||||||
if slot2 == slot {
|
if slot2 == slot {
|
||||||
count += 1;
|
count += 1;
|
||||||
let ai = AccountInfo {
|
let ai = AccountInfo::new(
|
||||||
store_id: account_info.store_id,
|
account_info.store_id,
|
||||||
offset: account_info.stored_account.offset,
|
account_info.stored_account.offset,
|
||||||
stored_size: account_info.stored_account.stored_size,
|
account_info.stored_account.stored_size,
|
||||||
lamports: account_info
|
account_info.stored_account.account_meta.lamports,
|
||||||
.stored_account
|
);
|
||||||
.account_meta
|
|
||||||
.lamports,
|
|
||||||
};
|
|
||||||
assert_eq!(&ai, account_info2);
|
assert_eq!(&ai, account_info2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -10999,30 +10996,10 @@ pub mod tests {
|
|||||||
let key0 = Pubkey::new_from_array([0u8; 32]);
|
let key0 = Pubkey::new_from_array([0u8; 32]);
|
||||||
let key1 = Pubkey::new_from_array([1u8; 32]);
|
let key1 = Pubkey::new_from_array([1u8; 32]);
|
||||||
let key2 = Pubkey::new_from_array([2u8; 32]);
|
let key2 = Pubkey::new_from_array([2u8; 32]);
|
||||||
let info0 = AccountInfo {
|
let info0 = AccountInfo::new(0, 0, 0, 0);
|
||||||
store_id: 0,
|
let info1 = AccountInfo::new(1, 0, 0, 0);
|
||||||
offset: 0,
|
let info2 = AccountInfo::new(2, 0, 0, 0);
|
||||||
stored_size: 0,
|
let info3 = AccountInfo::new(3, 0, 0, 0);
|
||||||
lamports: 0,
|
|
||||||
};
|
|
||||||
let info1 = AccountInfo {
|
|
||||||
store_id: 1,
|
|
||||||
offset: 0,
|
|
||||||
stored_size: 0,
|
|
||||||
lamports: 0,
|
|
||||||
};
|
|
||||||
let info2 = AccountInfo {
|
|
||||||
store_id: 2,
|
|
||||||
offset: 0,
|
|
||||||
stored_size: 0,
|
|
||||||
lamports: 0,
|
|
||||||
};
|
|
||||||
let info3 = AccountInfo {
|
|
||||||
store_id: 3,
|
|
||||||
offset: 0,
|
|
||||||
stored_size: 0,
|
|
||||||
lamports: 0,
|
|
||||||
};
|
|
||||||
let mut reclaims = vec![];
|
let mut reclaims = vec![];
|
||||||
accounts_index.upsert(
|
accounts_index.upsert(
|
||||||
0,
|
0,
|
||||||
@ -13331,12 +13308,7 @@ pub mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let do_test = |test_params: TestParameters| {
|
let do_test = |test_params: TestParameters| {
|
||||||
let account_info = AccountInfo {
|
let account_info = AccountInfo::new(42, 123, 234, 0);
|
||||||
store_id: 42,
|
|
||||||
offset: 123,
|
|
||||||
stored_size: 234,
|
|
||||||
lamports: 0,
|
|
||||||
};
|
|
||||||
let pubkey = solana_sdk::pubkey::new_rand();
|
let pubkey = solana_sdk::pubkey::new_rand();
|
||||||
let mut key_set = HashSet::default();
|
let mut key_set = HashSet::default();
|
||||||
key_set.insert(pubkey);
|
key_set.insert(pubkey);
|
||||||
|
Reference in New Issue
Block a user