Set BankRc slot correctly when restoring a bank snapshot
This commit is contained in:
@ -4,7 +4,10 @@ use bzip2::bufread::BzDecoder;
|
|||||||
use fs_extra::dir::CopyOptions;
|
use fs_extra::dir::CopyOptions;
|
||||||
use log::*;
|
use log::*;
|
||||||
use solana_measure::measure::Measure;
|
use solana_measure::measure::Measure;
|
||||||
use solana_runtime::{bank::Bank, status_cache::SlotDelta};
|
use solana_runtime::{
|
||||||
|
bank::{self, Bank},
|
||||||
|
status_cache::SlotDelta,
|
||||||
|
};
|
||||||
use solana_sdk::{clock::Slot, transaction};
|
use solana_sdk::{clock::Slot, transaction};
|
||||||
use std::{
|
use std::{
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
@ -266,7 +269,7 @@ pub fn untar_snapshot_in<P: AsRef<Path>, Q: AsRef<Path>>(
|
|||||||
|
|
||||||
fn rebuild_bank_from_snapshots<P>(
|
fn rebuild_bank_from_snapshots<P>(
|
||||||
snapshot_version: &str,
|
snapshot_version: &str,
|
||||||
local_account_paths: &[PathBuf],
|
account_paths: &[PathBuf],
|
||||||
unpacked_snapshots_dir: &PathBuf,
|
unpacked_snapshots_dir: &PathBuf,
|
||||||
append_vecs_path: P,
|
append_vecs_path: P,
|
||||||
) -> Result<Bank>
|
) -> Result<Bank>
|
||||||
@ -287,7 +290,7 @@ where
|
|||||||
info!("Loading bank from {:?}", &root_paths.snapshot_file_path);
|
info!("Loading bank from {:?}", &root_paths.snapshot_file_path);
|
||||||
let file = File::open(&root_paths.snapshot_file_path)?;
|
let file = File::open(&root_paths.snapshot_file_path)?;
|
||||||
let mut stream = BufReader::new(file);
|
let mut stream = BufReader::new(file);
|
||||||
let bank: Bank = match snapshot_version {
|
let mut bank: Bank = match snapshot_version {
|
||||||
env!("CARGO_PKG_VERSION") => deserialize_from(&mut stream)?,
|
env!("CARGO_PKG_VERSION") => deserialize_from(&mut stream)?,
|
||||||
"v0.22.3" => {
|
"v0.22.3" => {
|
||||||
let bank0223: solana_runtime::bank::LegacyBank0223 = deserialize_from(&mut stream)?;
|
let bank0223: solana_runtime::bank::LegacyBank0223 = deserialize_from(&mut stream)?;
|
||||||
@ -302,8 +305,12 @@ where
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Rebuild accounts
|
// Rebuild accounts
|
||||||
|
bank.set_bank_rc(
|
||||||
|
bank::BankRc::new(account_paths.to_vec(), 0, bank.slot()),
|
||||||
|
bank::StatusCacheRc::default(),
|
||||||
|
);
|
||||||
bank.rc
|
bank.rc
|
||||||
.accounts_from_stream(&mut stream, local_account_paths, append_vecs_path)?;
|
.accounts_from_stream(&mut stream, account_paths, append_vecs_path)?;
|
||||||
|
|
||||||
// Rebuild status cache
|
// Rebuild status cache
|
||||||
let status_cache_path = unpacked_snapshots_dir.join(SNAPSHOT_STATUS_CACHE_FILE_NAME);
|
let status_cache_path = unpacked_snapshots_dir.join(SNAPSHOT_STATUS_CACHE_FILE_NAME);
|
||||||
|
@ -347,7 +347,12 @@ impl<'a> Serialize for AccountsDBSerialize<'a> {
|
|||||||
let bank_hashes = self.accounts_db.bank_hashes.read().unwrap();
|
let bank_hashes = self.accounts_db.bank_hashes.read().unwrap();
|
||||||
serialize_into(
|
serialize_into(
|
||||||
&mut wr,
|
&mut wr,
|
||||||
&(self.slot, &*bank_hashes.get(&self.slot).unwrap()),
|
&(
|
||||||
|
self.slot,
|
||||||
|
&*bank_hashes
|
||||||
|
.get(&self.slot)
|
||||||
|
.unwrap_or_else(|| panic!("No bank_hashes entry for slot {}", self.slot)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.map_err(Error::custom)?;
|
.map_err(Error::custom)?;
|
||||||
let len = wr.position() as usize;
|
let len = wr.position() as usize;
|
||||||
|
@ -452,22 +452,6 @@ impl Bank {
|
|||||||
&self.collector_id
|
&self.collector_id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_with_genesis(
|
|
||||||
genesis_config: &GenesisConfig,
|
|
||||||
account_paths: Vec<PathBuf>,
|
|
||||||
status_cache_rc: &StatusCacheRc,
|
|
||||||
id: AppendVecId,
|
|
||||||
) -> Self {
|
|
||||||
let mut bank = Self::default();
|
|
||||||
bank.set_bank_rc(
|
|
||||||
&BankRc::new(account_paths, id, bank.slot()),
|
|
||||||
&status_cache_rc,
|
|
||||||
);
|
|
||||||
bank.process_genesis_config(genesis_config);
|
|
||||||
bank.ancestors.insert(0, 0);
|
|
||||||
bank
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn slot(&self) -> Slot {
|
pub fn slot(&self) -> Slot {
|
||||||
self.slot
|
self.slot
|
||||||
}
|
}
|
||||||
@ -1543,9 +1527,9 @@ impl Bank {
|
|||||||
self.rc.accounts.clone()
|
self.rc.accounts.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_bank_rc(&mut self, bank_rc: &BankRc, status_cache_rc: &StatusCacheRc) {
|
pub fn set_bank_rc(&mut self, bank_rc: BankRc, status_cache_rc: StatusCacheRc) {
|
||||||
self.rc.accounts = bank_rc.accounts.clone();
|
self.rc = bank_rc;
|
||||||
self.src.status_cache = status_cache_rc.status_cache.clone()
|
self.src = status_cache_rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_parent(&mut self, parent: &Arc<Bank>) {
|
pub fn set_parent(&mut self, parent: &Arc<Bank>) {
|
||||||
@ -4460,7 +4444,7 @@ mod tests {
|
|||||||
let (_accounts_dir, dbank_paths) = get_temp_accounts_paths(4).unwrap();
|
let (_accounts_dir, dbank_paths) = get_temp_accounts_paths(4).unwrap();
|
||||||
let ref_sc = StatusCacheRc::default();
|
let ref_sc = StatusCacheRc::default();
|
||||||
ref_sc.status_cache.write().unwrap().add_root(2);
|
ref_sc.status_cache.write().unwrap().add_root(2);
|
||||||
dbank.set_bank_rc(&BankRc::new(dbank_paths.clone(), 0, dbank.slot()), &ref_sc);
|
dbank.set_bank_rc(BankRc::new(dbank_paths.clone(), 0, dbank.slot()), ref_sc);
|
||||||
// Create a directory to simulate AppendVecs unpackaged from a snapshot tar
|
// Create a directory to simulate AppendVecs unpackaged from a snapshot tar
|
||||||
let copied_accounts = TempDir::new().unwrap();
|
let copied_accounts = TempDir::new().unwrap();
|
||||||
copy_append_vecs(&bank2.rc.accounts.accounts_db, copied_accounts.path()).unwrap();
|
copy_append_vecs(&bank2.rc.accounts.accounts_db, copied_accounts.path()).unwrap();
|
||||||
|
Reference in New Issue
Block a user