Rename prev_id to prev_hash

This commit is contained in:
Michael Vines
2019-03-01 08:44:55 -08:00
parent e993d511e3
commit 7e7b79ef34
4 changed files with 35 additions and 35 deletions

View File

@ -52,7 +52,7 @@ slot index and blob index for an entry, and the value is the entry data. Note bl
the ledger to find possible fork points. the ledger to find possible fork points.
* `last_index` - The index of the blob that is flagged as the last blob for this slot. This flag on a blob will be set by the leader for a slot when they are transmitting the last blob for a slot. * `last_index` - The index of the blob that is flagged as the last blob for this slot. This flag on a blob will be set by the leader for a slot when they are transmitting the last blob for a slot.
* `is_rooted` - True iff every block from 0...slot forms a full sequence without any holes. We can derive is_rooted for each slot with the following rules. Let slot(n) be the slot with index `n`, and slot(n).is_full() is true if the slot with index `n` has all the ticks expected for that slot. Let is_rooted(n) be the statement that "the slot(n).is_rooted is true". Then: * `is_rooted` - True iff every block from 0...slot forms a full sequence without any holes. We can derive is_rooted for each slot with the following rules. Let slot(n) be the slot with index `n`, and slot(n).is_full() is true if the slot with index `n` has all the ticks expected for that slot. Let is_rooted(n) be the statement that "the slot(n).is_rooted is true". Then:
is_rooted(0) is_rooted(0)
is_rooted(n+1) iff (is_rooted(n) and slot(n).is_full() is_rooted(n+1) iff (is_rooted(n) and slot(n).is_full()
@ -60,7 +60,7 @@ slot index and blob index for an entry, and the value is the entry data. Note bl
4. Subscriptions - The Blocktree records a set of slots that have been "subscribed" to. This means entries that chain to these slots will be sent on the Blocktree channel for consumption by the ReplayStage. See the `Blocktree APIs` for details. 4. Subscriptions - The Blocktree records a set of slots that have been "subscribed" to. This means entries that chain to these slots will be sent on the Blocktree channel for consumption by the ReplayStage. See the `Blocktree APIs` for details.
5. Update notifications - The Blocktree notifies listeners when slot(n).is_rooted is flipped from false to true for any `n`. 5. Update notifications - The Blocktree notifies listeners when slot(n).is_rooted is flipped from false to true for any `n`.
### Blocktree APIs ### Blocktree APIs
@ -75,13 +75,13 @@ Note: Cumulatively, this means that the replay stage will now have to know when
The bank exposes to replay stage: The bank exposes to replay stage:
1. `prev_id`: which PoH chain it's working on as indicated by the id of the last 1. `prev_hash`: which PoH chain it's working on as indicated by the hash of the last
entry it processed entry it processed
2. `tick_height`: the ticks in the PoH chain currently being verified by this 2. `tick_height`: the ticks in the PoH chain currently being verified by this
bank bank
3. `votes`: a stack of records that contain: 3. `votes`: a stack of records that contain:
1. `prev_ids`: what anything after this vote must chain to in PoH 1. `prev_hashes`: what anything after this vote must chain to in PoH
2. `tick_height`: the tick height at which this vote was cast 2. `tick_height`: the tick height at which this vote was cast
3. `lockout period`: how long a chain must be observed to be in the ledger to 3. `lockout period`: how long a chain must be observed to be in the ledger to
be able to be chained below this vote be able to be chained below this vote

View File

@ -55,18 +55,18 @@ pub struct Entry {
impl Entry { impl Entry {
/// Creates the next Entry `num_hashes` after `start_hash`. /// Creates the next Entry `num_hashes` after `start_hash`.
pub fn new(prev_id: &Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Self { pub fn new(prev_hash: &Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Self {
let entry = { let entry = {
if num_hashes == 0 && transactions.is_empty() { if num_hashes == 0 && transactions.is_empty() {
Entry { Entry {
num_hashes: 0, num_hashes: 0,
id: *prev_id, id: *prev_hash,
transactions, transactions,
} }
} else if num_hashes == 0 { } else if num_hashes == 0 {
// If you passed in transactions, but passed in num_hashes == 0, then // If you passed in transactions, but passed in num_hashes == 0, then
// next_hash will generate the next hash and set num_hashes == 1 // next_hash will generate the next hash and set num_hashes == 1
let id = next_hash(prev_id, 1, &transactions); let id = next_hash(prev_hash, 1, &transactions);
Entry { Entry {
num_hashes: 1, num_hashes: 1,
id, id,
@ -76,7 +76,7 @@ impl Entry {
// Otherwise, the next Entry `num_hashes` after `start_hash`. // Otherwise, the next Entry `num_hashes` after `start_hash`.
// If you wanted a tick for instance, then pass in num_hashes = 1 // If you wanted a tick for instance, then pass in num_hashes = 1
// and transactions = empty // and transactions = empty
let id = next_hash(prev_id, num_hashes, &transactions); let id = next_hash(prev_hash, num_hashes, &transactions);
Entry { Entry {
num_hashes, num_hashes,
id, id,
@ -461,11 +461,11 @@ pub fn make_consecutive_blobs(
#[cfg(test)] #[cfg(test)]
/// Creates the next Tick or Transaction Entry `num_hashes` after `start_hash`. /// Creates the next Tick or Transaction Entry `num_hashes` after `start_hash`.
pub fn next_entry(prev_id: &Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Entry { pub fn next_entry(prev_hash: &Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Entry {
assert!(num_hashes > 0 || transactions.is_empty()); assert!(num_hashes > 0 || transactions.is_empty());
Entry { Entry {
num_hashes, num_hashes,
id: next_hash(prev_id, num_hashes, &transactions), id: next_hash(prev_hash, num_hashes, &transactions),
transactions, transactions,
} }
} }
@ -641,11 +641,11 @@ mod tests {
fn test_next_entries() { fn test_next_entries() {
solana_logger::setup(); solana_logger::setup();
let id = Hash::default(); let id = Hash::default();
let next_id = hash(&id.as_ref()); let next_hash = hash(&id.as_ref());
let keypair = Keypair::new(); let keypair = Keypair::new();
let vote_account = Keypair::new(); let vote_account = Keypair::new();
let tx_small = VoteTransaction::new_vote(&vote_account, 1, next_id, 2); let tx_small = VoteTransaction::new_vote(&vote_account, 1, next_hash, 2);
let tx_large = BudgetTransaction::new(&keypair, keypair.pubkey(), 1, next_id); let tx_large = BudgetTransaction::new(&keypair, keypair.pubkey(), 1, next_hash);
let tx_small_size = tx_small.serialized_size().unwrap() as usize; let tx_small_size = tx_small.serialized_size().unwrap() as usize;
let tx_large_size = tx_large.serialized_size().unwrap() as usize; let tx_large_size = tx_large.serialized_size().unwrap() as usize;

View File

@ -197,8 +197,8 @@ mod tests {
#[test] #[test]
fn test_poh_recorder_no_zero_tick() { fn test_poh_recorder_no_zero_tick() {
let prev_id = Hash::default(); let prev_hash = Hash::default();
let mut poh_recorder = PohRecorder::new(0, prev_id); let mut poh_recorder = PohRecorder::new(0, prev_hash);
poh_recorder.tick(); poh_recorder.tick();
assert_eq!(poh_recorder.tick_cache.len(), 1); assert_eq!(poh_recorder.tick_cache.len(), 1);
assert_eq!(poh_recorder.tick_cache[0].1, 1); assert_eq!(poh_recorder.tick_cache[0].1, 1);
@ -207,8 +207,8 @@ mod tests {
#[test] #[test]
fn test_poh_recorder_tick_height_is_last_tick() { fn test_poh_recorder_tick_height_is_last_tick() {
let prev_id = Hash::default(); let prev_hash = Hash::default();
let mut poh_recorder = PohRecorder::new(0, prev_id); let mut poh_recorder = PohRecorder::new(0, prev_hash);
poh_recorder.tick(); poh_recorder.tick();
poh_recorder.tick(); poh_recorder.tick();
assert_eq!(poh_recorder.tick_cache.len(), 2); assert_eq!(poh_recorder.tick_cache.len(), 2);
@ -229,9 +229,9 @@ mod tests {
fn test_poh_recorder_clear() { fn test_poh_recorder_clear() {
let (genesis_block, _mint_keypair) = GenesisBlock::new(2); let (genesis_block, _mint_keypair) = GenesisBlock::new(2);
let bank = Arc::new(Bank::new(&genesis_block)); let bank = Arc::new(Bank::new(&genesis_block));
let prev_id = bank.last_id(); let prev_hash = bank.last_id();
let (entry_sender, _) = channel(); let (entry_sender, _) = channel();
let mut poh_recorder = PohRecorder::new(0, prev_id); let mut poh_recorder = PohRecorder::new(0, prev_hash);
let working_bank = WorkingBank { let working_bank = WorkingBank {
bank, bank,
@ -249,9 +249,9 @@ mod tests {
fn test_poh_recorder_tick_sent_after_min() { fn test_poh_recorder_tick_sent_after_min() {
let (genesis_block, _mint_keypair) = GenesisBlock::new(2); let (genesis_block, _mint_keypair) = GenesisBlock::new(2);
let bank = Arc::new(Bank::new(&genesis_block)); let bank = Arc::new(Bank::new(&genesis_block));
let prev_id = bank.last_id(); let prev_hash = bank.last_id();
let (entry_sender, entry_receiver) = channel(); let (entry_sender, entry_receiver) = channel();
let mut poh_recorder = PohRecorder::new(0, prev_id); let mut poh_recorder = PohRecorder::new(0, prev_hash);
let working_bank = WorkingBank { let working_bank = WorkingBank {
bank, bank,
@ -280,9 +280,9 @@ mod tests {
fn test_poh_recorder_tick_sent_upto_and_including_max() { fn test_poh_recorder_tick_sent_upto_and_including_max() {
let (genesis_block, _mint_keypair) = GenesisBlock::new(2); let (genesis_block, _mint_keypair) = GenesisBlock::new(2);
let bank = Arc::new(Bank::new(&genesis_block)); let bank = Arc::new(Bank::new(&genesis_block));
let prev_id = bank.last_id(); let prev_hash = bank.last_id();
let (entry_sender, entry_receiver) = channel(); let (entry_sender, entry_receiver) = channel();
let mut poh_recorder = PohRecorder::new(0, prev_id); let mut poh_recorder = PohRecorder::new(0, prev_hash);
poh_recorder.tick(); poh_recorder.tick();
poh_recorder.tick(); poh_recorder.tick();
@ -310,9 +310,9 @@ mod tests {
fn test_poh_recorder_record_to_early() { fn test_poh_recorder_record_to_early() {
let (genesis_block, _mint_keypair) = GenesisBlock::new(2); let (genesis_block, _mint_keypair) = GenesisBlock::new(2);
let bank = Arc::new(Bank::new(&genesis_block)); let bank = Arc::new(Bank::new(&genesis_block));
let prev_id = bank.last_id(); let prev_hash = bank.last_id();
let (entry_sender, entry_receiver) = channel(); let (entry_sender, entry_receiver) = channel();
let mut poh_recorder = PohRecorder::new(0, prev_id); let mut poh_recorder = PohRecorder::new(0, prev_hash);
let working_bank = WorkingBank { let working_bank = WorkingBank {
bank, bank,
@ -332,9 +332,9 @@ mod tests {
fn test_poh_recorder_record_at_min_passes() { fn test_poh_recorder_record_at_min_passes() {
let (genesis_block, _mint_keypair) = GenesisBlock::new(2); let (genesis_block, _mint_keypair) = GenesisBlock::new(2);
let bank = Arc::new(Bank::new(&genesis_block)); let bank = Arc::new(Bank::new(&genesis_block));
let prev_id = bank.last_id(); let prev_hash = bank.last_id();
let (entry_sender, entry_receiver) = channel(); let (entry_sender, entry_receiver) = channel();
let mut poh_recorder = PohRecorder::new(0, prev_id); let mut poh_recorder = PohRecorder::new(0, prev_hash);
let working_bank = WorkingBank { let working_bank = WorkingBank {
bank, bank,
@ -363,9 +363,9 @@ mod tests {
fn test_poh_recorder_record_at_max_fails() { fn test_poh_recorder_record_at_max_fails() {
let (genesis_block, _mint_keypair) = GenesisBlock::new(2); let (genesis_block, _mint_keypair) = GenesisBlock::new(2);
let bank = Arc::new(Bank::new(&genesis_block)); let bank = Arc::new(Bank::new(&genesis_block));
let prev_id = bank.last_id(); let prev_hash = bank.last_id();
let (entry_sender, entry_receiver) = channel(); let (entry_sender, entry_receiver) = channel();
let mut poh_recorder = PohRecorder::new(0, prev_id); let mut poh_recorder = PohRecorder::new(0, prev_hash);
let working_bank = WorkingBank { let working_bank = WorkingBank {
bank, bank,
@ -391,9 +391,9 @@ mod tests {
fn test_poh_cache_on_disconnect() { fn test_poh_cache_on_disconnect() {
let (genesis_block, _mint_keypair) = GenesisBlock::new(2); let (genesis_block, _mint_keypair) = GenesisBlock::new(2);
let bank = Arc::new(Bank::new(&genesis_block)); let bank = Arc::new(Bank::new(&genesis_block));
let prev_id = bank.last_id(); let prev_hash = bank.last_id();
let (entry_sender, entry_receiver) = channel(); let (entry_sender, entry_receiver) = channel();
let mut poh_recorder = PohRecorder::new(0, prev_id); let mut poh_recorder = PohRecorder::new(0, prev_hash);
let working_bank = WorkingBank { let working_bank = WorkingBank {
bank, bank,

View File

@ -124,9 +124,9 @@ mod tests {
fn test_poh_service() { fn test_poh_service() {
let (genesis_block, _mint_keypair) = GenesisBlock::new(2); let (genesis_block, _mint_keypair) = GenesisBlock::new(2);
let bank = Arc::new(Bank::new(&genesis_block)); let bank = Arc::new(Bank::new(&genesis_block));
let prev_id = bank.last_id(); let prev_hash = bank.last_id();
let (entry_sender, entry_receiver) = channel(); let (entry_sender, entry_receiver) = channel();
let poh_recorder = Arc::new(Mutex::new(PohRecorder::new(bank.tick_height(), prev_id))); let poh_recorder = Arc::new(Mutex::new(PohRecorder::new(bank.tick_height(), prev_hash)));
let exit = Arc::new(AtomicBool::new(false)); let exit = Arc::new(AtomicBool::new(false));
let working_bank = WorkingBank { let working_bank = WorkingBank {
bank: bank.clone(), bank: bank.clone(),
@ -204,9 +204,9 @@ mod tests {
fn test_poh_service_drops_working_bank() { fn test_poh_service_drops_working_bank() {
let (genesis_block, _mint_keypair) = GenesisBlock::new(2); let (genesis_block, _mint_keypair) = GenesisBlock::new(2);
let bank = Arc::new(Bank::new(&genesis_block)); let bank = Arc::new(Bank::new(&genesis_block));
let prev_id = bank.last_id(); let prev_hash = bank.last_id();
let (entry_sender, entry_receiver) = channel(); let (entry_sender, entry_receiver) = channel();
let poh_recorder = Arc::new(Mutex::new(PohRecorder::new(bank.tick_height(), prev_id))); let poh_recorder = Arc::new(Mutex::new(PohRecorder::new(bank.tick_height(), prev_hash)));
let exit = Arc::new(AtomicBool::new(false)); let exit = Arc::new(AtomicBool::new(false));
let working_bank = WorkingBank { let working_bank = WorkingBank {
bank: bank.clone(), bank: bank.clone(),