From 7e20ade044c93d3f5195e907ffcd49805368564f Mon Sep 17 00:00:00 2001 From: goshawk-3 Date: Mon, 22 Jan 2024 14:26:36 +0200 Subject: [PATCH] node: Use revert_to_finalized and get_finalized_state_root --- node/src/chain/acceptor.rs | 5 ++--- node/src/vm.rs | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/node/src/chain/acceptor.rs b/node/src/chain/acceptor.rs index 4a6677c311..56bfa32c25 100644 --- a/node/src/chain/acceptor.rs +++ b/node/src/chain/acceptor.rs @@ -409,8 +409,7 @@ impl Acceptor { 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", @@ -423,7 +422,7 @@ impl Acceptor { 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", diff --git a/node/src/vm.rs b/node/src/vm.rs index 637fb79554..9dadcb83d4 100644 --- a/node/src/vm.rs +++ b/node/src/vm.rs @@ -47,7 +47,10 @@ pub trait VMExecution: Send + Sync + 'static { ) -> anyhow::Result; 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]>; }