Skip to content

Commit

Permalink
consensus: use prev_state_root for verification
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Dec 16, 2024
1 parent 2aacfcb commit 253830d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions consensus/src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct RoundUpdate {

seed: Seed,
hash: [u8; 32],
state_root: [u8; 32],
att: Attestation,
att_voters: Vec<Voter>,
timestamp: u64,
Expand All @@ -59,6 +60,7 @@ impl RoundUpdate {
timestamp: tip_header.timestamp,
base_timeouts,
att_voters,
state_root: tip_header.state_hash,
}
}

Expand All @@ -81,6 +83,10 @@ impl RoundUpdate {
pub fn att_voters(&self) -> &Vec<Voter> {
&self.att_voters
}

pub fn state_root(&self) -> [u8; 32] {
self.state_root
}
}

#[async_trait::async_trait]
Expand Down
2 changes: 2 additions & 0 deletions consensus/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct CallParams {
pub to_slash: Vec<Slash>,
pub voters_pubkey: Vec<Voter>,
pub max_txs_bytes: usize,
pub prev_state_root: StateRoot,
}

#[derive(Default)]
Expand Down Expand Up @@ -77,6 +78,7 @@ pub trait Operations: Send + Sync {

async fn verify_state_transition(
&self,
prev_commit: StateRoot,
blk: &Block,
voters: &[Voter],
) -> Result<VerificationOutput, OperationError>;
Expand Down
1 change: 1 addition & 0 deletions consensus/src/proposal/block_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl<T: Operations> Generator<T> {
to_slash,
voters_pubkey: voters.to_owned(),
max_txs_bytes,
prev_state_root: ru.state_root(),
};

let result =
Expand Down
15 changes: 13 additions & 2 deletions consensus/src/validation/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,14 @@ impl<T: Operations + 'static, D: Database> ValidationStep<T, D> {
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);
Expand Down Expand Up @@ -154,11 +161,15 @@ impl<T: Operations + 'static, D: Database> ValidationStep<T, D> {
}

async fn call_vst(
prev_commit: [u8; 32],
candidate: &Block,
voters: &[Voter],
executor: &Arc<T>,
) -> 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
Expand Down

0 comments on commit 253830d

Please sign in to comment.