Skip to content

Commit

Permalink
node: Use revert_to_finalized and get_finalized_state_root
Browse files Browse the repository at this point in the history
  • Loading branch information
goshawk-3 authored and goshawk-3 committed Jan 23, 2024
1 parent a4acff5 commit 7e20ade
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 2 additions & 3 deletions node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
let target_state_hash = match target {
RevertTarget::LastFinalizedState => {
let vm = self.vm.read().await;
let base_root = vm.get_base_state_root()?;
let state_hash = vm.revert(base_root)?;
let state_hash = vm.revert_to_finalized()?;

info!(
event = "vm reverted",
Expand All @@ -423,7 +422,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
RevertTarget::Commit(state_hash) => {
let vm = self.vm.read().await;
let state_hash = vm.revert(state_hash)?;
let is_final = vm.get_base_state_root()? == state_hash;
let is_final = vm.get_finalized_state_root()? == state_hash;

info!(
event = "vm reverted",
Expand Down
5 changes: 4 additions & 1 deletion node/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ pub trait VMExecution: Send + Sync + 'static {
) -> anyhow::Result<Provisioners>;

fn get_state_root(&self) -> anyhow::Result<[u8; 32]>;
fn get_base_state_root(&self) -> anyhow::Result<[u8; 32]>;

/// Returns last finalized state root
fn get_finalized_state_root(&self) -> anyhow::Result<[u8; 32]>;

fn revert(&self, state_hash: [u8; 32]) -> anyhow::Result<[u8; 32]>;
fn revert_to_finalized(&self) -> anyhow::Result<[u8; 32]>;
}

0 comments on commit 7e20ade

Please sign in to comment.