Skip to content

Commit

Permalink
refactor(app): 📎 fold genesis::{AppState, Content} into `penumbra-a…
Browse files Browse the repository at this point in the history
…pp` (#4142)

fixes #4088.

see also #3761, 95a9d35.

this moves the genesis state for the application back into the
`penumbra_app` library, so that we maintain parity with our protobuf
definitions.
  • Loading branch information
cratelyn authored Apr 1, 2024
1 parent ca16ab1 commit 03a8c11
Show file tree
Hide file tree
Showing 20 changed files with 29 additions and 82 deletions.
21 changes: 0 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ members = [
"crates/core/component/sct",
"crates/core/component/shielded-pool",
"crates/core/component/stake",
"crates/core/genesis",
"crates/core/keys",
"crates/core/num",
"crates/core/transaction",
Expand Down Expand Up @@ -169,7 +168,6 @@ penumbra-distributions = { default-features = false, path = "crates/co
penumbra-fee = { default-features = false, path = "crates/core/component/fee" }
penumbra-funding = { default-features = false, path = "crates/core/component/funding" }
penumbra-governance = { default-features = false, path = "crates/core/component/governance" }
penumbra-genesis = { path = "crates/core/genesis" }
penumbra-ibc = { default-features = false, path = "crates/core/component/ibc" }
penumbra-keys = { default-features = false, path = "crates/core/keys" }
penumbra-mock-client = { path = "crates/test/mock-client" }
Expand Down
1 change: 0 additions & 1 deletion crates/bin/pd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ penumbra-compact-block = { workspace = true, default-features = true }
penumbra-custody = { workspace = true }
penumbra-dex = { workspace = true, features = ["parallel"], default-features = true }
penumbra-fee = { workspace = true, default-features = true }
penumbra-genesis = { workspace = true }
penumbra-governance = { workspace = true, features = ["parallel"], default-features = true }
penumbra-ibc = { workspace = true, features = ["rpc"], default-features = true }
penumbra-keys = { workspace = true, default-features = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/bin/pd/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Migration {

/* ---------- generate genesis ------------ */
let chain_id = migrated_state.get_chain_id().await?;
let app_state = penumbra_genesis::Content {
let app_state = penumbra_app::genesis::Content {
chain_id,
..Default::default()
};
Expand Down Expand Up @@ -150,7 +150,7 @@ impl Migration {
// to lookup a validator view from the chain, and specify the post-upgrade app hash and
// initial height.
let chain_id = migrated_state.get_chain_id().await?;
let app_state = penumbra_genesis::Content {
let app_state = penumbra_app::genesis::Content {
chain_id,
..Default::default()
};
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/pd/src/testnet/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Context;
use decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey};
use directories::UserDirs;
use penumbra_app::genesis::AppState;
use penumbra_custody::soft_kms::Config as SoftKmsConfig;
use penumbra_genesis::AppState;
use penumbra_keys::keys::{SpendKey, SpendKeyBytes};
use rand::Rng;
use rand_core::OsRng;
Expand Down
22 changes: 11 additions & 11 deletions crates/bin/pd/src/testnet/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct TestnetConfig {
/// The name of the network
pub name: String,
/// The Tendermint genesis for initial chain state.
pub genesis: Genesis<penumbra_genesis::AppState>,
pub genesis: Genesis<penumbra_app::genesis::AppState>,
/// Path to local directory where config files will be written to
pub testnet_dir: PathBuf,
/// Set of validators at genesis. Uses the convenient wrapper type
Expand Down Expand Up @@ -186,7 +186,7 @@ impl TestnetConfig {
epoch_duration: Option<u64>,
unbonding_delay: Option<u64>,
proposal_voting_blocks: Option<u64>,
) -> anyhow::Result<penumbra_genesis::Content> {
) -> anyhow::Result<penumbra_app::genesis::Content> {
let default_gov_params = penumbra_governance::params::GovernanceParameters::default();

let gov_params = penumbra_governance::params::GovernanceParameters {
Expand All @@ -198,7 +198,7 @@ impl TestnetConfig {
// Look up default app params, so we can fill in defaults.
let default_app_params = AppParameters::default();

let app_state = penumbra_genesis::Content {
let app_state = penumbra_app::genesis::Content {
chain_id: chain_id.to_string(),
stake_content: StakeContent {
validators: validators.into_iter().map(Into::into).collect(),
Expand Down Expand Up @@ -230,8 +230,8 @@ impl TestnetConfig {

/// Build Tendermint genesis data, based on Penumbra initial application state.
pub(crate) fn make_genesis(
app_state: penumbra_genesis::Content,
) -> anyhow::Result<Genesis<penumbra_genesis::AppState>> {
app_state: penumbra_app::genesis::Content,
) -> anyhow::Result<Genesis<penumbra_app::genesis::AppState>> {
// Use now as genesis time
let genesis_time = Time::from_unix_timestamp(
SystemTime::now()
Expand Down Expand Up @@ -272,7 +272,7 @@ impl TestnetConfig {
},
// always empty in genesis json
app_hash: tendermint::AppHash::default(),
app_state: penumbra_genesis::AppState::Content(app_state),
app_state: penumbra_app::genesis::AppState::Content(app_state),
// Set empty validator set for Tendermint config, which falls back to reading
// validators from the AppState, via ResponseInitChain:
// https://docs.tendermint.com/v0.32/tendermint-core/using-tendermint.html
Expand All @@ -282,12 +282,12 @@ impl TestnetConfig {
}

pub(crate) fn make_checkpoint(
genesis: Genesis<penumbra_genesis::AppState>,
genesis: Genesis<penumbra_app::genesis::AppState>,
checkpoint: Option<Vec<u8>>,
) -> Genesis<penumbra_genesis::AppState> {
) -> Genesis<penumbra_app::genesis::AppState> {
match checkpoint {
Some(checkpoint) => Genesis {
app_state: penumbra_genesis::AppState::Checkpoint(checkpoint),
app_state: penumbra_app::genesis::AppState::Checkpoint(checkpoint),
..genesis
},
None => genesis,
Expand Down Expand Up @@ -672,7 +672,7 @@ mod tests {
assert_eq!(testnet_config.name, "test-chain-1234");
assert_eq!(testnet_config.genesis.validators.len(), 0);
// No external address template was given, so only 1 validator will be present.
let penumbra_genesis::AppState::Content(app_state) = testnet_config.genesis.app_state
let penumbra_app::genesis::AppState::Content(app_state) = testnet_config.genesis.app_state
else {
unimplemented!("TODO: support checkpointed app state")
};
Expand Down Expand Up @@ -700,7 +700,7 @@ mod tests {
)?;
assert_eq!(testnet_config.name, "test-chain-4567");
assert_eq!(testnet_config.genesis.validators.len(), 0);
let penumbra_genesis::AppState::Content(app_state) = testnet_config.genesis.app_state
let penumbra_app::genesis::AppState::Content(app_state) = testnet_config.genesis.app_state
else {
unimplemented!("TODO: support checkpointed app state")
};
Expand Down
1 change: 0 additions & 1 deletion crates/core/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ penumbra-dex = { workspace = true, default-features = true }
penumbra-distributions = { workspace = true, default-features = true }
penumbra-fee = { workspace = true, default-features = true }
penumbra-funding = { workspace = true, default-features = true }
penumbra-genesis = { workspace = true }
penumbra-governance = { workspace = true, default-features = true }
penumbra-ibc = { workspace = true, features = ["component", "rpc"], default-features = true }
penumbra-keys = { workspace = true, default-features = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/core/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use penumbra_distributions::component::{Distributions, StateReadExt as _, StateW
use penumbra_fee::component::{Fee, StateReadExt as _, StateWriteExt as _};
use penumbra_funding::component::Funding;
use penumbra_funding::component::{StateReadExt as _, StateWriteExt as _};
use penumbra_genesis::AppState;
use penumbra_governance::component::{Governance, StateReadExt as _};
use penumbra_governance::StateWriteExt as _;
use penumbra_ibc::component::{Ibc, StateWriteExt as _};
Expand All @@ -39,6 +38,7 @@ use tendermint::validator::Update;
use tracing::Instrument;

use crate::action_handler::AppActionHandler;
use crate::genesis::AppState;
use crate::params::AppParameters;
use crate::{CommunityPoolStateReadExt, PenumbraHost};

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions crates/core/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

pub mod app;
pub mod genesis;
pub mod metrics;
pub mod params;
pub mod rpc;
Expand Down
6 changes: 3 additions & 3 deletions crates/core/app/src/server/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Consensus {
/// the database.
async fn init_chain(&mut self, init_chain: request::InitChain) -> Result<response::InitChain> {
// Note that errors cannot be handled in InitChain, the application must crash.
let app_state: penumbra_genesis::AppState =
let app_state: crate::genesis::AppState =
serde_json::from_slice(&init_chain.app_state_bytes)
.expect("can parse app_state in genesis file");

Expand All @@ -132,13 +132,13 @@ impl Consensus {
let validators = self.app.tendermint_validator_updates();

let app_hash = match &app_state {
penumbra_genesis::AppState::Checkpoint(h) => {
crate::genesis::AppState::Checkpoint(h) => {
tracing::info!(?h, "genesis state is a checkpoint");
// If we're starting from a checkpoint, we just need to forward the app hash
// back to CometBFT.
self.storage.latest_snapshot().root_hash().await?
}
penumbra_genesis::AppState::Content(_) => {
crate::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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use {
anyhow::{anyhow, Context},
cnidarium::TempStorage,
decaf377_rdsa::{SigningKey, SpendAuth},
penumbra_app::server::consensus::Consensus,
penumbra_genesis::AppState,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_keys::test_keys,
penumbra_mock_client::MockClient,
penumbra_mock_consensus::TestNode,
Expand All @@ -32,7 +31,7 @@ async fn app_can_define_and_delegate_to_a_validator() -> anyhow::Result<()> {
let storage = TempStorage::new().await?;

// Configure an AppState with slightly shorter epochs than usual.
let app_state = AppState::Content(penumbra_genesis::Content {
let app_state = AppState::Content(penumbra_app::genesis::Content {
sct_content: penumbra_sct::genesis::Content {
sct_params: penumbra_sct::params::SctParameters {
epoch_duration: EPOCH_DURATION,
Expand Down
5 changes: 2 additions & 3 deletions crates/core/app/tests/app_can_undelegate_from_a_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use {
anyhow::anyhow,
ark_ff::UniformRand,
cnidarium::TempStorage,
penumbra_app::server::consensus::Consensus,
penumbra_genesis::AppState,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_keys::test_keys,
penumbra_mock_client::MockClient,
penumbra_mock_consensus::TestNode,
Expand Down Expand Up @@ -59,7 +58,7 @@ async fn app_can_undelegate_from_a_validator() -> anyhow::Result<()> {
};

// Configure an AppState with slightly shorter epochs than usual.
let app_state = AppState::Content(penumbra_genesis::Content {
let app_state = AppState::Content(penumbra_app::genesis::Content {
sct_content: penumbra_sct::genesis::Content {
sct_params: penumbra_sct::params::SctParameters {
epoch_duration: EPOCH_DURATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use {
self::common::BuilderExt,
anyhow::Context,
cnidarium::TempStorage,
penumbra_app::server::consensus::Consensus,
penumbra_genesis::AppState,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_mock_consensus::TestNode,
penumbra_stake::{
component::validator_handler::validator_store::ValidatorDataRead, validator::Validator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use {
self::common::BuilderExt,
anyhow::Context,
cnidarium::TempStorage,
penumbra_app::server::consensus::Consensus,
penumbra_genesis::AppState,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_mock_consensus::TestNode,
penumbra_stake::{
component::validator_handler::validator_store::ValidatorDataRead, validator::Validator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use {
self::common::BuilderExt,
cnidarium::TempStorage,
decaf377_rdsa::{SigningKey, SpendAuth},
penumbra_app::server::consensus::Consensus,
penumbra_genesis::AppState,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_keys::test_keys,
penumbra_mock_client::MockClient,
penumbra_mock_consensus::TestNode,
Expand All @@ -32,7 +31,7 @@ async fn app_tracks_uptime_for_validators_only_once_active() -> anyhow::Result<(
let storage = TempStorage::new().await?;

// Configure an AppState with slightly shorter epochs than usual.
let app_state = AppState::Content(penumbra_genesis::Content {
let app_state = AppState::Content(penumbra_app::genesis::Content {
sct_content: penumbra_sct::genesis::Content {
sct_params: penumbra_sct::params::SctParameters {
epoch_duration: EPOCH_DURATION,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/app/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use {
cnidarium::TempStorage,
penumbra_app::{
app::App,
genesis::AppState,
server::consensus::{Consensus, ConsensusService},
},
penumbra_genesis::AppState,
penumbra_mock_consensus::TestNode,
std::ops::Deref,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/core/app/tests/common/test_node_builder_ext.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
penumbra_genesis::AppState,
penumbra_app::genesis::AppState,
penumbra_mock_consensus::builder::Builder,
penumbra_proto::{
core::keys::v1::{GovernanceKey, IdentityKey},
Expand Down
23 changes: 0 additions & 23 deletions crates/core/genesis/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion deployments/scripts/rust-docs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ cargo +nightly doc --no-deps \
-p penumbra-dex \
-p penumbra-distributions \
-p penumbra-fee \
-p penumbra-genesis \
-p penumbra-governance \
-p penumbra-ibc \
-p penumbra-keys \
Expand Down

0 comments on commit 03a8c11

Please sign in to comment.