diff --git a/consensus/src/commons.rs b/consensus/src/commons.rs index 674f66eeb..5dc108b81 100644 --- a/consensus/src/commons.rs +++ b/consensus/src/commons.rs @@ -33,6 +33,7 @@ pub struct RoundUpdate { seed: Seed, hash: [u8; 32], + state_root: [u8; 32], att: Attestation, att_voters: Vec, timestamp: u64, @@ -59,6 +60,7 @@ impl RoundUpdate { timestamp: tip_header.timestamp, base_timeouts, att_voters, + state_root: tip_header.state_hash, } } @@ -81,6 +83,10 @@ impl RoundUpdate { pub fn att_voters(&self) -> &Vec { &self.att_voters } + + pub fn state_root(&self) -> [u8; 32] { + self.state_root + } } #[async_trait::async_trait] diff --git a/consensus/src/operations.rs b/consensus/src/operations.rs index 4b776aec9..99246a082 100644 --- a/consensus/src/operations.rs +++ b/consensus/src/operations.rs @@ -26,6 +26,7 @@ pub struct CallParams { pub to_slash: Vec, pub voters_pubkey: Vec, pub max_txs_bytes: usize, + pub prev_state_root: StateRoot, } #[derive(Default)] @@ -77,6 +78,7 @@ pub trait Operations: Send + Sync { async fn verify_state_transition( &self, + prev_commit: StateRoot, blk: &Block, voters: &[Voter], ) -> Result; diff --git a/consensus/src/proposal/block_generator.rs b/consensus/src/proposal/block_generator.rs index 5ee57eddc..fe56b2103 100644 --- a/consensus/src/proposal/block_generator.rs +++ b/consensus/src/proposal/block_generator.rs @@ -132,6 +132,7 @@ impl Generator { to_slash, voters_pubkey: voters.to_owned(), max_txs_bytes, + prev_state_root: ru.state_root(), }; let result = diff --git a/consensus/src/validation/step.rs b/consensus/src/validation/step.rs index 01dc02418..ae3b38882 100644 --- a/consensus/src/validation/step.rs +++ b/consensus/src/validation/step.rs @@ -103,7 +103,14 @@ impl ValidationStep { error!(event = "invalid faults", ?err); Vote::Invalid(header.hash) } else { - match Self::call_vst(candidate, &voters, &executor).await { + match Self::call_vst( + ru.state_root(), + candidate, + &voters, + &executor, + ) + .await + { Ok(_) => Vote::Valid(header.hash), Err(err) => { error!(event = "failed_vst_call", ?err); @@ -154,11 +161,15 @@ impl ValidationStep { } async fn call_vst( + prev_commit: [u8; 32], candidate: &Block, voters: &[Voter], executor: &Arc, ) -> anyhow::Result<()> { - match executor.verify_state_transition(candidate, voters).await { + match executor + .verify_state_transition(prev_commit, candidate, voters) + .await + { Ok(output) => { // Ensure the `event_bloom` and `state_root` returned // from the VST call are the