Speedup rotation (#2468)

Speedup leader to validator transitions
This commit is contained in:
Sagar Dhawan
2019-01-26 13:58:08 +05:30
committed by GitHub
parent 4bb6549895
commit d65e7b9fcc
17 changed files with 712 additions and 548 deletions

View File

@@ -266,6 +266,15 @@ impl AccountsDB {
pub fn transaction_count(&self) -> u64 {
self.transaction_count
}
pub fn checkpoint_and_copy(&mut self) -> AccountsDB {
self.checkpoint();
let (accounts, tx_count) = self.checkpoints.front().unwrap();
let mut copy = AccountsDB::default();
copy.accounts = accounts.clone();
copy.transaction_count = *tx_count;
copy
}
}
impl Accounts {
@@ -399,12 +408,18 @@ impl Accounts {
pub fn depth(&self) -> usize {
self.accounts_db.read().unwrap().depth()
}
pub fn checkpoint_and_copy(&self) -> Accounts {
let db = self.accounts_db.write().unwrap().checkpoint_and_copy();
let mut copy = Accounts::default();
copy.accounts_db = RwLock::new(db);
copy
}
}
impl Checkpoint for AccountsDB {
fn checkpoint(&mut self) {
let mut accounts = HashMap::new();
std::mem::swap(&mut self.accounts, &mut accounts);
let accounts = self.accounts.clone();
self.checkpoints
.push_front((accounts, self.transaction_count()));