Skip to content

Commit

Permalink
node: try to load last accepted state after restart
Browse files Browse the repository at this point in the history
See also #2277
  • Loading branch information
herr-seppia committed Sep 5, 2024
1 parent ac26fe3 commit d55e923
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 17 additions & 5 deletions node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,27 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
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)
Expand Down
2 changes: 2 additions & 0 deletions node/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]>;

Expand Down

0 comments on commit d55e923

Please sign in to comment.