Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Checkpointing implementation #2793

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 4 additions & 3 deletions benches/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ fn bench_process_transaction(bencher: &mut Bencher) {

let mut id = bank.last_id();

for _ in 0..(MAX_ENTRY_IDS - 1) {
// TPU rejects ids that are to close to the last
for _ in 0..MAX_ENTRY_IDS / 2 - 1 {
id = hash(&id.as_ref());
bank.register_tick(&id);
id = hash(&id.as_ref())
}

bencher.iter(|| {
// Since benchmarker runs this multiple times, we need to clear the signatures.
bank.clear_signatures();
let results = bank.process_transactions(&transactions);
assert!(results.iter().all(Result::is_ok));
results.iter().for_each(|r| assert_eq!(Ok(()), *r));
})
}
4 changes: 2 additions & 2 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn main() {
}
("verify", _) => {
let bank = Bank::new(&genesis_block);
let mut last_id = bank.last_id();
let mut last_id = bank.active_fork().last_id();
let mut num_entries = 0;
for (i, entry) in entries.enumerate() {
if i >= head {
Expand All @@ -129,7 +129,7 @@ fn main() {
last_id = entry.id;
num_entries += 1;

if let Err(e) = bank.process_entry(&entry) {
if let Err(e) = bank.active_fork().process_entries(&[entry]) {
eprintln!("verify failed at entry[{}], err: {:?}", i + 2, e);
if !matches.is_present("continue") {
exit(1);
Expand Down
32 changes: 16 additions & 16 deletions src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ impl AccountsDB {
hash(&serialize(&ordered_accounts).unwrap())
}

fn load<U>(checkpoints: &[U], pubkey: &Pubkey) -> Option<Account>
fn load<U>(deltas: &[U], pubkey: &Pubkey) -> Option<Account>
where
U: Deref<Target = Self>,
{
for db in checkpoints {
for db in deltas {
if let Some(account) = db.accounts.get(pubkey) {
return Some(account.clone());
}
Expand All @@ -96,7 +96,7 @@ impl AccountsDB {
pub fn store(&mut self, purge: bool, pubkey: &Pubkey, account: &Account) {
if account.tokens == 0 {
if purge {
// purge if balance is 0 and no checkpoints
// purge if balance is 0 and no deltas
self.accounts.remove(pubkey);
} else {
// store default account if balance is 0 and there's a checkpoint
Expand Down Expand Up @@ -127,7 +127,7 @@ impl AccountsDB {
}
}
fn load_tx_accounts<U>(
checkpoints: &[U],
deltas: &[U],
tx: &Transaction,
error_counters: &mut ErrorCounters,
) -> Result<Vec<Account>>
Expand All @@ -148,7 +148,7 @@ impl AccountsDB {
// If a fee can pay for execution then the program will be scheduled
let mut called_accounts: Vec<Account> = vec![];
for key in &tx.account_keys {
called_accounts.push(Self::load(checkpoints, key).unwrap_or_default());
called_accounts.push(Self::load(deltas, key).unwrap_or_default());
}
if called_accounts.is_empty() || called_accounts[0].tokens == 0 {
error_counters.account_not_found += 1;
Expand All @@ -164,7 +164,7 @@ impl AccountsDB {
}

fn load_executable_accounts<U>(
checkpoints: &[U],
deltas: &[U],
mut program_id: Pubkey,
error_counters: &mut ErrorCounters,
) -> Result<Vec<(Pubkey, Account)>>
Expand All @@ -185,7 +185,7 @@ impl AccountsDB {
}
depth += 1;

let program = match Self::load(checkpoints, &program_id) {
let program = match Self::load(deltas, &program_id) {
Some(program) => program,
None => {
error_counters.account_not_found += 1;
Expand All @@ -207,7 +207,7 @@ impl AccountsDB {

/// For each program_id in the transaction, load its loaders.
fn load_loaders<U>(
checkpoints: &[U],
deltas: &[U],
tx: &Transaction,
error_counters: &mut ErrorCounters,
) -> Result<Vec<Vec<(Pubkey, Account)>>>
Expand All @@ -222,13 +222,13 @@ impl AccountsDB {
return Err(BankError::AccountNotFound);
}
let program_id = tx.program_ids[ix.program_ids_index as usize];
Self::load_executable_accounts(checkpoints, program_id, error_counters)
Self::load_executable_accounts(deltas, program_id, error_counters)
})
.collect()
}

fn load_accounts<U>(
checkpoints: &[U],
deltas: &[U],
txs: &[Transaction],
lock_results: Vec<Result<()>>,
error_counters: &mut ErrorCounters,
Expand All @@ -240,8 +240,8 @@ impl AccountsDB {
.zip(lock_results.into_iter())
.map(|etx| match etx {
(tx, Ok(())) => {
let accounts = Self::load_tx_accounts(checkpoints, tx, error_counters)?;
let loaders = Self::load_loaders(checkpoints, tx, error_counters)?;
let accounts = Self::load_tx_accounts(deltas, tx, error_counters)?;
let loaders = Self::load_loaders(deltas, tx, error_counters)?;
Ok((accounts, loaders))
}
(_, Err(e)) => Err(e),
Expand All @@ -267,11 +267,11 @@ impl AccountsDB {

impl Accounts {
/// Slow because lock is held for 1 operation insted of many
pub fn load_slow<U>(checkpoints: &[U], pubkey: &Pubkey) -> Option<Account>
pub fn load_slow<U>(deltas: &[U], pubkey: &Pubkey) -> Option<Account>
where
U: Deref<Target = Self>,
{
let dbs: Vec<_> = checkpoints
let dbs: Vec<_> = deltas
.iter()
.map(|obj| obj.accounts_db.read().unwrap())
.collect();
Expand Down Expand Up @@ -349,15 +349,15 @@ impl Accounts {
}

pub fn load_accounts<U>(
checkpoints: &[U],
deltas: &[U],
txs: &[Transaction],
results: Vec<Result<()>>,
error_counters: &mut ErrorCounters,
) -> Vec<Result<(InstructionAccounts, InstructionLoaders)>>
where
U: Deref<Target = Self>,
{
let dbs: Vec<_> = checkpoints
let dbs: Vec<_> = deltas
.iter()
.map(|obj| obj.accounts_db.read().unwrap())
.collect();
Expand Down
Loading