Skip to content

Commit

Permalink
consensus: change open_consensus_mode
Browse files Browse the repository at this point in the history
Change consensus loop to not cancel itself if the processed message is a quorum
  • Loading branch information
herr-seppia committed Jul 22, 2024
1 parent 4769ed3 commit 8fb7c1b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
12 changes: 9 additions & 3 deletions consensus/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -231,8 +232,13 @@ impl<T: Operations + 'static, D: Database + 'static> Consensus<T, D> {
}
}

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;
}
}
})
}
Expand Down
27 changes: 11 additions & 16 deletions consensus/src/execution_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}
}
}
Expand Down

0 comments on commit 8fb7c1b

Please sign in to comment.