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

[AUDIT][Med/Low Severity] Fix race condition in state update for block building #3508

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 37 additions & 19 deletions crates/task-impls/src/quorum_proposal_recv/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,26 @@ async fn validate_proposal_liveness<TYPES: NodeType, I: NodeImplementation<TYPES
)
.await;

let cur_view = task_state.cur_view;
if let Err(e) = update_view::<TYPES>(
view_number,
event_sender,
task_state.timeout,
OuterConsensus::new(Arc::clone(&task_state.consensus.inner_consensus)),
&mut task_state.cur_view,
&mut task_state.cur_view_time,
&mut task_state.timeout_task,
&task_state.output_event_stream,
SEND_VIEW_CHANGE_EVENT,
task_state.quorum_membership.leader(cur_view) == task_state.public_key,
)
.await
{
debug!("Liveness Branch - Failed to update view; error = {e:#}");
}

if !liveness_check {
bail!("Liveness invalid.");
bail!("Quorum Proposal failed the liveness check");
}

Ok(QuorumProposalValidity::Liveness)
Expand Down Expand Up @@ -139,24 +157,6 @@ pub(crate) async fn handle_quorum_proposal_recv<TYPES: NodeType, I: NodeImplemen
bail!("Invalid justify_qc in proposal for view {}", *view_number);
}

// NOTE: We could update our view with a valid TC but invalid QC, but that is not what we do here
if let Err(e) = update_view::<TYPES>(
view_number,
event_sender,
task_state.timeout,
OuterConsensus::new(Arc::clone(&task_state.consensus.inner_consensus)),
&mut task_state.cur_view,
&mut task_state.cur_view_time,
&mut task_state.timeout_task,
&task_state.output_event_stream,
SEND_VIEW_CHANGE_EVENT,
task_state.quorum_membership.leader(cur_view) == task_state.public_key,
)
.await
{
debug!("Failed to update view; error = {e:#}");
}

// Get the parent leaf and state.
let mut parent_leaf = task_state
.consensus
Expand Down Expand Up @@ -238,5 +238,23 @@ pub(crate) async fn handle_quorum_proposal_recv<TYPES: NodeType, I: NodeImplemen
)
.await?;

// NOTE: We could update our view with a valid TC but invalid QC, but that is not what we do here
if let Err(e) = update_view::<TYPES>(
view_number,
event_sender,
task_state.timeout,
OuterConsensus::new(Arc::clone(&task_state.consensus.inner_consensus)),
&mut task_state.cur_view,
&mut task_state.cur_view_time,
&mut task_state.timeout_task,
&task_state.output_event_stream,
SEND_VIEW_CHANGE_EVENT,
task_state.quorum_membership.leader(cur_view) == task_state.public_key,
)
.await
{
debug!("Full Branch - Failed to update view; error = {e:#}");
}

Ok(QuorumProposalValidity::Fully)
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ async fn test_quorum_proposal_recv_task() {
)]];

let expectations = vec![Expectations::from_outputs(vec![
exact(ViewChange(ViewNumber::new(2))),
exact(UpdateHighQc(proposals[1].data.justify_qc.clone())),
exact(ValidatedStateUpdated(
ViewNumber::new(2),
Expand All @@ -95,6 +94,7 @@ async fn test_quorum_proposal_recv_task() {
proposals[1].data.clone(),
leaves[0].clone(),
)),
exact(ViewChange(ViewNumber::new(2))),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a serial output, so this test changed but the liveness test did not need to.

])];

let state = QuorumProposalRecvTaskState::<TestTypes, MemoryImpl>::create_from(&handle).await;
Expand Down