rework defaults and construction of accountsdb, accounts, bank (#19083)
* rework defaults and construction of accountsdb, accounts, bank * merge issues
This commit is contained in:
parent
e4be00fece
commit
0028442e14
|
@ -87,7 +87,7 @@ impl AccountLocks {
|
|||
}
|
||||
|
||||
/// This structure handles synchronization for db
|
||||
#[derive(Default, Debug, AbiExample)]
|
||||
#[derive(Debug, AbiExample)]
|
||||
pub struct Accounts {
|
||||
/// Single global AccountsDb
|
||||
pub accounts_db: Arc<AccountsDb>,
|
||||
|
@ -97,6 +97,15 @@ pub struct Accounts {
|
|||
pub(crate) account_locks: Mutex<AccountLocks>,
|
||||
}
|
||||
|
||||
impl Default for Accounts {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
accounts_db: Arc::new(AccountsDb::default()),
|
||||
account_locks: Mutex::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for the load instructions
|
||||
pub type TransactionAccounts = Vec<(Pubkey, AccountSharedData)>;
|
||||
pub type TransactionRent = u64;
|
||||
|
@ -117,6 +126,13 @@ pub enum AccountAddressFilter {
|
|||
}
|
||||
|
||||
impl Accounts {
|
||||
pub fn default_for_tests() -> Self {
|
||||
Self {
|
||||
accounts_db: Arc::new(AccountsDb::default_for_tests()),
|
||||
account_locks: Mutex::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
paths: Vec<PathBuf>,
|
||||
cluster_type: &ClusterType,
|
||||
|
|
|
@ -24,7 +24,7 @@ use crate::{
|
|||
accounts_hash::{AccountsHash, CalculateHashIntermediate, HashStats, PreviousPass},
|
||||
accounts_index::{
|
||||
AccountIndexGetResult, AccountSecondaryIndexes, AccountsIndex, AccountsIndexRootsStats,
|
||||
IndexKey, IsCached, ScanResult, SlotList, SlotSlice, ZeroLamport,
|
||||
IndexKey, IsCached, ScanResult, SlotList, SlotSlice, ZeroLamport, BINS_DEFAULT,
|
||||
},
|
||||
ancestors::Ancestors,
|
||||
append_vec::{AppendVec, StoredAccountMeta, StoredMeta, StoredMetaWriteVersion},
|
||||
|
@ -1346,13 +1346,26 @@ impl<'a> ReadableAccount for StoredAccountMeta<'a> {
|
|||
|
||||
impl Default for AccountsDb {
|
||||
fn default() -> Self {
|
||||
Self::default_with_accounts_index(AccountInfoAccountsIndex::new(BINS_DEFAULT))
|
||||
}
|
||||
}
|
||||
|
||||
type GenerateIndexAccountsMap<'a> =
|
||||
HashMap<Pubkey, (StoredMetaWriteVersion, AppendVecId, StoredAccountMeta<'a>)>;
|
||||
|
||||
impl AccountsDb {
|
||||
pub fn default_for_tests() -> Self {
|
||||
Self::default_with_accounts_index(AccountInfoAccountsIndex::default_for_tests())
|
||||
}
|
||||
|
||||
fn default_with_accounts_index(accounts_index: AccountInfoAccountsIndex) -> Self {
|
||||
let num_threads = get_thread_count();
|
||||
const MAX_READ_ONLY_CACHE_DATA_SIZE: usize = 200_000_000;
|
||||
|
||||
let mut bank_hashes = HashMap::new();
|
||||
bank_hashes.insert(0, BankHashInfo::default());
|
||||
AccountsDb {
|
||||
accounts_index: AccountsIndex::new(crate::accounts_index::BINS_DEFAULT),
|
||||
accounts_index,
|
||||
storage: AccountStorage::default(),
|
||||
accounts_cache: AccountsCache::default(),
|
||||
sender_bg_hasher: None,
|
||||
|
@ -1393,12 +1406,7 @@ impl Default for AccountsDb {
|
|||
dirty_stores: DashMap::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type GenerateIndexAccountsMap<'a> =
|
||||
HashMap<Pubkey, (StoredMetaWriteVersion, AppendVecId, StoredAccountMeta<'a>)>;
|
||||
|
||||
impl AccountsDb {
|
||||
pub fn new(paths: Vec<PathBuf>, cluster_type: &ClusterType) -> Self {
|
||||
AccountsDb::new_with_config(
|
||||
paths,
|
||||
|
@ -1409,6 +1417,11 @@ impl AccountsDb {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn new_for_tests(paths: Vec<PathBuf>, cluster_type: &ClusterType) -> Self {
|
||||
// will diverge
|
||||
Self::new(paths, cluster_type)
|
||||
}
|
||||
|
||||
pub fn new_with_config(
|
||||
paths: Vec<PathBuf>,
|
||||
cluster_type: &ClusterType,
|
||||
|
@ -1416,6 +1429,7 @@ impl AccountsDb {
|
|||
caching_enabled: bool,
|
||||
shrink_ratio: AccountShrinkThreshold,
|
||||
) -> Self {
|
||||
let accounts_index = AccountsIndex::new(BINS_DEFAULT);
|
||||
let mut new = if !paths.is_empty() {
|
||||
Self {
|
||||
paths,
|
||||
|
@ -1424,7 +1438,7 @@ impl AccountsDb {
|
|||
account_indexes,
|
||||
caching_enabled,
|
||||
shrink_ratio,
|
||||
..Self::default()
|
||||
..Self::default_with_accounts_index(accounts_index)
|
||||
}
|
||||
} else {
|
||||
// Create a temporary set of accounts directories, used primarily
|
||||
|
@ -1437,7 +1451,7 @@ impl AccountsDb {
|
|||
account_indexes,
|
||||
caching_enabled,
|
||||
shrink_ratio,
|
||||
..Self::default()
|
||||
..Self::default_with_accounts_index(accounts_index)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1466,7 +1480,7 @@ impl AccountsDb {
|
|||
pub fn new_single_for_tests() -> Self {
|
||||
AccountsDb {
|
||||
min_num_stores: 0,
|
||||
..AccountsDb::new(Vec::new(), &ClusterType::Development)
|
||||
..AccountsDb::new_for_tests(Vec::new(), &ClusterType::Development)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -438,7 +438,7 @@ impl ComputeMeter for TransactionComputeMeter {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct BankRc {
|
||||
/// where all the Accounts are stored
|
||||
pub accounts: Arc<Accounts>,
|
||||
|
@ -884,7 +884,7 @@ impl AbiExample for OptionalDropCallback {
|
|||
/// Manager for the state of all accounts and programs after processing its entries.
|
||||
/// AbiExample is needed even without Serialize/Deserialize; actual (de-)serialization
|
||||
/// are implemented elsewhere for versioning
|
||||
#[derive(AbiExample, Debug, Default)]
|
||||
#[derive(AbiExample, Debug)]
|
||||
pub struct Bank {
|
||||
/// References to accounts, parent and signature status
|
||||
pub rc: BankRc,
|
||||
|
@ -1040,6 +1040,12 @@ pub struct Bank {
|
|||
pub freeze_started: AtomicBool,
|
||||
}
|
||||
|
||||
impl Default for Bank {
|
||||
fn default() -> Self {
|
||||
Self::default_with_accounts(Accounts::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BlockhashQueue {
|
||||
fn default() -> Self {
|
||||
Self::new(MAX_RECENT_BLOCKHASHES)
|
||||
|
@ -1109,6 +1115,65 @@ impl Bank {
|
|||
)
|
||||
}
|
||||
|
||||
fn default_with_accounts(accounts: Accounts) -> Self {
|
||||
Self {
|
||||
rc: BankRc::new(accounts, Slot::default()),
|
||||
src: StatusCacheRc::default(),
|
||||
blockhash_queue: RwLock::<BlockhashQueue>::default(),
|
||||
ancestors: Ancestors::default(),
|
||||
hash: RwLock::<Hash>::default(),
|
||||
parent_hash: Hash::default(),
|
||||
parent_slot: Slot::default(),
|
||||
hard_forks: Arc::<RwLock<HardForks>>::default(),
|
||||
transaction_count: AtomicU64::default(),
|
||||
transaction_error_count: AtomicU64::default(),
|
||||
transaction_entries_count: AtomicU64::default(),
|
||||
transactions_per_entry_max: AtomicU64::default(),
|
||||
tick_height: AtomicU64::default(),
|
||||
signature_count: AtomicU64::default(),
|
||||
capitalization: AtomicU64::default(),
|
||||
max_tick_height: u64::default(),
|
||||
hashes_per_tick: Option::<u64>::default(),
|
||||
ticks_per_slot: u64::default(),
|
||||
ns_per_slot: u128::default(),
|
||||
genesis_creation_time: UnixTimestamp::default(),
|
||||
slots_per_year: f64::default(),
|
||||
unused: u64::default(),
|
||||
slot: Slot::default(),
|
||||
bank_id: BankId::default(),
|
||||
epoch: Epoch::default(),
|
||||
block_height: u64::default(),
|
||||
collector_id: Pubkey::default(),
|
||||
collector_fees: AtomicU64::default(),
|
||||
fee_calculator: FeeCalculator::default(),
|
||||
fee_rate_governor: FeeRateGovernor::default(),
|
||||
collected_rent: AtomicU64::default(),
|
||||
rent_collector: RentCollector::default(),
|
||||
epoch_schedule: EpochSchedule::default(),
|
||||
inflation: Arc::<RwLock<Inflation>>::default(),
|
||||
stakes: RwLock::<Stakes>::default(),
|
||||
epoch_stakes: HashMap::<Epoch, EpochStakes>::default(),
|
||||
is_delta: AtomicBool::default(),
|
||||
message_processor: MessageProcessor::default(),
|
||||
compute_budget: Option::<ComputeBudget>::default(),
|
||||
feature_builtins: Arc::<Vec<(Builtin, Pubkey, ActivationType)>>::default(),
|
||||
last_vote_sync: AtomicU64::default(),
|
||||
rewards: RwLock::<Vec<(Pubkey, RewardInfo)>>::default(),
|
||||
cluster_type: Option::<ClusterType>::default(),
|
||||
lazy_rent_collection: AtomicBool::default(),
|
||||
no_stake_rewrite: AtomicBool::default(),
|
||||
rewards_pool_pubkeys: Arc::<HashSet<Pubkey>>::default(),
|
||||
cached_executors: RwLock::<CowCachedExecutors>::default(),
|
||||
transaction_debug_keys: Option::<Arc<HashSet<Pubkey>>>::default(),
|
||||
transaction_log_collector_config: Arc::<RwLock<TransactionLogCollectorConfig>>::default(
|
||||
),
|
||||
transaction_log_collector: Arc::<RwLock<TransactionLogCollector>>::default(),
|
||||
feature_set: Arc::<FeatureSet>::default(),
|
||||
drop_callback: RwLock::<OptionalDropCallback>::default(),
|
||||
freeze_started: AtomicBool::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_paths(
|
||||
genesis_config: &GenesisConfig,
|
||||
paths: Vec<PathBuf>,
|
||||
|
@ -1120,18 +1185,18 @@ impl Bank {
|
|||
shrink_ratio: AccountShrinkThreshold,
|
||||
debug_do_not_add_builtins: bool,
|
||||
) -> Self {
|
||||
let mut bank = Self::default();
|
||||
bank.ancestors = Ancestors::from(vec![bank.slot()]);
|
||||
bank.transaction_debug_keys = debug_keys;
|
||||
bank.cluster_type = Some(genesis_config.cluster_type);
|
||||
|
||||
bank.rc.accounts = Arc::new(Accounts::new_with_config(
|
||||
let accounts = Accounts::new_with_config(
|
||||
paths,
|
||||
&genesis_config.cluster_type,
|
||||
account_indexes,
|
||||
accounts_db_caching_enabled,
|
||||
shrink_ratio,
|
||||
));
|
||||
);
|
||||
let mut bank = Self::default_with_accounts(accounts);
|
||||
bank.ancestors = Ancestors::from(vec![bank.slot()]);
|
||||
bank.transaction_debug_keys = debug_keys;
|
||||
bank.cluster_type = Some(genesis_config.cluster_type);
|
||||
|
||||
bank.process_genesis_config(genesis_config);
|
||||
bank.finish_init(
|
||||
genesis_config,
|
||||
|
|
Loading…
Reference in New Issue