From 8ffd8a91b995a78882b2935ad1c8ae87565137d3 Mon Sep 17 00:00:00 2001 From: gui Date: Thu, 29 Aug 2024 09:02:55 +0900 Subject: [PATCH] panic on invalid environment variable --- substrate/frame/metadata-hash-extension/src/lib.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/substrate/frame/metadata-hash-extension/src/lib.rs b/substrate/frame/metadata-hash-extension/src/lib.rs index de9e5d617e59..ff9d3cec5930 100644 --- a/substrate/frame/metadata-hash-extension/src/lib.rs +++ b/substrate/frame/metadata-hash-extension/src/lib.rs @@ -71,7 +71,9 @@ enum MetadataHash { 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, + Err(_) => panic!("Invalid RUNTIME_METADATA_HASH environment variable: it must be a 32 \ + bytes value in hexadecimal: e.g. 0x1234567890abcdef1234567890ABCDEF. Upper case or \ + lower case, 0x prefix is optional."), } } else { None @@ -160,13 +162,16 @@ impl TransactionExtensionBase for CheckMetadataHash Ok(signed) } - fn weight() -> Weight { - Weight::default() - } } impl TransactionExtension for CheckMetadataHash { type Val = (); type Pre = (); + fn weight(&self, _: &T::RuntimeCall) -> Weight { + // The weight is the weight of implicit, it consists of a few match operation, it is + // negligible. + Weight::zero() + } + impl_tx_ext_default!(T::RuntimeCall; validate prepare); }