Skip to content

Commit

Permalink
Refactored to use single place for adding priority scores
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMHasperhoven committed Oct 22, 2024
1 parent ea1fe46 commit baea632
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions tools/compiler/src/processor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::anyhow;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::fs;
use std::path::Path;
use tracing::instrument;
Expand Down Expand Up @@ -103,7 +102,6 @@ pub fn generate_registry() -> AppResult<()> {
pub fn transport_metadata_along_channel(
ibc_data: &IbcInput,
source_asset: Metadata,
priority_scores_by_base: &HashMap<String, u64>,
) -> AppResult<Metadata> {
// The `Metadata` structure doesn't allow modifying the internals, so drop to raw proto data
let mut pb_metadata: pb::Metadata = source_asset.into();
Expand All @@ -126,11 +124,6 @@ pub fn transport_metadata_along_channel(
// Without this, decoding will fail because the asset ID won't match.
pb_metadata.penumbra_asset_id = None;

// Add priority score if available
if let Some(score) = priority_scores_by_base.get(&pb_metadata.base) {
pb_metadata.priority_score = *score;
}

tracing::trace!(?pb_metadata, "new");
Ok(Metadata::try_from(pb_metadata)?)
}
Expand All @@ -152,14 +145,6 @@ fn process_chain_config(chain_config: ChainConfig) -> AppResult<Registry> {
all_metadata.extend(generate_metadata_from_validators(&chain_config.validators)?);
all_metadata.extend(chain_config.native_assets.clone());

for metadata in &mut all_metadata {
if let Some(score) = chain_config.priority_scores_by_base.get(&metadata.base_denom().denom) {
let mut pb_metadata: pb::Metadata = metadata.clone().into();
pb_metadata.priority_score = *score;
*metadata = Metadata::try_from(pb_metadata)?;
}
}

// 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(LOCAL_COSMOS_REGISTRY_DIR)
Expand All @@ -182,12 +167,20 @@ fn process_chain_config(chain_config: ChainConfig) -> AppResult<Registry> {
let transferred_asset = transport_metadata_along_channel(
ibc_input,
source_asset_metadata,
&chain_config.priority_scores_by_base,
)?;
all_metadata.push(transferred_asset);
}
}

// add priority score if available
for metadata in &mut all_metadata {
if let Some(score) = chain_config.priority_scores_by_base.get(&metadata.base_denom().denom) {
let mut pb_metadata: pb::Metadata = metadata.clone().into();
pb_metadata.priority_score = *score;
*metadata = Metadata::try_from(pb_metadata)?;
}
}

Ok(Registry {
chain_id: chain_config.chain_id,
ibc_connections: chain_config
Expand Down

0 comments on commit baea632

Please sign in to comment.