Skip to content

Commit

Permalink
pd: fast-forward init when starting from genesis::Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Sep 21, 2023
1 parent 07a3b98 commit ceaeb3a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 33 deletions.
6 changes: 4 additions & 2 deletions crates/bin/pd/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ impl Consensus {
match &app_state {
genesis::AppState::Checkpoint(h) => {
println!("checkpoint: {h:?}");
// finalize a compact block
// start an epoch?
/* fast-forward to commit */
}
genesis::AppState::Content(_) => {
genesis::AppState::Content(genesis_app_state) => {
/* run application init_chain */

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

Expand Down
14 changes: 4 additions & 10 deletions crates/core/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,7 @@ impl App {
events
}

pub async fn init_chain(&mut self, app_state_general: &genesis::AppState) {
let app_state = match app_state_general {
genesis::AppState::Checkpoint(_) => {
unimplemented!("adding support with init handshake pr")
}
genesis::AppState::Content(state) => state,
};
pub async fn init_chain(&mut self, app_state: &genesis::Content) {
let mut state_tx = self
.state
.try_begin_transaction()
Expand Down Expand Up @@ -117,12 +111,12 @@ impl App {
},
);

Distributions::init_chain(&mut state_tx, app_state_general).await;
Staking::init_chain(&mut state_tx, app_state_general).await;
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_general).await;
ShieldedPool::init_chain(&mut state_tx, app_state).await;

// Create a synthetic height-zero block
App::finish_block(&mut state_tx).await;
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::AppState) -> anyhow::Result<Self>;
async fn apply_genesis(self, genesis: genesis::Content) -> 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::AppState) -> anyhow::Result<Self> {
async fn apply_genesis(self, genesis: genesis::Content) -> 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
2 changes: 1 addition & 1 deletion crates/core/component/distributions/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Distributions {}

#[async_trait]
impl Component for Distributions {
type AppState = genesis::AppState;
type AppState = genesis::Content;

async fn init_chain<S: StateWrite>(_state: S, _app_state: &Self::AppState) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@ pub struct ShieldedPool {}

#[async_trait]
impl Component for ShieldedPool {
type AppState = genesis::AppState;
type AppState = genesis::Content;

#[instrument(name = "shielded_pool", skip(state, app_state))]
async fn init_chain<S: StateWrite>(mut state: S, app_state: &genesis::AppState) {
let app_state = match app_state {
genesis::AppState::Checkpoint(_) => {
unimplemented!("adding support with init handshake pr")
}
genesis::AppState::Content(app_state) => app_state,
};

async fn init_chain<S: StateWrite>(mut state: S, app_state: &genesis::Content) {
// Register a denom for each asset in the genesis state
for allocation in &app_state.allocations {
tracing::debug!(?allocation, "processing allocation");
Expand Down
11 changes: 2 additions & 9 deletions crates/core/component/stake/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,17 +889,10 @@ impl<T: StateWrite + StateWriteExt + ?Sized> StakingImpl for T {}

#[async_trait]
impl Component for Staking {
type AppState = genesis::AppState;
type AppState = genesis::Content;

#[instrument(name = "staking", skip(state, app_state))]
async fn init_chain<S: StateWrite>(mut state: S, app_state: &genesis::AppState) {
let app_state = match app_state {
genesis::AppState::Checkpoint(_) => {
unimplemented!("adding support with init handshake pr")
}
genesis::AppState::Content(state) => state,
};

async fn init_chain<S: StateWrite>(mut state: S, app_state: &genesis::Content) {
let starting_height = state
.get_block_height()
.await
Expand Down

0 comments on commit ceaeb3a

Please sign in to comment.