Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalajiarun committed Dec 5, 2024
1 parent 3739e25 commit 1f2e658
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.
4 changes: 2 additions & 2 deletions consensus/consensus-types/src/pipelined_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ impl PipelinedBlock {
.expect("pre_commit_result_rx missing.")
}

pub fn set_qc(&self, qc: Option<Arc<QuorumCert>>) {
*self.block_qc.lock() = qc;
pub fn set_qc(&self, qc: Arc<QuorumCert>) {
*self.block_qc.lock() = Some(qc)
}
}

Expand Down
15 changes: 5 additions & 10 deletions consensus/consensus-types/src/proposal_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,8 @@ impl ProposalMsg {
}
}

/// Returns the epoch associated with the proposal after verifying that the
/// payload data is also associated with the same epoch
pub fn verified_epoch(&self) -> Result<u64> {
let proposal_epoch = self.proposal.epoch();

self.proposal
.payload()
.map_or(Ok(()), |p| p.verify_epoch(proposal_epoch))?;

Ok(proposal_epoch)
pub fn epoch(&self) -> u64 {
self.proposal.epoch()
}

/// Verifies that the ProposalMsg is well-formed.
Expand Down Expand Up @@ -85,6 +77,9 @@ impl ProposalMsg {
"Proposal {} does not define an author",
self.proposal
);
self.proposal
.payload()
.map_or(Ok(()), |p| p.verify_epoch(self.proposal.epoch()))?;
Ok(())
}

Expand Down
5 changes: 4 additions & 1 deletion consensus/src/block_storage/block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ impl BlockStore {
for block in &blocks_to_commit {
// Given the block is ready to commit, then it certainly must have a QC.
// However, we keep it an Option to be safe.
block.set_qc(self.get_quorum_cert_for_block(block.id()));
block.set_qc(
self.get_quorum_cert_for_block(block.id())
.expect(&format!("QC for block {} must exist", block.id())),
);
}

let block_tree = self.inner.clone();
Expand Down
27 changes: 10 additions & 17 deletions consensus/src/payload_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,21 +617,14 @@ async fn process_payload_helper<T: TDataInfo>(
}
}

let result = {
// If the future is completed then use the result.
if let Some(result) = fut.clone().now_or_never() {
result
} else {
// Otherwise, append the additional peers to existing responders list
// NB: this might append the same signers multiple times, but this
// should be very rare and has no negative effects.
for responders in existing_responders {
responders.lock().append(&mut signers.clone());
}
// Append the additional peers to existing responders list
// NB: this might append the same signers multiple times, but this
// should be very rare and has no negative effects.
for responders in existing_responders {
responders.lock().append(&mut signers.clone());
}

fut.await
}
};
let result = fut.await;

// If error, reschedule before returning the result
if result.is_err() {
Expand All @@ -642,14 +635,14 @@ async fn process_payload_helper<T: TDataInfo>(
let batches_and_responders = data_ptr
.batch_summary
.iter()
.map(|proof| {
.map(|summary| {
let mut signers = signers.clone();
signers.append(&mut proof.signers(ordered_authors));
signers.append(&mut summary.signers(ordered_authors));
if let Some(author) = block.author() {
signers.push(author);
}

(proof.info().clone(), Arc::new(Mutex::new(signers)))
(summary.info().clone(), Arc::new(Mutex::new(signers)))
})
.collect();
data_fut.fut = request_txns_from_quorum_store(
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/round_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl UnverifiedEvent {

pub fn epoch(&self) -> anyhow::Result<u64> {
match self {
UnverifiedEvent::ProposalMsg(p) => p.verified_epoch(),
UnverifiedEvent::ProposalMsg(p) => Ok(p.epoch()),
UnverifiedEvent::VoteMsg(v) => Ok(v.epoch()),
UnverifiedEvent::OrderVoteMsg(v) => Ok(v.epoch()),
UnverifiedEvent::SyncInfo(s) => Ok(s.epoch()),
Expand Down

0 comments on commit 1f2e658

Please sign in to comment.