diff --git a/cumulus/pallets/parachain-system/src/mock.rs b/cumulus/pallets/parachain-system/src/mock.rs index b76553a53841d..088c3d68992af 100644 --- a/cumulus/pallets/parachain-system/src/mock.rs +++ b/cumulus/pallets/parachain-system/src/mock.rs @@ -65,6 +65,7 @@ parameter_types! { apis: sp_version::create_apis_vec!([]), transaction_version: 1, state_version: 1, + extrinsic_state_version: 0, }; pub const ParachainId: ParaId = ParaId::new(200); pub const ReservedXcmpWeight: Weight = Weight::zero(); diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index 1ef018a8ca344..6aa2aeaa27c20 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -187,6 +187,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 1, + extrinsic_state_version: 0, }; /// This determines the average expected block time that we are targeting. diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 3010cbc69fa27..6fca130d09bd4 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -116,6 +116,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 14, state_version: 1, + extrinsic_state_version: 0, }; #[cfg(not(feature = "state-trie-version-1"))] @@ -129,6 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 14, state_version: 0, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index e0dff0c4516e3..748607e8c1e2d 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -114,6 +114,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 14, state_version: 0, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 0052e9dcb38a4..dfa19a791c4f4 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -206,6 +206,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 4, state_version: 1, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 717cde6280dbf..dd868f2e5bc2a 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -180,6 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 4, state_version: 1, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 6cb8e096e4b3f..8b2d9ad629efe 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -121,6 +121,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 5, state_version: 0, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 79b6b6be299be..0107049bed82b 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -138,6 +138,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 6, state_version: 1, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 0f01c2d74166e..3b67327b53efc 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -134,6 +134,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 0, state_version: 1, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 742b3a29275ca..8834eeab612e8 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -125,6 +125,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 0, state_version: 1, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index 2c51791c07405..1c8067401336a 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -104,6 +104,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 1, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 7805e0ad98292..fc842a39b0430 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -129,6 +129,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 0, state_version: 1, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index 8ea29c8aa218b..83b72c72d302f 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -129,6 +129,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 0, state_version: 1, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index cb868627e799e..29562a1f43c34 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -80,6 +80,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 2, state_version: 0, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index de95969f71d10..770d886829add 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -88,6 +88,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 0, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 541bcd05644f5..1377730407a0b 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -236,6 +236,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 1, + extrinsic_state_version: 0, }; /// This determines the average expected block time that we are targeting. diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 7faee4258f65e..9568f69f95b94 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -113,6 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 6, state_version: 0, + extrinsic_state_version: 0, }; pub const MILLISECS_PER_BLOCK: u64 = 6000; diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 3de77cb1e5811..451449563ce2f 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -103,6 +103,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 1, + extrinsic_state_version: 0, }; #[cfg(feature = "increment-spec-version")] @@ -117,6 +118,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 1, + extrinsic_state_version: 0, }; pub const MILLISECS_PER_BLOCK: u64 = 12000; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 3fd3f2bc63549..d00955c942f09 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -158,6 +158,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 24, state_version: 1, + extrinsic_state_version: 0, }; /// The BABE epoch configuration at genesis. diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index f472b619ba759..85ab0a61dcb86 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -112,6 +112,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 1, + extrinsic_state_version: 0, }; /// The BABE epoch configuration at genesis. diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index e1416c4b75437..75cd6d25f5efb 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -152,6 +152,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 24, state_version: 1, + extrinsic_state_version: 0, }; /// The BABE epoch configuration at genesis. diff --git a/substrate/bin/minimal/runtime/src/lib.rs b/substrate/bin/minimal/runtime/src/lib.rs index efee400c3f594..eb600497f549e 100644 --- a/substrate/bin/minimal/runtime/src/lib.rs +++ b/substrate/bin/minimal/runtime/src/lib.rs @@ -43,6 +43,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 1, + extrinsic_state_version: 0, }; /// The version information used to identify this runtime when compiled natively. diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index 5f399edda9878..28d0ba92ebe33 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -108,6 +108,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 1, + extrinsic_state_version: 0, }; /// This determines the average expected block time that we are targeting. diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 1043e5017dc36..87025887b7bd2 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -162,6 +162,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 2, state_version: 1, + extrinsic_state_version: 0, }; /// The BABE epoch configuration at genesis. diff --git a/substrate/client/executor/src/wasm_runtime.rs b/substrate/client/executor/src/wasm_runtime.rs index 501279a312cc0..fab04cd238b94 100644 --- a/substrate/client/executor/src/wasm_runtime.rs +++ b/substrate/client/executor/src/wasm_runtime.rs @@ -504,6 +504,7 @@ mod tests { apis: create_apis_vec!([(>::ID, 3)]), transaction_version: 3, state_version: 4, + extrinsic_state_version: 0, }; let version = decode_version(&old_runtime_version.encode()).unwrap(); @@ -516,14 +517,16 @@ mod tests { authoring_version: 1, spec_version: 1, impl_version: 1, - apis: create_apis_vec!([(>::ID, 4)]), + apis: create_apis_vec!([(>::ID, 5)]), transaction_version: 3, state_version: 4, + extrinsic_state_version: 1, }; let version = decode_version(&old_runtime_version.encode()).unwrap(); assert_eq!(3, version.transaction_version); assert_eq!(4, version.state_version); + assert_eq!(1, version.extrinsic_state_version); } #[test] @@ -542,6 +545,7 @@ mod tests { apis: create_apis_vec!([(>::ID, 4)]), transaction_version: 100, state_version: 1, + extrinsic_state_version: 0, }; let embedded = sp_version::embed::embed_runtime_version(&wasm, runtime_version.clone()) diff --git a/substrate/client/rpc-spec-v2/src/chain_head/tests.rs b/substrate/client/rpc-spec-v2/src/chain_head/tests.rs index c8f2362b9ebbf..6d6d4fc86cc6a 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/tests.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/tests.rs @@ -245,11 +245,11 @@ async fn follow_with_runtime() { // it is basically json-encoded substrate_test_runtime_client::runtime::VERSION let runtime_str = "{\"specName\":\"test\",\"implName\":\"parity-test\",\"authoringVersion\":0,\ - \"specVersion\":2,\"implVersion\":2,\"apis\":[[\"0xdf6acb689907609b\",4],\ + \"specVersion\":2,\"implVersion\":2,\"apis\":[[\"0xdf6acb689907609b\",5],\ [\"0x37e397fc7c91f5e4\",2],[\"0xd2bc9897eed08f15\",3],[\"0x40fe3ad401f8959a\",6],\ [\"0xbc9d89904f5b923f\",1],[\"0xc6e9a76309f39b09\",2],[\"0xdd718d5cc53262d4\",1],\ [\"0xcbca25e39f142387\",2],[\"0xf78b278be53f454c\",2],[\"0xab3c0572291feb8b\",1],\ - [\"0xed99c5acb25eedf5\",3],[\"0xfbc577b9d747efd6\",1]],\"transactionVersion\":1,\"stateVersion\":0}"; + [\"0xed99c5acb25eedf5\",3],[\"0xfbc577b9d747efd6\",1]],\"transactionVersion\":1,\"stateVersion\":0, \"extrinsicStateVersion\":0}"; let runtime: RuntimeVersion = serde_json::from_str(runtime_str).unwrap(); diff --git a/substrate/client/rpc/src/state/tests.rs b/substrate/client/rpc/src/state/tests.rs index 594f51efba686..e678866210f24 100644 --- a/substrate/client/rpc/src/state/tests.rs +++ b/substrate/client/rpc/src/state/tests.rs @@ -526,7 +526,7 @@ async fn should_return_runtime_version() { // it is basically json-encoded substrate_test_runtime_client::runtime::VERSION let result = "{\"specName\":\"test\",\"implName\":\"parity-test\",\"authoringVersion\":1,\ - \"specVersion\":2,\"implVersion\":2,\"apis\":[[\"0xdf6acb689907609b\",4],\ + \"specVersion\":2,\"implVersion\":2,\"apis\":[[\"0xdf6acb689907609b\",5],\ [\"0x37e397fc7c91f5e4\",2],[\"0xd2bc9897eed08f15\",3],[\"0x40fe3ad401f8959a\",6],\ [\"0xbc9d89904f5b923f\",1],[\"0xc6e9a76309f39b09\",2],[\"0xdd718d5cc53262d4\",1],\ [\"0xcbca25e39f142387\",2],[\"0xf78b278be53f454c\",2],[\"0xab3c0572291feb8b\",1],\ diff --git a/substrate/frame/support/test/compile_pass/src/lib.rs b/substrate/frame/support/test/compile_pass/src/lib.rs index b304dfcb2823e..744cfec2881a8 100644 --- a/substrate/frame/support/test/compile_pass/src/lib.rs +++ b/substrate/frame/support/test/compile_pass/src/lib.rs @@ -41,6 +41,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: sp_version::create_apis_vec!([]), transaction_version: 0, state_version: 0, + extrinsic_state_version: 0, }; pub type Signature = sr25519::Signature; diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 069217bcee46b..9ddf1d5c05c43 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -176,16 +176,22 @@ const LOG_TARGET: &str = "runtime::system"; /// /// The merkle proof is using the same trie as runtime state with /// `state_version` 0. -pub fn extrinsics_root(extrinsics: &[E]) -> H::Output { - extrinsics_data_root::(extrinsics.iter().map(codec::Encode::encode).collect()) +pub fn extrinsics_root( + extrinsics: &[E], + state_version: sp_core::storage::StateVersion, +) -> H::Output { + extrinsics_data_root::(extrinsics.iter().map(codec::Encode::encode).collect(), state_version) } /// Compute the trie root of a list of extrinsics. /// /// The merkle proof is using the same trie as runtime state with /// `state_version` 0. -pub fn extrinsics_data_root(xts: Vec>) -> H::Output { - H::ordered_trie_root(xts, sp_core::storage::StateVersion::V0) +pub fn extrinsics_data_root( + xts: Vec>, + state_version: sp_core::storage::StateVersion, +) -> H::Output { + H::ordered_trie_root(xts, state_version) } /// An object to track the currently used extrinsic weight in a block. @@ -1753,7 +1759,9 @@ impl Pallet { let extrinsics = (0..ExtrinsicCount::::take().unwrap_or_default()) .map(ExtrinsicData::::take) .collect(); - let extrinsics_root = extrinsics_data_root::(extrinsics); + let extrinsic_state_version = T::Version::get().extrinsic_state_version(); + let extrinsics_root = + extrinsics_data_root::(extrinsics, extrinsic_state_version); // move block hash pruning window by one block let block_hash_count = T::BlockHashCount::get(); diff --git a/substrate/frame/system/src/mock.rs b/substrate/frame/system/src/mock.rs index e33ac2f56c875..011276616c106 100644 --- a/substrate/frame/system/src/mock.rs +++ b/substrate/frame/system/src/mock.rs @@ -48,6 +48,7 @@ parameter_types! { apis: sp_version::create_apis_vec!([]), transaction_version: 1, state_version: 1, + extrinsic_state_version: 0, }; pub const DbWeight: RuntimeDbWeight = RuntimeDbWeight { read: 10, diff --git a/substrate/frame/system/src/tests.rs b/substrate/frame/system/src/tests.rs index e437e7f9f39b0..5250d9195e914 100644 --- a/substrate/frame/system/src/tests.rs +++ b/substrate/frame/system/src/tests.rs @@ -21,14 +21,13 @@ use frame_support::{ dispatch::{Pays, PostDispatchInfo, WithPostDispatchInfo}, traits::{OnRuntimeUpgrade, WhitelistedStorageKeys}, }; -use std::collections::BTreeSet; - use mock::{RuntimeOrigin, *}; -use sp_core::{hexdisplay::HexDisplay, H256}; +use sp_core::{hexdisplay::HexDisplay, storage::StateVersion, H256}; use sp_runtime::{ traits::{BlakeTwo256, Header}, DispatchError, DispatchErrorWithPostInfo, }; +use std::collections::BTreeSet; #[test] fn check_whitelist() { @@ -761,7 +760,8 @@ fn extrinsics_root_is_calculated_correctly() { System::note_finished_extrinsics(); let header = System::finalize(); - let ext_root = extrinsics_data_root::(vec![vec![1], vec![2]]); + let ext_root = + extrinsics_data_root::(vec![vec![1], vec![2]], StateVersion::V0); assert_eq!(ext_root, *header.extrinsics_root()); }); } diff --git a/substrate/primitives/api/src/lib.rs b/substrate/primitives/api/src/lib.rs index 1b8b7c40ae074..5befe896d7199 100644 --- a/substrate/primitives/api/src/lib.rs +++ b/substrate/primitives/api/src/lib.rs @@ -334,6 +334,7 @@ pub use sp_api_proc_macro::decl_runtime_apis; /// apis: RUNTIME_API_VERSIONS, /// transaction_version: 1, /// state_version: 1, +/// extrinsic_state_version: 0, /// }; /// /// # fn main() {} @@ -797,7 +798,7 @@ pub fn deserialize_runtime_api_info(bytes: [u8; RUNTIME_API_INFO_SIZE]) -> ([u8; decl_runtime_apis! { /// The `Core` runtime api that every Substrate runtime needs to implement. #[core_trait] - #[api_version(4)] + #[api_version(5)] pub trait Core { /// Returns the version of the runtime. fn version() -> RuntimeVersion; diff --git a/substrate/primitives/version/proc-macro/src/decl_runtime_version.rs b/substrate/primitives/version/proc-macro/src/decl_runtime_version.rs index 7ca2d9b71f60a..4924d7109906d 100644 --- a/substrate/primitives/version/proc-macro/src/decl_runtime_version.rs +++ b/substrate/primitives/version/proc-macro/src/decl_runtime_version.rs @@ -64,6 +64,7 @@ struct RuntimeVersion { apis: u8, transaction_version: u32, state_version: u8, + extrinsic_state_version: u8, } #[derive(Default, Debug)] @@ -75,6 +76,7 @@ struct ParseRuntimeVersion { impl_version: Option, transaction_version: Option, state_version: Option, + extrinsic_state_version: Option, } impl ParseRuntimeVersion { @@ -126,6 +128,8 @@ impl ParseRuntimeVersion { parse_once(&mut self.transaction_version, field_value, Self::parse_num_literal)?; } else if field_name == "state_version" { parse_once(&mut self.state_version, field_value, Self::parse_num_literal_u8)?; + } else if field_name == "extrinsic_state_version" { + parse_once(&mut self.extrinsic_state_version, field_value, Self::parse_num_literal_u8)?; } else if field_name == "apis" { // Intentionally ignored // @@ -199,6 +203,7 @@ impl ParseRuntimeVersion { impl_version, transaction_version, state_version, + extrinsic_state_version, } = self; Ok(RuntimeVersion { @@ -210,6 +215,7 @@ impl ParseRuntimeVersion { transaction_version: required!(transaction_version), state_version: required!(state_version), apis: 0, + extrinsic_state_version: extrinsic_state_version.unwrap_or(0), }) } } @@ -241,6 +247,7 @@ mod tests { apis: 0, transaction_version: 2, state_version: 1, + extrinsic_state_version: 0, } .encode(); @@ -256,6 +263,7 @@ mod tests { apis: Cow::Owned(vec![]), transaction_version: 2, state_version: 1, + extrinsic_state_version: 0 }, ); } diff --git a/substrate/primitives/version/src/lib.rs b/substrate/primitives/version/src/lib.rs index 13f4520f6e694..ee55db35f7ebb 100644 --- a/substrate/primitives/version/src/lib.rs +++ b/substrate/primitives/version/src/lib.rs @@ -80,6 +80,7 @@ pub mod embed; /// apis: RUNTIME_API_VERSIONS, /// transaction_version: 2, /// state_version: 1, +/// extrinsic_state_version: 0, /// }; /// /// # const RUNTIME_API_VERSIONS: sp_version::ApisVec = sp_version::create_apis_vec!([]); @@ -229,6 +230,10 @@ pub struct RuntimeVersion { /// Version of the state implementation used by this runtime. /// Use of an incorrect version is consensus breaking. pub state_version: u8, + + /// Version of the state implementation used by this runtime to derive extrinsic root. + /// Use of an incorrect version is consensus breaking. + pub extrinsic_state_version: u8, } impl RuntimeVersion { @@ -238,7 +243,8 @@ impl RuntimeVersion { /// runtime api: /// - `Core` version < 3 is a runtime version without a transaction version and state version. /// - `Core` version 3 is a runtime version without a state version. - /// - `Core` version 4 is the latest runtime version. + /// - `Core` version 4 is a runtime version without extrinsic state version. + /// - `Core` version 5 is the latest runtime version. pub fn decode_with_version_hint( input: &mut I, core_version: Option, @@ -255,6 +261,8 @@ impl RuntimeVersion { if core_version.map(|v| v >= 3).unwrap_or(false) { Decode::decode(input)? } else { 1 }; let state_version = if core_version.map(|v| v >= 4).unwrap_or(false) { Decode::decode(input)? } else { 0 }; + let extrinsic_state_version = + if core_version.map(|v| v >= 5).unwrap_or(false) { Decode::decode(input)? } else { 0 }; Ok(RuntimeVersion { spec_name, impl_name, @@ -264,6 +272,7 @@ impl RuntimeVersion { apis, transaction_version, state_version, + extrinsic_state_version, }) } } @@ -332,6 +341,15 @@ impl RuntimeVersion { // If version > than 1, keep using latest version. self.state_version.try_into().unwrap_or(StateVersion::V1) } + + /// Returns state version to use for extrinsic root derivation. + /// + /// For runtime with core api version less than 5, + /// V0 trie version will be used + /// Otherwise, uses the version passed or defaults to V0 if not provided. + pub fn extrinsic_state_version(&self) -> StateVersion { + self.extrinsic_state_version.try_into().unwrap_or(StateVersion::V0) + } } /// The version of the native runtime. diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 16ab467772f2f..6086ed52c7ce3 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -115,6 +115,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { apis: RUNTIME_API_VERSIONS, transaction_version: 1, state_version: 1, + extrinsic_state_version: 0, }; fn version() -> RuntimeVersion {