rename balance (#5984)
This commit is contained in:
@ -308,7 +308,7 @@ impl Accounts {
|
|||||||
|
|
||||||
pub fn load_by_program_fork(&self, fork: Fork, program_id: &Pubkey) -> Vec<(Pubkey, Account)> {
|
pub fn load_by_program_fork(&self, fork: Fork, program_id: &Pubkey) -> Vec<(Pubkey, Account)> {
|
||||||
self.scan_fork(fork, |stored_account| {
|
self.scan_fork(fork, |stored_account| {
|
||||||
if stored_account.balance.owner == *program_id {
|
if stored_account.account_meta.owner == *program_id {
|
||||||
Some((stored_account.meta.pubkey, stored_account.clone_account()))
|
Some((stored_account.meta.pubkey, stored_account.clone_account()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
//! commit for each fork entry would be indexed.
|
//! commit for each fork entry would be indexed.
|
||||||
|
|
||||||
use crate::accounts_index::{AccountsIndex, Fork};
|
use crate::accounts_index::{AccountsIndex, Fork};
|
||||||
use crate::append_vec::{AppendVec, StorageMeta, StoredAccount};
|
use crate::append_vec::{AppendVec, StoredAccount, StoredMeta};
|
||||||
use bincode::{deserialize_from, serialize_into};
|
use bincode::{deserialize_from, serialize_into};
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use fs_extra::dir::CopyOptions;
|
use fs_extra::dir::CopyOptions;
|
||||||
@ -723,7 +723,7 @@ impl AccountsDB {
|
|||||||
pub fn hash_stored_account(fork: Fork, account: &StoredAccount) -> Hash {
|
pub fn hash_stored_account(fork: Fork, account: &StoredAccount) -> Hash {
|
||||||
Self::hash_account_data(
|
Self::hash_account_data(
|
||||||
fork,
|
fork,
|
||||||
account.balance.lamports,
|
account.account_meta.lamports,
|
||||||
account.data,
|
account.data,
|
||||||
&account.meta.pubkey,
|
&account.meta.pubkey,
|
||||||
)
|
)
|
||||||
@ -756,7 +756,7 @@ impl AccountsDB {
|
|||||||
accounts: &[(&Pubkey, &Account)],
|
accounts: &[(&Pubkey, &Account)],
|
||||||
hashes: &[Hash],
|
hashes: &[Hash],
|
||||||
) -> Vec<AccountInfo> {
|
) -> Vec<AccountInfo> {
|
||||||
let with_meta: Vec<(StorageMeta, &Account)> = accounts
|
let with_meta: Vec<(StoredMeta, &Account)> = accounts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(pubkey, account)| {
|
.map(|(pubkey, account)| {
|
||||||
let write_version = self.write_version.fetch_add(1, Ordering::Relaxed) as u64;
|
let write_version = self.write_version.fetch_add(1, Ordering::Relaxed) as u64;
|
||||||
@ -765,7 +765,7 @@ impl AccountsDB {
|
|||||||
} else {
|
} else {
|
||||||
account.data.len() as u64
|
account.data.len() as u64
|
||||||
};
|
};
|
||||||
let meta = StorageMeta {
|
let meta = StoredMeta {
|
||||||
write_version,
|
write_version,
|
||||||
pubkey: **pubkey,
|
pubkey: **pubkey,
|
||||||
data_len,
|
data_len,
|
||||||
@ -1018,7 +1018,7 @@ impl AccountsDB {
|
|||||||
let account_info = AccountInfo {
|
let account_info = AccountInfo {
|
||||||
id,
|
id,
|
||||||
offset: stored_account.offset,
|
offset: stored_account.offset,
|
||||||
lamports: stored_account.balance.lamports,
|
lamports: stored_account.account_meta.lamports,
|
||||||
};
|
};
|
||||||
accum.insert(
|
accum.insert(
|
||||||
stored_account.meta.pubkey,
|
stored_account.meta.pubkey,
|
||||||
@ -1574,8 +1574,8 @@ pub mod tests {
|
|||||||
let fork_id = 42;
|
let fork_id = 42;
|
||||||
let num_threads = 2;
|
let num_threads = 2;
|
||||||
|
|
||||||
let min_file_bytes = std::mem::size_of::<StorageMeta>()
|
let min_file_bytes = std::mem::size_of::<StoredMeta>()
|
||||||
+ std::mem::size_of::<crate::append_vec::AccountBalance>();
|
+ std::mem::size_of::<crate::append_vec::AccountMeta>();
|
||||||
|
|
||||||
let db = Arc::new(AccountsDB::new_sized(None, min_file_bytes as u64));
|
let db = Arc::new(AccountsDB::new_sized(None, min_file_bytes as u64));
|
||||||
|
|
||||||
|
@ -2,14 +2,16 @@ use bincode::{deserialize_from, serialize_into, serialized_size};
|
|||||||
use memmap::MmapMut;
|
use memmap::MmapMut;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use solana_sdk::{account::Account, clock::Epoch, hash::Hash, pubkey::Pubkey};
|
use solana_sdk::{account::Account, clock::Epoch, hash::Hash, pubkey::Pubkey};
|
||||||
use std::fmt;
|
use std::{
|
||||||
use std::fs::{create_dir_all, remove_file, OpenOptions};
|
fmt,
|
||||||
use std::io;
|
fs::{create_dir_all, remove_file, OpenOptions},
|
||||||
use std::io::{Cursor, Seek, SeekFrom, Write};
|
io,
|
||||||
use std::mem;
|
io::{Cursor, Seek, SeekFrom, Write},
|
||||||
use std::path::{Path, PathBuf};
|
mem,
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
path::{Path, PathBuf},
|
||||||
use std::sync::Mutex;
|
sync::atomic::{AtomicUsize, Ordering},
|
||||||
|
sync::Mutex,
|
||||||
|
};
|
||||||
|
|
||||||
//Data is aligned at the next 64 byte offset. Without alignment loading the memory may
|
//Data is aligned at the next 64 byte offset. Without alignment loading the memory may
|
||||||
//crash on some architectures.
|
//crash on some architectures.
|
||||||
@ -19,9 +21,9 @@ macro_rules! align_up {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// StorageMeta contains enough context to recover the index from storage itself
|
/// Meta contains enough context to recover the index from storage itself
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
pub struct StorageMeta {
|
pub struct StoredMeta {
|
||||||
/// global write version
|
/// global write version
|
||||||
pub write_version: u64,
|
pub write_version: u64,
|
||||||
/// key for the account
|
/// key for the account
|
||||||
@ -30,7 +32,7 @@ pub struct StorageMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq)]
|
||||||
pub struct AccountBalance {
|
pub struct AccountMeta {
|
||||||
/// lamports in the account
|
/// lamports in the account
|
||||||
pub lamports: u64,
|
pub lamports: u64,
|
||||||
/// the program that owns this account. If executable, the program that loads this account.
|
/// the program that owns this account. If executable, the program that loads this account.
|
||||||
@ -45,9 +47,9 @@ pub struct AccountBalance {
|
|||||||
/// The Account is stored separately from its data, so getting the actual account requires a clone
|
/// The Account is stored separately from its data, so getting the actual account requires a clone
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct StoredAccount<'a> {
|
pub struct StoredAccount<'a> {
|
||||||
pub meta: &'a StorageMeta,
|
pub meta: &'a StoredMeta,
|
||||||
/// account data
|
/// account data
|
||||||
pub balance: &'a AccountBalance,
|
pub account_meta: &'a AccountMeta,
|
||||||
pub data: &'a [u8],
|
pub data: &'a [u8],
|
||||||
pub offset: usize,
|
pub offset: usize,
|
||||||
pub hash: &'a Hash,
|
pub hash: &'a Hash,
|
||||||
@ -56,10 +58,10 @@ pub struct StoredAccount<'a> {
|
|||||||
impl<'a> StoredAccount<'a> {
|
impl<'a> StoredAccount<'a> {
|
||||||
pub fn clone_account(&self) -> Account {
|
pub fn clone_account(&self) -> Account {
|
||||||
Account {
|
Account {
|
||||||
lamports: self.balance.lamports,
|
lamports: self.account_meta.lamports,
|
||||||
owner: self.balance.owner,
|
owner: self.account_meta.owner,
|
||||||
executable: self.balance.executable,
|
executable: self.account_meta.executable,
|
||||||
rent_epoch: self.balance.rent_epoch,
|
rent_epoch: self.account_meta.rent_epoch,
|
||||||
data: self.data.to_vec(),
|
data: self.data.to_vec(),
|
||||||
hash: *self.hash,
|
hash: *self.hash,
|
||||||
}
|
}
|
||||||
@ -243,14 +245,14 @@ impl AppendVec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_account<'a>(&'a self, offset: usize) -> Option<(StoredAccount<'a>, usize)> {
|
pub fn get_account<'a>(&'a self, offset: usize) -> Option<(StoredAccount<'a>, usize)> {
|
||||||
let (meta, next): (&'a StorageMeta, _) = self.get_type(offset)?;
|
let (meta, next): (&'a StoredMeta, _) = self.get_type(offset)?;
|
||||||
let (balance, next): (&'a AccountBalance, _) = self.get_type(next)?;
|
let (account_meta, next): (&'a AccountMeta, _) = self.get_type(next)?;
|
||||||
let (hash, next): (&'a Hash, _) = self.get_type(next)?;
|
let (hash, next): (&'a Hash, _) = self.get_type(next)?;
|
||||||
let (data, next) = self.get_slice(next, meta.data_len as usize)?;
|
let (data, next) = self.get_slice(next, meta.data_len as usize)?;
|
||||||
Some((
|
Some((
|
||||||
StoredAccount {
|
StoredAccount {
|
||||||
meta,
|
meta,
|
||||||
balance,
|
account_meta,
|
||||||
data,
|
data,
|
||||||
offset,
|
offset,
|
||||||
hash,
|
hash,
|
||||||
@ -258,10 +260,10 @@ impl AppendVec {
|
|||||||
next,
|
next,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
pub fn get_account_test(&self, offset: usize) -> Option<(StorageMeta, Account)> {
|
pub fn get_account_test(&self, offset: usize) -> Option<(StoredMeta, Account)> {
|
||||||
let stored = self.get_account(offset)?;
|
let (stored_account, _) = self.get_account(offset)?;
|
||||||
let meta = stored.0.meta.clone();
|
let meta = stored_account.meta.clone();
|
||||||
Some((meta, stored.0.clone_account()))
|
Some((meta, stored_account.clone_account()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_path(&self) -> PathBuf {
|
pub fn get_path(&self) -> PathBuf {
|
||||||
@ -280,26 +282,26 @@ impl AppendVec {
|
|||||||
#[allow(clippy::mutex_atomic)]
|
#[allow(clippy::mutex_atomic)]
|
||||||
pub fn append_accounts(
|
pub fn append_accounts(
|
||||||
&self,
|
&self,
|
||||||
accounts: &[(StorageMeta, &Account)],
|
accounts: &[(StoredMeta, &Account)],
|
||||||
hashes: &[Hash],
|
hashes: &[Hash],
|
||||||
) -> Vec<usize> {
|
) -> Vec<usize> {
|
||||||
let mut offset = self.append_offset.lock().unwrap();
|
let mut offset = self.append_offset.lock().unwrap();
|
||||||
let mut rv = vec![];
|
let mut rv = vec![];
|
||||||
for ((storage_meta, account), hash) in accounts.iter().zip(hashes) {
|
for ((stored_meta, account), hash) in accounts.iter().zip(hashes) {
|
||||||
let meta_ptr = storage_meta as *const StorageMeta;
|
let meta_ptr = stored_meta as *const StoredMeta;
|
||||||
let balance = AccountBalance {
|
let account_meta = AccountMeta {
|
||||||
lamports: account.lamports,
|
lamports: account.lamports,
|
||||||
owner: account.owner,
|
owner: account.owner,
|
||||||
executable: account.executable,
|
executable: account.executable,
|
||||||
rent_epoch: account.rent_epoch,
|
rent_epoch: account.rent_epoch,
|
||||||
};
|
};
|
||||||
let balance_ptr = &balance as *const AccountBalance;
|
let account_meta_ptr = &account_meta as *const AccountMeta;
|
||||||
let data_len = storage_meta.data_len as usize;
|
let data_len = stored_meta.data_len as usize;
|
||||||
let data_ptr = account.data.as_ptr();
|
let data_ptr = account.data.as_ptr();
|
||||||
let hash_ptr = hash.as_ref().as_ptr();
|
let hash_ptr = hash.as_ref().as_ptr();
|
||||||
let ptrs = [
|
let ptrs = [
|
||||||
(meta_ptr as *const u8, mem::size_of::<StorageMeta>()),
|
(meta_ptr as *const u8, mem::size_of::<StoredMeta>()),
|
||||||
(balance_ptr as *const u8, mem::size_of::<AccountBalance>()),
|
(account_meta_ptr as *const u8, mem::size_of::<AccountMeta>()),
|
||||||
(hash_ptr as *const u8, mem::size_of::<Hash>()),
|
(hash_ptr as *const u8, mem::size_of::<Hash>()),
|
||||||
(data_ptr, data_len),
|
(data_ptr, data_len),
|
||||||
];
|
];
|
||||||
@ -314,7 +316,7 @@ impl AppendVec {
|
|||||||
|
|
||||||
pub fn append_account(
|
pub fn append_account(
|
||||||
&self,
|
&self,
|
||||||
storage_meta: StorageMeta,
|
storage_meta: StoredMeta,
|
||||||
account: &Account,
|
account: &Account,
|
||||||
hash: Hash,
|
hash: Hash,
|
||||||
) -> Option<usize> {
|
) -> Option<usize> {
|
||||||
@ -322,14 +324,10 @@ impl AppendVec {
|
|||||||
.first()
|
.first()
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append_account_test(&self, data: &(StorageMeta, Account)) -> Option<usize> {
|
|
||||||
self.append_account(data.0.clone(), &data.1, Hash::default())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod test_utils {
|
pub mod test_utils {
|
||||||
use super::StorageMeta;
|
use super::StoredMeta;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use solana_sdk::account::Account;
|
use solana_sdk::account::Account;
|
||||||
@ -363,16 +361,16 @@ pub mod test_utils {
|
|||||||
TempFile { path: buf }
|
TempFile { path: buf }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_test_account(sample: usize) -> (StorageMeta, Account) {
|
pub fn create_test_account(sample: usize) -> (StoredMeta, Account) {
|
||||||
let data_len = sample % 256;
|
let data_len = sample % 256;
|
||||||
let mut account = Account::new(sample as u64, 0, &Pubkey::default());
|
let mut account = Account::new(sample as u64, 0, &Pubkey::default());
|
||||||
account.data = (0..data_len).map(|_| data_len as u8).collect();
|
account.data = (0..data_len).map(|_| data_len as u8).collect();
|
||||||
let storage_meta = StorageMeta {
|
let stored_meta = StoredMeta {
|
||||||
write_version: 0,
|
write_version: 0,
|
||||||
pubkey: Pubkey::default(),
|
pubkey: Pubkey::default(),
|
||||||
data_len: data_len as u64,
|
data_len: data_len as u64,
|
||||||
};
|
};
|
||||||
(storage_meta, account)
|
(stored_meta, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,6 +452,12 @@ pub mod tests {
|
|||||||
use solana_sdk::timing::duration_as_ms;
|
use solana_sdk::timing::duration_as_ms;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
impl AppendVec {
|
||||||
|
fn append_account_test(&self, data: &(StoredMeta, Account)) -> Option<usize> {
|
||||||
|
self.append_account(data.0.clone(), &data.1, Hash::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_append_vec_one() {
|
fn test_append_vec_one() {
|
||||||
let path = get_append_vec_path("test_append");
|
let path = get_append_vec_path("test_append");
|
||||||
|
Reference in New Issue
Block a user