Rename LastIdQueue to HashQueue

This commit is contained in:
Michael Vines 2019-03-01 09:24:16 -08:00
parent 558f10c862
commit 360055ad70
2 changed files with 12 additions and 12 deletions

View File

@ -4,7 +4,7 @@
//! already been signed and verified. //! already been signed and verified.
use crate::accounts::{Accounts, ErrorCounters, InstructionAccounts, InstructionLoaders}; use crate::accounts::{Accounts, ErrorCounters, InstructionAccounts, InstructionLoaders};
use crate::last_id_queue::LastIdQueue; use crate::last_id_queue::HashQueue;
use crate::runtime::{self, RuntimeError}; use crate::runtime::{self, RuntimeError};
use crate::status_cache::StatusCache; use crate::status_cache::StatusCache;
use bincode::serialize; use bincode::serialize;
@ -86,7 +86,7 @@ pub struct Bank {
status_cache: RwLock<BankStatusCache>, status_cache: RwLock<BankStatusCache>,
/// FIFO queue of `last_id` items /// FIFO queue of `last_id` items
last_id_queue: RwLock<LastIdQueue>, last_id_queue: RwLock<HashQueue>,
/// Previous checkpoint of this bank /// Previous checkpoint of this bank
parent: RwLock<Option<Arc<Bank>>>, parent: RwLock<Option<Arc<Bank>>>,
@ -744,7 +744,7 @@ impl Bank {
} }
#[cfg(test)] #[cfg(test)]
pub fn last_ids(&self) -> &RwLock<LastIdQueue> { pub fn last_ids(&self) -> &RwLock<HashQueue> {
&self.last_id_queue &self.last_id_queue
} }
} }

View File

@ -3,23 +3,23 @@ use solana_sdk::hash::Hash;
use solana_sdk::timing::{timestamp, MAX_ENTRY_IDS}; use solana_sdk::timing::{timestamp, MAX_ENTRY_IDS};
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
struct LastIdEntry { struct HashQueueEntry {
timestamp: u64, timestamp: u64,
tick_height: u64, tick_height: u64,
} }
/// Low memory overhead, so can be cloned for every checkpoint /// Low memory overhead, so can be cloned for every checkpoint
#[derive(Clone)] #[derive(Clone)]
pub struct LastIdQueue { pub struct HashQueue {
/// updated whenever an id is registered, at each tick ;) /// updated whenever an id is registered, at each tick ;)
tick_height: u64, tick_height: u64,
/// last tick to be registered /// last tick to be registered
last_id: Option<Hash>, last_id: Option<Hash>,
entries: HashMap<Hash, LastIdEntry>, entries: HashMap<Hash, HashQueueEntry>,
} }
impl Default for LastIdQueue { impl Default for HashQueue {
fn default() -> Self { fn default() -> Self {
Self { Self {
entries: HashMap::new(), entries: HashMap::new(),
@ -29,7 +29,7 @@ impl Default for LastIdQueue {
} }
} }
impl LastIdQueue { impl HashQueue {
pub fn tick_height(&self) -> u64 { pub fn tick_height(&self) -> u64 {
self.tick_height self.tick_height
} }
@ -56,7 +56,7 @@ impl LastIdQueue {
pub fn genesis_last_id(&mut self, last_id: &Hash) { pub fn genesis_last_id(&mut self, last_id: &Hash) {
self.entries.insert( self.entries.insert(
*last_id, *last_id,
LastIdEntry { HashQueueEntry {
tick_height: 0, tick_height: 0,
timestamp: timestamp(), timestamp: timestamp(),
}, },
@ -82,7 +82,7 @@ impl LastIdQueue {
self.entries.insert( self.entries.insert(
*last_id, *last_id,
LastIdEntry { HashQueueEntry {
tick_height, tick_height,
timestamp: timestamp(), timestamp: timestamp(),
}, },
@ -141,7 +141,7 @@ mod tests {
#[test] #[test]
fn test_register_tick() { fn test_register_tick() {
let last_id = Hash::default(); let last_id = Hash::default();
let mut entry_queue = LastIdQueue::default(); let mut entry_queue = HashQueue::default();
assert!(!entry_queue.check_entry(last_id)); assert!(!entry_queue.check_entry(last_id));
entry_queue.register_tick(&last_id); entry_queue.register_tick(&last_id);
assert!(entry_queue.check_entry(last_id)); assert!(entry_queue.check_entry(last_id));
@ -149,7 +149,7 @@ mod tests {
#[test] #[test]
fn test_reject_old_last_id() { fn test_reject_old_last_id() {
let last_id = Hash::default(); let last_id = Hash::default();
let mut entry_queue = LastIdQueue::default(); let mut entry_queue = HashQueue::default();
for i in 0..MAX_ENTRY_IDS { for i in 0..MAX_ENTRY_IDS {
let last_id = hash(&serialize(&i).unwrap()); // Unique hash let last_id = hash(&serialize(&i).unwrap()); // Unique hash
entry_queue.register_tick(&last_id); entry_queue.register_tick(&last_id);