Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up init/join network CLI commands #3196

Merged
merged 28 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a8e20f5
Package wasm artifacts with chain dist
sug0 May 7, 2024
5c01709
Stop copying wasm checksums twice to chain dist archive
sug0 May 7, 2024
6ad0237
Do not include base dir in chain dist archive
sug0 May 7, 2024
229502b
Only emit chain dist archive from `init-network`
sug0 May 7, 2024
611ae38
Skip nonexistent wasm artifacts in `init-network`
sug0 May 7, 2024
5d56cb7
Return path to release archive from `init-network`
sug0 May 7, 2024
11ae122
Fix `init-network` in integration tests
sug0 May 7, 2024
2a3cf72
Fix `join-network` in light of `init-network` changes
sug0 May 8, 2024
2cbba3e
Rework `fetch-wasms` command
sug0 May 8, 2024
010aeb9
Introduce helper fns to fetch wasm artifacts dir
sug0 May 8, 2024
7658ae2
Optionally add persistent peers to CometBFT
sug0 May 8, 2024
bcffea5
Remove fetch wasms CLI cmd
sug0 May 10, 2024
5a96cae
scripts/gen_localnet.py: Format code
sug0 May 8, 2024
004d1ba
scripts/gen_localnet.py: Move code to main function
sug0 May 8, 2024
4a43c4b
scripts/gen_localnet.py: Refactor to improve code quality
sug0 May 8, 2024
ff687dd
scripts/gen_localnet.py: Make script executable
sug0 May 8, 2024
33c8485
scripts/gen_localnet.py: Generalize `join-network`
sug0 May 9, 2024
824f9e4
scripts/gen_localnet.py: Copy pre-genesis wallet to validator dir
sug0 May 9, 2024
cff5ec3
scripts/gen_localnet.py: Move `init-network` to fn
sug0 May 9, 2024
ca275fc
scripts/gen_localnet.py: Use modified templates
sug0 May 9, 2024
31c0b34
scripts/gen_localnet.py: Add colored output
sug0 May 9, 2024
313d5a6
scripts/gen_localnet.py: Log which validator is joining network
sug0 May 9, 2024
39836d7
scripts/gen_localnet.py: Remove chain id from cmd str
sug0 May 9, 2024
0a2d646
scripts/gen_localnet.py: Support multiple validators
sug0 May 9, 2024
b93426e
scripts/gen_localnet.py: Organize CLI args
sug0 May 9, 2024
b8bd8f2
scripts/gen_localnet.py: Parse epoch duration
sug0 May 9, 2024
fd58288
Remove unused global args in `init-network`
sug0 May 10, 2024
a61cbed
Changelog for #3196
sug0 May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/3196-chain-init-cleanup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Clean up init/join network CLI commands and the `gen_localnet.py` script.
([\#3196](https://github.com/anoma/namada/pull/3196))
2 changes: 2 additions & 0 deletions Cargo.lock

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

56 changes: 8 additions & 48 deletions crates/apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,6 @@ pub mod cmds {
#[derive(Clone, Debug)]
pub enum Utils {
JoinNetwork(JoinNetwork),
FetchWasms(FetchWasms),
ValidateWasm(ValidateWasm),
InitNetwork(InitNetwork),
DeriveGenesisAddresses(DeriveGenesisAddresses),
Expand All @@ -2187,7 +2186,6 @@ pub mod cmds {
matches.subcommand_matches(Self::CMD).and_then(|matches| {
let join_network =
SubCmd::parse(matches).map(Self::JoinNetwork);
let fetch_wasms = SubCmd::parse(matches).map(Self::FetchWasms);
let validate_wasm =
SubCmd::parse(matches).map(Self::ValidateWasm);
let init_network =
Expand All @@ -2214,7 +2212,6 @@ pub mod cmds {
let parse_migrations_json =
SubCmd::parse(matches).map(Self::ParseMigrationJson);
join_network
.or(fetch_wasms)
.or(validate_wasm)
.or(init_network)
.or(derive_addresses)
Expand All @@ -2235,7 +2232,6 @@ pub mod cmds {
App::new(Self::CMD)
.about("Utilities.")
.subcommand(JoinNetwork::def())
.subcommand(FetchWasms::def())
.subcommand(ValidateWasm::def())
.subcommand(InitNetwork::def())
.subcommand(DeriveGenesisAddresses::def())
Expand Down Expand Up @@ -2273,25 +2269,6 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct FetchWasms(pub args::FetchWasms);

impl SubCmd for FetchWasms {
const CMD: &'static str = "fetch-wasms";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| Self(args::FetchWasms::parse(matches)))
}

fn def() -> App {
App::new(Self::CMD)
.about("Ensure pre-built wasms are present")
.add_args::<args::FetchWasms>()
}
}

#[derive(Clone, Debug)]
pub struct ValidateWasm(pub args::ValidateWasm);

Expand Down Expand Up @@ -2995,6 +2972,7 @@ pub mod args {
use crate::facade::tendermint_rpc::Url;

pub const ADDRESS: Arg<WalletAddress> = arg("address");
pub const ADD_PERSISTENT_PEERS: ArgFlag = flag("add-persistent-peers");
pub const ALIAS_OPT: ArgOpt<String> = ALIAS.opt();
pub const ALIAS: Arg<String> = arg("alias");
pub const ALIAS_FORCE: ArgFlag = flag("alias-force");
Expand Down Expand Up @@ -3069,7 +3047,6 @@ pub mod args {
arg("destination-validator");
pub const DISCORD_OPT: ArgOpt<String> = arg_opt("discord-handle");
pub const DO_IT: ArgFlag = flag("do-it");
pub const DONT_ARCHIVE: ArgFlag = flag("dont-archive");
pub const DONT_PREFETCH_WASM: ArgFlag = flag("dont-prefetch-wasm");
pub const DRY_RUN_TX: ArgFlag = flag("dry-run");
pub const DRY_RUN_WRAPPER_TX: ArgFlag = flag("dry-run-wrapper");
Expand Down Expand Up @@ -7165,6 +7142,7 @@ pub mod args {
pub pre_genesis_path: Option<PathBuf>,
pub dont_prefetch_wasm: bool,
pub allow_duplicate_ip: bool,
pub add_persistent_peers: bool,
}

impl Args for JoinNetwork {
Expand All @@ -7174,12 +7152,14 @@ pub mod args {
let pre_genesis_path = PRE_GENESIS_PATH.parse(matches);
let dont_prefetch_wasm = DONT_PREFETCH_WASM.parse(matches);
let allow_duplicate_ip = ALLOW_DUPLICATE_IP.parse(matches);
let add_persistent_peers = ADD_PERSISTENT_PEERS.parse(matches);
Self {
chain_id,
genesis_validator,
pre_genesis_path,
dont_prefetch_wasm,
allow_duplicate_ip,
add_persistent_peers,
}
}

Expand All @@ -7195,6 +7175,10 @@ pub mod args {
"Toggle to disable guard against peers connecting from the \
same IP. This option shouldn't be used in mainnet.",
))
.arg(ADD_PERSISTENT_PEERS.def().help(
"Whether to add persistent peers to the P2P config of CometBFT, \
derived from the list of genesis validators.",
))
}
}

Expand Down Expand Up @@ -7230,22 +7214,6 @@ pub mod args {
}
}

#[derive(Clone, Debug)]
pub struct FetchWasms {
pub chain_id: ChainId,
}

impl Args for FetchWasms {
fn parse(matches: &ArgMatches) -> Self {
let chain_id = CHAIN_ID.parse(matches);
Self { chain_id }
}

fn def(app: App) -> App {
app.arg(CHAIN_ID.def().help("The chain ID. The chain must be known in the https://github.com/heliaxdev/anoma-network-config repository, in which case it should have pre-built wasms available for download."))
}
}

#[derive(Clone, Debug)]
pub struct ValidateWasm {
pub code_path: PathBuf,
Expand Down Expand Up @@ -7273,7 +7241,6 @@ pub mod args {
pub chain_id_prefix: ChainIdPrefix,
pub genesis_time: DateTimeUtc,
pub consensus_timeout_commit: Timeout,
pub dont_archive: bool,
pub archive_dir: Option<PathBuf>,
}

Expand All @@ -7285,15 +7252,13 @@ pub mod args {
let genesis_time = GENESIS_TIME.parse(matches);
let consensus_timeout_commit =
CONSENSUS_TIMEOUT_COMMIT.parse(matches);
let dont_archive = DONT_ARCHIVE.parse(matches);
let archive_dir = ARCHIVE_DIR.parse(matches);
Self {
templates_path,
wasm_checksums_path,
chain_id_prefix,
genesis_time,
consensus_timeout_commit,
dont_archive,
archive_dir,
}
}
Expand All @@ -7320,11 +7285,6 @@ pub mod args {
"The Tendermint consensus timeout_commit configuration as \
e.g. `1s` or `1000ms`. Defaults to 10 seconds.",
))
.arg(
DONT_ARCHIVE
.def()
.help("Do NOT create the release archive."),
)
.arg(ARCHIVE_DIR.def().help(
"Specify a directory into which to store the archive. Default \
is the current working directory.",
Expand Down
5 changes: 1 addition & 4 deletions crates/apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,14 +727,11 @@ impl CliApi {
Utils::JoinNetwork(JoinNetwork(args)) => {
utils::join_network(global_args, args).await
}
Utils::FetchWasms(FetchWasms(args)) => {
utils::fetch_wasms(global_args, args).await
}
Utils::ValidateWasm(ValidateWasm(args)) => {
utils::validate_wasm(args)
}
Utils::InitNetwork(InitNetwork(args)) => {
utils::init_network(global_args, args)
utils::init_network(args);
}
Utils::GenesisBond(GenesisBond(args)) => {
utils::genesis_bond(args)
Expand Down
36 changes: 25 additions & 11 deletions crates/apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ pub struct ChainContext {
pub native_token: Address,
}

/// Convenience function wrapping over [`wasm_dir_from_env_or`].
pub fn wasm_dir_from_env_or_args(
global_args: &args::Global,
) -> Option<PathBuf> {
wasm_dir_from_env_or(global_args.wasm_dir.as_ref())
}

/// Return the wasm artifacts path in use.
pub fn wasm_dir_from_env_or<P: AsRef<Path>>(
wasm_dir: Option<&P>,
) -> Option<PathBuf> {
wasm_dir
.map(|wasm_dir| wasm_dir.as_ref().to_owned())
.or_else(|| {
env::var(ENV_VAR_WASM_DIR)
.ok()
.map(|wasm_dir| wasm_dir.into())
})
}

impl Context {
pub fn new<IO: Io>(global_args: args::Global) -> Result<Self> {
let global_config = read_or_try_new_global_config(&global_args);
Expand Down Expand Up @@ -154,18 +174,12 @@ impl Context {
);
};

// If the WASM dir specified, put it in the config
match global_args.wasm_dir.as_ref() {
Some(wasm_dir) => {
config.wasm_dir = wasm_dir.clone();
}
None => {
if let Ok(wasm_dir) = env::var(ENV_VAR_WASM_DIR) {
let wasm_dir: PathBuf = wasm_dir.into();
config.wasm_dir = wasm_dir;
}
}
// Put WASM dir path in the config
if let Some(wasm_dir) = wasm_dir_from_env_or_args(&global_args)
{
config.wasm_dir = wasm_dir;
}

Some(ChainContext {
wallet,
config,
Expand Down
Loading
Loading