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

Implement CheckMetadataHash extension #4274

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

Conversation

bkchr
Copy link
Member

@bkchr bkchr commented Apr 24, 2024

This implements the CheckMetadataHash extension as described in RFC78.

Besides the signed extension, the substrate-wasm-builder is extended to support generating the metadata-hash.

Closes: #291

Basically combines all the recommended calls into one
`build_using_defaults()` call or `init_with_defaults()` when there are
some custom changes required.
@bkchr bkchr requested review from a team and koute as code owners April 24, 2024 21:56
@paritytech-review-bot paritytech-review-bot bot requested a review from a team April 25, 2024 09:41
None => Err(UnknownTransaction::CannotLookup.into()),
},
// Unknown `mode`, let's reject it.
_ => Err(UnknownTransaction::CannotLookup.into()),
Copy link
Member

Choose a reason for hiding this comment

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

Could it not use an enum for mode, so that it already fails to decode an invalid mode?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ha! smart idea :D

@paritytech-review-bot paritytech-review-bot bot requested a review from a team April 25, 2024 09:42
0 => Ok(EncodeNoneToEmpty(None)),
1 => match option_env!("RUNTIME_METADATA_HASH") {
Some(hash) => Ok(EncodeNoneToEmpty(Some(array_bytes::hex2array_unchecked(hash)))),
None => Err(UnknownTransaction::CannotLookup.into()),
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this error variant help so much with debugging... alternatively there is only Other(_), which is not so nice either.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, maybe something in general that we could fix with a better "system" for error reporting in this case. Just returning strings is also not such a great idea.

@paritytech-review-bot paritytech-review-bot bot requested a review from a team April 25, 2024 09:48
@paritytech-review-bot paritytech-review-bot bot requested a review from a team April 25, 2024 09:48
@paritytech-review-bot paritytech-review-bot bot requested a review from a team April 25, 2024 09:49

/// Extract the `SS58` from the constants in the given `metadata`.
fn extract_ss58_prefix(metadata: &RuntimeMetadata) -> u16 {
let RuntimeMetadata::V15(ref metadata) = metadata else {
Copy link
Member

Choose a reason for hiding this comment

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

OT: what do you use for Runtime API debugging?
I have been using some CLI like this, but nothing proper: https://github.com/ggwpez/frame-runtime-api

Copy link
Member Author

Choose a reason for hiding this comment

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

Debugging for what? I mean what did you debug? Just that the return value is correct?

Copy link
Member

Choose a reason for hiding this comment

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

Yea just calling runtime APIs and inspecting the return values.

Copy link
Member Author

Choose a reason for hiding this comment

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

Never really needed to debug them, so I did not require anything like that so far 🙈

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-clippy
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6087098

Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

LGTM

(probably waiting for audit i guess)

substrate/frame/metadata-hash-extension/Cargo.toml Outdated Show resolved Hide resolved
@mustermeiszer
Copy link

@bkchr will this be backported to earlier releases of the polkadot-sdk and if so, which ones?

@joepetrowski
Copy link
Contributor

I think at least back to 1.7.0 for use in polkadot-fellows/runtimes#288

@mustermeiszer
Copy link

Thanks, thats great!

@bkchr
Copy link
Member Author

bkchr commented May 7, 2024

We probably even go back until 1.1. Need to check how complicated that will get.

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Signed Metadata
5 participants