Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
FM-365: Import the snapshot and update the app state
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Nov 22, 2023
1 parent 34d15b5 commit 82b193c
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions fendermint/app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,9 +882,33 @@ where
.await
{
Ok(snapshot) => {
if let Some(_snapshot) = snapshot {
tracing::info!("received all snapshot chunks");
// TODO: Import the snapshot.
if let Some(snapshot) = snapshot {
tracing::info!(
download_dir = snapshot.snapshot_dir.to_string_lossy().to_string(),
height = snapshot.manifest.block_height,
"received all snapshot chunks",
);

// Ideally we would import into some isolated store then validate,
// but for now let's trust that all is well.
if let Err(e) = snapshot.import(self.state_store_clone(), true).await {
tracing::error!(error =? e, "failed to import snapshot");
return Ok(response::ApplySnapshotChunk {
result: response::ApplySnapshotChunkResult::RejectSnapshot,
..default
});
}

tracing::info!(
height = snapshot.manifest.block_height,
"imported snapshot"
);

// Now insert the new state into the history.
let mut state = self.committed_state()?;
state.block_height = snapshot.manifest.block_height;
state.state_params = snapshot.manifest.state_params;
self.set_committed_state(state)?;
}
return Ok(response::ApplySnapshotChunk {
result: response::ApplySnapshotChunkResult::Accept,
Expand Down

0 comments on commit 82b193c

Please sign in to comment.