Skip to content

Commit

Permalink
node: 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 253830d commit c85b12a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 7 additions & 3 deletions node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
let mut task = self.task.write().await;

let mut tip = self.tip.write().await;
let prev_header = tip.inner().header().clone();
let mut provisioners_list = self.provisioners_list.write().await;
let block_time =
blk.header().timestamp - tip.inner().header().timestamp;
Expand All @@ -636,7 +637,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
// Verify Block Header
let (pni, prev_block_voters, tip_block_voters) = verify_block_header(
self.db.clone(),
&tip.inner().header().clone(),
&prev_header,
&provisioners_list,
blk.header(),
)
Expand All @@ -658,8 +659,11 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
let vm = self.vm.write().await;

let (stakes, finality) = self.db.read().await.update(|db| {
let (txs, verification_output, stake_events) =
vm.accept(blk, &prev_block_voters[..])?;
let (txs, verification_output, stake_events) = vm.accept(
prev_header.state_hash,
blk,
&prev_block_voters[..],
)?;
for spent_tx in txs.iter() {
events.push(TransactionEvent::Executed(spent_tx).into());
}
Expand Down
3 changes: 2 additions & 1 deletion node/src/chain/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,15 @@ impl<DB: database::DB, VM: vm::VMExecution> Operations for Executor<DB, VM> {

async fn verify_state_transition(
&self,
prev_root: [u8; 32],
blk: &Block,
voters: &[Voter],
) -> Result<VerificationOutput, OperationError> {
info!("verifying state");

let vm = self.vm.read().await;

vm.verify_state_transition(blk, voters)
vm.verify_state_transition(prev_root, blk, voters)
.map_err(OperationError::InvalidVST)
}

Expand Down
2 changes: 2 additions & 0 deletions node/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ pub trait VMExecution: Send + Sync + 'static {

fn verify_state_transition(
&self,
prev_root: [u8; 32],
blk: &Block,
voters: &[Voter],
) -> anyhow::Result<VerificationOutput>;

fn accept(
&self,
prev_root: [u8; 32],
blk: &Block,
voters: &[Voter],
) -> anyhow::Result<(
Expand Down

0 comments on commit c85b12a

Please sign in to comment.