diff --git a/src/blocktree.rs b/src/blocktree.rs index 62ea2a23b2..409efac30e 100644 --- a/src/blocktree.rs +++ b/src/blocktree.rs @@ -320,10 +320,6 @@ pub struct Blocktree { ticks_per_slot: u64, } -// TODO: Once we support a window that knows about different leader -// slots, change functions where this is used to take slot height -// as a variable argument -pub const DEFAULT_SLOT_HEIGHT: u64 = 0; // Column family for metadata about a leader slot pub const META_CF: &str = "meta"; // Column family for the data in a leader slot @@ -1178,7 +1174,7 @@ impl Blocktree { // don't count as ticks, even if they're empty entries fn write_genesis_blobs(&self, blobs: &[Blob]) -> Result<()> { // TODO: change bootstrap height to number of slots - let meta_key = MetaCf::key(DEFAULT_SLOT_HEIGHT); + let meta_key = MetaCf::key(0); let mut bootstrap_meta = SlotMeta::new(0, 1); let last = blobs.last().unwrap(); @@ -1255,7 +1251,7 @@ pub fn create_new_ledger( // Add a single tick linked back to the genesis_block to bootstrap the ledger let blocktree = Blocktree::open_config(ledger_path, ticks_per_slot)?; let entries = crate::entry::create_ticks(1, genesis_block.last_id()); - blocktree.write_entries(DEFAULT_SLOT_HEIGHT, 0, 0, &entries)?; + blocktree.write_entries(0, 0, 0, &entries)?; Ok((1, 1, entries[0].id)) } @@ -1274,7 +1270,7 @@ where let mut b = entry.borrow().to_blob(); b.set_index(idx as u64); b.forward(true); - b.set_slot(DEFAULT_SLOT_HEIGHT); + b.set_slot(0); b }) .collect(); @@ -1313,7 +1309,7 @@ pub fn create_tmp_sample_blocktree( let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap(); blocktree - .write_entries(DEFAULT_SLOT_HEIGHT, tick_height, entry_height, &entries) + .write_entries(0, tick_height, entry_height, &entries) .unwrap(); tick_height += num_extra_ticks; entry_height += entries.len() as u64; @@ -1441,8 +1437,8 @@ pub mod tests { let ledger = Blocktree::open(&ledger_path).unwrap(); // Test meta column family - let meta = SlotMeta::new(DEFAULT_SLOT_HEIGHT, 1); - let meta_key = MetaCf::key(DEFAULT_SLOT_HEIGHT); + let meta = SlotMeta::new(0, 1); + let meta_key = MetaCf::key(0); ledger.meta_cf.put(&meta_key, &meta).unwrap(); let result = ledger .meta_cf @@ -1454,7 +1450,7 @@ pub mod tests { // Test erasure column family let erasure = vec![1u8; 16]; - let erasure_key = ErasureCf::key(DEFAULT_SLOT_HEIGHT, 0); + let erasure_key = ErasureCf::key(0, 0); ledger.erasure_cf.put(&erasure_key, &erasure).unwrap(); let result = ledger @@ -1467,7 +1463,7 @@ pub mod tests { // Test data column family let data = vec![2u8; 16]; - let data_key = DataCf::key(DEFAULT_SLOT_HEIGHT, 0); + let data_key = DataCf::key(0, 0); ledger.data_cf.put(&data_key, &data).unwrap(); let result = ledger @@ -1486,7 +1482,7 @@ pub mod tests { #[test] fn test_read_blobs_bytes() { let shared_blobs = make_tiny_test_entries(10).to_shared_blobs(); - let slot = DEFAULT_SLOT_HEIGHT; + let slot = 0; index_blobs(&shared_blobs, &mut 0, &[slot; 10]); let blob_locks: Vec<_> = shared_blobs.iter().map(|b| b.read().unwrap()).collect(); @@ -1652,7 +1648,7 @@ pub mod tests { for (i, b) in shared_blobs.iter().enumerate() { let mut w_b = b.write().unwrap(); w_b.set_index(1 << (i * 8)); - w_b.set_slot(DEFAULT_SLOT_HEIGHT); + w_b.set_slot(0); } blocktree @@ -1835,7 +1831,7 @@ pub mod tests { assert_eq!(blocktree.get_slot_entries(0, 0, None).unwrap(), expected,); - let meta_key = MetaCf::key(DEFAULT_SLOT_HEIGHT); + let meta_key = MetaCf::key(0); let meta = blocktree.meta_cf.get(&meta_key).unwrap().unwrap(); assert_eq!(meta.consumed, num_unique_entries); assert_eq!(meta.received, num_unique_entries); diff --git a/src/chacha.rs b/src/chacha.rs index 2f05ca324b..6234c1c7d1 100644 --- a/src/chacha.rs +++ b/src/chacha.rs @@ -1,4 +1,4 @@ -use crate::blocktree::{Blocktree, DEFAULT_SLOT_HEIGHT}; +use crate::blocktree::Blocktree; use std::fs::File; use std::io; use std::io::{BufWriter, Write}; @@ -50,12 +50,8 @@ pub fn chacha_cbc_encrypt_ledger( let mut entry = slice; loop { - match blocktree.read_blobs_bytes( - entry, - ENTRIES_PER_SEGMENT - total_entries, - &mut buffer, - DEFAULT_SLOT_HEIGHT, - ) { + match blocktree.read_blobs_bytes(entry, ENTRIES_PER_SEGMENT - total_entries, &mut buffer, 0) + { Ok((num_entries, entry_len)) => { debug!( "chacha: encrypting slice: {} num_entries: {} entry_len: {}", @@ -95,7 +91,7 @@ pub fn chacha_cbc_encrypt_ledger( #[cfg(test)] mod tests { use crate::blocktree::get_tmp_ledger_path; - use crate::blocktree::{Blocktree, DEFAULT_SLOT_HEIGHT}; + use crate::blocktree::Blocktree; use crate::chacha::chacha_cbc_encrypt_ledger; use crate::entry::Entry; use ring::signature::Ed25519KeyPair; @@ -149,9 +145,7 @@ mod tests { let out_path = Path::new("test_chacha_encrypt_file_output.txt.enc"); let entries = make_tiny_deterministic_test_entries(32); - blocktree - .write_entries(DEFAULT_SLOT_HEIGHT, 0, 0, &entries) - .unwrap(); + blocktree.write_entries(0, 0, 0, &entries).unwrap(); let mut key = hex!( "abcd1234abcd1234abcd1234abcd1234 abcd1234abcd1234abcd1234abcd1234 diff --git a/src/chacha_cuda.rs b/src/chacha_cuda.rs index 590232cf65..05c40bcbd6 100644 --- a/src/chacha_cuda.rs +++ b/src/chacha_cuda.rs @@ -1,7 +1,7 @@ // Module used by validators to approve storage mining proofs // // in parallel using the GPU -use crate::blocktree::{Blocktree, DEFAULT_SLOT_HEIGHT}; +use crate::blocktree::Blocktree; use crate::chacha::{CHACHA_BLOCK_SIZE, CHACHA_KEY_SIZE}; use crate::sigverify::{ chacha_cbc_encrypt_many_sample, chacha_end_sha_state, chacha_init_sha_state, @@ -47,12 +47,8 @@ pub fn chacha_cbc_encrypt_file_many_keys( chacha_init_sha_state(int_sha_states.as_mut_ptr(), num_keys as u32); } loop { - match blocktree.read_blobs_bytes( - entry, - ENTRIES_PER_SEGMENT - total_entries, - &mut buffer, - DEFAULT_SLOT_HEIGHT, - ) { + match blocktree.read_blobs_bytes(entry, ENTRIES_PER_SEGMENT - total_entries, &mut buffer, 0) + { Ok((num_entries, entry_len)) => { debug!( "chacha_cuda: encrypting segment: {} num_entries: {} entry_len: {}", @@ -110,7 +106,7 @@ pub fn chacha_cbc_encrypt_file_many_keys( #[cfg(test)] mod tests { use crate::blocktree::get_tmp_ledger_path; - use crate::blocktree::{Blocktree, DEFAULT_SLOT_HEIGHT}; + use crate::blocktree::Blocktree; use crate::chacha::chacha_cbc_encrypt_ledger; use crate::chacha_cuda::chacha_cbc_encrypt_file_many_keys; use crate::entry::make_tiny_test_entries; @@ -130,9 +126,7 @@ mod tests { let ticks_per_slot = 16; let blocktree = Arc::new(Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap()); - blocktree - .write_entries(DEFAULT_SLOT_HEIGHT, 0, 0, &entries) - .unwrap(); + blocktree.write_entries(0, 0, 0, &entries).unwrap(); let out_path = Path::new("test_chacha_encrypt_file_many_keys_single_output.txt.enc"); @@ -165,9 +159,7 @@ mod tests { let ledger_path = get_tmp_ledger_path(ledger_dir); let ticks_per_slot = 16; let blocktree = Arc::new(Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap()); - blocktree - .write_entries(DEFAULT_SLOT_HEIGHT, 0, 0, &entries) - .unwrap(); + blocktree.write_entries(0, 0, 0, &entries).unwrap(); let out_path = Path::new("test_chacha_encrypt_file_many_keys_multiple_output.txt.enc"); diff --git a/src/db_window.rs b/src/db_window.rs index 08faca2bb5..13eb68e549 100644 --- a/src/db_window.rs +++ b/src/db_window.rs @@ -245,7 +245,7 @@ mod test { #[test] pub fn test_find_missing_data_indexes_sanity() { - let slot = DEFAULT_SLOT_HEIGHT; + let slot = 0; let blocktree_path = get_tmp_ledger_path("test_find_missing_data_indexes_sanity"); let blocktree = Blocktree::open(&blocktree_path).unwrap(); @@ -290,7 +290,7 @@ mod test { #[test] pub fn test_find_missing_data_indexes() { - let slot = DEFAULT_SLOT_HEIGHT; + let slot = 0; let blocktree_path = get_tmp_ledger_path("test_find_missing_data_indexes"); let blocktree = Blocktree::open(&blocktree_path).unwrap(); @@ -442,7 +442,7 @@ mod test { #[test] pub fn test_no_missing_blob_indexes() { - let slot = DEFAULT_SLOT_HEIGHT; + let slot = 0; let blocktree_path = get_tmp_ledger_path("test_find_missing_data_indexes"); let blocktree = Blocktree::open(&blocktree_path).unwrap(); @@ -476,7 +476,7 @@ mod test { // Setup the window let offset = 0; let num_blobs = NUM_DATA + 2; - let slot_height = DEFAULT_SLOT_HEIGHT; + let slot_height = 0; let mut window = setup_window_ledger(offset, num_blobs, false, slot_height); let end_index = (offset + num_blobs) % window.len(); @@ -495,7 +495,7 @@ mod test { let ledger_path = get_tmp_ledger_path("test_try_erasure"); let blocktree = Arc::new(generate_blocktree_from_window(&ledger_path, &window, false)); - try_erasure(&blocktree, DEFAULT_SLOT_HEIGHT).expect("Expected successful erasure attempt"); + try_erasure(&blocktree, 0).expect("Expected successful erasure attempt"); window[erased_index].data = erased_data; { @@ -545,11 +545,7 @@ mod test { let original_entries = make_tiny_test_entries(num_entries); let shared_blobs = original_entries.clone().to_shared_blobs(); - index_blobs( - &shared_blobs, - &mut 0, - &vec![DEFAULT_SLOT_HEIGHT; num_entries], - ); + index_blobs(&shared_blobs, &mut 0, &vec![0; num_entries]); for blob in shared_blobs.iter().rev() { process_blob(&leader_scheduler, &blocktree, blob) diff --git a/src/erasure.rs b/src/erasure.rs index 0fcddaaa5c..f39aca048a 100644 --- a/src/erasure.rs +++ b/src/erasure.rs @@ -502,7 +502,7 @@ fn categorize_blob( pub mod test { use super::*; use crate::blocktree::get_tmp_ledger_path; - use crate::blocktree::{Blocktree, DEFAULT_SLOT_HEIGHT}; + use crate::blocktree::Blocktree; use crate::entry::{make_tiny_test_entries, EntrySlice}; use crate::packet::{index_blobs, SharedBlob, BLOB_DATA_SIZE, BLOB_SIZE}; @@ -902,11 +902,7 @@ pub mod test { fn generate_test_blobs(offset: usize, num_blobs: usize) -> Vec { let blobs = make_tiny_test_entries(num_blobs).to_shared_blobs(); - index_blobs( - &blobs, - &mut (offset as u64), - &vec![DEFAULT_SLOT_HEIGHT; blobs.len()], - ); + index_blobs(&blobs, &mut (offset as u64), &vec![0; blobs.len()]); blobs } @@ -954,7 +950,7 @@ pub mod test { // Setup the window let offset = 0; let num_blobs = NUM_DATA + 2; - let mut window = setup_window_ledger(offset, num_blobs, true, DEFAULT_SLOT_HEIGHT); + let mut window = setup_window_ledger(offset, num_blobs, true, 0); // Test erasing a data block let erase_offset = offset % window.len(); @@ -987,7 +983,7 @@ pub mod test { ref_l2.data[..ref_l2.data_size() as usize] ); assert_eq!(result.index(), offset as u64); - assert_eq!(result.slot(), DEFAULT_SLOT_HEIGHT as u64); + assert_eq!(result.slot(), 0 as u64); } drop(blocktree); Blocktree::destroy(&ledger_path) @@ -1002,7 +998,7 @@ pub mod test { // Setup the window let offset = 0; let num_blobs = NUM_DATA + 2; - let mut window = setup_window_ledger(offset, num_blobs, true, DEFAULT_SLOT_HEIGHT); + let mut window = setup_window_ledger(offset, num_blobs, true, 0); // Tests erasing a coding block and a data block let coding_start = offset - (offset % NUM_DATA) + (NUM_DATA - NUM_CODING); @@ -1040,7 +1036,7 @@ pub mod test { ref_l2.data[..ref_l2.data_size() as usize] ); assert_eq!(result.index(), coding_start as u64); - assert_eq!(result.slot(), DEFAULT_SLOT_HEIGHT as u64); + assert_eq!(result.slot(), 0 as u64); // Check the recovered erasure result let ref_l = refwindowcoding.clone().unwrap(); @@ -1053,7 +1049,7 @@ pub mod test { ref_l2.data()[..ref_l2.size() as usize] ); assert_eq!(result.index(), coding_start as u64); - assert_eq!(result.slot(), DEFAULT_SLOT_HEIGHT as u64); + assert_eq!(result.slot(), 0 as u64); } drop(blocktree); Blocktree::destroy(&ledger_path) diff --git a/src/fullnode.rs b/src/fullnode.rs index be48e79464..3b590637c5 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -407,7 +407,7 @@ impl Service for Fullnode { #[cfg(test)] mod tests { use super::*; - use crate::blocktree::{create_tmp_sample_blocktree, tmp_copy_blocktree, DEFAULT_SLOT_HEIGHT}; + use crate::blocktree::{create_tmp_sample_blocktree, tmp_copy_blocktree}; use crate::entry::make_consecutive_blobs; use crate::leader_scheduler::make_active_set_entries; use crate::streamer::responder; @@ -761,12 +761,7 @@ mod tests { let last_id = active_set_entries.last().unwrap().id; blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - entry_height, - active_set_entries, - ) + .write_entries(0, tick_height, entry_height, active_set_entries) .unwrap(); entry_height += active_set_entries_len; diff --git a/src/replay_stage.rs b/src/replay_stage.rs index 0997313d7d..012b8749f5 100644 --- a/src/replay_stage.rs +++ b/src/replay_stage.rs @@ -465,7 +465,7 @@ impl Service for ReplayStage { #[cfg(test)] mod test { use super::*; - use crate::blocktree::{create_tmp_sample_blocktree, Blocktree, DEFAULT_SLOT_HEIGHT}; + use crate::blocktree::{create_tmp_sample_blocktree, Blocktree}; use crate::cluster_info::{ClusterInfo, Node}; use crate::entry::create_ticks; use crate::entry::{next_entry_mut, Entry}; @@ -534,12 +534,7 @@ mod test { { let blocktree = Blocktree::open(&my_ledger_path).unwrap(); blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - entry_height, - active_set_entries, - ) + .write_entries(0, tick_height, entry_height, active_set_entries) .unwrap(); tick_height += num_ending_ticks; } @@ -577,12 +572,7 @@ mod test { // Write the entries to the ledger, replay_stage should get notified of changes let meta = blocktree.meta(0).unwrap().unwrap(); blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - meta.consumed, - &entries_to_send, - ) + .write_entries(0, tick_height, meta.consumed, &entries_to_send) .unwrap(); info!("Wait for replay_stage to exit and check return value is correct"); @@ -676,12 +666,7 @@ mod test { info!("Send ReplayStage an entry, should see it on the ledger writer receiver"); let next_tick = create_ticks(1, last_entry_id); blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - entry_height, - next_tick.clone(), - ) + .write_entries(0, tick_height, entry_height, next_tick.clone()) .unwrap(); let received_tick = ledger_writer_recv @@ -743,12 +728,7 @@ mod test { { let blocktree = Blocktree::open_config(&my_ledger_path, ticks_per_slot).unwrap(); blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - genesis_entry_height, - &active_set_entries, - ) + .write_entries(0, tick_height, genesis_entry_height, &active_set_entries) .unwrap(); } @@ -802,7 +782,7 @@ mod test { let entry = next_entry_mut(&mut last_id, num_hashes, vec![]); blocktree .write_entries( - DEFAULT_SLOT_HEIGHT, + 0, tick_height + i as u64, meta.consumed + i as u64, vec![entry.clone()], diff --git a/src/storage_stage.rs b/src/storage_stage.rs index b008b06e83..25e9ac450f 100644 --- a/src/storage_stage.rs +++ b/src/storage_stage.rs @@ -444,7 +444,7 @@ impl Service for StorageStage { #[cfg(test)] mod tests { - use crate::blocktree::{create_tmp_sample_blocktree, Blocktree, DEFAULT_SLOT_HEIGHT}; + use crate::blocktree::{create_tmp_sample_blocktree, Blocktree}; use crate::cluster_info::{ClusterInfo, NodeInfo}; use crate::entry::{make_tiny_test_entries, Entry}; use crate::service::Service; @@ -511,12 +511,7 @@ mod tests { let entries = make_tiny_test_entries(64); let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap(); blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - genesis_entry_height, - &entries, - ) + .write_entries(0, tick_height, genesis_entry_height, &entries) .unwrap(); let cluster_info = test_cluster_info(keypair.pubkey()); @@ -581,12 +576,7 @@ mod tests { let entries = make_tiny_test_entries(128); let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap(); blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - genesis_entry_height, - &entries, - ) + .write_entries(0, tick_height, genesis_entry_height, &entries) .unwrap(); let cluster_info = test_cluster_info(keypair.pubkey()); diff --git a/tests/multinode.rs b/tests/multinode.rs index 90704dc768..413fd9149a 100644 --- a/tests/multinode.rs +++ b/tests/multinode.rs @@ -1,8 +1,6 @@ use log::*; use solana::blob_fetch_stage::BlobFetchStage; -use solana::blocktree::{ - create_tmp_sample_blocktree, tmp_copy_blocktree, Blocktree, DEFAULT_SLOT_HEIGHT, -}; +use solana::blocktree::{create_tmp_sample_blocktree, tmp_copy_blocktree, Blocktree}; use solana::client::mk_client; use solana::cluster_info::{Node, NodeInfo}; use solana::entry::{reconstruct_entries_from_blobs, Entry}; @@ -69,12 +67,7 @@ fn test_multi_node_ledger_window() -> result::Result<()> { last_entry_id, ); blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - last_entry_height, - &entries, - ) + .write_entries(0, tick_height, last_entry_height, &entries) .unwrap(); last_entry_height += entries.len() as u64; @@ -912,12 +905,7 @@ fn test_leader_to_validator_transition() { { let blocktree = Blocktree::open_config(&leader_ledger_path, ticks_per_slot).unwrap(); blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - genesis_entry_height, - &active_set_entries, - ) + .write_entries(0, tick_height, genesis_entry_height, &active_set_entries) .unwrap(); } info!("leader id: {}", leader_keypair.pubkey()); @@ -1015,12 +1003,7 @@ fn test_leader_validator_basic() { { let blocktree = Blocktree::open_config(&leader_ledger_path, ticks_per_slot).unwrap(); blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - genesis_entry_height, - &active_set_entries, - ) + .write_entries(0, tick_height, genesis_entry_height, &active_set_entries) .unwrap(); } @@ -1170,12 +1153,7 @@ fn test_dropped_handoff_recovery() { { let blocktree = Blocktree::open_config(&genesis_ledger_path, ticks_per_slot).unwrap(); blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - genesis_entry_height, - &active_set_entries, - ) + .write_entries(0, tick_height, genesis_entry_height, &active_set_entries) .unwrap(); } @@ -1341,12 +1319,7 @@ fn test_full_leader_validator_network() { let blocktree = Blocktree::open_config(&bootstrap_leader_ledger_path, ticks_per_slot).unwrap(); blocktree - .write_entries( - DEFAULT_SLOT_HEIGHT, - tick_height, - entry_height, - &active_set_entries, - ) + .write_entries(0, tick_height, entry_height, &active_set_entries) .unwrap(); entry_height += active_set_entries.len() as u64; } diff --git a/tests/replicator.rs b/tests/replicator.rs index 68d3d77aa3..7fa218e1a9 100644 --- a/tests/replicator.rs +++ b/tests/replicator.rs @@ -8,7 +8,6 @@ extern crate serde_json; use bincode::deserialize; use solana::blocktree::{ create_tmp_sample_blocktree, get_tmp_ledger_path, tmp_copy_blocktree, Blocktree, - DEFAULT_SLOT_HEIGHT, }; use solana::client::mk_client; use solana::cluster_info::{ClusterInfo, Node, NodeInfo}; @@ -155,7 +154,7 @@ fn test_replicator_startup_basic() { let cluster_info = ClusterInfo::new(tn.info.clone()); let repair_index = replicator.entry_height(); let req = cluster_info - .window_index_request_bytes(DEFAULT_SLOT_HEIGHT, repair_index) + .window_index_request_bytes(0, repair_index) .unwrap(); let exit = Arc::new(AtomicBool::new(false));