Skip to content

Commit

Permalink
app: wrap up chain init api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Jan 26, 2024
1 parent 41c2562 commit 350f309
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions crates/core/component/community-pool/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ impl Component for CommunityPool {
#[instrument(name = "community_pool", skip(state, app_state))]
async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&Self::AppState>) {
match app_state {
Some(content) => {
state.put_community_pool_params(content.community_pool_params.clone());
Some(genesis) => {
state.put_community_pool_params(genesis.community_pool_params.clone());
}
None => {}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/core/component/distributions/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ impl Component for Distributions {
async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&Self::AppState>) {
match app_state {
None => { /* Checkpoint -- no-op */ }
Some(content) => {
state.put_distributions_params(content.distributions_params.clone());
Some(genesis) => {
state.put_distributions_params(genesis.distributions_params.clone());
}
};
}
Expand Down
6 changes: 3 additions & 3 deletions crates/core/component/fee/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod view;

use std::sync::Arc;

use crate::{genesis::Content, state_key};
use crate::{genesis, state_key};
use async_trait::async_trait;
use cnidarium::StateWrite;
use cnidarium_component::Component;
Expand All @@ -15,10 +15,10 @@ pub struct Fee {}

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

#[instrument(name = "staking", skip(state, app_state))]
async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&Content>) {
async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&Self::AppState>) {
match app_state {
Some(genesis) => {
state.put_fee_params(genesis.fee_params.clone());
Expand Down
4 changes: 2 additions & 2 deletions crates/core/component/funding/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ use cnidarium_component::Component;
use tendermint::v0_37::abci;
use tracing::instrument;

use crate::genesis::Content;
use crate::genesis;

pub struct Funding {}

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

#[instrument(name = "funding", skip(state, app_state))]
async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&Self::AppState>) {
Expand Down
4 changes: 2 additions & 2 deletions crates/core/component/governance/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl Component for Governance {
#[instrument(name = "governance", skip(state, app_state))]
async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&Self::AppState>) {
match app_state {
Some(content) => {
state.put_governance_params(content.governance_params.clone());
Some(genesis) => {
state.put_governance_params(genesis.governance_params.clone());
// Clients need to be able to read the next proposal number, even when no proposals have
// been submitted yet
state.init_proposal_counter();
Expand Down
3 changes: 3 additions & 0 deletions crates/core/component/ibc/src/component/ibc_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use super::HostInterface;

pub struct Ibc {}

// Note: [`Ibc`] does not implement the [`cnidarium_component::Component`] trait
// this is because we want to have a bound on [`HostInterface`] in the `begin_block`
// processing.
impl Ibc {
#[instrument(name = "ibc", skip(state, app_state))]
pub async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&genesis::Content>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;

use crate::genesis;
use anyhow::Result;
use async_trait::async_trait;
use cnidarium::StateWrite;
Expand All @@ -8,23 +9,21 @@ use penumbra_sct::CommitmentSource;
use tendermint::v0_37::abci;
use tracing::instrument;

use crate::genesis::Content as GenesisContent;

use super::{NoteManager, SupplyWrite};

pub struct ShieldedPool {}

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

#[instrument(name = "shielded_pool", skip(state, app_state))]
async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&GenesisContent>) {
async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&Self::AppState>) {
match app_state {
None => { /* Checkpoint -- no-op */ }
Some(app_state) => {
Some(genesis) => {
// Register a denom for each asset in the genesis state
for allocation in &app_state.allocations {
for allocation in &genesis.allocations {
tracing::debug!(?allocation, "processing allocation");
assert_ne!(
allocation.raw_amount,
Expand Down
20 changes: 9 additions & 11 deletions crates/core/component/stake/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use penumbra_proto::{state::future::DomainFuture, StateReadProto, StateWriteProt
use penumbra_sct::CommitmentSource;
use penumbra_shielded_pool::{
component::{NoteManager, SupplyRead, SupplyWrite},
genesis::Content as ShieldedPoolGenesisContent,
};
use sha2::{Digest, Sha256};
use tendermint::validator::Update;
Expand All @@ -47,7 +46,6 @@ use tracing::{instrument, Instrument};

use crate::{
funding_stream::Recipient,
genesis::Content as GenesisContent,
params::StakeParameters,
rate::{BaseRateData, RateData},
state_key,
Expand Down Expand Up @@ -1128,16 +1126,16 @@ impl<T: StateWrite + StateWriteExt + ?Sized> StakingImpl for T {}

#[async_trait]
impl Component for Staking {
type AppState = (GenesisContent, ShieldedPoolGenesisContent);
type AppState = (
crate::genesis::Content,
penumbra_shielded_pool::genesis::Content,
);

#[instrument(name = "staking", skip(state, app_state))]
async fn init_chain<S: StateWrite>(
mut state: S,
app_state: Option<&(GenesisContent, ShieldedPoolGenesisContent)>,
) {
async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&Self::AppState>) {
match app_state {
Some((staking_app_state, shielded_pool_app_state)) => {
state.put_stake_params(staking_app_state.stake_params.clone());
Some((staking_genesis, sp_genesis)) => {
state.put_stake_params(staking_genesis.stake_params.clone());

let starting_height = state
.get_block_height()
Expand All @@ -1159,15 +1157,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 &shielded_pool_app_state.allocations {
for allocation in &sp_genesis.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 &staking_app_state.validators {
for validator in &staking_genesis.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 350f309

Please sign in to comment.