Fix tests and move bank dependency slightly

This commit is contained in:
Tyera Eulberg
2019-02-27 16:07:55 -07:00
committed by Grimes
parent a67a88c8ef
commit 873007bae1
3 changed files with 27 additions and 31 deletions

View File

@ -82,7 +82,7 @@ impl BlockstreamService {
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
debug!("Blockstream error: {:?}, {:?}", e, blockstream.output); debug!("Blockstream error: {:?}, {:?}", e, blockstream.output);
}); });
if 0 == entry_meta.num_ticks_left_in_slot { if entry_meta.is_end_of_slot {
blockstream.queued_block = Some(BlockData { blockstream.queued_block = Some(BlockData {
slot: entry_meta.slot, slot: entry_meta.slot,
tick_height: entry_meta.tick_height, tick_height: entry_meta.tick_height,
@ -144,7 +144,7 @@ mod test {
tick_height: x, tick_height: x,
slot: slot_height, slot: slot_height,
slot_leader: leader_id, slot_leader: leader_id,
num_ticks_left_in_slot: ticks_per_slot - ((x + 1) % ticks_per_slot), is_end_of_slot: x == ticks_per_slot - 1,
parent_slot, parent_slot,
entry, entry,
}; };
@ -159,7 +159,7 @@ mod test {
tick_height: ticks_per_slot - 1, tick_height: ticks_per_slot - 1,
slot: 0, slot: 0,
slot_leader: leader_id, slot_leader: leader_id,
num_ticks_left_in_slot: 0, is_end_of_slot: true,
parent_slot: None, parent_slot: None,
entry, entry,
}; };

View File

@ -29,7 +29,7 @@ pub struct EntryMeta {
pub tick_height: u64, pub tick_height: u64,
pub slot: u64, pub slot: u64,
pub slot_leader: Pubkey, pub slot_leader: Pubkey,
pub num_ticks_left_in_slot: u64, pub is_end_of_slot: bool,
pub parent_slot: Option<u64>, pub parent_slot: Option<u64>,
pub entry: Entry, pub entry: Entry,
} }
@ -40,7 +40,7 @@ impl EntryMeta {
tick_height: 0, tick_height: 0,
slot: 0, slot: 0,
slot_leader: Pubkey::default(), slot_leader: Pubkey::default(),
num_ticks_left_in_slot: 0, is_end_of_slot: false,
parent_slot: None, parent_slot: None,
entry, entry,
} }

View File

@ -301,10 +301,11 @@ impl ReplayStage {
if !entries.is_empty() { if !entries.is_empty() {
if let Err(e) = Self::forward_entries( if let Err(e) = Self::forward_entries(
&entries, entries.clone(),
slot, slot,
current_leader_id, current_leader_id,
&bank, bank.ticks_per_slot(),
bank.tick_height(),
&blocktree, &blocktree,
&forward_entry_sender, &forward_entry_sender,
) { ) {
@ -437,34 +438,36 @@ impl ReplayStage {
} }
fn forward_entries( fn forward_entries(
entries: &[Entry], entries: Vec<Entry>,
slot: u64, slot: u64,
slot_leader: Pubkey, slot_leader: Pubkey,
bank: &Arc<Bank>, ticks_per_slot: u64,
bank_tick_height: u64,
blocktree: &Arc<Blocktree>, blocktree: &Arc<Blocktree>,
forward_entry_sender: &EntrySender, forward_entry_sender: &EntrySender,
) -> Result<()> { ) -> Result<()> {
let parent_slot = blocktree.meta(slot).unwrap().map(|meta| meta.parent_slot); let blocktree_meta = blocktree.meta(slot).unwrap().unwrap();
let mut entry_tick_height = bank.tick_height(); let parent_slot = if slot == 0 {
let mut num_ticks_left_in_slot = None
bank.ticks_per_slot() - entry_tick_height % bank.ticks_per_slot() - 1; } else {
Some(blocktree_meta.parent_slot)
};
let mut tick_height = bank_tick_height;
let mut entries_with_meta = Vec::new(); let mut entries_with_meta = Vec::new();
for entry in entries.iter() { for entry in entries.into_iter() {
if entry.is_tick() { if entry.is_tick() {
entry_tick_height += 1; tick_height += 1;
if num_ticks_left_in_slot == 0 {
num_ticks_left_in_slot = bank.ticks_per_slot();
} }
num_ticks_left_in_slot -= 1; let is_end_of_slot = (tick_height + 1 % ticks_per_slot) == 0;
} let entry_meta = EntryMeta {
entries_with_meta.push(EntryMeta { tick_height,
tick_height: entry_tick_height,
slot, slot,
slot_leader, slot_leader,
num_ticks_left_in_slot, is_end_of_slot,
parent_slot, parent_slot,
entry: entry.clone(), entry,
}); };
entries_with_meta.push(entry_meta);
} }
forward_entry_sender.send(entries_with_meta)?; forward_entry_sender.send(entries_with_meta)?;
Ok(()) Ok(())
@ -566,7 +569,6 @@ mod test {
let my_node = Node::new_localhost_with_pubkey(my_id); let my_node = Node::new_localhost_with_pubkey(my_id);
// Set up the cluster info // Set up the cluster info
let cluster_info_me = Arc::new(RwLock::new(ClusterInfo::new(my_node.info.clone()))); let cluster_info_me = Arc::new(RwLock::new(ClusterInfo::new(my_node.info.clone())));
let (ledger_entry_sender, _ledger_entry_receiver) = channel();
let mut last_entry_id = Hash::default(); let mut last_entry_id = Hash::default();
let mut current_blob_index = 0; let mut current_blob_index = 0;
let mut last_id = Hash::default(); let mut last_id = Hash::default();
@ -584,12 +586,9 @@ mod test {
&bank, &bank,
&cluster_info_me, &cluster_info_me,
&voting_keypair, &voting_keypair,
&ledger_entry_sender,
&mut current_blob_index, &mut current_blob_index,
&mut last_entry_id, &mut last_entry_id,
&Arc::new(RpcSubscriptions::default()), &Arc::new(RpcSubscriptions::default()),
0,
None,
); );
match res { match res {
@ -609,12 +608,9 @@ mod test {
&bank, &bank,
&cluster_info_me, &cluster_info_me,
&voting_keypair, &voting_keypair,
&ledger_entry_sender,
&mut current_blob_index, &mut current_blob_index,
&mut last_entry_id, &mut last_entry_id,
&Arc::new(RpcSubscriptions::default()), &Arc::new(RpcSubscriptions::default()),
0,
None,
); );
match res { match res {