Skip to content

Commit

Permalink
feat: more logging statements throughout compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
conorsch committed Sep 12, 2024
1 parent 9efaaec commit 6f8efd9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
18 changes: 13 additions & 5 deletions tools/compiler/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use anyhow::Context;
use std::fs;
use std::path::Path;

use penumbra_asset::asset::Metadata;
use penumbra_proto::core::asset::v1::AssetImage;
use serde::{Deserialize, Serialize};
use tracing::instrument;

use crate::error::AppResult;
use crate::processor::Globals;
Expand Down Expand Up @@ -91,9 +93,10 @@ pub const LOCAL_INPUT_DIR: &str = "../../input";
/// input/
/// ├── penumbra-testnet-deimos-6.json
/// └── mars-1.json
#[instrument]
pub fn get_chain_configs(input_dir: &str) -> AppResult<Vec<ChainConfig>> {
let input_path = Path::new(input_dir).join("chains");
let chain_configs = fs::read_dir(input_path)?;
let chain_configs = fs::read_dir(input_path).context("failed to open chain config dir")?;
Ok(chain_configs
.into_iter()
.map(|input| -> AppResult<ChainConfig> {
Expand All @@ -105,34 +108,38 @@ pub fn get_chain_configs(input_dir: &str) -> AppResult<Vec<ChainConfig>> {
.filter_map(|result| match result {
Ok(config) => Some(config),
Err(e) => {
tracing::info!("{}", e.to_string());
tracing::error!("{}", e.to_string());
None
}
})
.collect())
}

// Validates globals and copies over to registry without change
#[instrument]
pub fn copy_globals(input_dir: &str, registry_dir: &str) -> AppResult<()> {
let input_path = Path::new(input_dir).join("globals.json");
let json_data = fs::read_to_string(input_path)?;
tracing::debug!(?input_path, "reading globals json file");
let json_data = fs::read_to_string(input_path).context("failed to read globals json file")?;
let globals_input: GlobalsInput = serde_json::from_str(&json_data)?;
let globals: Globals = globals_input.try_into()?;

// Write the validated JSON data to the output file
let output_path = Path::new(registry_dir).join("globals.json");
let output_json = serde_json::to_string_pretty::<Globals>(&globals)?;
fs::write(output_path, output_json)?;
fs::write(output_path, output_json).context("failed to write globals json")?;

Ok(())
}

// Deletes and re-creates registry dir
/// Deletes and re-creates registry dir
#[instrument]
pub fn reset_registry_dir(path: &str) -> AppResult<()> {
let dir_path = Path::new(path);

// Create the directory if it doesn't exist
if !dir_path.exists() {
tracing::debug!("creating top-level registry dir");
fs::create_dir_all(dir_path)?;
}

Expand All @@ -148,6 +155,7 @@ pub fn reset_registry_dir(path: &str) -> AppResult<()> {

// Create the "chains" directory inside
let chains_dir = dir_path.join("chains");
tracing::debug!(?chains_dir, "creating chain dir");
fs::create_dir(chains_dir)?;

Ok(())
Expand Down
3 changes: 2 additions & 1 deletion tools/compiler/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct Registry {
pub numeraires: Vec<String>,
}

#[instrument]
pub fn generate_registry() -> AppResult<()> {
reset_registry_dir(LOCAL_REGISTRY_DIR)?;
copy_globals(LOCAL_INPUT_DIR, LOCAL_REGISTRY_DIR)?;
Expand Down Expand Up @@ -137,6 +138,7 @@ pub fn base64_id(id: &Id) -> AppResult<String> {
Ok(base64_str)
}

#[tracing::instrument(skip_all)]
fn process_chain_config(chain_config: ChainConfig) -> AppResult<Registry> {
let mut all_metadata = Vec::new();

Expand All @@ -145,7 +147,6 @@ fn process_chain_config(chain_config: ChainConfig) -> AppResult<Registry> {

// For each ibc connection, grab all metadata of native assets from the cosmos registry
for ibc_input in &chain_config.ibc_connections {
// let assetlist_path = Path::new("./src/chain-registry")
let assetlist_path = Path::new(LOCAL_COSMOS_REGISTRY_DIR)
.join(&ibc_input.cosmos_registry_dir)
.join("assetlist.json");
Expand Down

0 comments on commit 6f8efd9

Please sign in to comment.