Skip to content

proof: add decimal display as TLV field to meta reveal #998

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

Closed
wants to merge 4 commits into from

Conversation

guggero
Copy link
Member

@guggero guggero commented Jul 9, 2024

Minimal implementation that fixes #956.
Also fixes #997.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 💃🏾

@jharveyb jharveyb self-requested a review July 10, 2024 03:03
Copy link
Contributor

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

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

Looks good overall! Def cleaner than what we had before.

Added comments + I think we want to add this field to the AssetMeta proto as well + pipe it through there? If it's actually going to be a TLV field.

message AssetMeta {

rpcserver.go Outdated
@@ -552,15 +552,13 @@ func (r *rpcServer) MintAsset(ctx context.Context,
// If a custom decimal display was requested, add that to the
// metadata and re-validate it.
if metaType == proof.MetaJson && req.Asset.DecimalDisplay != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this condition now needs to change and not require the metaType to be JSON?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! Fixed this and a couple of other occurrences of similar checks.

@jharveyb
Copy link
Contributor

Also, I don't see the utility of adding this field as JSON in the metadata any more?

IIRC the actual user request was 'it shows up in RPC responses', and if its also discoverable from decoding proofs then it seems redundant. AFAICT we never read it after setting it.

@Roasbeef
Copy link
Member

Also, I don't see the utility of adding this field as JSON in the metadata any more?

Good point, we can just leave it out there.

@Roasbeef
Copy link
Member

I think we want to add this field to the AssetMeta proto as well

Technically it's part of the the metal reveal, which contains the raw asset meta, and now these additional bytes. I guess it's useful though to have it there if people want to use FetchAssetMeta to query the decimal value.

@jharveyb
Copy link
Contributor

I think we want to add this field to the AssetMeta proto as well

Technically it's part of the the metal reveal, which contains the raw asset meta, and now these additional bytes. I guess it's useful though to have it there if people want to use FetchAssetMeta to query the decimal value.

Just realized it's now also input for MetaReveal.MetaHash() - so definitely 'consensus' if we're going to leave that as is.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Discussed offline, and concluded that this approach was a bit too slick to be true:

  • Old clients won't know of this meta reveal field.
  • They'll parse the meta reveal w/o the new field, then go to check against the meta hash.
  • That fails as they didn't include the portion they didn't know about.

Copy link
Member

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

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

So the purpose here was to drop this field to the MetaReveal level in order to support dec display for custom meta data?

Type: MetaJson,
Data: []byte(`{"key": "value"}`),
DecimalDisplay: 8,
},
Copy link
Member

Choose a reason for hiding this comment

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

could also check against Opaque data type and also with 0 dec display

@guggero
Copy link
Member Author

guggero commented Jul 10, 2024

Discussed offline, and concluded that this approach was a bit too slick to be true:

* Old clients won't know of this meta reveal field.

* They'll parse the meta reveal w/o the new field, then go to check against the meta hash.

* That fails as they didn't include the portion they didn't know about.

Ah, yes, nice catch.

Adding a summary of my comments made offline here for reference:

I see two possibilities for something we could do now:

  1. don't add the decimal display to the meta hash (e.g. don't commit to it, just put it there as informational piece of data). not super nice and probably opens the door for shenanigans
  2. add a "feature bit" to the meta type that indicates the meta data is nested TLV. then old nodes just read in the meta data as a blob and arrive at the correct hash. and new nodes would see the feature bit and do a second round of TLV decode on the data, being able to read and interpret extra fields that we put in there (the "actual" raw meta data being one of the sub fields). should work but feels veeery hacky...

I guess doing the two-level TLV encoding would qualify as "carveout/placeholder for future fields" as described in the issue #997. it just feels very hacky if we need to describe it in the BIP as "two levels of TLV encoding, depending on a feature bit"... but happy to go ahead and implement it, if we think it's the way to go

@guggero guggero force-pushed the tlv-decimal-display branch from 3636c9c to 03b0b0c Compare July 10, 2024 18:20
guggero added 4 commits July 10, 2024 20:20
With this commit we add the decimal display as a new TLV field on the
meta reveal. We'll still encode it within the JSON meta data if the meta
data is of type JSON. For all other types we can now also carry the
value, to make sure we don't put any type constraints on future asset
mints (in case issuers want to use a different format than JSON).

Since we're using TLV, old meta reveals should still be read correctly
and the default value of 0 is assumed for any meta reveal that doesn't
have the explicit record set.
We'll add a unit test for that in the next commit.
@guggero guggero force-pushed the tlv-decimal-display branch from 03b0b0c to 4f32e71 Compare July 10, 2024 18:21
@guggero
Copy link
Member Author

guggero commented Jul 15, 2024

Okay, the current approach doesn't work and any quick hacks are too hacky. I'll implement the proper carve out to be able to do this properly in the next major version in an upcoming PR.

@guggero guggero closed this Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
5 participants