Skip to content

Commit

Permalink
[fix] hyperledger-iroha#4256: Introduce predictable ordering after to…
Browse files Browse the repository at this point in the history
…o many failed view changes (hyperledger-iroha#4263)

Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic authored Feb 8, 2024
1 parent 7792d2c commit 513c0cf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/src/sumeragi/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ impl Sumeragi {
if cache_full || (deadline_reached && cache_non_empty) {
let transactions = self.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 = self.wsv.clone();
Expand All @@ -650,8 +651,14 @@ impl Sumeragi {
.chain(current_view_change_index, &mut new_wsv)
.sign(&self.key_pair);

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");
info!(%addr, created_in_ms=%created_in.as_millis(), block_payload_hash=%new_block.payload().hash(), "Block created");

if created_in > self.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 = 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 513c0cf

Please sign in to comment.