@ -1,9 +1,11 @@
|
|||||||
use clap::{value_t, App, Arg};
|
use clap::{value_t, App, Arg};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use solana_measure::measure::Measure;
|
use solana_measure::measure::Measure;
|
||||||
use solana_runtime::accounts::{create_test_accounts, update_accounts, Accounts};
|
use solana_runtime::{
|
||||||
|
accounts::{create_test_accounts, update_accounts, Accounts},
|
||||||
|
accounts_index::Ancestors,
|
||||||
|
};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
@ -76,7 +78,7 @@ fn main() {
|
|||||||
num_slots,
|
num_slots,
|
||||||
create_time
|
create_time
|
||||||
);
|
);
|
||||||
let mut ancestors: HashMap<u64, usize> = vec![(0, 0)].into_iter().collect();
|
let mut ancestors: Ancestors = vec![(0, 0)].into_iter().collect();
|
||||||
for i in 1..num_slots {
|
for i in 1..num_slots {
|
||||||
ancestors.insert(i as u64, i - 1);
|
ancestors.insert(i as u64, i - 1);
|
||||||
accounts.add_root(i as u64);
|
accounts.add_root(i as u64);
|
||||||
|
@ -2,7 +2,7 @@ use crate::{
|
|||||||
accounts_db::{
|
accounts_db::{
|
||||||
AccountInfo, AccountStorage, AccountsDB, AppendVecId, BankHashInfo, ErrorCounters,
|
AccountInfo, AccountStorage, AccountsDB, AppendVecId, BankHashInfo, ErrorCounters,
|
||||||
},
|
},
|
||||||
accounts_index::AccountsIndex,
|
accounts_index::{AccountsIndex, Ancestors},
|
||||||
append_vec::StoredAccount,
|
append_vec::StoredAccount,
|
||||||
bank::{HashAgeKind, TransactionProcessResult},
|
bank::{HashAgeKind, TransactionProcessResult},
|
||||||
blockhash_queue::BlockhashQueue,
|
blockhash_queue::BlockhashQueue,
|
||||||
@ -82,7 +82,7 @@ impl Accounts {
|
|||||||
|
|
||||||
pub fn new_with_frozen_accounts(
|
pub fn new_with_frozen_accounts(
|
||||||
paths: Vec<PathBuf>,
|
paths: Vec<PathBuf>,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
frozen_account_pubkeys: &[Pubkey],
|
frozen_account_pubkeys: &[Pubkey],
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut accounts = Accounts {
|
let mut accounts = Accounts {
|
||||||
@ -95,11 +95,7 @@ impl Accounts {
|
|||||||
accounts
|
accounts
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn freeze_accounts(
|
pub fn freeze_accounts(&mut self, ancestors: &Ancestors, frozen_account_pubkeys: &[Pubkey]) {
|
||||||
&mut self,
|
|
||||||
ancestors: &HashMap<Slot, usize>,
|
|
||||||
frozen_account_pubkeys: &[Pubkey],
|
|
||||||
) {
|
|
||||||
Arc::get_mut(&mut self.accounts_db)
|
Arc::get_mut(&mut self.accounts_db)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.freeze_accounts(ancestors, frozen_account_pubkeys);
|
.freeze_accounts(ancestors, frozen_account_pubkeys);
|
||||||
@ -107,7 +103,7 @@ impl Accounts {
|
|||||||
|
|
||||||
pub fn from_stream<R: Read, P: AsRef<Path>>(
|
pub fn from_stream<R: Read, P: AsRef<Path>>(
|
||||||
account_paths: &[PathBuf],
|
account_paths: &[PathBuf],
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
frozen_account_pubkeys: &[Pubkey],
|
frozen_account_pubkeys: &[Pubkey],
|
||||||
stream: &mut BufReader<R>,
|
stream: &mut BufReader<R>,
|
||||||
stream_append_vecs_path: P,
|
stream_append_vecs_path: P,
|
||||||
@ -140,7 +136,7 @@ impl Accounts {
|
|||||||
fn load_tx_accounts(
|
fn load_tx_accounts(
|
||||||
&self,
|
&self,
|
||||||
storage: &AccountStorage,
|
storage: &AccountStorage,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
accounts_index: &AccountsIndex<AccountInfo>,
|
accounts_index: &AccountsIndex<AccountInfo>,
|
||||||
tx: &Transaction,
|
tx: &Transaction,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
@ -222,7 +218,7 @@ impl Accounts {
|
|||||||
|
|
||||||
fn load_executable_accounts(
|
fn load_executable_accounts(
|
||||||
storage: &AccountStorage,
|
storage: &AccountStorage,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
accounts_index: &AccountsIndex<AccountInfo>,
|
accounts_index: &AccountsIndex<AccountInfo>,
|
||||||
program_id: &Pubkey,
|
program_id: &Pubkey,
|
||||||
error_counters: &mut ErrorCounters,
|
error_counters: &mut ErrorCounters,
|
||||||
@ -267,7 +263,7 @@ impl Accounts {
|
|||||||
/// For each program_id in the transaction, load its loaders.
|
/// For each program_id in the transaction, load its loaders.
|
||||||
fn load_loaders(
|
fn load_loaders(
|
||||||
storage: &AccountStorage,
|
storage: &AccountStorage,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
accounts_index: &AccountsIndex<AccountInfo>,
|
accounts_index: &AccountsIndex<AccountInfo>,
|
||||||
tx: &Transaction,
|
tx: &Transaction,
|
||||||
error_counters: &mut ErrorCounters,
|
error_counters: &mut ErrorCounters,
|
||||||
@ -295,7 +291,7 @@ impl Accounts {
|
|||||||
|
|
||||||
pub fn load_accounts(
|
pub fn load_accounts(
|
||||||
&self,
|
&self,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
txs: &[Transaction],
|
txs: &[Transaction],
|
||||||
txs_iteration_order: Option<&[usize]>,
|
txs_iteration_order: Option<&[usize]>,
|
||||||
lock_results: Vec<TransactionProcessResult>,
|
lock_results: Vec<TransactionProcessResult>,
|
||||||
@ -359,11 +355,7 @@ impl Accounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Slow because lock is held for 1 operation instead of many
|
/// Slow because lock is held for 1 operation instead of many
|
||||||
pub fn load_slow(
|
pub fn load_slow(&self, ancestors: &Ancestors, pubkey: &Pubkey) -> Option<(Account, Slot)> {
|
||||||
&self,
|
|
||||||
ancestors: &HashMap<Slot, usize>,
|
|
||||||
pubkey: &Pubkey,
|
|
||||||
) -> Option<(Account, Slot)> {
|
|
||||||
let (account, slot) = self
|
let (account, slot) = self
|
||||||
.accounts_db
|
.accounts_db
|
||||||
.load_slow(ancestors, pubkey)
|
.load_slow(ancestors, pubkey)
|
||||||
@ -454,7 +446,7 @@ impl Accounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn verify_bank_hash(&self, slot: Slot, ancestors: &HashMap<Slot, usize>) -> bool {
|
pub fn verify_bank_hash(&self, slot: Slot, ancestors: &Ancestors) -> bool {
|
||||||
if let Err(err) = self.accounts_db.verify_bank_hash(slot, ancestors) {
|
if let Err(err) = self.accounts_db.verify_bank_hash(slot, ancestors) {
|
||||||
warn!("verify_bank_hash failed: {:?}", err);
|
warn!("verify_bank_hash failed: {:?}", err);
|
||||||
false
|
false
|
||||||
@ -465,7 +457,7 @@ impl Accounts {
|
|||||||
|
|
||||||
pub fn load_by_program(
|
pub fn load_by_program(
|
||||||
&self,
|
&self,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
program_id: Option<&Pubkey>,
|
program_id: Option<&Pubkey>,
|
||||||
) -> Vec<(Pubkey, Account)> {
|
) -> Vec<(Pubkey, Account)> {
|
||||||
self.accounts_db.scan_accounts(
|
self.accounts_db.scan_accounts(
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
//! commit for each slot entry would be indexed.
|
//! commit for each slot entry would be indexed.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
accounts_index::{AccountsIndex, SlotList, SlotSlice},
|
accounts_index::{AccountsIndex, Ancestors, SlotList, SlotSlice},
|
||||||
append_vec::{AppendVec, StoredAccount, StoredMeta},
|
append_vec::{AppendVec, StoredAccount, StoredMeta},
|
||||||
bank::deserialize_from_snapshot,
|
bank::deserialize_from_snapshot,
|
||||||
};
|
};
|
||||||
@ -1072,7 +1072,7 @@ impl AccountsDB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scan_accounts<F, A>(&self, ancestors: &HashMap<Slot, usize>, scan_func: F) -> A
|
pub fn scan_accounts<F, A>(&self, ancestors: &Ancestors, scan_func: F) -> A
|
||||||
where
|
where
|
||||||
F: Fn(&mut A, Option<(&Pubkey, Account, Slot)>) -> (),
|
F: Fn(&mut A, Option<(&Pubkey, Account, Slot)>) -> (),
|
||||||
A: Default,
|
A: Default,
|
||||||
@ -1154,7 +1154,7 @@ impl AccountsDB {
|
|||||||
|
|
||||||
pub fn load(
|
pub fn load(
|
||||||
storage: &AccountStorage,
|
storage: &AccountStorage,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
accounts_index: &AccountsIndex<AccountInfo>,
|
accounts_index: &AccountsIndex<AccountInfo>,
|
||||||
pubkey: &Pubkey,
|
pubkey: &Pubkey,
|
||||||
) -> Option<(Account, Slot)> {
|
) -> Option<(Account, Slot)> {
|
||||||
@ -1172,11 +1172,7 @@ impl AccountsDB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_slow(
|
pub fn load_slow(&self, ancestors: &Ancestors, pubkey: &Pubkey) -> Option<(Account, Slot)> {
|
||||||
&self,
|
|
||||||
ancestors: &HashMap<Slot, usize>,
|
|
||||||
pubkey: &Pubkey,
|
|
||||||
) -> Option<(Account, Slot)> {
|
|
||||||
let accounts_index = self.accounts_index.read().unwrap();
|
let accounts_index = self.accounts_index.read().unwrap();
|
||||||
let storage = self.storage.read().unwrap();
|
let storage = self.storage.read().unwrap();
|
||||||
Self::load(&storage, ancestors, &accounts_index, pubkey)
|
Self::load(&storage, ancestors, &accounts_index, pubkey)
|
||||||
@ -1519,7 +1515,7 @@ impl AccountsDB {
|
|||||||
|
|
||||||
fn calculate_accounts_hash(
|
fn calculate_accounts_hash(
|
||||||
&self,
|
&self,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
check_hash: bool,
|
check_hash: bool,
|
||||||
) -> Result<Hash, BankHashVerificationError> {
|
) -> Result<Hash, BankHashVerificationError> {
|
||||||
use BankHashVerificationError::*;
|
use BankHashVerificationError::*;
|
||||||
@ -1581,7 +1577,7 @@ impl AccountsDB {
|
|||||||
bank_hash_info.snapshot_hash
|
bank_hash_info.snapshot_hash
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_accounts_hash(&self, slot: Slot, ancestors: &HashMap<Slot, usize>) -> Hash {
|
pub fn update_accounts_hash(&self, slot: Slot, ancestors: &Ancestors) -> Hash {
|
||||||
let hash = self.calculate_accounts_hash(ancestors, false).unwrap();
|
let hash = self.calculate_accounts_hash(ancestors, false).unwrap();
|
||||||
let mut bank_hashes = self.bank_hashes.write().unwrap();
|
let mut bank_hashes = self.bank_hashes.write().unwrap();
|
||||||
let mut bank_hash_info = bank_hashes.get_mut(&slot).unwrap();
|
let mut bank_hash_info = bank_hashes.get_mut(&slot).unwrap();
|
||||||
@ -1592,7 +1588,7 @@ impl AccountsDB {
|
|||||||
pub fn verify_bank_hash(
|
pub fn verify_bank_hash(
|
||||||
&self,
|
&self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
) -> Result<(), BankHashVerificationError> {
|
) -> Result<(), BankHashVerificationError> {
|
||||||
use BankHashVerificationError::*;
|
use BankHashVerificationError::*;
|
||||||
|
|
||||||
@ -1780,11 +1776,7 @@ impl AccountsDB {
|
|||||||
hashes
|
hashes
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn freeze_accounts(
|
pub fn freeze_accounts(&mut self, ancestors: &Ancestors, account_pubkeys: &[Pubkey]) {
|
||||||
&mut self,
|
|
||||||
ancestors: &HashMap<Slot, usize>,
|
|
||||||
account_pubkeys: &[Pubkey],
|
|
||||||
) {
|
|
||||||
for account_pubkey in account_pubkeys {
|
for account_pubkey in account_pubkeys {
|
||||||
if let Some((account, _slot)) = self.load_slow(ancestors, &account_pubkey) {
|
if let Some((account, _slot)) = self.load_slow(ancestors, &account_pubkey) {
|
||||||
let frozen_account_info = FrozenAccountInfo {
|
let frozen_account_info = FrozenAccountInfo {
|
||||||
@ -1985,8 +1977,8 @@ pub mod tests {
|
|||||||
use std::{fs, str::FromStr};
|
use std::{fs, str::FromStr};
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
fn linear_ancestors(end_slot: u64) -> HashMap<Slot, usize> {
|
fn linear_ancestors(end_slot: u64) -> Ancestors {
|
||||||
let mut ancestors: HashMap<Slot, usize> = vec![(0, 0)].into_iter().collect();
|
let mut ancestors: Ancestors = vec![(0, 0)].into_iter().collect();
|
||||||
for i in 1..end_slot {
|
for i in 1..end_slot {
|
||||||
ancestors.insert(i, (i - 1) as usize);
|
ancestors.insert(i, (i - 1) as usize);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ use std::{
|
|||||||
|
|
||||||
pub type SlotList<T> = Vec<(Slot, T)>;
|
pub type SlotList<T> = Vec<(Slot, T)>;
|
||||||
pub type SlotSlice<'s, T> = &'s [(Slot, T)];
|
pub type SlotSlice<'s, T> = &'s [(Slot, T)];
|
||||||
|
pub type Ancestors = HashMap<Slot, usize>;
|
||||||
|
|
||||||
pub type RefCount = u64;
|
pub type RefCount = u64;
|
||||||
type AccountMapEntry<T> = (AtomicU64, RwLock<SlotList<T>>);
|
type AccountMapEntry<T> = (AtomicU64, RwLock<SlotList<T>>);
|
||||||
|
|
||||||
@ -20,7 +22,7 @@ pub struct AccountsIndex<T> {
|
|||||||
|
|
||||||
impl<T: Clone> AccountsIndex<T> {
|
impl<T: Clone> AccountsIndex<T> {
|
||||||
/// call func with every pubkey and index visible from a given set of ancestors
|
/// call func with every pubkey and index visible from a given set of ancestors
|
||||||
pub fn scan_accounts<F>(&self, ancestors: &HashMap<Slot, usize>, mut func: F)
|
pub fn scan_accounts<F>(&self, ancestors: &Ancestors, mut func: F)
|
||||||
where
|
where
|
||||||
F: FnMut(&Pubkey, (&T, Slot)) -> (),
|
F: FnMut(&Pubkey, (&T, Slot)) -> (),
|
||||||
{
|
{
|
||||||
@ -56,7 +58,7 @@ impl<T: Clone> AccountsIndex<T> {
|
|||||||
|
|
||||||
// find the latest slot and T in a slice for a given ancestor
|
// find the latest slot and T in a slice for a given ancestor
|
||||||
// returns index into 'slice' if found, None if not.
|
// returns index into 'slice' if found, None if not.
|
||||||
fn latest_slot(&self, ancestors: &HashMap<Slot, usize>, slice: SlotSlice<T>) -> Option<usize> {
|
fn latest_slot(&self, ancestors: &Ancestors, slice: SlotSlice<T>) -> Option<usize> {
|
||||||
let mut max = 0;
|
let mut max = 0;
|
||||||
let mut rv = None;
|
let mut rv = None;
|
||||||
for (i, (slot, _t)) in slice.iter().rev().enumerate() {
|
for (i, (slot, _t)) in slice.iter().rev().enumerate() {
|
||||||
@ -73,7 +75,7 @@ impl<T: Clone> AccountsIndex<T> {
|
|||||||
pub fn get(
|
pub fn get(
|
||||||
&self,
|
&self,
|
||||||
pubkey: &Pubkey,
|
pubkey: &Pubkey,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
) -> Option<(RwLockReadGuard<SlotList<T>>, usize)> {
|
) -> Option<(RwLockReadGuard<SlotList<T>>, usize)> {
|
||||||
self.account_maps.get(pubkey).and_then(|list| {
|
self.account_maps.get(pubkey).and_then(|list| {
|
||||||
let list_r = list.1.read().unwrap();
|
let list_r = list.1.read().unwrap();
|
||||||
|
@ -8,6 +8,7 @@ use crate::{
|
|||||||
TransactionLoaders,
|
TransactionLoaders,
|
||||||
},
|
},
|
||||||
accounts_db::{AccountsDBSerialize, ErrorCounters, SnapshotStorage, SnapshotStorages},
|
accounts_db::{AccountsDBSerialize, ErrorCounters, SnapshotStorage, SnapshotStorages},
|
||||||
|
accounts_index::Ancestors,
|
||||||
blockhash_queue::BlockhashQueue,
|
blockhash_queue::BlockhashQueue,
|
||||||
epoch_stakes::{EpochStakes, NodeVoteAccounts},
|
epoch_stakes::{EpochStakes, NodeVoteAccounts},
|
||||||
message_processor::{MessageProcessor, ProcessInstruction},
|
message_processor::{MessageProcessor, ProcessInstruction},
|
||||||
@ -94,7 +95,7 @@ impl BankRc {
|
|||||||
pub fn from_stream<R: Read, P: AsRef<Path>>(
|
pub fn from_stream<R: Read, P: AsRef<Path>>(
|
||||||
account_paths: &[PathBuf],
|
account_paths: &[PathBuf],
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
frozen_account_pubkeys: &[Pubkey],
|
frozen_account_pubkeys: &[Pubkey],
|
||||||
mut stream: &mut BufReader<R>,
|
mut stream: &mut BufReader<R>,
|
||||||
stream_append_vecs_path: P,
|
stream_append_vecs_path: P,
|
||||||
@ -231,7 +232,7 @@ pub struct Bank {
|
|||||||
blockhash_queue: RwLock<BlockhashQueue>,
|
blockhash_queue: RwLock<BlockhashQueue>,
|
||||||
|
|
||||||
/// The set of parents including this bank
|
/// The set of parents including this bank
|
||||||
pub ancestors: HashMap<Slot, usize>,
|
pub ancestors: Ancestors,
|
||||||
|
|
||||||
/// Hash of this Bank's state. Only meaningful after freezing.
|
/// Hash of this Bank's state. Only meaningful after freezing.
|
||||||
hash: RwLock<Hash>,
|
hash: RwLock<Hash>,
|
||||||
@ -1866,7 +1867,7 @@ impl Bank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_account_modified_since_parent(&self, pubkey: &Pubkey) -> Option<(Account, Slot)> {
|
pub fn get_account_modified_since_parent(&self, pubkey: &Pubkey) -> Option<(Account, Slot)> {
|
||||||
let just_self: HashMap<u64, usize> = vec![(self.slot(), 0)].into_iter().collect();
|
let just_self: Ancestors = vec![(self.slot(), 0)].into_iter().collect();
|
||||||
if let Some((account, slot)) = self.rc.accounts.load_slow(&just_self, pubkey) {
|
if let Some((account, slot)) = self.rc.accounts.load_slow(&just_self, pubkey) {
|
||||||
if slot == self.slot() {
|
if slot == self.slot() {
|
||||||
return Some((account, slot));
|
return Some((account, slot));
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use crate::accounts_index::Ancestors;
|
||||||
|
|
||||||
use log::*;
|
use log::*;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@ -85,7 +87,7 @@ impl<T: Serialize + Clone> StatusCache<T> {
|
|||||||
&self,
|
&self,
|
||||||
sig: &Signature,
|
sig: &Signature,
|
||||||
transaction_blockhash: &Hash,
|
transaction_blockhash: &Hash,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
) -> Option<(Slot, T)> {
|
) -> Option<(Slot, T)> {
|
||||||
let map = self.cache.get(transaction_blockhash)?;
|
let map = self.cache.get(transaction_blockhash)?;
|
||||||
let (_, index, sigmap) = map;
|
let (_, index, sigmap) = map;
|
||||||
@ -106,7 +108,7 @@ impl<T: Serialize + Clone> StatusCache<T> {
|
|||||||
pub fn get_signature_slot(
|
pub fn get_signature_slot(
|
||||||
&self,
|
&self,
|
||||||
signature: &Signature,
|
signature: &Signature,
|
||||||
ancestors: &HashMap<Slot, usize>,
|
ancestors: &Ancestors,
|
||||||
) -> Option<(Slot, T)> {
|
) -> Option<(Slot, T)> {
|
||||||
let mut keys = vec![];
|
let mut keys = vec![];
|
||||||
let mut val: Vec<_> = self.cache.iter().map(|(k, _)| *k).collect();
|
let mut val: Vec<_> = self.cache.iter().map(|(k, _)| *k).collect();
|
||||||
|
Reference in New Issue
Block a user