Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify candidate block header #1252

Merged
merged 12 commits into from
Jan 12, 2024
12 changes: 5 additions & 7 deletions consensus/src/ratification/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use node_data::message::{AsyncQueue, Message, Payload, Topics};
use std::sync::Arc;
use tokio::sync::Mutex;

use tracing::{debug, error};
use tracing::{error, info, Instrument};

pub struct RatificationStep<T, DB> {
handler: Arc<Mutex<handler::RatificationHandler>>,
Expand Down Expand Up @@ -54,12 +54,8 @@ impl<T: Operations + 'static, DB: Database> RatificationStep<T, DB> {
},
);

debug!(
event = "voting",
vtype = "ratification",
hash = to_str(&result.hash),
validation_bitset = result.sv.bitset
);
// Publish ratification vote
info!(event = "send_vote", validation_bitset = result.sv.bitset);

// Publish
outbound.send(msg.clone()).await.unwrap_or_else(|err| {
Expand Down Expand Up @@ -123,13 +119,15 @@ impl<T: Operations + 'static, DB: Database> RatificationStep<T, DB> {

if ctx.am_member(committee) {
let mut handler = self.handler.lock().await;
let hash = to_str(&handler.validation_result().hash);

let vote_msg = Self::try_vote(
&ctx.round_update,
ctx.iteration,
handler.validation_result(),
ctx.outbound.clone(),
)
.instrument(tracing::info_span!("ratification", hash,))
.await;

// Collect my own vote
Expand Down
19 changes: 10 additions & 9 deletions consensus/src/validation/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use node_data::message::{self, AsyncQueue, Message, Payload, Topics};
use std::sync::Arc;
use tokio::sync::Mutex;
use tokio::task::JoinSet;
use tracing::{debug, error, Instrument};
use tracing::{debug, error, info, Instrument};

pub struct ValidationStep<T> {
handler: Arc<Mutex<handler::ValidationHandler>>,
Expand All @@ -42,7 +42,7 @@ impl<T: Operations + 'static> ValidationStep<T> {
)
.await
}
.instrument(tracing::info_span!("voting", hash)),
.instrument(tracing::info_span!("validation", hash,)),
);
}

Expand All @@ -54,32 +54,33 @@ impl<T: Operations + 'static> ValidationStep<T> {
inbound: AsyncQueue<Message>,
executor: Arc<Mutex<T>>,
) {
let hash = candidate.header().hash;
let header = candidate.header();

// A Validation step with empty/default Block produces a Nil Vote
if hash == [0u8; 32] {
if header.hash == [0u8; 32] {
goshawk-3 marked this conversation as resolved.
Show resolved Hide resolved
Self::cast_vote([0u8; 32], ru, iteration, outbound, inbound).await;
return;
}

// Verify candidate header all fields except the winning certificate
// Verify candidate header (all fields except the winning certificate)
// NB: Winning certificate is produced only on reaching consensus
if let Err(err) = executor
.lock()
.await
.verify_block_header(candidate.header(), true)
.verify_block_header(header, true)
.await
{
error!(event = "invalid_header", ?err);
error!(event = "invalid_header", ?err, ?header);
return;
};

// Call Verify State Transition to make sure transactions set is valid
if let Err(err) = Self::call_vst(candidate, ru, executor).await {
error!(event = "failed_vst_call", ?err);
goshawk-3 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Self::cast_vote(hash, ru, iteration, outbound, inbound).await;
Self::cast_vote(header.hash, ru, iteration, outbound, inbound).await;
}

async fn cast_vote(
Expand All @@ -106,7 +107,7 @@ impl<T: Operations + 'static> ValidationStep<T> {
);

// Publish validation vote
debug!(event = "voting", vtype = "validation", hash = to_str(&hash));
info!(event = "send_vote");

// Publish
outbound.send(msg.clone()).await.unwrap_or_else(|err| {
Expand Down