From bb53aa7cd48163f71a65cce8145fa8c0f844dcc9 Mon Sep 17 00:00:00 2001 From: Federico Franzoni <8609060+fed-franz@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:02:24 +0200 Subject: [PATCH] node: use consensus_header in verify_att --- node/benches/accept.rs | 10 ++++++--- node/src/chain/header_validation.rs | 33 ++++++++--------------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/node/benches/accept.rs b/node/benches/accept.rs index 897f50d015..954bccbb32 100644 --- a/node/benches/accept.rs +++ b/node/benches/accept.rs @@ -26,6 +26,7 @@ use node_data::ledger::{Attestation, StepVotes}; use node_data::message::payload::{ QuorumType, RatificationResult, ValidationResult, Vote, }; +use node_data::message::ConsensusHeader; use node_data::{ledger, StepName}; use rand::rngs::StdRng; use rand::SeedableRng; @@ -155,12 +156,15 @@ pub fn verify_att(c: &mut Criterion) { format!("{} prov", input.provisioners), ), move |b| { + let consensus_header = ConsensusHeader { + prev_block_hash: [0u8; 32], + round: tip_header.height + 1, + iteration: 0, + }; b.to_async(FuturesExecutor).iter(|| async { chain::verify_att( &att, - [0u8; 32], - tip_header.height + 1, - iteration, + consensus_header, tip_header.seed, &provisioners, ) diff --git a/node/src/chain/header_validation.rs b/node/src/chain/header_validation.rs index cfc53e271b..791d7ad175 100644 --- a/node/src/chain/header_validation.rs +++ b/node/src/chain/header_validation.rs @@ -186,9 +186,7 @@ impl<'a, DB: database::DB> Validator<'a, DB> { let (_, _, voters) = verify_att( &candidate_block.prev_block_cert, - self.prev_header.prev_block_hash, - self.prev_header.height, - self.prev_header.iteration, + self.prev_header.get_consensus_header(), prev_block_seed, self.provisioners.prev(), ) @@ -230,9 +228,7 @@ impl<'a, DB: database::DB> Validator<'a, DB> { let (_, rat_quorum, _) = verify_att( att, - self.prev_header.hash, - candidate_block.height, - iter as u8, + candidate_block.get_consensus_header(), self.prev_header.seed, self.provisioners.current(), ) @@ -253,9 +249,7 @@ impl<'a, DB: database::DB> Validator<'a, DB> { ) -> anyhow::Result> { let (_, _, voters) = verify_att( &candidate_block.att, - self.prev_header.hash, - candidate_block.height, - candidate_block.iteration, + candidate_block.get_consensus_header(), self.prev_header.seed, self.provisioners.current(), ) @@ -275,9 +269,7 @@ impl<'a, DB: database::DB> Validator<'a, DB> { ) -> anyhow::Result> { let (_, _, voters) = verify_att( &blk.att, - blk.prev_block_hash, - blk.height, - blk.iteration, + blk.get_consensus_header(), prev_block_seed, provisioners, ) @@ -331,9 +323,7 @@ pub async fn verify_faults( pub async fn verify_att( att: &ledger::Attestation, - prev_block_hash: [u8; 32], - round: u64, - iteration: u8, + consensus_header: ConsensusHeader, curr_seed: Signature, curr_eligible_provisioners: &Provisioners, ) -> anyhow::Result<(QuorumResult, QuorumResult, Vec)> { @@ -341,11 +331,6 @@ pub async fn verify_att( let mut result = (QuorumResult::default(), QuorumResult::default()); - let consensus_header = ConsensusHeader { - iteration, - round, - prev_block_hash, - }; let v_committee; let r_committee; @@ -369,8 +354,8 @@ pub async fn verify_att( return Err(anyhow!( "invalid validation, vote = {:?}, round = {}, iter = {}, seed = {}, sv = {:?}, err = {}", vote, - round, - iteration, + consensus_header.round, + consensus_header.iteration, to_str(curr_seed.inner()), att.validation, e @@ -397,8 +382,8 @@ pub async fn verify_att( return Err(anyhow!( "invalid ratification, vote = {:?}, round = {}, iter = {}, seed = {}, sv = {:?}, err = {}", vote, - round, - iteration, + consensus_header.round, + consensus_header.iteration, to_str(curr_seed.inner()), att.ratification, e,