-
Notifications
You must be signed in to change notification settings - Fork 660
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
base: george/restore-gav-tx-ext
Are you sure you want to change the base?
Changes from 6 commits
25350a5
8144c61
edffdaf
20a74ea
eea48de
19923a1
456d683
6d40a23
8ffd8a9
7bd871e
5301304
4050200
6d94fa4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ extern crate alloc; | |
extern crate self as frame_metadata_hash_extension; | ||
|
||
use codec::{Decode, Encode}; | ||
use frame_support::DebugNoBound; | ||
use frame_support::{pallet_prelude::Weight, DebugNoBound}; | ||
use frame_system::Config; | ||
use scale_info::TypeInfo; | ||
use sp_runtime::{ | ||
|
@@ -68,12 +68,20 @@ enum MetadataHash { | |
Custom([u8; 32]), | ||
} | ||
|
||
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 commentThe 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 commentThe 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 commentThe 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. |
||
} | ||
} else { | ||
None | ||
}; | ||
|
||
impl MetadataHash { | ||
/// Returns the metadata hash. | ||
fn hash(&self) -> Option<[u8; 32]> { | ||
match self { | ||
Self::FetchFromEnv => | ||
option_env!("RUNTIME_METADATA_HASH").map(array_bytes::hex2array_unchecked), | ||
Self::FetchFromEnv => RUNTIME_METADATA, | ||
Self::Custom(hash) => Some(*hash), | ||
} | ||
} | ||
|
@@ -152,6 +160,9 @@ impl<T: Config + Send + Sync> TransactionExtensionBase for CheckMetadataHash<T> | |
|
||
Ok(signed) | ||
} | ||
fn weight() -> Weight { | ||
Weight::default() | ||
} | ||
} | ||
impl<T: Config + Send + Sync> TransactionExtension<T::RuntimeCall> for CheckMetadataHash<T> { | ||
type Val = (); | ||
|
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