Skip to content

Commit

Permalink
pd: write post genesis height when starting from a checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Sep 21, 2023
1 parent d00ba3e commit 8454cde
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions crates/bin/pd/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,22 @@ impl Consensus {
let app_state: genesis::AppState = serde_json::from_slice(&init_chain.app_state_bytes)
.expect("can parse app_state in genesis file");

match &app_state {
let initial_height = match &app_state {
genesis::AppState::Checkpoint(h) => {
tracing::info!(?h, "genesis state is a checkpoint");
init_chain.initial_height.into()
}
genesis::AppState::Content(_) => {
tracing::info!("genesis state is a full configuration");
// Check that we haven't got a duplicated InitChain message for some reason:
if self.storage.latest_version() != u64::MAX {
anyhow::bail!("database already initialized");
}
1u64
}
}
};

self.app.init_chain(&app_state).await;
self.app.init_chain(initial_height, &app_state).await;

// Extract the Tendermint validators from the app state
//
Expand Down
6 changes: 4 additions & 2 deletions crates/core/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl App {
events
}

pub async fn init_chain(&mut self, app_state: &genesis::AppState) {
pub async fn init_chain(&mut self, post_genesis_height: u64, app_state: &genesis::AppState) {
let mut state_tx = self
.state
.try_begin_transaction()
Expand Down Expand Up @@ -119,7 +119,9 @@ impl App {
Governance::init_chain(&mut state_tx, &()).await;
ShieldedPool::init_chain(&mut state_tx, app_state).await;
}
genesis::AppState::Checkpoint(_) => { /* no-op */ }
genesis::AppState::Checkpoint(_) => {
state_tx.put_block_height(post_genesis_height);
}
};

App::finish_block(&mut state_tx).await;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/app/src/temp_storage_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl TempStorageExt for TempStorage {

// Apply the genesis state to the storage
let mut app = App::new(self.latest_snapshot()).await?;
app.init_chain(&genesis).await;
app.init_chain(1u64, &genesis).await;
app.commit(self.deref().clone()).await;

Ok(self)
Expand Down

0 comments on commit 8454cde

Please sign in to comment.