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

Allow Proposal requesting from any DA node #3619

Merged
merged 6 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions crates/task-impls/src/consensus/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ pub async fn create_and_send_proposal<TYPES: NodeType, V: Versions>(
proposed_leaf.view_number(),
);

consensus
.write()
.await
.update_last_proposed_view(message.clone())?;

jparr721 marked this conversation as resolved.
Show resolved Hide resolved
async_sleep(Duration::from_millis(round_start_delay)).await;

broadcast_event(
Expand Down
2 changes: 1 addition & 1 deletion crates/task-impls/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> ConsensusTaskSt
}

if let Err(e) = self.consensus.write().await.update_high_qc(qc.clone()) {
tracing::error!("{e:?}");
tracing::trace!("{e:?}");
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 was intentional. This is a useless log and noisy as heck.

}
debug!(
"Attempting to publish proposal after forming a QC for view {}",
Expand Down
97 changes: 51 additions & 46 deletions crates/task-impls/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,24 +469,26 @@ pub async fn validate_proposal_safety_and_liveness<TYPES: NodeType, V: Versions>
},
};

if let Err(e) = consensus
.write()
.await
.update_validated_state_map(view_number, view.clone())
{
tracing::trace!("{e:?}");
}
consensus
.write()
.await
.update_saved_leaves(proposed_leaf.clone());
let mut consensus_write = consensus.write().await;
if let Err(e) = consensus_write.update_validated_state_map(view_number, view.clone()) {
tracing::trace!("{e:?}");
}
consensus_write.update_saved_leaves(proposed_leaf.clone());

// Broadcast that we've updated our consensus state so that other tasks know it's safe to grab.
broadcast_event(
Arc::new(HotShotEvent::ValidatedStateUpdated(view_number, view)),
&event_stream,
)
.await;
// Update our internal storage of the proposal. The proposal is valid, so
// we swallow this error and just log if it occurs.
if let Err(e) = consensus_write.update_last_proposed_view(proposal.clone()) {
tracing::debug!("Internal proposal update failed; error = {e:#}");
};

// Broadcast that we've updated our consensus state so that other tasks know it's safe to grab.
broadcast_event(
Arc::new(HotShotEvent::ValidatedStateUpdated(view_number, view)),
&event_stream,
)
.await;
}

UpgradeCertificate::validate(
&proposal.data.upgrade_certificate,
Expand All @@ -505,37 +507,39 @@ pub async fn validate_proposal_safety_and_liveness<TYPES: NodeType, V: Versions>
// passes.

// Liveness check.
let read_consensus = consensus.read().await;
let liveness_check = justify_qc.view_number() > read_consensus.locked_view();

// Safety check.
// Check if proposal extends from the locked leaf.
let outcome = read_consensus.visit_leaf_ancestors(
justify_qc.view_number(),
Terminator::Inclusive(read_consensus.locked_view()),
false,
|leaf, _, _| {
// if leaf view no == locked view no then we're done, report success by
// returning true
leaf.view_number() != read_consensus.locked_view()
},
);
let safety_check = outcome.is_ok();

ensure!(safety_check || liveness_check, {
if let Err(e) = outcome {
broadcast_event(
Event {
view_number,
event: EventType::Error { error: Arc::new(e) },
},
&event_sender,
)
.await;
}
{
Copy link
Contributor Author

@jparr721 jparr721 Aug 28, 2024

Choose a reason for hiding this comment

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

These dangling handles on the consensus type bit me while I was developing this. Multi-line accesses/mutations are in their own scope to ensure that lower calls do not block waiting for a lock that'll never be available. I just wrapped it so that way the consensus handles in this file go out of scope. It's on the roadmap to refactor a lot of this during the dependency refactor rollout.

let read_consensus = consensus.read().await;
let liveness_check = justify_qc.view_number() > read_consensus.locked_view();

// Safety check.
// Check if proposal extends from the locked leaf.
let outcome = read_consensus.visit_leaf_ancestors(
justify_qc.view_number(),
Terminator::Inclusive(read_consensus.locked_view()),
false,
|leaf, _, _| {
// if leaf view no == locked view no then we're done, report success by
// returning true
leaf.view_number() != read_consensus.locked_view()
},
);
let safety_check = outcome.is_ok();

ensure!(safety_check || liveness_check, {
if let Err(e) = outcome {
broadcast_event(
Event {
view_number,
event: EventType::Error { error: Arc::new(e) },
},
&event_sender,
)
.await;
}

format!("Failed safety and liveness check \n High QC is {:?} Proposal QC is {:?} Locked view is {:?}", read_consensus.high_qc(), proposal.data.clone(), read_consensus.locked_view())
});
format!("Failed safety and liveness check \n High QC is {:?} Proposal QC is {:?} Locked view is {:?}", read_consensus.high_qc(), proposal.data.clone(), read_consensus.locked_view())
});
}

// We accept the proposal, notify the application layer

Expand All @@ -550,6 +554,7 @@ pub async fn validate_proposal_safety_and_liveness<TYPES: NodeType, V: Versions>
&event_sender,
)
.await;

// Notify other tasks
broadcast_event(
Arc::new(HotShotEvent::QuorumProposalValidated(
Expand Down
2 changes: 1 addition & 1 deletion crates/task-impls/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl<
MessageKind::<TYPES>::from_consensus_message(SequencingMessage::General(
GeneralConsensusMessage::ProposalRequested(req.clone(), signature),
)),
TransmitType::Direct(membership.leader(req.view_number)),
TransmitType::DaCommitteeBroadcast,
),
HotShotEvent::QuorumProposalResponseSend(sender_key, proposal) => (
sender_key.clone(),
Expand Down
4 changes: 0 additions & 4 deletions crates/task-impls/src/quorum_proposal/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ impl<TYPES: NodeType, V: Versions> ProposalDependencyHandle<TYPES, V> {
proposed_leaf.view_number(),
);

self.consensus
.write()
.await
.update_last_proposed_view(message.clone())?;
jparr721 marked this conversation as resolved.
Show resolved Hide resolved
async_sleep(Duration::from_millis(self.round_start_delay)).await;
broadcast_event(
Arc::new(HotShotEvent::QuorumProposalSend(
Expand Down
1 change: 1 addition & 0 deletions crates/task-impls/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type Signature<TYPES> =
impl<TYPES: NodeType, I: NodeImplementation<TYPES>> TaskState for NetworkRequestState<TYPES, I> {
type Event = HotShotEvent<TYPES>;

#[instrument(skip_all, target = "NetworkRequestState", fields(id = self.id))]
async fn handle_event(
&mut self,
event: Arc<Self::Event>,
Expand Down