Skip to content

Commit

Permalink
pd: rename "testnet" subcommand to "network"
Browse files Browse the repository at this point in the history
Mostly a cosmetic change, since it's a rename. Requires lots of
carry-over throughout the docs. Kept the internal APIs the same for the
most part. This is a breaking change from the context of node operators,
though, because now pd will look in a different location for info.
  • Loading branch information
conorsch committed Jul 1, 2024
1 parent f454f80 commit f7aaf61
Show file tree
Hide file tree
Showing 32 changed files with 206 additions and 266 deletions.
10 changes: 5 additions & 5 deletions crates/bin/pcli/tests/network_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,8 @@ fn mismatched_consensus_key_update_fails() {
let mut new_validator_def: ValidatorToml = toml::from_str(&template_content)
.expect("Could not parse initial validator template as TOML");

// Now we retrieve the actual tendermint consensus key from the testnet data dir.
// Doing so assumes that the testnet-generated data was previously but in place,
// Now we retrieve the actual cometbft consensus key from the network data dir.
// Doing so assumes that the generated data was previously but in place,
// which is a reasonable assumption in the context of running smoketest suite.
let userdir = UserDirs::new().unwrap();
let homedir = userdir
Expand All @@ -876,7 +876,7 @@ fn mismatched_consensus_key_update_fails() {
let tm_key_filepath: PathBuf = [
homedir,
".penumbra",
"testnet_data",
"network_data",
"node0",
"cometbft",
"config",
Expand All @@ -886,10 +886,10 @@ fn mismatched_consensus_key_update_fails() {
.collect();
let tm_key_config: Value =
serde_json::from_str(&std::fs::read_to_string(tm_key_filepath).unwrap())
.expect("Could not read tendermint key config file");
.expect("Could not read cometbft key config file");
let tm_key: tendermint::PublicKey =
serde_json::value::from_value(tm_key_config["pub_key"].clone())
.expect("Could not parse tendermint key config file");
.expect("Could not parse cometbft key config file");

// Modify initial validator definition template to use actual tm key.
new_validator_def.consensus_key = tm_key;
Expand Down
27 changes: 14 additions & 13 deletions crates/bin/pd/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum RootCommand {
/// Starts the Penumbra daemon.
Start {
/// The path used to store all `pd`-related data and configuration.
/// If unset, defaults to ~/.penumbra/testnet_data/node0/pd.
/// If unset, defaults to ~/.penumbra/network_data/node0/pd.
#[clap(long, env = "PENUMBRA_PD_HOME", display_order = 100)]
home: Option<PathBuf>,
/// Bind the ABCI server to this socket.
Expand Down Expand Up @@ -48,7 +48,7 @@ pub enum RootCommand {
/// NOTE: This option automatically provisions TLS certificates from
/// Let's Encrypt and caches them in the `home` directory. The
/// production LE CA has rate limits, so be careful using this option
/// with `pd testnet unsafe-reset-all`, which will delete the certificates
/// with `pd network unsafe-reset-all`, which will delete the certificates
/// and force re-issuance, possibly hitting the rate limit. See the
/// `--acme-staging` option.
#[clap(long, value_name = "DOMAIN", display_order = 200)]
Expand Down Expand Up @@ -94,14 +94,14 @@ pub enum RootCommand {
enable_expensive_rpc: bool,
},

/// Generate, join, or reset a testnet.
Testnet {
/// Generate, join, or reset a network.
Network {
/// Path to directory to store output in. Must not exist. Defaults to
/// ~/.penumbra/testnet_data".
/// ~/.penumbra/network_data".
#[clap(long)]
testnet_dir: Option<PathBuf>,
network_dir: Option<PathBuf>,
#[clap(subcommand)]
tn_cmd: TestnetCommand,
net_cmd: NetworkCommand,
},

/// Export the storage state the full node.
Expand Down Expand Up @@ -148,9 +148,9 @@ pub enum RootCommand {
}

#[derive(Debug, Subcommand)]
pub enum TestnetCommand {
pub enum NetworkCommand {
/// Generates a directory structure containing necessary files to create a new
/// testnet from genesis, based on input configuration.
/// network config from genesis, based on input configuration.
Generate {
/// The `timeout_commit` parameter (block interval) to configure Tendermint with.
#[clap(long)]
Expand All @@ -164,7 +164,7 @@ pub enum TestnetCommand {
/// Maximum number of validators in the consensus set.
#[clap(long)]
active_validator_limit: Option<u64>,
/// Whether to preserve the chain ID (useful for public testnets) or append a random suffix (useful for dev/testing).
/// Whether to preserve the chain ID (useful for public networks) or append a random suffix (useful for dev/testing).
#[clap(long)]
preserve_chain_id: bool,
/// Path to CSV file containing initial allocations [default: latest testnet].
Expand Down Expand Up @@ -209,9 +209,10 @@ pub enum TestnetCommand {
external_addresses: Option<String>,
},

/// Like `testnet generate`, but joins the testnet to which the specified node belongs
/// Like `network generate`, but joins the network to which the specified node belongs.
/// Requires a URL for the CometBFT RPC for the bootstrap node.
Join {
/// URL of the remote Tendermint RPC endpoint for bootstrapping connection.
/// URL of the remote CometBFT RPC endpoint for bootstrapping connection.
#[clap(
env = "PENUMBRA_PD_JOIN_URL",
default_value = "https://rpc.testnet.penumbra.zone"
Expand Down Expand Up @@ -243,6 +244,6 @@ pub enum TestnetCommand {
leave_archive: bool,
},

/// Reset all `pd` testnet state.
/// Reset all `pd` network state. This is a destructive action!
UnsafeResetAll {},
}
2 changes: 1 addition & 1 deletion crates/bin/pd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod metrics;

pub mod cli;
pub mod migrate;
pub mod testnet;
pub mod network;
pub mod zipserve;

pub use crate::metrics::register_metrics;
Expand Down
60 changes: 30 additions & 30 deletions crates/bin/pd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use anyhow::{anyhow, Context};
use cnidarium::Storage;
use metrics_exporter_prometheus::PrometheusBuilder;
use pd::{
cli::{Opt, RootCommand, TestnetCommand},
cli::{Opt, RootCommand, NetworkCommand},
migrate::Migration::{ReadyToStart, Testnet78},
testnet::{
config::{get_testnet_dir, parse_tm_address, url_has_necessary_parts},
generate::TestnetConfig,
join::testnet_join,
network::{
config::{get_network_dir, parse_tm_address, url_has_necessary_parts},
generate::NetworkConfig,
join::network_join,
},
};
use penumbra_app::SUBSTORE_PREFIXES;
Expand Down Expand Up @@ -93,7 +93,7 @@ async fn main() -> anyhow::Result<()> {
// to a sane value if unspecified.
let pd_home = match home {
Some(h) => h,
None => get_testnet_dir(None).join("node0").join("pd"),
None => get_network_dir(None).join("node0").join("pd"),
};
let rocksdb_home = pd_home.join("rocksdb");

Expand Down Expand Up @@ -237,25 +237,25 @@ async fn main() -> anyhow::Result<()> {
};
}

RootCommand::Testnet {
tn_cmd: TestnetCommand::UnsafeResetAll {},
testnet_dir,
RootCommand::Network {
net_cmd: NetworkCommand::UnsafeResetAll {},
network_dir,
} => {
let testnet_dir = get_testnet_dir(testnet_dir);
if testnet_dir.exists() {
tracing::info!("Removing testnet directory: {}", testnet_dir.display());
std::fs::remove_dir_all(testnet_dir)?;
let network_dir = get_network_dir(network_dir);
if network_dir.exists() {
tracing::info!("Removing testnet directory: {}", network_dir.display());
std::fs::remove_dir_all(network_dir)?;
} else {
tracing::info!(
"Testnet directory does not exist, so not removing: {}",
testnet_dir.display()
network_dir.display()
);
}
}

RootCommand::Testnet {
tn_cmd:
TestnetCommand::Join {
RootCommand::Network {
net_cmd:
NetworkCommand::Join {
node,
archive_url,
moniker,
Expand All @@ -264,9 +264,9 @@ async fn main() -> anyhow::Result<()> {
tendermint_p2p_bind,
leave_archive,
},
testnet_dir,
network_dir,
} => {
let output_dir = get_testnet_dir(testnet_dir);
let output_dir = get_network_dir(network_dir);

// If the output directory already exists, bail out, rather than overwriting.
if output_dir.exists() {
Expand All @@ -291,9 +291,9 @@ async fn main() -> anyhow::Result<()> {
None => format!("node-{}", hex::encode(OsRng.gen::<u32>().to_le_bytes())),
};

// Join the target testnet, looking up network info and writing
// local configs for pd and tendermint.
testnet_join(
// Join the target network, looking up network info and writing
// local configs for pd and cometbft.
network_join(
output_dir.clone(),
node,
&node_name,
Expand All @@ -305,14 +305,14 @@ async fn main() -> anyhow::Result<()> {

// Download and extract archive URL, if set.
if let Some(archive_url) = archive_url {
pd::testnet::join::unpack_state_archive(archive_url, output_dir, leave_archive)
pd::network::join::unpack_state_archive(archive_url, output_dir, leave_archive)
.await?;
}
}

RootCommand::Testnet {
tn_cmd:
TestnetCommand::Generate {
RootCommand::Network {
net_cmd:
NetworkCommand::Generate {
peer_address_template,
timeout_commit,
epoch_duration,
Expand All @@ -326,7 +326,7 @@ async fn main() -> anyhow::Result<()> {
external_addresses,
proposal_voting_blocks,
},
testnet_dir,
network_dir,
} => {
// Build script computes the latest testnet name and sets it as an env variable
let chain_id = match preserve_chain_id {
Expand All @@ -342,7 +342,7 @@ async fn main() -> anyhow::Result<()> {
}
};

let output_dir = get_testnet_dir(testnet_dir);
let output_dir = get_network_dir(network_dir);
// If the output directory already exists, bail out, rather than overwriting.
if output_dir.exists() {
anyhow::bail!(
Expand Down Expand Up @@ -371,7 +371,7 @@ async fn main() -> anyhow::Result<()> {

// Build and write local configs based on input flags.
tracing::info!(?chain_id, "Generating network config");
let t = TestnetConfig::generate(
let t = NetworkConfig::generate(
&chain_id,
Some(output_dir),
peer_address_template,
Expand Down Expand Up @@ -448,7 +448,7 @@ async fn main() -> anyhow::Result<()> {
None => {
// If no pd_home was configured, we're assuming we set up the
// data in the default location, in which case we also know where comet lives.
let base = get_testnet_dir(None).join("node0");
let base = get_network_dir(None).join("node0");
(base.join("pd"), Some(base.join("cometbft")))
}
};
Expand Down
8 changes: 4 additions & 4 deletions crates/bin/pd/src/migrate/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use penumbra_app::app::StateReadExt as _;
use penumbra_sct::component::clock::{EpochManager, EpochRead};
use std::path::PathBuf;

use crate::testnet::generate::TestnetConfig;
use crate::network::generate::NetworkConfig;
pub async fn migrate(
storage: Storage,
path_to_export: PathBuf,
Expand Down Expand Up @@ -47,7 +47,7 @@ pub async fn migrate(
chain_id,
..Default::default()
};
let mut genesis = TestnetConfig::make_genesis(app_state.clone()).expect("can make genesis");
let mut genesis = NetworkConfig::make_genesis(app_state.clone()).expect("can make genesis");
genesis.app_hash = app_hash
.0
.to_vec()
Expand All @@ -60,15 +60,15 @@ pub async fn migrate(
now
});
let checkpoint = app_hash.0.to_vec();
let genesis = TestnetConfig::make_checkpoint(genesis, Some(checkpoint));
let genesis = NetworkConfig::make_checkpoint(genesis, Some(checkpoint));

let genesis_json = serde_json::to_string(&genesis).expect("can serialize genesis");
tracing::info!("genesis: {}", genesis_json);
let genesis_path = path_to_export.join("genesis.json");
std::fs::write(genesis_path, genesis_json).expect("can write genesis");

let validator_state_path = path_to_export.join("priv_validator_state.json");
let fresh_validator_state = crate::testnet::generate::TestnetValidator::initial_state();
let fresh_validator_state = crate::network::generate::NetworkValidator::initial_state();
std::fs::write(validator_state_path, fresh_validator_state).expect("can write validator state");
Ok(())
}
8 changes: 4 additions & 4 deletions crates/bin/pd/src/migrate/testnet72.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use tonic::IntoRequest;

use crate::testnet::generate::TestnetConfig;
use crate::network::generate::NetworkConfig;

/// The context holding various query services we need to help perform the migration.
#[derive(Clone)]
Expand Down Expand Up @@ -173,7 +173,7 @@ pub async fn migrate(
chain_id,
..Default::default()
};
let mut genesis = TestnetConfig::make_genesis(app_state.clone()).expect("can make genesis");
let mut genesis = NetworkConfig::make_genesis(app_state.clone()).expect("can make genesis");
genesis.app_hash = post_upgrade_root_hash
.0
.to_vec()
Expand All @@ -186,15 +186,15 @@ pub async fn migrate(
now
});
let checkpoint = post_upgrade_root_hash.0.to_vec();
let genesis = TestnetConfig::make_checkpoint(genesis, Some(checkpoint));
let genesis = NetworkConfig::make_checkpoint(genesis, Some(checkpoint));

let genesis_json = serde_json::to_string(&genesis).expect("can serialize genesis");
tracing::info!("genesis: {}", genesis_json);
let genesis_path = path_to_export.join("genesis.json");
std::fs::write(genesis_path, genesis_json).expect("can write genesis");

let validator_state_path = path_to_export.join("priv_validator_state.json");
let fresh_validator_state = crate::testnet::generate::TestnetValidator::initial_state();
let fresh_validator_state = crate::network::generate::NetworkValidator::initial_state();
std::fs::write(validator_state_path, fresh_validator_state).expect("can write validator state");

tracing::info!(
Expand Down
8 changes: 4 additions & 4 deletions crates/bin/pd/src/migrate/testnet74.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use penumbra_proto::{penumbra::core::component as pb, StateReadProto, StateWrite
use penumbra_sct::component::clock::{EpochManager, EpochRead};
use std::path::PathBuf;

use crate::testnet::generate::TestnetConfig;
use crate::network::generate::NetworkConfig;

/// Writes the auction parameters to the chain state.
async fn write_auction_parameters(delta: &mut StateDelta<Snapshot>) -> anyhow::Result<()> {
Expand Down Expand Up @@ -177,7 +177,7 @@ pub async fn migrate(
chain_id,
..Default::default()
};
let mut genesis = TestnetConfig::make_genesis(app_state.clone()).expect("can make genesis");
let mut genesis = NetworkConfig::make_genesis(app_state.clone()).expect("can make genesis");
genesis.app_hash = post_upgrade_root_hash
.0
.to_vec()
Expand All @@ -190,15 +190,15 @@ pub async fn migrate(
now
});
let checkpoint = post_upgrade_root_hash.0.to_vec();
let genesis = TestnetConfig::make_checkpoint(genesis, Some(checkpoint));
let genesis = NetworkConfig::make_checkpoint(genesis, Some(checkpoint));

let genesis_json = serde_json::to_string(&genesis).expect("can serialize genesis");
tracing::info!("genesis: {}", genesis_json);
let genesis_path = path_to_export.join("genesis.json");
std::fs::write(genesis_path, genesis_json).expect("can write genesis");

let validator_state_path = path_to_export.join("priv_validator_state.json");
let fresh_validator_state = crate::testnet::generate::TestnetValidator::initial_state();
let fresh_validator_state = crate::network::generate::NetworkValidator::initial_state();
std::fs::write(validator_state_path, fresh_validator_state).expect("can write validator state");

tracing::info!(
Expand Down
Loading

0 comments on commit f7aaf61

Please sign in to comment.