From 8fb7c1b8c9da4930e1cacbf3c52b870015afe1b5 Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Mon, 22 Jul 2024 10:52:52 +0200 Subject: [PATCH] consensus: change open_consensus_mode Change consensus loop to not cancel itself if the processed message is a quorum --- consensus/src/consensus.rs | 12 +++++++++--- consensus/src/execution_ctx.rs | 27 +++++++++++---------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/consensus/src/consensus.rs b/consensus/src/consensus.rs index 6a4a503e5a..95c0915410 100644 --- a/consensus/src/consensus.rs +++ b/consensus/src/consensus.rs @@ -5,6 +5,7 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use crate::commons::{ConsensusError, Database, QuorumMsgSender, RoundUpdate}; +use crate::config::CONSENSUS_MAX_ITER; use crate::operations::Operations; use crate::phase::Phase; @@ -15,7 +16,7 @@ use crate::proposal; use crate::queue::MsgRegistry; use crate::user::provisioners::Provisioners; use crate::{ratification, validation}; -use tracing::{debug, info, Instrument}; +use tracing::{debug, error, info, Instrument}; use crate::iteration_ctx::IterationCtx; use crate::step_votes_reg::AttInfoRegistry; @@ -231,8 +232,13 @@ impl Consensus { } } - iter_ctx.on_close(); - iter += 1; + if iter >= CONSENSUS_MAX_ITER - 1 { + error!("Trying to move to an out of bound iteration this should be a bug"); + error!("Sticking to the same iter {iter}"); + } else { + iter_ctx.on_close(); + iter += 1; + } } }) } diff --git a/consensus/src/execution_ctx.rs b/consensus/src/execution_ctx.rs index f60640ac79..0525c7b598 100644 --- a/consensus/src/execution_ctx.rs +++ b/consensus/src/execution_ctx.rs @@ -24,9 +24,7 @@ use node_data::StepName; use crate::config::{CONSENSUS_MAX_ITER, EMERGENCY_MODE_ITERATION_THRESHOLD}; use crate::ratification::step::RatificationStep; use crate::validation::step::ValidationStep; -use node_data::message::payload::{ - QuorumType, RatificationResult, ValidationResult, Vote, -}; +use node_data::message::payload::{QuorumType, ValidationResult}; use std::sync::Arc; use std::time::Duration; use tokio::sync::Mutex; @@ -158,20 +156,14 @@ impl<'a, DB: Database, T: Operations + 'static> ExecutionCtx<'a, DB, T> { match time::timeout_at(deadline, inbound.recv()).await { // Inbound message event Ok(Ok(msg)) => { - let success_quorum = match &msg.payload { - Payload::Quorum(q) => matches!( - q.att.result, - RatificationResult::Success(Vote::Valid(_)) - ), - _ => false, - }; - if let Some(step_result) = self.process_inbound_msg(phase.clone(), msg).await { - if open_consensus_mode && !success_quorum { - // In open consensus mode, consensus step is - // terminated only in case of a success quorum + if open_consensus_mode { + // In open consensus mode, consensus step is never + // terminated. + // The acceptor will cancel the consensus if the + // block is accepted continue; } @@ -186,8 +178,11 @@ impl<'a, DB: Database, T: Operations + 'static> ExecutionCtx<'a, DB, T> { // Increase timeout for next execution of this step and move on. Err(_) => { info!(event = "timeout-ed"); - - return self.process_timeout_event(phase).await; + if open_consensus_mode { + error!("Timeout detected during last step running. This should never happen") + } else { + return self.process_timeout_event(phase).await; + } } } }