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

Optimize building chain ctx #3655

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changelog/unreleased/improvements/3655-speed-up-ctx-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- Speeds up client commands on networks with massive balances.toml
files. Previously, to retrieve the native token of some network,
we had to parse these giant files. Now, we only parse the
necessary genesis toml files required to retrieve the native token.
([\#3655](https://github.com/anoma/namada/pull/3655))
5 changes: 2 additions & 3 deletions crates/apps_lib/src/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,9 @@ impl Context {
let mut config =
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)
let native_token =
genesis::chain::Finalized::read_native_token(&chain_dir)
.expect("Missing genesis files");
let native_token = genesis.get_native_token().clone();
let wallet = if wallet::exists(&chain_dir) {
wallet::load(&chain_dir).unwrap()
} else {
Expand Down
18 changes: 18 additions & 0 deletions crates/apps_lib/src/config/genesis/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ impl Finalized {
Ok(())
}

/// Attempt to read the address of the native token.
pub fn read_native_token(input_dir: &Path) -> eyre::Result<Address> {
let tokens_file = input_dir.join(templates::TOKENS_FILE_NAME);
let parameters_file = input_dir.join(templates::PARAMETERS_FILE_NAME);

let mut tokens: FinalizedTokens = read_toml(&tokens_file, "Tokens")?;
let parameters: FinalizedParameters =
read_toml(&parameters_file, "Parameters")?;

let alias = &parameters.parameters.native_token;

Ok(tokens
.token
.remove(alias)
.expect("The native token must exist")
.address)
}

/// Try to read all genesis and the chain metadata TOML files from the given
/// directory.
pub fn read_toml_files(input_dir: &Path) -> eyre::Result<Self> {
Expand Down