Skip to content

Commit

Permalink
Merge branch 'tiago/remove-genesis-aliases' (#2186)
Browse files Browse the repository at this point in the history
* tiago/remove-genesis-aliases:
  changelog: add #2186
  small grammar fixes
  benches: fix the default validator key for signing txs
  genesis: update starter README
  genesis: update README and update files
  Mandatory `--pre-genesis` flag
  Pre-genesis wallet fixes
  Tune error message on invalid chain id
  Make pre-genesis a global arg
  Add some lobsters or something
  Revert "Fix bug in cli arg multi"
  Fix bug in cli arg multi
  Fix e2e test setup
  Change aliases arg
  Check if two pubkeys are used for the same established acc
  Improve genesis tx signing's janky code
  Output unsigned established account txs struct
  Fix signatures once again
  Denominate amounts before signing them
  Fix localnet template sigs
  Set new pre-genesis txs timestamp
  Genesis bond subcmd
  Revert "Use a Unix epoch as a pre-genesis tx timestamp"
  Use a Unix epoch as a pre-genesis tx timestamp
  Fix typo
  Convert some static strs to consts
  Make `vp_user` a constant
  Update masp proofs
  gen_localnet working on mac os
  End-to-end test fixes
  add other missing e2e tests to CI
  fix `test_bond_queries` and trigger in CI
  Fix e2e wallet tests
  Temporarily disable test_bond_queries
  fixing more dumb shit
  Appease clippy
  Set chain id in e2e tests through env var
  Allow the chain id to be configured through an env var
  Fixed stupid epoch sleep and now pass chain-id to post-genesis ledger commands
  [fix] Wallet can generated keys without genesis files
  more e2e fixes
  [fix]: fix e2e test
  Fix setup process on e2e tests
  Rename sign genesis txs subcmd
  Generate localnet script fixes
  Improve signing failure error msg
  Update masp proofs
  Add base dir arg to gen localnet script
  Fix dev genesis
  wip: fixing localnet genesis templates
  lifetime heaven
  lifetime hell
  Validator key validation
  Sign over an actual become validator tx
  Implement signable tx helper
  Sign over an actual bond tx
  sumbish
  Temporarily revert hw wallet signing changes
  some dicking around
  [feat]: Fixed cli tooling for multi-signing txs
  Revert "Unify genesis templates"
  Unify genesis templates
  Revert "Remove established account init CLI subcmd"
  clippy is pleased
  wip mess
  Implement serde serialization for validator meta
  Implement Display and FromStr for established addrs
  Fix rebase + multisig related compilation issues
  Remove established account init CLI subcmd
  rebased on v0.27 and some initial multisig fixes
  Fix masp integration tests
  Update masp proofs
  CLI utils subcmd to derive genesis account addrs
  Rework CLI utils subcmd to generate validator account genesis tx
  CLI utils subcmd to generate established account genesis tx
  Fix PoS rewards rounding errors in unit tests
  Adjust dev genesis
  Early check of available balance to bond
  Fix localnet genesis templates
  Load test established addrs from pre-genesis wallet
  Remove aliases from genesis templates
  • Loading branch information
tzemanovic committed Dec 7, 2023
2 parents ce8167c + 62730cb commit f5cd5a3
Show file tree
Hide file tree
Showing 89 changed files with 3,144 additions and 2,884 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Changed pre-genesis established addresses to be derived from their data.
Improved signing of pre-genesis transactions to use the same format as
regular transactions. Genesis token balances now can be directly assigned to
established addresses. ([\#2186](https://github.com/anoma/namada/pull/2186))
3 changes: 3 additions & 0 deletions .github/workflows/scripts/e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"e2e::ledger_tests::change_validator_metadata": 31,
"e2e::ledger_tests::pos_rewards": 44,
"e2e::ledger_tests::test_invalid_validator_txs": 73,
"e2e::ledger_tests::test_bond_queries": 95,
"e2e::ledger_tests::suspend_ledger": 30,
"e2e::ledger_tests::stop_ledger_at_height": 18,
"e2e::wallet_tests::wallet_address_cmds": 1,
"e2e::wallet_tests::wallet_encrypted_key_cmds": 1,
"e2e::wallet_tests::wallet_encrypted_key_cmds_env_var": 1,
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ impl Default for BenchShieldedCtx {
wallet.save().unwrap();

let ctx = Context::new::<StdIo>(crate::cli::args::Global {
is_pre_genesis: false,
chain_id: Some(shell.inner.chain_id.clone()),
base_dir,
wasm_dir: Some(WASM_DIR.into()),
Expand Down
506 changes: 298 additions & 208 deletions apps/src/lib/cli.rs

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@ impl CliApi {
&mut args.tx.ledger_address,
)
});
client.wait_until_node_is_synced(io).await?;
client.wait_until_node_is_synced(&io).await?;
let args = args.to_sdk(&mut ctx);
let cli::context::ChainContext {
mut wallet,
wallet,
mut config,
mut shielded,
shielded,
native_token,
} = ctx.take_chain_or_exit();
let namada = NamadaImpl::native_new(
&client,
&mut wallet,
&mut shielded,
client,
wallet,
shielded,
io,
native_token,
);
Expand Down Expand Up @@ -645,6 +645,15 @@ impl CliApi {
Utils::InitNetwork(InitNetwork(args)) => {
utils::init_network(global_args, args)
}
Utils::GenesisBond(GenesisBond(args)) => {
utils::genesis_bond(args)
}
Utils::DeriveGenesisAddresses(DeriveGenesisAddresses(args)) => {
utils::derive_genesis_addresses(global_args, args)
}
Utils::InitGenesisEstablishedAccount(
InitGenesisEstablishedAccount(args),
) => utils::init_genesis_established_account(global_args, args),
Utils::InitGenesisValidator(InitGenesisValidator(args)) => {
utils::init_genesis_validator(global_args, args)
}
Expand All @@ -668,8 +677,8 @@ impl CliApi {
Utils::ValidateGenesisTemplates(ValidateGenesisTemplates(
args,
)) => utils::validate_genesis_templates(global_args, args),
Utils::SignGenesisTx(SignGenesisTx(args)) => {
utils::sign_genesis_tx(global_args, args)
Utils::SignGenesisTxs(SignGenesisTxs(args)) => {
utils::sign_genesis_tx(global_args, args).await
}
},
}
Expand Down
33 changes: 24 additions & 9 deletions apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;

use color_eyre::eyre::Result;
use namada::core::types::chain::ChainId;
use namada::ledger::ibc::storage::ibc_token;
use namada::types::address::{Address, InternalAddress};
use namada::types::ethereum_events::EthAddress;
Expand All @@ -28,6 +29,9 @@ use crate::{wallet, wasm_loader};
/// Env. var to set wasm directory
pub const ENV_VAR_WASM_DIR: &str = "NAMADA_WASM_DIR";

/// Env. var to read the Namada chain id from
pub const ENV_VAR_CHAIN_ID: &str = "NAMADA_CHAIN_ID";

/// A raw address (bech32m encoding) or an alias of an address that may be found
/// in the wallet
pub type WalletAddress = FromContext<Address>;
Expand Down Expand Up @@ -92,13 +96,19 @@ impl Context {
pub fn new<IO: Io>(global_args: args::Global) -> Result<Self> {
let global_config = read_or_try_new_global_config(&global_args);

let chain = match global_config.default_chain_id.as_ref() {
Some(default_chain_id) => {
tracing::info!("Default chain ID: {default_chain_id}");
let env_var_chain_id = std::env::var(ENV_VAR_CHAIN_ID)
.ok()
.and_then(|chain_id| ChainId::from_str(&chain_id).ok());
let chain_id = env_var_chain_id
.as_ref()
.or(global_args.chain_id.as_ref())
.or(global_config.default_chain_id.as_ref());

let chain = match chain_id {
Some(chain_id) if !global_args.is_pre_genesis => {
let mut config =
Config::load(&global_args.base_dir, default_chain_id, None);
let chain_dir =
global_args.base_dir.join(default_chain_id.as_str());
Config::load(&global_args.base_dir, chain_id, None);
let chain_dir = global_args.base_dir.join(chain_id.as_str());
let genesis =
genesis::chain::Finalized::read_toml_files(&chain_dir)
.expect("Missing genesis files");
Expand Down Expand Up @@ -131,7 +141,7 @@ impl Context {
native_token,
})
}
None => None,
_ => None,
};

Ok(Self {
Expand Down Expand Up @@ -183,8 +193,13 @@ impl Context {

fn safe_exit_on_missing_chain_context() -> ! {
eprintln!(
"No chain is configured. You may need to run `namada client utils \
join-network` command."
"Failed to construct Namada chain context. If no chain is configured, \
you may need to run `namada client utils join-network`. If the chain \
is configured, you may need to set the chain id with `--chain-id \
<chainid>`, via the env var `{ENV_VAR_CHAIN_ID}`, or configure the \
default chain id in the `global-config.toml` file. If you do intend \
to run pre-genesis operations, pass the `--pre-genesis` flag as the \
first argument to the command."
);
utils::safe_exit(1)
}
Expand Down
131 changes: 92 additions & 39 deletions apps/src/lib/cli/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ const RELAYER_KEY_ENV_VAR: &str = "NAMADA_RELAYER_KEY";
pub type App = clap::Command;
pub type ClapArg = clap::Arg;

/// Mode of operation of [`ArgMulti`] where zero or
/// more arguments may be present (i.e. `<pattern>*`).
pub enum GlobStar {}

/// Mode of operation of [`ArgMulti`] where at least
/// one argument must be present (i.e. `<pattern>+`).
pub enum GlobPlus {}

pub trait Cmd: Sized {
fn add_sub(app: App) -> App;
fn parse(matches: &ArgMatches) -> Option<Self>;
Expand Down Expand Up @@ -93,9 +101,9 @@ pub struct ArgFlag {
}

#[allow(dead_code)]
pub struct ArgMulti<T> {
pub struct ArgMulti<T, K> {
pub name: &'static str,
pub r#type: PhantomData<T>,
pub r#type: PhantomData<(T, K)>,
}

pub const fn arg<T>(name: &'static str) -> Arg<T> {
Expand Down Expand Up @@ -138,8 +146,7 @@ pub const fn flag(name: &'static str) -> ArgFlag {
ArgFlag { name }
}

#[allow(dead_code)]
pub const fn arg_multi<T>(name: &'static str) -> ArgMulti<T> {
pub const fn arg_multi<T, K>(name: &'static str) -> ArgMulti<T, K> {
ArgMulti {
name,
r#type: PhantomData,
Expand All @@ -163,7 +170,15 @@ impl<T> Arg<T> {
}

#[allow(dead_code)]
pub const fn multi(self) -> ArgMulti<T> {
pub const fn multi_glob_star(self) -> ArgMulti<T, GlobStar> {
ArgMulti {
name: self.name,
r#type: PhantomData,
}
}

#[allow(dead_code)]
pub const fn multi_glob_plus(self) -> ArgMulti<T, GlobPlus> {
ArgMulti {
name: self.name,
r#type: PhantomData,
Expand Down Expand Up @@ -237,18 +252,20 @@ where
}
}

impl<T> ArgMulti<FromContext<T>>
where
T: FromStr,
<T as FromStr>::Err: Debug,
{
impl<T, K> ArgMulti<T, K> {
pub fn def(&self) -> ClapArg {
ClapArg::new(self.name)
.long(self.name)
.num_args(1..)
.value_delimiter(',')
}
}

impl<T> ArgMulti<FromContext<T>, GlobStar>
where
T: FromStr,
<T as FromStr>::Err: Debug,
{
pub fn parse(&self, matches: &ArgMatches) -> Vec<FromContext<T>> {
matches
.get_many(self.name)
Expand All @@ -258,52 +275,58 @@ where
}
}

impl<T> ArgDefaultFromCtx<FromContext<T>>
impl<T> ArgMulti<FromContext<T>, GlobPlus>
where
T: FromStr,
<T as FromStr>::Err: Debug,
{
pub fn def(&self) -> ClapArg {
ClapArg::new(self.name).long(self.name).num_args(1)
}

pub fn parse(&self, matches: &ArgMatches) -> FromContext<T> {
let raw = parse_opt(matches, self.name).unwrap_or_else(|| {
let DefaultFn(default) = self.default;
default()
});
FromContext::new(raw)
pub fn parse(&self, matches: &ArgMatches) -> Vec<FromContext<T>> {
matches
.get_many(self.name)
.unwrap_or_else(|| {
eprintln!("Missing at least one argument to `--{}`", self.name);
safe_exit(1)
})
.map(|raw: &String| FromContext::new(raw.to_string()))
.collect()
}
}

impl ArgFlag {
pub fn def(&self) -> ClapArg {
ClapArg::new(self.name)
.long(self.name)
.action(ArgAction::SetTrue)
}

pub fn parse(&self, matches: &ArgMatches) -> bool {
matches.get_flag(self.name)
impl<T> ArgMulti<T, GlobStar>
where
T: FromStr,
<T as FromStr>::Err: Debug,
{
pub fn parse(&self, matches: &ArgMatches) -> Vec<T> {
matches
.get_many(self.name)
.unwrap_or_default()
.map(|raw: &String| {
raw.parse().unwrap_or_else(|e| {
eprintln!(
"Failed to parse the {} argument. Raw value: {}, \
error: {:?}",
self.name, raw, e
);
safe_exit(1)
})
})
.collect()
}
}

#[allow(dead_code)]
impl<T> ArgMulti<T>
impl<T> ArgMulti<T, GlobPlus>
where
T: FromStr,
<T as FromStr>::Err: Debug,
{
pub fn def(&self) -> ClapArg {
ClapArg::new(self.name)
.long(self.name)
.action(ArgAction::Append)
}

pub fn parse(&self, matches: &ArgMatches) -> Vec<T> {
matches
.get_many(self.name)
.unwrap_or_default()
.unwrap_or_else(|| {
eprintln!("Missing at least one argument to `--{}`", self.name);
safe_exit(1)
})
.map(|raw: &String| {
raw.parse().unwrap_or_else(|e| {
eprintln!(
Expand All @@ -318,6 +341,36 @@ where
}
}

impl<T> ArgDefaultFromCtx<FromContext<T>>
where
T: FromStr,
<T as FromStr>::Err: Debug,
{
pub fn def(&self) -> ClapArg {
ClapArg::new(self.name).long(self.name).num_args(1)
}

pub fn parse(&self, matches: &ArgMatches) -> FromContext<T> {
let raw = parse_opt(matches, self.name).unwrap_or_else(|| {
let DefaultFn(default) = self.default;
default()
});
FromContext::new(raw)
}
}

impl ArgFlag {
pub fn def(&self) -> ClapArg {
ClapArg::new(self.name)
.long(self.name)
.action(ArgAction::SetTrue)
}

pub fn parse(&self, matches: &ArgMatches) -> bool {
matches.get_flag(self.name)
}
}

/// Extensions for defining commands and arguments.
/// Every function here should have a matcher in [`ArgMatchesExt`].
pub trait AppExt {
Expand Down
Loading

0 comments on commit f5cd5a3

Please sign in to comment.