Skip to content

Commit ece488c

Browse files
Niederbmasapr
andauthored
Check metadata hash (#776)
* Activate metadata-hash feature in kitchensink-runtime to see if we can reproduce the signing issues * Test with a newer docker image * Test a docker image that should still work * Implement empty hash and deactivate metadata hash check * Fix failing build. - Deactivate two tests for now * Cleanup/Remove old changes * Introduce feature to disable the metadata-hash-check * Fix conditional compilation * - Disable tests when the metadata-hash-check feature is active - Add feature to the main Cargo.toml * Test with newer docker image * Add feature to testing code * Make taplo fmt happy * Activate the metadata-hash feature per default in testing code * Use H256 instead of byte array * Make clippy happy by adding more clutter to the code :-( --------- Co-authored-by: masapr <[email protected]>
1 parent 2a4209e commit ece488c

File tree

10 files changed

+56
-17
lines changed

10 files changed

+56
-17
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ jobs:
225225

226226
- name: Run latest node
227227
run: |
228-
docker run -p 9944:9944 -p 9933:9933 -p 30333:30333 paritypr/substrate:master-1680977e --dev --rpc-external &
228+
docker run -p 9944:9944 -p 9933:9933 -p 30333:30333 paritypr/substrate:master-18228a9b --dev --rpc-external &
229229
230230
- name: Wait until node has started
231231
run: sleep 20s

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ staking-xt = ["std", "ac-primitives/staking-xt"]
105105
# of the functionality this feature provides.
106106
contracts-xt = ["std", "ac-primitives/contracts-xt"]
107107

108+
# Provides compatibility to RFC-0078: "Merkelized Metadata" but disables the check of the metadata hash
109+
disable-metadata-hash-check = ["ac-primitives/disable-metadata-hash-check"]
110+
108111
# Enables all std features of dependencies in case of std build.
109112
std = [
110113
# crates.io no_std

examples/async/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch =
2626
sp-weights = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "master" }
2727

2828
# local deps
29-
substrate-api-client = { path = "../..", version = "0.17", features = ["staking-xt", "contracts-xt"] }
29+
substrate-api-client = { path = "../..", version = "0.17", features = ["staking-xt", "contracts-xt", "disable-metadata-hash-check"] }

examples/sync/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch =
1515
sp-weights = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "master" }
1616

1717
# local deps
18-
substrate-api-client = { path = "../..", version = "0.17", default-features = false, features = ["tungstenite-client", "ws-client"] }
18+
substrate-api-client = { path = "../..", version = "0.17", default-features = false, features = ["tungstenite-client", "ws-client", "disable-metadata-hash-check"] }

primitives/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ default = ["std"]
4747
disable_target_static_assertions = [
4848
"sp-runtime-interface/disable_target_static_assertions",
4949
]
50+
disable-metadata-hash-check = []
5051
std = [
5152
"codec/std",
5253
"primitive-types/std",

primitives/src/extrinsics/extrinsic_params.rs

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
use crate::config::Config;
1919
use codec::{Decode, Encode};
20+
#[cfg(feature = "disable-metadata-hash-check")]
21+
use primitive_types::H256;
2022
use sp_runtime::{
2123
generic::Era,
2224
traits::{BlakeTwo256, Hash},
@@ -38,11 +40,20 @@ pub struct GenericSignedExtra<Tip, Index> {
3840
#[codec(compact)]
3941
pub nonce: Index,
4042
pub tip: Tip,
43+
#[cfg(feature = "disable-metadata-hash-check")]
44+
pub check_hash: u8,
4145
}
4246

4347
impl<Tip, Index> GenericSignedExtra<Tip, Index> {
4448
pub fn new(era: Era, nonce: Index, tip: Tip) -> Self {
45-
Self { era, nonce, tip }
49+
#[cfg(feature = "disable-metadata-hash-check")]
50+
{
51+
Self { era, nonce, tip, check_hash: 0 }
52+
}
53+
#[cfg(not(feature = "disable-metadata-hash-check"))]
54+
{
55+
Self { era, nonce, tip }
56+
}
4657
}
4758
}
4859

@@ -55,6 +66,9 @@ impl<Tip, Index> GenericSignedExtra<Tip, Index> {
5566
// defines what is returned upon the `additional_signed` call. The AdditionalSigned defined here
5667
// must mirror these return values.
5768
// Example: https://github.com/paritytech/substrate/blob/23bb5a6255bbcd7ce2999044710428bc4a7a924f/frame/system/src/extensions/check_non_zero_sender.rs#L64-L66
69+
#[cfg(feature = "disable-metadata-hash-check")]
70+
pub type GenericAdditionalSigned<Hash> = ((), u32, u32, Hash, Hash, (), (), (), Option<H256>);
71+
#[cfg(not(feature = "disable-metadata-hash-check"))]
5872
pub type GenericAdditionalSigned<Hash> = ((), u32, u32, Hash, Hash, (), (), ());
5973

6074
/// This trait allows you to configure the "signed extra" and
@@ -179,16 +193,33 @@ where
179193
}
180194

181195
fn additional_signed(&self) -> Self::AdditionalSigned {
182-
(
183-
(),
184-
self.spec_version,
185-
self.transaction_version,
186-
self.genesis_hash,
187-
self.mortality_checkpoint,
188-
(),
189-
(),
190-
(),
191-
)
196+
#[cfg(feature = "disable-metadata-hash-check")]
197+
{
198+
(
199+
(),
200+
self.spec_version,
201+
self.transaction_version,
202+
self.genesis_hash,
203+
self.mortality_checkpoint,
204+
(),
205+
(),
206+
(),
207+
None,
208+
)
209+
}
210+
#[cfg(not(feature = "disable-metadata-hash-check"))]
211+
{
212+
(
213+
(),
214+
self.spec_version,
215+
self.transaction_version,
216+
self.genesis_hash,
217+
self.mortality_checkpoint,
218+
(),
219+
(),
220+
(),
221+
)
222+
}
192223
}
193224
}
194225

primitives/src/extrinsics/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ mod tests {
325325
assert_eq!(call, call1);
326326
}
327327

328+
// Currently does not with available version of substrate extrinsic
329+
#[cfg(not(feature = "disable-metadata-hash-check"))]
328330
#[test]
329331
fn xt_hash_matches_substrate_impl() {
330332
// Define extrinsic params.
@@ -384,6 +386,8 @@ mod tests {
384386
)
385387
}
386388

389+
// Currently does not work with stored bytes. Need to create a new version
390+
#[cfg(not(feature = "disable-metadata-hash-check"))]
387391
#[test]
388392
fn xt_hash_matches_substrate_impl_large_xt() {
389393
// Define xt parameters,

testing/async/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", bran
2323
pallet-staking = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "master" }
2424

2525
# local deps
26-
substrate-api-client = { path = "../..", version = "0.17", features = ["staking-xt", "contracts-xt"] }
26+
substrate-api-client = { path = "../..", version = "0.17", features = ["staking-xt", "contracts-xt", "disable-metadata-hash-check"] }

testing/async/examples/state_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async fn main() {
127127
.get_storage_keys_paged(Some(storage_key_prefix), max_keys, None, None)
128128
.await
129129
.unwrap();
130-
assert_eq!(storage_keys.len() as u32, 13);
130+
assert_eq!(storage_keys.len() as u32, 14);
131131

132132
let max_keys = 20;
133133
let storage_keys = api

testing/sync/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "ma
1212
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "master" }
1313

1414
# local deps
15-
substrate-api-client = { path = "../..", version = "0.17", default-features = false, features = ["tungstenite-client", "ws-client"] }
15+
substrate-api-client = { path = "../..", version = "0.17", default-features = false, features = ["tungstenite-client", "ws-client", "disable-metadata-hash-check"] }
1616
ac-keystore = { path = "../../keystore" }

0 commit comments

Comments
 (0)