Skip to content

Commit

Permalink
app: remove the rest of the checks
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Jan 26, 2024
1 parent 8351d22 commit 41c2562
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 30 deletions.
42 changes: 23 additions & 19 deletions crates/core/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use penumbra_funding::component::Funding;
use penumbra_funding::component::{StateReadExt as _, StateWriteExt as _};
use penumbra_governance::component::{Governance, StateReadExt as _};
use penumbra_governance::StateWriteExt as _;
use penumbra_ibc::component::{IBCComponent, StateWriteExt as _};
use penumbra_ibc::component::{Ibc, StateWriteExt as _};
use penumbra_ibc::StateReadExt as _;
use penumbra_proto::core::app::v1alpha1::TransactionsByHeightResponse;
use penumbra_proto::DomainType;
Expand Down Expand Up @@ -74,7 +74,7 @@ impl App {
// access. This method "externally" applies the state delta to the
// inter-block state.
//
// Invariant: state_tx and self.state are the only two references to the
// Invariant: `state_tx` and `self.state` are the only two references to the
// inter-block state.
fn apply(&mut self, state_tx: StateDelta<InterBlockState>) -> Vec<Event> {
let (state2, mut cache) = state_tx.flatten();
Expand All @@ -97,13 +97,9 @@ impl App {
match app_state {
genesis::AppState::Content(app_state) => {
state_tx.put_chain_params(app_state.chain_content.chain_params.clone());
state_tx.put_funding_params(app_state.funding_content.funding_params.clone());
state_tx
.put_governance_params(app_state.governance_content.governance_params.clone());
state_tx.put_ibc_params(app_state.ibc_content.ibc_params.clone());
state_tx.put_stake_params(app_state.stake_content.stake_params.clone());

// TEMP: Hardcoding FMD parameters until we have a mechanism to change them. See issue #1226.
// TODO(erwan): moving this when we gut the chain component.
state_tx.put_current_fmd_parameters(FmdParameters::default());
state_tx.put_previous_fmd_parameters(FmdParameters::default());

Expand All @@ -130,7 +126,8 @@ impl App {

ShieldedPool::init_chain(&mut state_tx, Some(&app_state.shielded_pool_content))
.await;
Distributions::init_chain(&mut state_tx, Some(&app_state.distributions_content)).await;
Distributions::init_chain(&mut state_tx, Some(&app_state.distributions_content))
.await;
Staking::init_chain(
&mut state_tx,
Some(&(
Expand All @@ -139,13 +136,13 @@ impl App {
)),
)
.await;
Ibc::init_chain(&mut state_tx, Some(&())).await;
Ibc::init_chain(&mut state_tx, Some(&app_state.ibc_content)).await;
Dex::init_chain(&mut state_tx, Some(&())).await;
CommunityPool::init_chain(&mut state_tx, Some(&app_state.community_pool_content))
.await;
Governance::init_chain(&mut state_tx, Some(&app_state.governance_content)).await;
Fee::init_chain(&mut state_tx, Some(&app_state.fee_content)).await;
Funding::init_chain(&mut state_tx, Some(&())).await;
Funding::init_chain(&mut state_tx, Some(&app_state.funding_content)).await;

state_tx
.finish_block(state_tx.app_params_updated())
Expand All @@ -159,6 +156,7 @@ impl App {
Ibc::init_chain(&mut state_tx, None).await;
Dex::init_chain(&mut state_tx, None).await;
Governance::init_chain(&mut state_tx, None).await;
CommunityPool::init_chain(&mut state_tx, None).await;
Fee::init_chain(&mut state_tx, None).await;
Funding::init_chain(&mut state_tx, None).await;
}
Expand Down Expand Up @@ -247,23 +245,24 @@ impl App {
if let Some(community_pool_params) = app_params.new.community_pool_params {
state_tx.put_community_pool_params(community_pool_params);
}
if let Some(ibc_params) = app_params.new.ibc_params {
state_tx.put_ibc_params(ibc_params);
}
if let Some(stake_params) = app_params.new.stake_params {
state_tx.put_stake_params(stake_params);
if let Some(distributions_params) = app_params.new.distributions_params {
state_tx.put_distributions_params(distributions_params);
}
if let Some(fee_params) = app_params.new.fee_params {
state_tx.put_fee_params(fee_params);
}
if let Some(funding_params) = app_params.new.funding_params {
state_tx.put_funding_params(funding_params);
}
if let Some(governance_params) = app_params.new.governance_params {
state_tx.put_governance_params(governance_params);
}
if let Some(distributions_params) = app_params.new.distributions_params {
state_tx.put_distributions_params(distributions_params);
if let Some(ibc_params) = app_params.new.ibc_params {
state_tx.put_ibc_params(ibc_params);
}
if let Some(stake_params) = app_params.new.stake_params {
state_tx.put_stake_params(stake_params);
}

// TODO(erwan): Untracked, but will add funding params here.
}

// Run each of the begin block handlers for each component, in sequence:
Expand All @@ -275,6 +274,7 @@ impl App {
begin_block,
)
.await;
CommunityPool::begin_block(&mut arc_state_tx, begin_block).await;
Governance::begin_block(&mut arc_state_tx, begin_block).await;
Staking::begin_block(&mut arc_state_tx, begin_block).await;
Fee::begin_block(&mut arc_state_tx, begin_block).await;
Expand Down Expand Up @@ -390,6 +390,7 @@ impl App {
Distributions::end_block(&mut arc_state_tx, end_block).await;
Ibc::end_block(&mut arc_state_tx, end_block).await;
Dex::end_block(&mut arc_state_tx, end_block).await;
CommunityPool::end_block(&mut arc_state_tx, end_block).await;
Governance::end_block(&mut arc_state_tx, end_block).await;
Staking::end_block(&mut arc_state_tx, end_block).await;
Fee::end_block(&mut arc_state_tx, end_block).await;
Expand Down Expand Up @@ -494,6 +495,9 @@ impl App {
Dex::end_epoch(&mut arc_state_tx)
.await
.expect("able to call end_epoch on dex component");
CommunityPool::end_epoch(&mut arc_state_tx)
.await
.expect("able to call end_epoch on Community Pool component");
Governance::end_epoch(&mut arc_state_tx)
.await
.expect("able to call end_epoch on Governance component");
Expand Down
1 change: 0 additions & 1 deletion crates/core/component/funding/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ impl Component for Funding {
match app_state {
None => { /* Checkpoint -- no-op */ }
Some(genesis) => {

state.put_funding_params(genesis.funding_params.clone());
}
};
Expand Down
2 changes: 1 addition & 1 deletion crates/core/component/governance/src/component.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use crate::{genesis, };
use crate::genesis;
use anyhow::{Context, Result};
use async_trait::async_trait;
use cnidarium::StateWrite;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/component/ibc/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ pub use connection::StateWriteExt as ConnectionStateWriteExt;
pub use host_interface::HostInterface;
pub use view::{StateReadExt, StateWriteExt};

pub use ibc_component::IBCComponent;
pub use ibc_component::Ibc;
16 changes: 11 additions & 5 deletions crates/core/component/ibc/src/component/ibc_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ use ibc_types::{
use tendermint::abci;
use tracing::instrument;

use crate::component::{client::StateWriteExt as _, client_counter::ClientCounter};
use crate::{
component::{client::StateWriteExt as _, client_counter::ClientCounter},
genesis, StateWriteExt as _,
};

use super::HostInterface;

pub struct IBCComponent {}
pub struct Ibc {}

impl IBCComponent {
impl Ibc {
#[instrument(name = "ibc", skip(state, app_state))]
pub async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&()>) {
pub async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&genesis::Content>) {
match app_state {
Some(_) => state.put_client_counter(ClientCounter(0)),
Some(genesis) => {
state.put_ibc_params(genesis.ibc_params.clone());
state.put_client_counter(ClientCounter(0))
}
None => { /* perform upgrade specific check */ }
}
}
Expand Down
8 changes: 5 additions & 3 deletions crates/core/component/stake/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,9 @@ impl Component for Staking {
app_state: Option<&(GenesisContent, ShieldedPoolGenesisContent)>,
) {
match app_state {
Some((app_state, sp_app_state)) => {
Some((staking_app_state, shielded_pool_app_state)) => {
state.put_stake_params(staking_app_state.stake_params.clone());

let starting_height = state
.get_block_height()
.await
Expand All @@ -1157,15 +1159,15 @@ impl Component for Staking {
// Compile totals of genesis allocations by denom, which we can use
// to compute the delegation tokens for each validator.
let mut genesis_allocations = BTreeMap::<_, Amount>::new();
for allocation in &sp_app_state.allocations {
for allocation in &shielded_pool_app_state.allocations {
let value = allocation.value();
*genesis_allocations.entry(value.asset_id).or_default() += value.amount;
}

// Add initial validators to the JMT
// Validators are indexed in the JMT by their public key,
// and there is a separate key containing the list of all validator keys.
for validator in &app_state.validators {
for validator in &staking_app_state.validators {
// Parse the proto into a domain type.
let validator = Validator::try_from(validator.clone())
.expect("should be able to parse genesis validator");
Expand Down

0 comments on commit 41c2562

Please sign in to comment.