Remove ticks_per_slot from Blocktree::write_entries(), it already knows

This commit is contained in:
Michael Vines 2019-02-12 13:18:49 -08:00
parent 6abdd6401d
commit e341b33f21
7 changed files with 20 additions and 38 deletions

View File

@ -485,7 +485,6 @@ impl Blocktree {
&self,
start_slot: u64,
num_ticks_in_start_slot: u64,
ticks_per_slot: u64,
start_index: u64,
entries: I,
) -> Result<()>
@ -493,6 +492,8 @@ impl Blocktree {
I: IntoIterator,
I::Item: Borrow<Entry>,
{
let ticks_per_slot = self.ticks_per_slot;
assert!(num_ticks_in_start_slot < ticks_per_slot);
let mut remaining_ticks_in_slot = ticks_per_slot - num_ticks_in_start_slot;
@ -1289,7 +1290,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, config)?;
let entries = crate::entry::create_ticks(1, genesis_block.last_id());
blocktree.write_entries(DEFAULT_SLOT_HEIGHT, 0, std::u64::MAX, 0, &entries)?;
blocktree.write_entries(DEFAULT_SLOT_HEIGHT, 0, 0, &entries)?;
Ok((1, 1, entries[0].id))
}
@ -1354,13 +1355,7 @@ pub fn create_tmp_sample_ledger(
// create_new_ledger creates one beginning tick
tick_height += num_extra_ticks;
blocktree
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
config.ticks_per_slot,
entry_height,
&entries,
)
.write_entries(DEFAULT_SLOT_HEIGHT, tick_height, entry_height, &entries)
.unwrap();
entry_height += entries.len() as u64;
last_id = entries.last().unwrap().id;
@ -1855,7 +1850,6 @@ mod tests {
.write_entries(
0u64,
0,
std::u64::MAX,
(entries.len() - 1) as u64,
&entries[entries.len() - 1..],
)

View File

@ -95,7 +95,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, BlocktreeConfig, DEFAULT_SLOT_HEIGHT};
use crate::chacha::chacha_cbc_encrypt_ledger;
use crate::entry::Entry;
use ring::signature::Ed25519KeyPair;
@ -144,13 +144,15 @@ mod tests {
solana_logger::setup();
let ledger_dir = "chacha_test_encrypt_file";
let ledger_path = get_tmp_ledger_path(ledger_dir);
let blocktree = Arc::new(Blocktree::open(&ledger_path).unwrap());
let ticks_per_slot = 16;
let blocktree = Arc::new(
Blocktree::open_config(&ledger_path, &BlocktreeConfig::new(ticks_per_slot)).unwrap(),
);
let out_path = Path::new("test_chacha_encrypt_file_output.txt.enc");
let entries = make_tiny_deterministic_test_entries(32);
let ticks_per_slot = 16;
blocktree
.write_entries(DEFAULT_SLOT_HEIGHT, 0, ticks_per_slot, 0, &entries)
.write_entries(DEFAULT_SLOT_HEIGHT, 0, 0, &entries)
.unwrap();
let mut key = hex!(

View File

@ -110,7 +110,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, BlocktreeConfig, DEFAULT_SLOT_HEIGHT};
use crate::chacha::chacha_cbc_encrypt_ledger;
use crate::chacha_cuda::chacha_cbc_encrypt_file_many_keys;
use crate::entry::make_tiny_test_entries;
@ -127,11 +127,13 @@ mod tests {
let entries = make_tiny_test_entries(32);
let ledger_dir = "test_encrypt_file_many_keys_single";
let ledger_path = get_tmp_ledger_path(ledger_dir);
let blocktree = Arc::new(Blocktree::open(&ledger_path).unwrap());
let ticks_per_slot = 16;
let blocktree = Arc::new(
Blocktree::open_config(&ledger_path, &BlocktreeConfig::new(ticks_per_slot)).unwrap(),
);
blocktree
.write_entries(DEFAULT_SLOT_HEIGHT, 0, ticks_per_slot, 0, &entries)
.write_entries(DEFAULT_SLOT_HEIGHT, 0, 0, &entries)
.unwrap();
let out_path = Path::new("test_chacha_encrypt_file_many_keys_single_output.txt.enc");
@ -163,10 +165,12 @@ mod tests {
let entries = make_tiny_test_entries(32);
let ledger_dir = "test_encrypt_file_many_keys_multiple";
let ledger_path = get_tmp_ledger_path(ledger_dir);
let blocktree = Arc::new(Blocktree::open(&ledger_path).unwrap());
let ticks_per_slot = 16;
let blocktree = Arc::new(
Blocktree::open_config(&ledger_path, &BlocktreeConfig::new(ticks_per_slot)).unwrap(),
);
blocktree
.write_entries(DEFAULT_SLOT_HEIGHT, 0, ticks_per_slot, 0, &entries)
.write_entries(DEFAULT_SLOT_HEIGHT, 0, 0, &entries)
.unwrap();
let out_path = Path::new("test_chacha_encrypt_file_many_keys_multiple_output.txt.enc");

View File

@ -1044,7 +1044,6 @@ mod tests {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
ticks_per_slot,
entry_height,
active_set_entries,
)

View File

@ -433,7 +433,6 @@ mod test {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
ticks_per_slot,
entry_height,
active_set_entries,
)
@ -480,7 +479,6 @@ mod test {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
ticks_per_slot,
meta.consumed,
&entries_to_send,
)
@ -525,7 +523,6 @@ mod test {
// Create keypair for the leader
let leader_id = Keypair::new().pubkey();
let ticks_per_slot = std::u64::MAX;
let (
_mint_keypair,
my_ledger_path,
@ -584,7 +581,6 @@ mod test {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
ticks_per_slot,
entry_height,
next_tick.clone(),
)
@ -658,7 +654,6 @@ mod test {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
ticks_per_slot,
genesis_entry_height,
&active_set_entries,
)
@ -717,7 +712,6 @@ mod test {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height + i as u64,
ticks_per_slot,
meta.consumed + i as u64,
vec![entry.clone()],
)

View File

@ -491,7 +491,6 @@ mod tests {
solana_logger::setup();
let keypair = Arc::new(Keypair::new());
let exit = Arc::new(AtomicBool::new(false));
let ticks_per_slot = std::u64::MAX;
let blocktree_config = BlocktreeConfig::default();
let (_mint, ledger_path, tick_height, genesis_entry_height, _last_id, _last_entry_id) =
@ -510,7 +509,6 @@ mod tests {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
ticks_per_slot,
genesis_entry_height,
&entries,
)
@ -569,7 +567,6 @@ mod tests {
solana_logger::setup();
let keypair = Arc::new(Keypair::new());
let exit = Arc::new(AtomicBool::new(false));
let ticks_per_slot = std::u64::MAX;
let blocktree_config = BlocktreeConfig::default();
let (_mint, ledger_path, tick_height, genesis_entry_height, _last_id, _last_entry_id) =
@ -588,7 +585,6 @@ mod tests {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
ticks_per_slot,
genesis_entry_height,
&entries,
)

View File

@ -91,7 +91,6 @@ fn test_multi_node_ledger_window() -> result::Result<()> {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
blocktree_config.ticks_per_slot,
last_entry_height,
&entries,
)
@ -969,7 +968,6 @@ fn test_leader_to_validator_transition() {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
ticks_per_slot,
genesis_entry_height,
&active_set_entries,
)
@ -1082,7 +1080,6 @@ fn test_leader_validator_basic() {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
ticks_per_slot,
genesis_entry_height,
&active_set_entries,
)
@ -1252,7 +1249,6 @@ fn test_dropped_handoff_recovery() {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
ticks_per_slot,
genesis_entry_height,
&active_set_entries,
)
@ -1440,7 +1436,6 @@ fn test_full_leader_validator_network() {
.write_entries(
DEFAULT_SLOT_HEIGHT,
tick_height,
ticks_per_slot,
entry_height,
&active_set_entries,
)
@ -1823,9 +1818,7 @@ fn test_fullnode_rotate(ticks_per_slot: u64, slots_per_epoch: u64) {
let entries = solana::entry::create_ticks(1, last_entry_id);
let blocktree = Blocktree::open_config(&leader_ledger_path, &blocktree_config).unwrap();
blocktree
.write_entries(1, 0, blocktree_config.ticks_per_slot, 0, &entries)
.unwrap();
blocktree.write_entries(1, 0, 0, &entries).unwrap();
tick_height_of_next_rotation += 1;
}