Consolidate logic with entry helper function
Creates an entry and updates the hash. Also cleanup blobs creation in test_replay
This commit is contained in:
parent
aec44e3761
commit
f1221d724d
|
@ -311,6 +311,12 @@ impl EntrySlice for [Entry] {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn next_entry_mut(start: &mut Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Entry {
|
||||
let entry = Entry::new(&start, 0, num_hashes, transactions);
|
||||
*start = entry.id;
|
||||
entry
|
||||
}
|
||||
|
||||
/// Creates the next entries for given transactions, outputs
|
||||
/// updates start_hash to id of last Entry, sets num_hashes to 0
|
||||
pub fn next_entries_mut(
|
||||
|
@ -389,8 +395,7 @@ pub fn next_entries(
|
|||
pub fn create_ticks(num_ticks: u64, mut hash: Hash) -> Vec<Entry> {
|
||||
let mut ticks = Vec::with_capacity(num_ticks as usize);
|
||||
for _ in 0..num_ticks {
|
||||
let new_tick = Entry::new(&hash, 0, 1, vec![]);
|
||||
hash = new_tick.id;
|
||||
let new_tick = next_entry_mut(&mut hash, 1, vec![]);
|
||||
ticks.push(new_tick);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//! managing the schedule for leader rotation
|
||||
|
||||
use crate::bank::Bank;
|
||||
use crate::entry::{create_ticks, Entry};
|
||||
use crate::entry::{create_ticks, next_entry_mut, Entry};
|
||||
use crate::voting_keypair::VotingKeypair;
|
||||
use bincode::serialize;
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
|
@ -421,8 +421,8 @@ pub fn make_active_set_entries(
|
|||
*last_tick_id,
|
||||
0,
|
||||
);
|
||||
let transfer_entry = Entry::new(last_entry_id, 0, 1, vec![transfer_tx]);
|
||||
let mut last_entry_id = transfer_entry.id;
|
||||
let mut last_entry_id = *last_entry_id;
|
||||
let transfer_entry = next_entry_mut(&mut last_entry_id, 1, vec![transfer_tx]);
|
||||
|
||||
// 2) Create and register a vote account for active_keypair
|
||||
let voting_keypair = VotingKeypair::new_local(active_keypair);
|
||||
|
@ -430,14 +430,12 @@ pub fn make_active_set_entries(
|
|||
|
||||
let new_vote_account_tx =
|
||||
VoteTransaction::new_account(active_keypair, vote_account_id, *last_tick_id, 1, 1);
|
||||
let new_vote_account_entry = Entry::new(&last_entry_id, 0, 1, vec![new_vote_account_tx]);
|
||||
last_entry_id = new_vote_account_entry.id;
|
||||
let new_vote_account_entry = next_entry_mut(&mut last_entry_id, 1, vec![new_vote_account_tx]);
|
||||
|
||||
// 3) Create vote entry
|
||||
let vote_tx =
|
||||
VoteTransaction::new_vote(&voting_keypair, tick_height_to_vote_on, *last_tick_id, 0);
|
||||
let vote_entry = Entry::new(&last_entry_id, 0, 1, vec![vote_tx]);
|
||||
last_entry_id = vote_entry.id;
|
||||
let vote_entry = next_entry_mut(&mut last_entry_id, 1, vec![vote_tx]);
|
||||
|
||||
// 4) Create the ending empty ticks
|
||||
let mut txs = vec![transfer_entry, new_vote_account_entry, vote_entry];
|
||||
|
|
|
@ -363,7 +363,7 @@ mod test {
|
|||
};
|
||||
use crate::cluster_info::{ClusterInfo, Node};
|
||||
use crate::entry::create_ticks;
|
||||
use crate::entry::Entry;
|
||||
use crate::entry::{next_entry_mut, Entry};
|
||||
use crate::fullnode::new_bank_from_ledger;
|
||||
use crate::genesis_block::GenesisBlock;
|
||||
use crate::leader_scheduler::{make_active_set_entries, LeaderSchedulerConfig};
|
||||
|
@ -469,8 +469,7 @@ mod test {
|
|||
let total_entries_to_send = 2 * ticks_per_slot as usize - 2;
|
||||
let mut entries_to_send = vec![];
|
||||
while entries_to_send.len() < total_entries_to_send {
|
||||
let entry = Entry::new(&mut last_id, 0, 1, vec![]);
|
||||
last_id = entry.id;
|
||||
let entry = next_entry_mut(&mut last_id, 1, vec![]);
|
||||
entries_to_send.push(entry);
|
||||
}
|
||||
|
||||
|
@ -706,8 +705,7 @@ mod test {
|
|||
let leader_rotation_index = (active_window_tick_length - tick_height - 1) as usize;
|
||||
let mut expected_last_id = Hash::default();
|
||||
for i in 0..total_entries_to_send {
|
||||
let entry = Entry::new(&mut last_id, 0, num_hashes, vec![]);
|
||||
last_id = entry.id;
|
||||
let entry = next_entry_mut(&mut last_id, num_hashes, vec![]);
|
||||
blocktree
|
||||
.write_entries(
|
||||
DEFAULT_SLOT_HEIGHT,
|
||||
|
@ -758,8 +756,7 @@ mod test {
|
|||
let mut last_id = Hash::default();
|
||||
let mut entries = Vec::new();
|
||||
for _ in 0..5 {
|
||||
let entry = Entry::new(&mut last_id, 0, 1, vec![]); //just ticks
|
||||
last_id = entry.id;
|
||||
let entry = next_entry_mut(&mut last_id, 1, vec![]); //just ticks
|
||||
entries.push(entry);
|
||||
}
|
||||
|
||||
|
|
43
src/tvu.rs
43
src/tvu.rs
|
@ -213,13 +213,13 @@ pub mod tests {
|
|||
use crate::bank::Bank;
|
||||
use crate::blocktree::get_tmp_ledger_path;
|
||||
use crate::cluster_info::{ClusterInfo, Node};
|
||||
use crate::entry::Entry;
|
||||
use crate::entry::next_entry_mut;
|
||||
use crate::entry::EntrySlice;
|
||||
use crate::genesis_block::GenesisBlock;
|
||||
use crate::gossip_service::GossipService;
|
||||
use crate::packet::SharedBlob;
|
||||
use crate::packet::index_blobs;
|
||||
use crate::storage_stage::STORAGE_ROTATE_TEST_COUNT;
|
||||
use crate::streamer;
|
||||
use bincode::serialize;
|
||||
use solana_sdk::system_transaction::SystemTransaction;
|
||||
use std::fs::remove_dir_all;
|
||||
use std::time::Duration;
|
||||
|
@ -372,10 +372,8 @@ pub mod tests {
|
|||
let transfer_amount = 501;
|
||||
let bob_keypair = Keypair::new();
|
||||
for i in 0..num_transfers {
|
||||
let entry0 = Entry::new(&cur_hash, 0, i, vec![]);
|
||||
cur_hash = entry0.id;
|
||||
let entry_tick0 = Entry::new(&cur_hash, 0, i + 1, vec![]);
|
||||
cur_hash = entry_tick0.id;
|
||||
let entry0 = next_entry_mut(&mut cur_hash, i, vec![]);
|
||||
let entry_tick0 = next_entry_mut(&mut cur_hash, i + 1, vec![]);
|
||||
|
||||
let tx0 = SystemTransaction::new_account(
|
||||
&mint_keypair,
|
||||
|
@ -384,30 +382,19 @@ pub mod tests {
|
|||
cur_hash,
|
||||
0,
|
||||
);
|
||||
let entry_tick1 = Entry::new(&cur_hash, 0, i + 1, vec![]);
|
||||
cur_hash = entry_tick1.id;
|
||||
let entry1 = Entry::new(&cur_hash, 0, i + num_transfers, vec![tx0]);
|
||||
let entry_tick2 = Entry::new(&entry1.id, 0, i + 1, vec![]);
|
||||
cur_hash = entry_tick2.id;
|
||||
let entry_tick1 = next_entry_mut(&mut cur_hash, i + 1, vec![]);
|
||||
let entry1 = next_entry_mut(&mut cur_hash, i + num_transfers, vec![tx0]);
|
||||
let entry_tick2 = next_entry_mut(&mut cur_hash, i + 1, vec![]);
|
||||
|
||||
alice_ref_balance -= transfer_amount;
|
||||
|
||||
for entry in vec![entry0, entry_tick0, entry_tick1, entry1, entry_tick2] {
|
||||
let b = SharedBlob::default();
|
||||
{
|
||||
let mut w = b.write().unwrap();
|
||||
w.set_index(blob_idx);
|
||||
blob_idx += 1;
|
||||
w.forward(true);
|
||||
|
||||
let serialized_entry = serialize(&entry).unwrap();
|
||||
|
||||
w.data_mut()[..serialized_entry.len()].copy_from_slice(&serialized_entry);
|
||||
w.set_size(serialized_entry.len());
|
||||
w.meta.set_addr(&tvu_addr);
|
||||
}
|
||||
msgs.push(b);
|
||||
}
|
||||
let entries = vec![entry0, entry_tick0, entry_tick1, entry1, entry_tick2];
|
||||
let blobs = entries.to_shared_blobs();
|
||||
index_blobs(&blobs, &mut blob_idx, &vec![0; blobs.len()]);
|
||||
blobs
|
||||
.iter()
|
||||
.for_each(|b| b.write().unwrap().meta.set_addr(&tvu_addr));
|
||||
msgs.extend(blobs.into_iter());
|
||||
}
|
||||
|
||||
// send the blobs into the socket
|
||||
|
|
Loading…
Reference in New Issue