Skip to content

Commit

Permalink
Determine transaction indexes in PohRecorder; add field to WorkingBank
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Jun 7, 2022
1 parent ff74b86 commit d44da7e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions poh/src/poh_recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub struct WorkingBank {
pub start: Arc<Instant>,
pub min_tick_height: u64,
pub max_tick_height: u64,
pub transaction_index: usize,
}

#[derive(Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -501,6 +502,7 @@ impl PohRecorder {
start: Arc::new(Instant::now()),
min_tick_height: bank.tick_height(),
max_tick_height: bank.max_tick_height(),
transaction_index: 0,
};
trace!("new working bank");
assert_eq!(working_bank.bank.ticks_per_slot(), self.ticks_per_slot());
Expand Down Expand Up @@ -756,9 +758,9 @@ impl PohRecorder {
self.flush_cache_no_tick_us += flush_cache_time.as_us();
flush_cache_res?;

let working_bank = self
let mut working_bank = self
.working_bank
.as_ref()
.as_mut()
.ok_or(PohRecorderError::MaxHeightReached)?;
if bank_slot != working_bank.bank.slot() {
return Err(PohRecorderError::MaxHeightReached);
Expand All @@ -774,6 +776,7 @@ impl PohRecorder {
drop(poh_lock);

if let Some(poh_entry) = record_mixin_res {
let num_transactions = transactions.len();
let (send_entry_res, send_entry_time) = measure!(
{
let entry = Entry {
Expand All @@ -788,7 +791,14 @@ impl PohRecorder {
);
self.send_entry_us += send_entry_time.as_us();
send_entry_res?;
return Ok(vec![]);
let transaction_index_next_batch = working_bank
.transaction_index
.saturating_add(num_transactions);
let transaction_indexes: Vec<_> =
(working_bank.transaction_index..transaction_index_next_batch).collect();
working_bank.transaction_index = transaction_index_next_batch;
self.working_bank = Some(working_bank.clone());
return Ok(transaction_indexes);
}

// record() might fail if the next PoH hash needs to be a tick. But that's ok, tick()
Expand Down

0 comments on commit d44da7e

Please sign in to comment.