Skip to content

Commit

Permalink
pd: inconditionally finalize pregenesis compact block
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Sep 21, 2023
1 parent ceaeb3a commit 645b7a8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 47 deletions.
13 changes: 5 additions & 8 deletions crates/bin/pd/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,19 @@ impl Consensus {

match &app_state {
genesis::AppState::Checkpoint(h) => {
println!("checkpoint: {h:?}");
// finalize a compact block
// start an epoch?
/* fast-forward to commit */
tracing::info!(?h, "genesis state is a checkpoint");
}
genesis::AppState::Content(genesis_app_state) => {
/* run application init_chain */

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");
}
self.app.init_chain(&genesis_app_state).await;
}
}

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

// Extract the Tendermint validators from the app state
//
// NOTE: we ignore the validators passed to InitChain.validators, and instead expect them
Expand Down
76 changes: 39 additions & 37 deletions crates/core/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,49 +78,51 @@ impl App {
events
}

pub async fn init_chain(&mut self, app_state: &genesis::Content) {
pub async fn init_chain(&mut self, app_state: &genesis::AppState) {
let mut state_tx = self
.state
.try_begin_transaction()
.expect("state Arc should not be referenced elsewhere");
match app_state {
genesis::AppState::Content(app_state) => {
state_tx.put_chain_params(app_state.chain_params.clone());

// TEMP: Hardcoding FMD parameters until we have a mechanism to change them. See issue #1226.
state_tx.put_current_fmd_parameters(FmdParameters::default());
state_tx.put_previous_fmd_parameters(FmdParameters::default());

// The genesis block height is 0
state_tx.put_block_height(0);

state_tx.put_epoch_by_height(
0,
penumbra_chain::Epoch {
index: 0,
start_height: 0,
},
);

// We need to set the epoch for the first block as well, since we set
// the epoch by height in end_block, and end_block isn't called after init_chain.
state_tx.put_epoch_by_height(
1,
penumbra_chain::Epoch {
index: 0,
start_height: 0,
},
);

Distributions::init_chain(&mut state_tx, app_state).await;
Staking::init_chain(&mut state_tx, app_state).await;
IBCComponent::init_chain(&mut state_tx, &()).await;
Dex::init_chain(&mut state_tx, &()).await;
Governance::init_chain(&mut state_tx, &()).await;
ShieldedPool::init_chain(&mut state_tx, app_state).await;
}
genesis::AppState::Checkpoint(_) => { /* no-op */ }
};

state_tx.put_chain_params(app_state.chain_params.clone());

// TEMP: Hardcoding FMD parameters until we have a mechanism to change them. See issue #1226.
state_tx.put_current_fmd_parameters(FmdParameters::default());
state_tx.put_previous_fmd_parameters(FmdParameters::default());

// The genesis block height is 0
state_tx.put_block_height(0);

state_tx.put_epoch_by_height(
0,
penumbra_chain::Epoch {
index: 0,
start_height: 0,
},
);

// We need to set the epoch for the first block as well, since we set
// the epoch by height in end_block, and end_block isn't called after init_chain.
state_tx.put_epoch_by_height(
1,
penumbra_chain::Epoch {
index: 0,
start_height: 0,
},
);

Distributions::init_chain(&mut state_tx, app_state).await;
Staking::init_chain(&mut state_tx, app_state).await;
IBCComponent::init_chain(&mut state_tx, &()).await;
Dex::init_chain(&mut state_tx, &()).await;
Governance::init_chain(&mut state_tx, &()).await;
ShieldedPool::init_chain(&mut state_tx, app_state).await;

// Create a synthetic height-zero block
App::finish_block(&mut state_tx).await;

state_tx.apply();
}

Expand Down
4 changes: 2 additions & 2 deletions crates/core/app/src/temp_storage_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use crate::app::App;

#[async_trait]
pub trait TempStorageExt: Sized {
async fn apply_genesis(self, genesis: genesis::Content) -> anyhow::Result<Self>;
async fn apply_genesis(self, genesis: genesis::AppState) -> anyhow::Result<Self>;
async fn apply_default_genesis(self) -> anyhow::Result<Self>;
}

#[async_trait]
impl TempStorageExt for TempStorage {
async fn apply_genesis(self, genesis: genesis::Content) -> anyhow::Result<Self> {
async fn apply_genesis(self, genesis: genesis::AppState) -> anyhow::Result<Self> {
// Check that we haven't already applied a genesis state:
if self.latest_version() != u64::MAX {
anyhow::bail!("database already initialized");
Expand Down

0 comments on commit 645b7a8

Please sign in to comment.