Skip to content

Commit

Permalink
feat: remove has_txn and exponential timeout check from block proposa…
Browse files Browse the repository at this point in the history
…l timeout
  • Loading branch information
86667 committed Oct 25, 2024
1 parent 4bb3f84 commit 8b9d622
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
19 changes: 4 additions & 15 deletions zilliqa/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,8 @@ impl Consensus {
return Ok(None);
}

let (
time_since_last_view_change,
exponential_backoff_timeout,
minimum_time_left_for_empty_block,
) = self.get_consensus_timeout_params();
let (time_since_last_view_change, exponential_backoff_timeout, _) =
self.get_consensus_timeout_params();

trace!(
"timeout reached create_next_block_on_timeout: {}",
Expand All @@ -439,15 +436,8 @@ impl Consensus {
let empty_block_timeout_ms =
self.config.consensus.empty_block_timeout.as_millis() as u64;

let has_txns_for_next_block = self.transaction_pool.has_txn_ready();

// Check if enough time elapsed or there's something in mempool or we don't have enough
// time but let's try at least until new view can happen
if time_since_last_view_change > empty_block_timeout_ms
|| has_txns_for_next_block
|| (time_since_last_view_change + minimum_time_left_for_empty_block
>= exponential_backoff_timeout)
{
// Check if enough time elapsed to propse block
if time_since_last_view_change > empty_block_timeout_ms {
if let Ok(Some((block, transactions))) = self.propose_new_block() {
self.create_next_block_on_timeout = false;
return Ok(Some((
Expand All @@ -465,7 +455,6 @@ impl Consensus {

// Now consider whether we want to timeout - the timeout duration doubles every time, so it
// Should eventually have all nodes on the same view

if time_since_last_view_change < exponential_backoff_timeout {
trace!(
"Not proceeding with view change. Current view: {} - time since last: {}, timeout requires: {}",
Expand Down
15 changes: 0 additions & 15 deletions zilliqa/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,21 +340,6 @@ impl TransactionPool {
self.hash_to_index.clear();
std::mem::take(&mut self.transactions).into_values()
}

/// Check the ready transactions in arbitrary order, for one that is Ready
pub fn has_txn_ready(&self) -> bool {
for ReadyItem { tx_index, .. } in self.ready.iter() {
// A transaction might have been ready, but it might have gotten popped
// or the sender's nonce might have increased, making it invalid. In this case,
// we will have a stale reference would still exist in the heap.
let Some(_) = self.transactions.get(tx_index) else {
continue;
};

return true;
}
false
}
}

#[cfg(test)]
Expand Down

0 comments on commit 8b9d622

Please sign in to comment.