Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fold bank serialisation into serde snapshot #10581

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions core/tests/bank_forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ mod tests {
fn restore_from_snapshot(
old_bank_forks: &BankForks,
old_last_slot: Slot,
old_genesis_config: &GenesisConfig,
account_paths: &[PathBuf],
) {
let (snapshot_path, snapshot_package_output_path) = old_bank_forks
Expand All @@ -134,7 +135,7 @@ mod tests {
&CompressionType::Bzip2,
),
CompressionType::Bzip2,
&GenesisConfig::default(),
old_genesis_config,
)
.unwrap();

Expand Down Expand Up @@ -169,7 +170,6 @@ mod tests {
let mut snapshot_test_config = SnapshotTestConfig::new(snapshot_version, 1);

let bank_forks = &mut snapshot_test_config.bank_forks;
let accounts_dir = &snapshot_test_config.accounts_dir;
let mint_keypair = &snapshot_test_config.genesis_config_info.mint_keypair;

let (s, _r) = channel();
Expand All @@ -185,6 +185,7 @@ mod tests {
bank_forks.set_root(bank.slot(), &sender, None);
}
}

// Generate a snapshot package for last bank
let last_bank = bank_forks.get(last_slot).unwrap();
let snapshot_config = &snapshot_test_config.snapshot_config;
Expand All @@ -203,10 +204,12 @@ mod tests {
snapshot_version,
)
.unwrap();

snapshot_utils::archive_snapshot_package(&snapshot_package).unwrap();

restore_from_snapshot(bank_forks, last_slot, &[accounts_dir.path().to_path_buf()]);
// Restore bank from snapshot
let account_paths = &[snapshot_test_config.accounts_dir.path().to_path_buf()];
let genesis_config = &snapshot_test_config.genesis_config_info.genesis_config;
restore_from_snapshot(bank_forks, last_slot, genesis_config, account_paths);
}

fn run_test_bank_forks_snapshot_n(snapshot_version: SnapshotVersion) {
Expand Down
4 changes: 3 additions & 1 deletion programs/librapay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ pub fn create_genesis<T: Client>(from: &Keypair, client: &T, amount: u64) -> Key

let instruction = librapay_instruction::genesis(&genesis.pubkey(), amount);
let message = Message::new(&[instruction], Some(&from.pubkey()));
client.send_and_confirm_message(&[from, &genesis], message).unwrap();
client
.send_and_confirm_message(&[from, &genesis], message)
.unwrap();

genesis
}
Expand Down
32 changes: 8 additions & 24 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,49 +65,33 @@ pub enum AccountAddressFilter {
}

impl Accounts {
pub(crate) fn new_empty(accounts_db: AccountsDB) -> Self {
pub fn new(paths: Vec<PathBuf>) -> Self {
Self {
accounts_db: Arc::new(accounts_db),
slot: 0,
accounts_db: Arc::new(AccountsDB::new(paths)),
account_locks: Mutex::new(HashSet::new()),
readonly_locks: Arc::new(RwLock::new(Some(HashMap::new()))),
..Self::default()
}
}

pub fn new(paths: Vec<PathBuf>) -> Self {
Self::new_with_frozen_accounts(paths, &HashMap::default(), &[])
}

pub fn new_from_parent(parent: &Accounts, slot: Slot, parent_slot: Slot) -> Self {
let accounts_db = parent.accounts_db.clone();
accounts_db.set_hash(slot, parent_slot);
Accounts {
Self {
slot,
accounts_db,
account_locks: Mutex::new(HashSet::new()),
readonly_locks: Arc::new(RwLock::new(Some(HashMap::new()))),
}
}

pub fn new_with_frozen_accounts(
paths: Vec<PathBuf>,
ancestors: &Ancestors,
frozen_account_pubkeys: &[Pubkey],
) -> Self {
let mut accounts = Accounts {
pub(crate) fn new_empty(accounts_db: AccountsDB) -> Self {
Self {
slot: 0,
accounts_db: Arc::new(AccountsDB::new(paths)),
accounts_db: Arc::new(accounts_db),
account_locks: Mutex::new(HashSet::new()),
readonly_locks: Arc::new(RwLock::new(Some(HashMap::new()))),
};
accounts.freeze_accounts(ancestors, frozen_account_pubkeys);
accounts
}

pub fn freeze_accounts(&mut self, ancestors: &Ancestors, frozen_account_pubkeys: &[Pubkey]) {
Arc::get_mut(&mut self.accounts_db)
.unwrap()
.freeze_accounts(ancestors, frozen_account_pubkeys);
}
}

/// Return true if the slice has any duplicate elements
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ impl AccountsDB {
hashes
}

pub fn freeze_accounts(&mut self, ancestors: &Ancestors, account_pubkeys: &[Pubkey]) {
pub(crate) fn freeze_accounts(&mut self, ancestors: &Ancestors, account_pubkeys: &[Pubkey]) {
for account_pubkey in account_pubkeys {
if let Some((account, _slot)) = self.load_slow(ancestors, &account_pubkey) {
let frozen_account_info = FrozenAccountInfo {
Expand Down Expand Up @@ -1976,7 +1976,7 @@ impl AccountsDB {
}
}

pub fn print_accounts_stats(&self, label: &'static str) {
pub(crate) fn print_accounts_stats(&self, label: &'static str) {
self.print_index(label);
self.print_count_and_status(label);
}
Expand Down
Loading