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

Add type info to oracle data #1184

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Add type info to oracle data #1184

wants to merge 6 commits into from

Conversation

JesseAbram
Copy link
Member

@JesseAbram JesseAbram commented Nov 22, 2024

Adds a type to be added with oracle data to allow developers to know the expected type of the oracle data

@JesseAbram JesseAbram marked this pull request as ready for review December 2, 2024 19:47
Copy link
Contributor

@ameba23 ameba23 left a comment

Choose a reason for hiding this comment

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

⭐ the code all looks perfect but i think we need clarity on how this is intended to be used. Eg: if the type is a custom struct with several fields, how should this be expressed in the type definition?

This feels a bit the same as the schema definitions for programs - we have a field but no clear rules about how it should be filled in.

let headings = get_oracle_headings(&api, &rpc).await?;
Ok(serde_json::to_string_pretty(&headings)?)
let oracles_data = get_oracle_headings(&api, &rpc).await?;
Ok(format!("{:?}", oracles_data))
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, if cli.json is true, all output should be JSON. In this case it probably doesnt matter because i doubt the devops team need to use this in a script. But ideally we should do something like:

if cli.json {
  Ok(serde_json::to_string_pretty(&oracles_data)?)
} else {
  Ok(format!("{:?}", oracles_data))
}

OracleInfo {
oracle_data: BoundedVec::try_from(block_number.encode())
.expect("Block number fits in bounded vec; qed"),
oracle_type: "u32".as_bytes().to_vec(),
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 not need to say something like scale encoded u32? Or are we assuming that oracle_data types will always be scale encoded and implement Encode / Decode?

It seems strange that elsewhere we use JSON for program aux data / config, but use scale here. Using both would mean programs need to have dependencies for both json and scale.

If i just read u32 i would expect to use either u32::to_be_bytes() or u32::to_le_bytes().

Copy link
Member Author

Choose a reason for hiding this comment

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

ye, I chose scale because it plays really nicely with substrate, I mean Im open for other optinons here, but pretty much we should force all oracle info data types to be the same type either scale or json (im still in favour of scale in substrate)

@JesseAbram
Copy link
Member Author

⭐ the code all looks perfect but i think we need clarity on how this is intended to be used. Eg: if the type is a custom struct with several fields, how should this be expressed in the type definition?

This feels a bit the same as the schema definitions for programs - we have a field but no clear rules about how it should be filled in.

I see it as different as with programs anyone can build it and write it for themselves so they can use it personally and not need to get the schemas from anyone else. And if anyone else wants to use it, well they should already be going to a third party anyways to verify the code etc.

With oracle data it is set by governance and set once for the whole chain usage. Thus governance can determine if the type is proper and there is no need to go to a third party anyways, so it is a closed loop.

As for custom struct again this can only be set by governance so im all for cross that bridge when we get there

Copy link
Collaborator

@HCastano HCastano left a comment

Choose a reason for hiding this comment

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

I disagree with putting schemas on-chain. It's pretty fragile, error prone, and expensive storage wise. For example, if we decide to change the BlockNumber type for whatever reason this code could break (this is just an example for the current code, but I assume you'll eventually want to add other types for which change might be more realistic).

I haven't followed the Oracle story very closely either, so I'm not entirely sure what the end goal with this is either. So maybe something you and I will have to catch up on.

Comment on lines +29 to +30
- In [#1184](https://github.com/entropyxyz/entropy-core/pull/1184/) The ```OracleData``` mapping now holds a
struct ```OracleInfo``` which includes the ```oracle_data``` and the ```oracle_type```
Copy link
Collaborator

Choose a reason for hiding this comment

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

For non-code blocks there should only be a single tick used.

Suggested change
- In [#1184](https://github.com/entropyxyz/entropy-core/pull/1184/) The ```OracleData``` mapping now holds a
struct ```OracleInfo``` which includes the ```oracle_data``` and the ```oracle_type```
- In [#1184](https://github.com/entropyxyz/entropy-core/pull/1184/) The `OracleData` mapping now
holds a struct `OracleInfo` which includes the `oracle_data` and the `oracle_type`

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.

3 participants