-
Notifications
You must be signed in to change notification settings - Fork 766
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
[After Transaction Extension PR] CheckMetadataHash transaction extension benchmark. #5277
[After Transaction Extension PR] CheckMetadataHash transaction extension benchmark. #5277
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this extension doesn't need the benchmarks and can remain weightless. I'm not completely sure whether this extra code in utils
is worth the effort for the benefit of doing that check at compile time though.
let high = from_hex_digit_panic(hex_str.as_bytes()[start + i * 2]); | ||
let low = from_hex_digit_panic(hex_str.as_bytes()[start + i * 2 + 1]); | ||
|
||
let (Some(high), Some(low)) = (high, low) else { return None }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let high = from_hex_digit_panic(hex_str.as_bytes()[start + i * 2]); | |
let low = from_hex_digit_panic(hex_str.as_bytes()[start + i * 2 + 1]); | |
let (Some(high), Some(low)) = (high, low) else { return None }; | |
let high = from_hex_digit_panic(hex_str.as_bytes()[start + i * 2])?; | |
let low = from_hex_digit_panic(hex_str.as_bytes()[start + i * 2 + 1])?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
not allowed in const fn
|
||
/// Function to convert hex string to Option<[u8; 32]> in a const context. | ||
/// Returns `None` if fails to decode. | ||
pub const fn hex_str_to_32_bytes(hex_str: &str) -> Option<[u8; HASH_LEN]> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please upstream this? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discovered const-hex
, it seems popular. I will switch to it.
Co-authored-by: Bastian Köcher <[email protected]>
Cargo.toml
Outdated
@@ -668,6 +668,7 @@ codec = { version = "3.6.12", default-features = false, package = "parity-scale- | |||
collectives-westend-emulated-chain = { path = "cumulus/parachains/integration-tests/emulated/chains/parachains/collectives/collectives-westend" } | |||
collectives-westend-runtime = { path = "cumulus/parachains/runtimes/collectives/collectives-westend" } | |||
color-eyre = { version = "0.6.1", default-features = false } | |||
const-hex = { version = "1.10.0", default-features = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a new dependency because some of our dependency already depend on it.
I picked up the version already used by some dependencies in the Cargo.lock
const RUNTIME_METADATA: Option<[u8; 32]> = if let Some(hex) = option_env!("RUNTIME_METADATA_HASH") { | ||
match const_hex::const_decode_to_array(hex.as_bytes()) { | ||
Ok(hex) => Some(hex), | ||
Err(_) => None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot find a way to print some error in const fn, but this behavior is unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can panic in const? That should be good enough here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, done in 8ffd8a9
Note that I can't put the exact error in the panic because it only accepts a string literal.
The CI pipeline was cancelled due to failure one of the required jobs. |
…gui-check-metadata-hash-benchmarks
I can't reopen the PR, moved to #6141 |
After #3685
The transaction extensions cost is:
array_bytes::hex2array_unchecked
to convert a hexadecimal string into a 32 bytes array.So I feel introducing a new pallet to have it benchmarked is overkill.
In this PR:
array_bytes::hex2array_unchecked
call and changed to a const implementation.Alternative 1:
Alternative 2:
cc @georgepisaltu