Rebase and panic with no accounts
Add Accounts::has_accounts function for hash_internal_state calculation.
This commit is contained in:
parent
c276375a0e
commit
180d297df8
|
@ -1,4 +1,5 @@
|
||||||
use crate::appendvec::AppendVec;
|
use crate::appendvec::AppendVec;
|
||||||
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use crate::bank::{BankError, Result};
|
use crate::bank::{BankError, Result};
|
||||||
use crate::runtime::has_duplicates;
|
use crate::runtime::has_duplicates;
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
|
@ -66,7 +67,7 @@ pub struct ErrorCounters {
|
||||||
|
|
||||||
const ACCOUNT_DATA_FILE_SIZE: u64 = 64 * 1024 * 1024;
|
const ACCOUNT_DATA_FILE_SIZE: u64 = 64 * 1024 * 1024;
|
||||||
const ACCOUNT_DATA_FILE: &str = "data";
|
const ACCOUNT_DATA_FILE: &str = "data";
|
||||||
const NUM_ACCOUNT_DIRS: usize = 4;
|
const NUM_ACCOUNT_DIRS: usize = 1;
|
||||||
|
|
||||||
/// An offset into the AccountsDB::storage vector
|
/// An offset into the AccountsDB::storage vector
|
||||||
type AppendVecId = usize;
|
type AppendVecId = usize;
|
||||||
|
@ -185,7 +186,8 @@ impl AccountsDB {
|
||||||
let paths: Vec<String> = paths.split(',').map(|s| s.to_string()).collect();
|
let paths: Vec<String> = paths.split(',').map(|s| s.to_string()).collect();
|
||||||
let mut stores: Vec<AccountStorage> = vec![];
|
let mut stores: Vec<AccountStorage> = vec![];
|
||||||
paths.iter().for_each(|p| {
|
paths.iter().for_each(|p| {
|
||||||
let path = format!("{}/{}", p, std::process::id());
|
let keypair = Keypair::new();
|
||||||
|
let path = format!("{}/{}", p, keypair.pubkey());
|
||||||
let storage = AccountStorage {
|
let storage = AccountStorage {
|
||||||
appendvec: self.new_account_storage(&path),
|
appendvec: self.new_account_storage(&path),
|
||||||
status: AtomicUsize::new(AccountStorageStatus::StorageAvailable as usize),
|
status: AtomicUsize::new(AccountStorageStatus::StorageAvailable as usize),
|
||||||
|
@ -242,6 +244,19 @@ impl AccountsDB {
|
||||||
accounts
|
accounts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_accounts(&self, fork: Fork) -> bool {
|
||||||
|
let index = self.index_info.index.read().unwrap();
|
||||||
|
|
||||||
|
for account_map in index.values() {
|
||||||
|
for (v_fork, _) in account_map.0.iter() {
|
||||||
|
if fork == *v_fork {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
pub fn hash_internal_state(&self, fork: Fork) -> Option<Hash> {
|
pub fn hash_internal_state(&self, fork: Fork) -> Option<Hash> {
|
||||||
let mut ordered_accounts = BTreeMap::new();
|
let mut ordered_accounts = BTreeMap::new();
|
||||||
let rindex = self.index_info.index.read().unwrap();
|
let rindex = self.index_info.index.read().unwrap();
|
||||||
|
@ -414,6 +429,7 @@ impl AccountsDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn store_accounts(
|
pub fn store_accounts(
|
||||||
&self,
|
&self,
|
||||||
fork: Fork,
|
fork: Fork,
|
||||||
|
@ -587,19 +603,26 @@ impl AccountsDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Accounts {
|
impl Accounts {
|
||||||
pub fn new(in_paths: &str) -> Self {
|
fn make_new_dir() -> String {
|
||||||
static ACCOUNT_DIR: AtomicUsize = AtomicUsize::new(0);
|
static ACCOUNT_DIR: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
let dir = ACCOUNT_DIR.fetch_add(1, Ordering::Relaxed);
|
||||||
|
format!("accountsdb/{}", dir.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_default_paths() -> String {
|
||||||
|
let mut paths = Self::make_new_dir();
|
||||||
|
for _ in 1..NUM_ACCOUNT_DIRS {
|
||||||
|
paths.push_str(",");
|
||||||
|
paths.push_str(&Self::make_new_dir());
|
||||||
|
}
|
||||||
|
paths
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(in_paths: &str) -> Self {
|
||||||
let paths = if !in_paths.is_empty() {
|
let paths = if !in_paths.is_empty() {
|
||||||
in_paths.to_string()
|
in_paths.to_string()
|
||||||
} else {
|
} else {
|
||||||
let mut dir: usize;
|
Self::make_default_paths()
|
||||||
dir = ACCOUNT_DIR.fetch_add(1, Ordering::Relaxed);
|
|
||||||
let mut paths = dir.to_string();
|
|
||||||
for _ in 1..NUM_ACCOUNT_DIRS {
|
|
||||||
dir = ACCOUNT_DIR.fetch_add(1, Ordering::Relaxed);
|
|
||||||
paths = format!("{},{}", paths, dir.to_string());
|
|
||||||
}
|
|
||||||
paths
|
|
||||||
};
|
};
|
||||||
let accounts_db = AccountsDB::default();
|
let accounts_db = AccountsDB::default();
|
||||||
accounts_db.add_storage(&paths);
|
accounts_db.add_storage(&paths);
|
||||||
|
@ -683,6 +706,10 @@ impl Accounts {
|
||||||
.for_each(|(tx, result)| Self::unlock_account(tx, result, &mut account_locks));
|
.for_each(|(tx, result)| Self::unlock_account(tx, result, &mut account_locks));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_accounts(&self, fork: Fork) -> bool {
|
||||||
|
self.accounts_db.has_accounts(fork)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_accounts(
|
pub fn load_accounts(
|
||||||
&self,
|
&self,
|
||||||
fork: Fork,
|
fork: Fork,
|
||||||
|
@ -734,10 +761,6 @@ impl Accounts {
|
||||||
self.accounts_db.write().unwrap().squash(&dbs);
|
self.accounts_db.write().unwrap().squash(&dbs);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_accounts(&self, fork: Fork) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -644,7 +644,7 @@ impl Bank {
|
||||||
if let Some(accounts) = &self.accounts {
|
if let Some(accounts) = &self.accounts {
|
||||||
accounts.clone()
|
accounts.clone()
|
||||||
} else {
|
} else {
|
||||||
Arc::new(Accounts::new(""))
|
panic!("no accounts!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,13 +107,14 @@ pub struct BankForksInfo {
|
||||||
pub fn process_blocktree(
|
pub fn process_blocktree(
|
||||||
genesis_block: &GenesisBlock,
|
genesis_block: &GenesisBlock,
|
||||||
blocktree: &Blocktree,
|
blocktree: &Blocktree,
|
||||||
|
account_paths: &str,
|
||||||
) -> Result<(BankForks, Vec<BankForksInfo>)> {
|
) -> Result<(BankForks, Vec<BankForksInfo>)> {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
info!("processing ledger...");
|
info!("processing ledger...");
|
||||||
|
|
||||||
// Setup bank for slot 0
|
// Setup bank for slot 0
|
||||||
let (mut bank_forks, mut pending_slots) = {
|
let (mut bank_forks, mut pending_slots) = {
|
||||||
let bank0 = Bank::new(&genesis_block);
|
let bank0 = Bank::new_with_paths(&genesis_block, account_paths);
|
||||||
let slot = 0;
|
let slot = 0;
|
||||||
let entry_height = 0;
|
let entry_height = 0;
|
||||||
let last_entry_id = bank0.last_id();
|
let last_entry_id = bank0.last_id();
|
||||||
|
@ -297,7 +298,7 @@ mod tests {
|
||||||
fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 2, 1, last_id);
|
fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 2, 1, last_id);
|
||||||
|
|
||||||
let (mut _bank_forks, bank_forks_info) =
|
let (mut _bank_forks, bank_forks_info) =
|
||||||
process_blocktree(&genesis_block, &blocktree).unwrap();
|
process_blocktree(&genesis_block, &blocktree, "").unwrap();
|
||||||
|
|
||||||
assert_eq!(bank_forks_info.len(), 1);
|
assert_eq!(bank_forks_info.len(), 1);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -356,7 +357,7 @@ mod tests {
|
||||||
info!("last_fork2_entry_id: {:?}", last_fork2_entry_id);
|
info!("last_fork2_entry_id: {:?}", last_fork2_entry_id);
|
||||||
|
|
||||||
let (mut bank_forks, bank_forks_info) =
|
let (mut bank_forks, bank_forks_info) =
|
||||||
process_blocktree(&genesis_block, &blocktree).unwrap();
|
process_blocktree(&genesis_block, &blocktree, "").unwrap();
|
||||||
|
|
||||||
assert_eq!(bank_forks_info.len(), 2); // There are two forks
|
assert_eq!(bank_forks_info.len(), 2); // There are two forks
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -474,7 +475,7 @@ mod tests {
|
||||||
Blocktree::open(&ledger_path).expect("Expected to successfully open database ledger");
|
Blocktree::open(&ledger_path).expect("Expected to successfully open database ledger");
|
||||||
blocktree.write_entries(1, 0, 0, &entries).unwrap();
|
blocktree.write_entries(1, 0, 0, &entries).unwrap();
|
||||||
let entry_height = genesis_block.ticks_per_slot + entries.len() as u64;
|
let entry_height = genesis_block.ticks_per_slot + entries.len() as u64;
|
||||||
let (bank_forks, bank_forks_info) = process_blocktree(&genesis_block, &blocktree).unwrap();
|
let (bank_forks, bank_forks_info) = process_blocktree(&genesis_block, &blocktree, "").unwrap();
|
||||||
|
|
||||||
assert_eq!(bank_forks_info.len(), 1);
|
assert_eq!(bank_forks_info.len(), 1);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -85,7 +85,7 @@ impl Default for FullnodeConfig {
|
||||||
blockstream: None,
|
blockstream: None,
|
||||||
storage_rotate_count: NUM_HASHES_FOR_STORAGE_ROTATE,
|
storage_rotate_count: NUM_HASHES_FOR_STORAGE_ROTATE,
|
||||||
tick_config: PohServiceConfig::default(),
|
tick_config: PohServiceConfig::default(),
|
||||||
account_paths: "0,1,2,3".to_string(),
|
account_paths: "".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,7 @@ pub fn new_banks_from_blocktree(
|
||||||
.expect("Expected to successfully open database ledger");
|
.expect("Expected to successfully open database ledger");
|
||||||
|
|
||||||
let (bank_forks, bank_forks_info) =
|
let (bank_forks, bank_forks_info) =
|
||||||
blocktree_processor::process_blocktree(&genesis_block, &blocktree)
|
blocktree_processor::process_blocktree(&genesis_block, &blocktree, account_paths)
|
||||||
.expect("process_blocktree failed");
|
.expect("process_blocktree failed");
|
||||||
|
|
||||||
(
|
(
|
||||||
|
|
|
@ -139,7 +139,7 @@ impl Replicator {
|
||||||
GenesisBlock::load(ledger_path).expect("Expected to successfully open genesis block");
|
GenesisBlock::load(ledger_path).expect("Expected to successfully open genesis block");
|
||||||
|
|
||||||
let (bank_forks, _bank_forks_info) =
|
let (bank_forks, _bank_forks_info) =
|
||||||
blocktree_processor::process_blocktree(&genesis_block, &blocktree)
|
blocktree_processor::process_blocktree(&genesis_block, &blocktree, "")
|
||||||
.expect("process_blocktree failed");
|
.expect("process_blocktree failed");
|
||||||
|
|
||||||
let blocktree = Arc::new(blocktree);
|
let blocktree = Arc::new(blocktree);
|
||||||
|
|
Loading…
Reference in New Issue