Skip to content

Commit

Permalink
Introduce feature to disable the metadata-hash-check
Browse files Browse the repository at this point in the history
  • Loading branch information
Niederb committed Jul 2, 2024
1 parent fa057b7 commit 26e8ac6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ default = ["std"]
disable_target_static_assertions = [
"sp-runtime-interface/disable_target_static_assertions",
]
disable-metadata-hash-check = []
std = [
"codec/std",
"primitive-types/std",
Expand Down
19 changes: 19 additions & 0 deletions primitives/src/extrinsics/extrinsic_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ pub struct GenericSignedExtra<Tip, Index> {
#[codec(compact)]
pub nonce: Index,
pub tip: Tip,
#[cfg(feature = "disable-metadata-hash-check")]
pub check_hash: u8,
}

impl<Tip, Index> GenericSignedExtra<Tip, Index> {
pub fn new(era: Era, nonce: Index, tip: Tip) -> Self {
#[cfg(feature = "disable-metadata-hash-check")]
Self { era, nonce, tip, check_hash: 0 }
#[cfg(not(feature = "disable-metadata-hash-check"))]
Self { era, nonce, tip }
}
}

Expand All @@ -56,7 +60,10 @@ impl<Tip, Index> GenericSignedExtra<Tip, Index> {
// defines what is returned upon the `additional_signed` call. The AdditionalSigned defined here
// must mirror these return values.
// Example: https://github.com/paritytech/substrate/blob/23bb5a6255bbcd7ce2999044710428bc4a7a924f/frame/system/src/extensions/check_non_zero_sender.rs#L64-L66
#[cfg(feature = "disable-metadata-hash-check")]
pub type GenericAdditionalSigned<Hash> = ((), u32, u32, Hash, Hash, (), (), (), Option<[u8; 32]>);
#[cfg(not(feature = "disable-metadata-hash-check"))]
pub type GenericAdditionalSigned<Hash> = ((), u32, u32, Hash, Hash, (), (), ());

/// This trait allows you to configure the "signed extra" and
/// "additional" parameters that are signed and used in substrate extrinsics.
Expand Down Expand Up @@ -180,6 +187,7 @@ where
}

fn additional_signed(&self) -> Self::AdditionalSigned {
#[cfg(feature = "disable-metadata-hash-check")]
(
(),
self.spec_version,
Expand All @@ -191,6 +199,17 @@ where
(),
None,
)
#[cfg(not(feature = "disable-metadata-hash-check"))]
(
(),
self.spec_version,
self.transaction_version,
self.genesis_hash,
self.mortality_checkpoint,
(),
(),
(),
)
}
}

Expand Down
22 changes: 18 additions & 4 deletions primitives/src/extrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,23 @@ mod tests {
use super::*;
use crate::AssetRuntimeConfig;
use extrinsic_params::{GenericAdditionalParams, GenericExtrinsicParams, PlainTip};
use solochain_template_runtime::{BalancesCall, RuntimeCall, SignedExtra};
use frame_system::{
CheckEra, CheckGenesis, CheckNonZeroSender, CheckNonce, CheckSpecVersion, CheckTxVersion,
CheckWeight,
};
use pallet_transaction_payment::ChargeTransactionPayment;
use solochain_template_runtime::{
BalancesCall, Runtime, RuntimeCall, SignedExtra, SystemCall, UncheckedExtrinsic, VERSION,
};
use sp_core::{crypto::Ss58Codec, Pair, H256 as Hash};
use sp_runtime::{generic::Era, testing::sr25519, AccountId32, MultiAddress, MultiSignature};
use sp_keyring::AccountKeyring;
use sp_runtime::{
generic::Era, testing::sr25519, traits::Hash as HashTrait, AccountId32, MultiAddress,
MultiSignature,
};

type PlainTipExtrinsicParams =
GenericExtrinsicParams<crate::DefaultRuntimeConfig, PlainTip<u128>>;

#[test]
fn encode_decode_roundtrip_works() {
Expand Down Expand Up @@ -311,7 +325,7 @@ mod tests {
assert_eq!(call, call1);
}

/*#[test]
#[test]
fn xt_hash_matches_substrate_impl() {
// Define extrinsic params.
let alice = MultiAddress::Id(AccountKeyring::Alice.to_account_id());
Expand Down Expand Up @@ -426,5 +440,5 @@ mod tests {
<Runtime as frame_system::Config>::Hashing::hash_of(&substrate_extrinsic),
<Runtime as frame_system::Config>::Hashing::hash_of(&api_client_extrinsic)
)
}*/
}
}

0 comments on commit 26e8ac6

Please sign in to comment.