Skip to content

Commit

Permalink
optqs inline batch verification
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalajiarun committed Dec 16, 2024
1 parent 0a3cb49 commit e989225
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
35 changes: 26 additions & 9 deletions consensus/consensus-types/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,23 @@ impl Payload {
Ok(())
}

pub fn verify_inline_batches<'a>(
inline_batches: impl Iterator<Item = (&'a BatchInfo, &'a Vec<SignedTransaction>)>,
) -> anyhow::Result<()> {
for (batch, payload) in inline_batches {
// TODO: Can cloning be avoided here?
let computed_digest = BatchPayload::new(batch.author(), payload.clone()).hash();
ensure!(
computed_digest == *batch.digest(),
"Hash of the received inline batch doesn't match the digest value for batch {}: {} != {}",
batch,
computed_digest,
batch.digest()
);
}
Ok(())
}

pub fn verify(
&self,
validator: &ValidatorVerifier,
Expand All @@ -506,20 +523,20 @@ impl Payload {
),
(true, Payload::QuorumStoreInlineHybrid(inline_batches, proof_with_data, _)) => {
Self::verify_with_cache(&proof_with_data.proofs, validator, proof_cache)?;
for (batch, payload) in inline_batches.iter() {
// TODO: Can cloning be avoided here?
if BatchPayload::new(batch.author(), payload.clone()).hash() != *batch.digest()
{
return Err(anyhow::anyhow!(
"Hash of the received inline batch doesn't match the digest value",
));
}
}
Self::verify_inline_batches(
inline_batches.iter().map(|(info, txns)| (info, txns)),
)?;
Ok(())
},
(true, Payload::OptQuorumStore(opt_quorum_store)) => {
let proof_with_data = opt_quorum_store.proof_with_data();
Self::verify_with_cache(&proof_with_data.batch_summary, validator, proof_cache)?;
Self::verify_inline_batches(
opt_quorum_store
.inline_batches()
.iter()
.map(|batch| (batch.info(), batch.transactions())),
)?;
Ok(())
},
(_, _) => Err(anyhow::anyhow!(
Expand Down
4 changes: 4 additions & 0 deletions consensus/consensus-types/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ impl InlineBatch {
pub fn info(&self) -> &BatchInfo {
&self.batch_info
}

pub fn transactions(&self) -> &Vec<SignedTransaction> {
&self.transactions
}
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
Expand Down
1 change: 1 addition & 0 deletions consensus/src/round_manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ impl NodeSetup {
self.vote_queue.pop_front().unwrap()
}

#[allow(unused)]
pub async fn next_order_vote(&mut self) -> OrderVoteMsg {
while self.order_vote_queue.is_empty() {
self.next_network_message().await;
Expand Down

0 comments on commit e989225

Please sign in to comment.