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

Correct derivation of Penumbra asset ID #4

Merged
merged 1 commit into from
Apr 11, 2024

Conversation

hdevalence
Copy link
Contributor

Rather than manually computing the asset ID, we use the existing penumbra_asset::asset::Metadata structure to derive it from the metadata. This also ensures that we're running our transported Metadata objects through the (de)serialization code we'll eventually use to process them in the client.

@hdevalence hdevalence requested a review from grod220 April 11, 2024 04:25
Rather than manually computing the asset ID, we use the existing
`penumbra_asset::asset::Metadata` structure to derive it from the metadata.
This also ensures that we're running our transported `Metadata` objects through
the (de)serialization code we'll eventually use to process them in the client.
@hdevalence hdevalence force-pushed the improve-metadata-handling branch from 46cd87e to 5ac5062 Compare April 11, 2024 04:40
Comment on lines +74 to +81
// Prefix the channel to the base denom.
prefix_channel(&mut pb_metadata.base);
// Prefix the channel to the display denom.
prefix_channel(&mut pb_metadata.display);
// Prefix the channel to all denom units.
for denom_unit in pb_metadata.denom_units.iter_mut() {
prefix_channel(&mut denom_unit.denom);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should apply the prefix across all denoms and units. Also, I think the Rust Metadata parsing will reject if the base and display don't index into denom_units.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we seemed to miss this in our current registry too: https://github.com/penumbra-zone/web/blob/main/packages/constants/src/local-asset-registry.json#L176-L188. Good to know.

@hdevalence
Copy link
Contributor Author

We should check this against the actual IBC data.

@hdevalence hdevalence merged commit 0cbdba3 into main Apr 11, 2024
3 checks passed
@grod220 grod220 deleted the improve-metadata-handling branch April 11, 2024 09:19
let asset_json = serde_json::to_string(&source_asset)?;
let transferred_asset =
transport_metadata_along_channel(&ibc_data, serde_json::from_str(&asset_json)?);
tracing::info!(?asset_json, transferred_asset_json = ?serde_json::to_string(&transferred_asset));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this outputting something helpful for you? I just see what feels like a bunch of noise. But maybe it's me not familiar with this tracing library.

Screenshot 2024-04-11 at 1 00 45 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was using it to inspect the JSON output and determine how the encodings differed during debugging. We can remove

pb_metadata.penumbra_asset_id = None;

tracing::debug!(?pb_metadata, "new");
Metadata::try_from(pb_metadata).unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we should return a result here. I'll get this in a later PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think so, if we had valid Metadata to start, our modifications should also be valid, or else the compiler should fail.

Comment on lines +74 to +81
// Prefix the channel to the base denom.
prefix_channel(&mut pb_metadata.base);
// Prefix the channel to the display denom.
prefix_channel(&mut pb_metadata.display);
// Prefix the channel to all denom units.
for denom_unit in pb_metadata.denom_units.iter_mut() {
prefix_channel(&mut denom_unit.denom);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we seemed to miss this in our current registry too: https://github.com/penumbra-zone/web/blob/main/packages/constants/src/local-asset-registry.json#L176-L188. Good to know.

// Prefix the channel to the base denom.
prefix_channel(&mut pb_metadata.base);
// Prefix the channel to the display denom.
prefix_channel(&mut pb_metadata.display);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we indeed want to show transfer/channel-0/usomo in our UI if we believe it's the canonical one? I believe minifront is using display in a few places 🤔 . I suppose if we rely on symbol, this wouldn't be an issue anyway. Though, a native assets on two different connected chains could in theory conflict on symbol.

Copy link
Contributor Author

@hdevalence hdevalence Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we should use this as a forcing function to only ever use the symbol field in normie UI

@@ -74,5 +74,6 @@ pub fn get_chain_configs() -> AppResult<Vec<ChainConfig>> {
};
Ok(chain_config)
})
.collect()
.filter_map(|result| result.ok())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to throw if the user did not set up the file structure correctly? Wouldn't this mean it kinda would silently fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I did this along the way to starting towards having it consume a git submodule and change the input directory structure, which I abandoned and then wrote up as a follow on issue. Getting output of some kind felt (feels) more important

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants