Purge remaining last_id (now called block_hash)

This commit is contained in:
Michael Vines
2019-03-02 10:09:09 -08:00
committed by Greg Fitzgerald
parent 2bfad87a5f
commit 258cf21416
39 changed files with 369 additions and 369 deletions

View File

@ -27,9 +27,9 @@ pub struct ErrorCounters {
pub account_not_found: usize,
pub account_in_use: usize,
pub account_loaded_twice: usize,
pub last_id_not_found: usize,
pub last_id_too_old: usize,
pub reserve_last_id: usize,
pub block_hash_not_found: usize,
pub block_hash_too_old: usize,
pub reserve_block_hash: usize,
pub insufficient_funds: usize,
pub duplicate_signature: usize,
pub call_chain_too_deep: usize,

View File

@ -426,7 +426,7 @@ impl Bank {
.zip(lock_results.into_iter())
.map(|(tx, lock_res)| {
if lock_res.is_ok() && !hash_queue.check_entry_age(tx.recent_block_hash, max_age) {
error_counters.reserve_last_id += 1;
error_counters.reserve_block_hash += 1;
Err(BankError::BlockHashNotFound)
} else {
lock_res
@ -523,16 +523,16 @@ impl Bank {
.increment_transaction_count(self.accounts_id, tx_count);
inc_new_counter_info!("bank-process_transactions-txs", tx_count);
if 0 != error_counters.last_id_not_found {
if 0 != error_counters.block_hash_not_found {
inc_new_counter_info!(
"bank-process_transactions-error-last_id_not_found",
error_counters.last_id_not_found
"bank-process_transactions-error-block_hash_not_found",
error_counters.block_hash_not_found
);
}
if 0 != error_counters.reserve_last_id {
if 0 != error_counters.reserve_block_hash {
inc_new_counter_info!(
"bank-process_transactions-error-reserve_last_id",
error_counters.reserve_last_id
"bank-process_transactions-error-reserve_block_hash",
error_counters.reserve_block_hash
);
}
if 0 != error_counters.duplicate_signature {
@ -633,15 +633,15 @@ impl Bank {
}
/// Create, sign, and process a Transaction from `keypair` to `to` of
/// `n` tokens where `last_id` is the last Entry ID observed by the client.
/// `n` tokens where `block_hash` is the last Entry ID observed by the client.
pub fn transfer(
&self,
n: u64,
keypair: &Keypair,
to: Pubkey,
last_id: Hash,
block_hash: Hash,
) -> Result<Signature> {
let tx = SystemTransaction::new_account(keypair, to, n, last_id, 0);
let tx = SystemTransaction::new_account(keypair, to, n, block_hash, 0);
let signature = tx.signatures[0];
self.process_transaction(&tx).map(|_| signature)
}

View File

@ -31,8 +31,8 @@ impl<T: Clone> Default for StatusCache<T> {
}
impl<T: Clone> StatusCache<T> {
pub fn new(last_id: &Hash) -> Self {
let keys = (0..27).map(|i| last_id.hash_at_index(i)).collect();
pub fn new(block_hash: &Hash) -> Self {
let keys = (0..27).map(|i| block_hash.hash_at_index(i)).collect();
Self {
signatures: Bloom::new(38_340_234, keys),
failures: HashMap::new(),
@ -118,8 +118,8 @@ impl<T: Clone> StatusCache<T> {
}
/// Crate a new cache, pushing the old cache into the merged queue
pub fn new_cache(&mut self, last_id: &Hash) {
let mut old = Self::new(last_id);
pub fn new_cache(&mut self, block_hash: &Hash) {
let mut old = Self::new(block_hash);
std::mem::swap(&mut old.signatures, &mut self.signatures);
std::mem::swap(&mut old.failures, &mut self.failures);
assert!(old.merges.is_empty());
@ -175,8 +175,8 @@ mod tests {
#[test]
fn test_has_signature() {
let sig = Signature::default();
let last_id = hash(Hash::default().as_ref());
let mut status_cache = BankStatusCache::new(&last_id);
let block_hash = hash(Hash::default().as_ref());
let mut status_cache = BankStatusCache::new(&block_hash);
assert_eq!(status_cache.has_signature(&sig), false);
assert_eq!(status_cache.get_signature_status(&sig), None);
status_cache.add(&sig);
@ -187,12 +187,12 @@ mod tests {
#[test]
fn test_has_signature_checkpoint() {
let sig = Signature::default();
let last_id = hash(Hash::default().as_ref());
let mut first = BankStatusCache::new(&last_id);
let block_hash = hash(Hash::default().as_ref());
let mut first = BankStatusCache::new(&block_hash);
first.add(&sig);
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
let last_id = hash(last_id.as_ref());
let second = StatusCache::new(&last_id);
let block_hash = hash(block_hash.as_ref());
let second = StatusCache::new(&block_hash);
let checkpoints = [&second, &first];
assert_eq!(
BankStatusCache::get_signature_status_all(&checkpoints, &sig),
@ -204,12 +204,12 @@ mod tests {
#[test]
fn test_new_cache() {
let sig = Signature::default();
let last_id = hash(Hash::default().as_ref());
let mut first = BankStatusCache::new(&last_id);
let block_hash = hash(Hash::default().as_ref());
let mut first = BankStatusCache::new(&block_hash);
first.add(&sig);
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
let last_id = hash(last_id.as_ref());
first.new_cache(&last_id);
let block_hash = hash(block_hash.as_ref());
first.new_cache(&block_hash);
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
assert!(first.has_signature(&sig));
first.clear();
@ -220,13 +220,13 @@ mod tests {
#[test]
fn test_new_cache_full() {
let sig = Signature::default();
let last_id = hash(Hash::default().as_ref());
let mut first = BankStatusCache::new(&last_id);
let block_hash = hash(Hash::default().as_ref());
let mut first = BankStatusCache::new(&block_hash);
first.add(&sig);
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
for _ in 0..(MAX_CACHE_ENTRIES + 1) {
let last_id = hash(last_id.as_ref());
first.new_cache(&last_id);
let block_hash = hash(block_hash.as_ref());
first.new_cache(&block_hash);
}
assert_eq!(first.get_signature_status(&sig), None);
assert!(!first.has_signature(&sig));
@ -235,17 +235,17 @@ mod tests {
#[test]
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);
let block_hash = hash(Hash::default().as_ref());
let mut first = BankStatusCache::new(&block_hash);
first.add(&sig);
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
// give first a merge
let last_id = hash(last_id.as_ref());
first.new_cache(&last_id);
let block_hash = hash(block_hash.as_ref());
first.new_cache(&block_hash);
let last_id = hash(last_id.as_ref());
let mut second = BankStatusCache::new(&last_id);
let block_hash = hash(block_hash.as_ref());
let mut second = BankStatusCache::new(&block_hash);
second.squash(&[&first]);
@ -256,21 +256,21 @@ mod tests {
#[test]
#[ignore] // takes a lot of time or RAM or both..
fn test_status_cache_squash_overflow() {
let mut last_id = hash(Hash::default().as_ref());
let mut cache = BankStatusCache::new(&last_id);
let mut block_hash = hash(Hash::default().as_ref());
let mut cache = BankStatusCache::new(&block_hash);
let parents: Vec<_> = (0..MAX_CACHE_ENTRIES)
.map(|_| {
last_id = hash(last_id.as_ref());
block_hash = hash(block_hash.as_ref());
BankStatusCache::new(&last_id)
BankStatusCache::new(&block_hash)
})
.collect();
let mut parents_refs: Vec<_> = parents.iter().collect();
last_id = hash(Hash::default().as_ref());
let mut root = BankStatusCache::new(&last_id);
block_hash = hash(Hash::default().as_ref());
let mut root = BankStatusCache::new(&block_hash);
let sig = Signature::default();
root.add(&sig);
@ -290,8 +290,8 @@ mod tests {
#[test]
fn test_failure_status() {
let sig = Signature::default();
let last_id = hash(Hash::default().as_ref());
let mut first = StatusCache::new(&last_id);
let block_hash = hash(Hash::default().as_ref());
let mut first = StatusCache::new(&block_hash);
first.add(&sig);
first.save_failure_status(&sig, BankError::DuplicateSignature);
assert_eq!(first.has_signature(&sig), true);
@ -304,8 +304,8 @@ mod tests {
#[test]
fn test_clear_signatures() {
let sig = Signature::default();
let last_id = hash(Hash::default().as_ref());
let mut first = StatusCache::new(&last_id);
let block_hash = hash(Hash::default().as_ref());
let mut first = StatusCache::new(&block_hash);
first.add(&sig);
assert_eq!(first.has_signature(&sig), true);
first.save_failure_status(&sig, BankError::DuplicateSignature);
@ -320,11 +320,11 @@ mod tests {
#[test]
fn test_clear_signatures_all() {
let sig = Signature::default();
let last_id = hash(Hash::default().as_ref());
let mut first = StatusCache::new(&last_id);
let block_hash = hash(Hash::default().as_ref());
let mut first = StatusCache::new(&block_hash);
first.add(&sig);
assert_eq!(first.has_signature(&sig), true);
let mut second = StatusCache::new(&last_id);
let mut second = StatusCache::new(&block_hash);
let mut checkpoints = [&mut second, &mut first];
BankStatusCache::clear_all(&mut checkpoints);
assert_eq!(