From fb9b069b3e8be0a512d1d4fcb843e35ec8b5e3f8 Mon Sep 17 00:00:00 2001 From: Rob Walker Date: Mon, 25 Feb 2019 19:39:08 -0800 Subject: [PATCH] merge_parents() => squash() --- runtime/src/accounts.rs | 14 +++++++------- runtime/src/bank.rs | 19 ++++++++----------- runtime/src/status_cache.rs | 17 +++++++++-------- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index f751ed0c1ab127..85ec79cc6ab929 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -257,7 +257,7 @@ impl AccountsDB { } /// become the root accountsDB - fn merge_parents(&mut self, parents: &[U]) + fn squash(&mut self, parents: &[U]) where U: Deref, { @@ -407,8 +407,8 @@ impl Accounts { } /// accounts starts with an empty data structure for every child/fork - /// this merges all the parents/checkpoints - pub fn merge_parents(&self, parents: &[U]) + /// this function squashes all the parents into this instance + pub fn squash(&self, parents: &[U]) where U: Deref, { @@ -419,7 +419,7 @@ impl Accounts { .map(|obj| obj.accounts_db.read().unwrap()) .collect(); - self.accounts_db.write().unwrap().merge_parents(&dbs); + self.accounts_db.write().unwrap().squash(&dbs); } } @@ -832,7 +832,7 @@ mod tests { } #[test] - fn test_accounts_merge_parents() { + fn test_accounts_squash() { let mut db0 = AccountsDB::default(); let key = Pubkey::default(); let account = Account::new(1, 0, key); @@ -844,8 +844,8 @@ mod tests { let mut db1 = AccountsDB::default(); db1.store(false, &key, &Account::new(0, 0, key)); - // merge, which should whack key's account - db1.merge_parents(&[&db0]); + // squash, which should whack key's account + db1.squash(&[&db0]); assert_eq!(AccountsDB::load(&[&db1], &key), None); } diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 468863728231c3..a1aa5f5afaa026 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -163,25 +163,22 @@ impl Bank { } } - /// merge (i.e. pull) the parent's state up into this Bank, + /// squash the parent's state up into this Bank, /// this Bank becomes a root - pub fn merge_parents(&self) { + pub fn squash(&self) { self.freeze(); let parents = self.parents(); *self.parent.write().unwrap() = None; let parent_accounts: Vec<_> = parents.iter().map(|b| &b.accounts).collect(); - self.accounts.merge_parents(&parent_accounts); + self.accounts.squash(&parent_accounts); let parent_caches: Vec<_> = parents .iter() .map(|b| b.status_cache.read().unwrap()) .collect(); - self.status_cache - .write() - .unwrap() - .merge_parents(&parent_caches); + self.status_cache.write().unwrap().squash(&parent_caches); } /// Return the more recent checkpoint of this bank instance. @@ -1472,7 +1469,7 @@ mod tests { } #[test] - fn test_bank_hash_internal_state_merge_parents() { + fn test_bank_hash_internal_state_squash() { let bank0 = Arc::new(Bank::new(&GenesisBlock::new(10).0)); let bank1 = Bank::new_from_parent_and_id(&bank0, 1); @@ -1480,7 +1477,7 @@ mod tests { assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state()); // remove parent - bank1.merge_parents(); + bank1.squash(); assert!(bank1.parents().is_empty()); // hash should still match @@ -1489,7 +1486,7 @@ mod tests { /// Verifies that last ids and accounts are correctly referenced from parent #[test] - fn test_bank_merge_parents() { + fn test_bank_squash() { let (genesis_block, mint_keypair) = GenesisBlock::new(2); let key1 = Keypair::new(); let key2 = Keypair::new(); @@ -1526,7 +1523,7 @@ mod tests { ); // works iteration 0, no-ops on iteration 1 and 2 - bank.merge_parents(); + bank.squash(); } } diff --git a/runtime/src/status_cache.rs b/runtime/src/status_cache.rs index fe49f4132eefa1..c0d97aafd7a90b 100644 --- a/runtime/src/status_cache.rs +++ b/runtime/src/status_cache.rs @@ -84,8 +84,9 @@ impl StatusCache { self.get_signature_status_merged(sig) } - fn merge_parent_is_full(&mut self, parent: &Self) -> bool { - // flatten the parent and their merges into self.merges, limit + fn squash_parent_is_full(&mut self, parent: &Self) -> bool { + // flatten and squash the parent and its merges into self.merges, + // returns true if self is full self.merges.push_back(StatusCache { signatures: parent.signatures.clone(), @@ -106,12 +107,12 @@ impl StatusCache { /// copy the parents and parents' merges up to this instance, up to /// MAX_CACHE_ENTRIES deep - pub fn merge_parents(&mut self, parents: &[U]) + pub fn squash(&mut self, parents: &[U]) where U: Deref, { for parent in parents { - if self.merge_parent_is_full(parent) { + if self.squash_parent_is_full(parent) { break; } } @@ -233,7 +234,7 @@ mod tests { } #[test] - fn test_status_cache_merge_parents_has_signature() { + fn test_status_cache_squash_has_signature() { let sig = Signature::default(); let last_id = hash(Hash::default().as_ref()); let mut first = BankStatusCache::new(&last_id); @@ -247,7 +248,7 @@ mod tests { let last_id = hash(last_id.as_ref()); let mut second = BankStatusCache::new(&last_id); - second.merge_parents(&[&first]); + second.squash(&[&first]); assert_eq!(second.get_signature_status(&sig), Some(Ok(()))); assert!(second.has_signature(&sig)); @@ -255,7 +256,7 @@ mod tests { #[test] #[ignore] // takes a lot of time or RAM or both.. - fn test_status_cache_merge_parents_overflow() { + fn test_status_cache_squash_overflow() { let mut last_id = hash(Hash::default().as_ref()); let mut cache = BankStatusCache::new(&last_id); @@ -281,7 +282,7 @@ mod tests { assert!(root.has_signature(&sig)); // will overflow - cache.merge_parents(&parents_refs); + cache.squash(&parents_refs); assert_eq!(cache.get_signature_status(&sig), None); assert!(!cache.has_signature(&sig));