From d55e923f09b7889ee18af3907dd325cdec784c97 Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Thu, 5 Sep 2024 17:59:06 +0200 Subject: [PATCH] node: try to load last accepted state after restart See also #2277 --- node/src/chain/acceptor.rs | 22 +++++++++++++++++----- node/src/vm.rs | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/node/src/chain/acceptor.rs b/node/src/chain/acceptor.rs index d287f35b59..33c6f2863c 100644 --- a/node/src/chain/acceptor.rs +++ b/node/src/chain/acceptor.rs @@ -164,15 +164,27 @@ impl Acceptor { let state_root = vm.read().await.get_state_root()?; info!( - event = "VM state loaded", + event = "VM finalized state loaded", state_root = hex::encode(state_root), ); - // Detect a consistency issue between VM and Ledger states. if tip_height > 0 && tip_state_hash != state_root { - info!("revert to last finalized state"); - // Revert to last known finalized state. - acc.try_revert(RevertTarget::LastFinalizedState).await?; + if let Err(error) = vm.read().await.move_to_commit(tip_state_hash) { + warn!( + event = "Cannot move to tip_state_hash", + ?error, + state_root = hex::encode(tip_state_hash) + ); + + info!("revert to last finalized state"); + // Revert to last known finalized state. + acc.try_revert(RevertTarget::LastFinalizedState).await?; + } else { + info!( + event = "VM accepted state loaded", + state_root = hex::encode(tip_state_hash), + ); + } } Ok(acc) diff --git a/node/src/vm.rs b/node/src/vm.rs index 8e29e30184..adfdc85856 100644 --- a/node/src/vm.rs +++ b/node/src/vm.rs @@ -63,6 +63,8 @@ pub trait VMExecution: Send + Sync + 'static { fn get_state_root(&self) -> anyhow::Result<[u8; 32]>; + fn move_to_commit(&self, commit: [u8; 32]) -> anyhow::Result<()>; + /// Returns last finalized state root fn get_finalized_state_root(&self) -> anyhow::Result<[u8; 32]>;