Skip to content

Commit

Permalink
[fix] #4083: Introduce predictable ordering after too many failed vie…
Browse files Browse the repository at this point in the history
…w changes

Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Feb 7, 2024
1 parent e1b9751 commit a147031
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/sumeragi/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ fn process_message_independent(
if cache_full || (deadline_reached && cache_non_empty) {
let transactions = sumeragi.transaction_cache.clone();
info!(%addr, txns=%transactions.len(), "Creating block...");
let create_block_start_time = Instant::now();

// TODO: properly process triggers!
let mut new_wsv = sumeragi.wsv.clone();
Expand All @@ -625,10 +626,15 @@ fn process_message_independent(
}
};

let created_in = create_block_start_time.elapsed();
if let Some(current_topology) = current_topology.is_consensus_required() {
info!(%addr, block_payload_hash=%new_block.payload().hash(), "Block created");
*voting_block = Some(VotingBlock::new(new_block.clone(), new_wsv));
info!(%addr, created_in_ms=%created_in.as_millis(), block_payload_hash=%new_block.payload().hash(), "Block created");

if created_in > sumeragi.pipeline_time() / 2 {
warn!("Creating block takes too much time. This might prevent consensus from operating. Consider increasing `commit_time` or decreasing `max_transactions_in_block`");
}

*voting_block = Some(VotingBlock::new(new_block.clone(), new_wsv));
let msg = MessagePacket::new(
view_change_proof_chain.clone(),
Some(BlockCreated::from(new_block).into()),
Expand Down
20 changes: 20 additions & 0 deletions core/src/sumeragi/network_topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,26 @@ impl Topology {
// Rotate all once for every view_change
topology.rotate_all_n(view_change_index);

{
// FIXME: This is a hack to prevent consensus from running amock due to
// a bug in the implementation by reverting to predictable ordering

let view_change_limit: usize = view_change_index
.saturating_sub(10)
.try_into()
.expect("u64 must fit into usize");

if view_change_limit > 1 {
iroha_logger::error!("Restarting consensus(internal bug). Report to developers");
let mut peers: Vec<_> = topology.ordered_peers.iter().cloned().collect();

peers.sort();
let peers_count = peers.len();
peers.rotate_right(view_change_limit % peers_count);
topology = Topology::new(peers.into_iter().collect());
}
}

topology
}

Expand Down

0 comments on commit a147031

Please sign in to comment.