remove ticks_per_slot from blocktree (#3297)
This commit is contained in:
parent
c208f4dbb5
commit
9f02a8d3d0
|
@ -127,7 +127,7 @@ mod test {
|
|||
genesis_block.ticks_per_slot = ticks_per_slot;
|
||||
|
||||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||
let blocktree = Blocktree::open(&ledger_path).unwrap();
|
||||
|
||||
// Set up blockstream
|
||||
let mut blockstream = Blockstream::new("test_stream".to_string());
|
||||
|
@ -150,7 +150,9 @@ mod test {
|
|||
let expected_entries = entries.clone();
|
||||
let expected_tick_heights = [5, 6, 7, 8, 8, 9];
|
||||
|
||||
blocktree.write_entries(1, 0, 0, &entries).unwrap();
|
||||
blocktree
|
||||
.write_entries(1, 0, 0, ticks_per_slot, &entries)
|
||||
.unwrap();
|
||||
|
||||
slot_full_sender.send((1, leader_id)).unwrap();
|
||||
BlockstreamService::process_entries(
|
||||
|
|
|
@ -142,7 +142,6 @@ pub struct Blocktree {
|
|||
data_cf: DataCf,
|
||||
erasure_cf: ErasureCf,
|
||||
pub new_blobs_signals: Vec<SyncSender<bool>>,
|
||||
ticks_per_slot: u64,
|
||||
}
|
||||
|
||||
// Column family for metadata about a leader slot
|
||||
|
@ -161,24 +160,6 @@ impl Blocktree {
|
|||
Ok((blocktree, signal_receiver))
|
||||
}
|
||||
|
||||
pub fn open_config(ledger_path: &str, ticks_per_slot: u64) -> Result<Self> {
|
||||
let mut blocktree = Self::open(ledger_path)?;
|
||||
blocktree.ticks_per_slot = ticks_per_slot;
|
||||
Ok(blocktree)
|
||||
}
|
||||
|
||||
pub fn open_with_config_signal(
|
||||
ledger_path: &str,
|
||||
ticks_per_slot: u64,
|
||||
) -> Result<(Self, Receiver<bool>)> {
|
||||
let mut blocktree = Self::open(ledger_path)?;
|
||||
let (signal_sender, signal_receiver) = sync_channel(1);
|
||||
blocktree.new_blobs_signals = vec![signal_sender];
|
||||
blocktree.ticks_per_slot = ticks_per_slot;
|
||||
|
||||
Ok((blocktree, signal_receiver))
|
||||
}
|
||||
|
||||
pub fn meta(&self, slot: u64) -> Result<Option<SlotMeta>> {
|
||||
self.meta_cf.get(&MetaCf::key(slot))
|
||||
}
|
||||
|
@ -239,14 +220,13 @@ impl Blocktree {
|
|||
start_slot: u64,
|
||||
num_ticks_in_start_slot: u64,
|
||||
start_index: u64,
|
||||
ticks_per_slot: u64,
|
||||
entries: I,
|
||||
) -> Result<()>
|
||||
where
|
||||
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;
|
||||
|
||||
|
@ -958,9 +938,9 @@ pub fn create_new_ledger(ledger_path: &str, genesis_block: &GenesisBlock) -> Res
|
|||
genesis_block.write(&ledger_path)?;
|
||||
|
||||
// Fill slot 0 with ticks that link back to the genesis_block to bootstrap the ledger.
|
||||
let blocktree = Blocktree::open_config(ledger_path, ticks_per_slot)?;
|
||||
let blocktree = Blocktree::open(ledger_path)?;
|
||||
let entries = crate::entry::create_ticks(ticks_per_slot, genesis_block.hash());
|
||||
blocktree.write_entries(0, 0, 0, &entries)?;
|
||||
blocktree.write_entries(0, 0, 0, ticks_per_slot, &entries)?;
|
||||
|
||||
Ok(entries.last().unwrap().hash)
|
||||
}
|
||||
|
@ -1079,10 +1059,12 @@ pub mod tests {
|
|||
let ticks_per_slot = 10;
|
||||
let num_slots = 10;
|
||||
let num_ticks = ticks_per_slot * num_slots;
|
||||
let ledger = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||
let ledger = Blocktree::open(&ledger_path).unwrap();
|
||||
|
||||
let ticks = create_ticks(num_ticks, Hash::default());
|
||||
ledger.write_entries(0, 0, 0, ticks.clone()).unwrap();
|
||||
ledger
|
||||
.write_entries(0, 0, 0, ticks_per_slot, ticks.clone())
|
||||
.unwrap();
|
||||
|
||||
for i in 0..num_slots {
|
||||
let meta = ledger.meta(i).unwrap().unwrap();
|
||||
|
@ -1112,6 +1094,7 @@ pub mod tests {
|
|||
num_slots,
|
||||
ticks_per_slot - 1,
|
||||
ticks_per_slot - 2,
|
||||
ticks_per_slot,
|
||||
&ticks[0..2],
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -1159,11 +1142,15 @@ pub mod tests {
|
|||
let ticks2 = ticks.split_off(num_ticks as usize);
|
||||
assert_eq!(ticks.len(), ticks2.len());
|
||||
{
|
||||
let ledger = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||
let ledger = Blocktree::open(&ledger_path).unwrap();
|
||||
|
||||
ledger.write_entries(0, 0, 0, &ticks).unwrap();
|
||||
ledger
|
||||
.write_entries(0, 0, 0, ticks_per_slot, &ticks)
|
||||
.unwrap();
|
||||
ledger.reset_slot_consumed(0).unwrap();
|
||||
ledger.write_entries(0, 0, 0, &ticks2).unwrap();
|
||||
ledger
|
||||
.write_entries(0, 0, 0, ticks_per_slot, &ticks2)
|
||||
.unwrap();
|
||||
|
||||
let ledger_ticks = ledger.get_slot_entries(0, 0, None).unwrap();
|
||||
|
||||
|
@ -1483,7 +1470,7 @@ pub mod tests {
|
|||
pub fn test_insert_data_blobs_consecutive() {
|
||||
let blocktree_path = get_tmp_ledger_path("test_insert_data_blobs_consecutive");
|
||||
{
|
||||
let blocktree = Blocktree::open_config(&blocktree_path, 32).unwrap();
|
||||
let blocktree = Blocktree::open(&blocktree_path).unwrap();
|
||||
let slot = 0;
|
||||
let parent_slot = 0;
|
||||
// Write entries
|
||||
|
@ -1618,6 +1605,7 @@ pub mod tests {
|
|||
0u64,
|
||||
0,
|
||||
(entries.len() - 1) as u64,
|
||||
16,
|
||||
&entries[entries.len() - 1..],
|
||||
)
|
||||
.unwrap();
|
||||
|
|
|
@ -12,7 +12,6 @@ use rocksdb::{
|
|||
};
|
||||
|
||||
use solana_sdk::hash::Hash;
|
||||
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
|
||||
|
||||
use std::fs;
|
||||
use std::io;
|
||||
|
@ -105,14 +104,12 @@ impl Blocktree {
|
|||
// Create the erasure column family
|
||||
let erasure_cf = ErasureCf::new(db.clone());
|
||||
|
||||
let ticks_per_slot = DEFAULT_TICKS_PER_SLOT;
|
||||
Ok(Blocktree {
|
||||
db,
|
||||
meta_cf,
|
||||
data_cf,
|
||||
erasure_cf,
|
||||
new_blobs_signals: vec![],
|
||||
ticks_per_slot,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -274,8 +274,8 @@ mod tests {
|
|||
let (ledger_path, mut blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||
debug!("ledger_path: {:?}", ledger_path);
|
||||
|
||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot)
|
||||
.expect("Expected to successfully open database ledger");
|
||||
let blocktree =
|
||||
Blocktree::open(&ledger_path).expect("Expected to successfully open database ledger");
|
||||
|
||||
// Write slot 1
|
||||
// slot 1, points at slot 0. Missing one tick
|
||||
|
@ -334,8 +334,8 @@ mod tests {
|
|||
slot 4
|
||||
|
||||
*/
|
||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot)
|
||||
.expect("Expected to successfully open database ledger");
|
||||
let blocktree =
|
||||
Blocktree::open(&ledger_path).expect("Expected to successfully open database ledger");
|
||||
|
||||
// Fork 1, ending at slot 3
|
||||
let last_slot1_entry_hash =
|
||||
|
@ -472,7 +472,9 @@ mod tests {
|
|||
|
||||
let blocktree =
|
||||
Blocktree::open(&ledger_path).expect("Expected to successfully open database ledger");
|
||||
blocktree.write_entries(1, 0, 0, &entries).unwrap();
|
||||
blocktree
|
||||
.write_entries(1, 0, 0, genesis_block.ticks_per_slot, &entries)
|
||||
.unwrap();
|
||||
let entry_height = genesis_block.ticks_per_slot + entries.len() as u64;
|
||||
let (bank_forks, bank_forks_info) =
|
||||
process_blocktree(&genesis_block, &blocktree, None).unwrap();
|
||||
|
|
|
@ -142,11 +142,13 @@ mod tests {
|
|||
let ledger_dir = "chacha_test_encrypt_file";
|
||||
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());
|
||||
let blocktree = Arc::new(Blocktree::open(&ledger_path).unwrap());
|
||||
let out_path = Path::new("test_chacha_encrypt_file_output.txt.enc");
|
||||
|
||||
let entries = make_tiny_deterministic_test_entries(32);
|
||||
blocktree.write_entries(0, 0, 0, &entries).unwrap();
|
||||
blocktree
|
||||
.write_entries(0, 0, 0, ticks_per_slot, &entries)
|
||||
.unwrap();
|
||||
|
||||
let mut key = hex!(
|
||||
"abcd1234abcd1234abcd1234abcd1234 abcd1234abcd1234abcd1234abcd1234
|
||||
|
|
|
@ -127,9 +127,11 @@ mod tests {
|
|||
let ledger_dir = "test_encrypt_file_many_keys_single";
|
||||
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());
|
||||
let blocktree = Arc::new(Blocktree::open(&ledger_path).unwrap());
|
||||
|
||||
blocktree.write_entries(0, 0, 0, &entries).unwrap();
|
||||
blocktree
|
||||
.write_entries(0, 0, 0, ticks_per_slot, &entries)
|
||||
.unwrap();
|
||||
|
||||
let out_path = Path::new("test_chacha_encrypt_file_many_keys_single_output.txt.enc");
|
||||
|
||||
|
@ -161,8 +163,10 @@ mod tests {
|
|||
let ledger_dir = "test_encrypt_file_many_keys_multiple";
|
||||
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(0, 0, 0, &entries).unwrap();
|
||||
let blocktree = Arc::new(Blocktree::open(&ledger_path).unwrap());
|
||||
blocktree
|
||||
.write_entries(0, 0, 0, ticks_per_slot, &entries)
|
||||
.unwrap();
|
||||
|
||||
let out_path = Path::new("test_chacha_encrypt_file_many_keys_multiple_output.txt.enc");
|
||||
|
||||
|
|
|
@ -282,9 +282,8 @@ pub fn new_banks_from_blocktree(
|
|||
let genesis_block =
|
||||
GenesisBlock::load(blocktree_path).expect("Expected to successfully open genesis block");
|
||||
|
||||
let (blocktree, ledger_signal_receiver) =
|
||||
Blocktree::open_with_config_signal(blocktree_path, genesis_block.ticks_per_slot)
|
||||
.expect("Expected to successfully open database ledger");
|
||||
let (blocktree, ledger_signal_receiver) = Blocktree::open_with_signal(blocktree_path)
|
||||
.expect("Expected to successfully open database ledger");
|
||||
|
||||
let (bank_forks, bank_forks_info) =
|
||||
blocktree_processor::process_blocktree(&genesis_block, &blocktree, account_paths)
|
||||
|
|
|
@ -440,7 +440,9 @@ mod test {
|
|||
|
||||
info!("Send ReplayStage an entry, should see it on the ledger writer receiver");
|
||||
let next_tick = create_ticks(1, bank.last_blockhash());
|
||||
blocktree.write_entries(1, 0, 0, next_tick.clone()).unwrap();
|
||||
blocktree
|
||||
.write_entries(1, 0, 0, genesis_block.ticks_per_slot, next_tick.clone())
|
||||
.unwrap();
|
||||
|
||||
let received_tick = ledger_writer_recv
|
||||
.recv()
|
||||
|
|
|
@ -513,8 +513,10 @@ mod tests {
|
|||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
let entries = make_tiny_test_entries(64);
|
||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||
blocktree.write_entries(1, 0, 0, &entries).unwrap();
|
||||
let blocktree = Blocktree::open(&ledger_path).unwrap();
|
||||
blocktree
|
||||
.write_entries(1, 0, 0, ticks_per_slot, &entries)
|
||||
.unwrap();
|
||||
|
||||
let cluster_info = test_cluster_info(&keypair.pubkey());
|
||||
|
||||
|
@ -575,8 +577,10 @@ mod tests {
|
|||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
let entries = make_tiny_test_entries(128);
|
||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||
blocktree.write_entries(1, 0, 0, &entries).unwrap();
|
||||
let blocktree = Blocktree::open(&ledger_path).unwrap();
|
||||
blocktree
|
||||
.write_entries(1, 0, 0, ticks_per_slot, &entries)
|
||||
.unwrap();
|
||||
|
||||
let cluster_info = test_cluster_info(&keypair.pubkey());
|
||||
|
||||
|
|
Loading…
Reference in New Issue