Skip to content

Commit

Permalink
add extrinsic_state_version to RuntimeVersion and bump CoreApi vers…
Browse files Browse the repository at this point in the history
…ion to 5
  • Loading branch information
vedhavyas authored and nazar-pc committed Jan 15, 2024
1 parent 127b9be commit b980518
Show file tree
Hide file tree
Showing 34 changed files with 82 additions and 14 deletions.
1 change: 1 addition & 0 deletions cumulus/pallets/parachain-system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions cumulus/parachain-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cumulus/parachains/runtimes/starters/seedling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cumulus/parachains/runtimes/starters/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions cumulus/test/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/minimal/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion substrate/client/executor/src/wasm_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ mod tests {
apis: create_apis_vec!([(<dyn Core::<Block>>::ID, 3)]),
transaction_version: 3,
state_version: 4,
extrinsic_state_version: 0,
};

let version = decode_version(&old_runtime_version.encode()).unwrap();
Expand All @@ -516,14 +517,16 @@ mod tests {
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: create_apis_vec!([(<dyn Core::<Block>>::ID, 4)]),
apis: create_apis_vec!([(<dyn Core::<Block>>::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]
Expand All @@ -542,6 +545,7 @@ mod tests {
apis: create_apis_vec!([(<dyn Core::<Block>>::ID, 4)]),
transaction_version: 100,
state_version: 1,
extrinsic_state_version: 0,
};

let embedded = sp_version::embed::embed_runtime_version(&wasm, runtime_version.clone())
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/rpc-spec-v2/src/chain_head/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions substrate/frame/support/test/compile_pass/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 13 additions & 5 deletions substrate/frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<H: Hash, E: codec::Encode>(extrinsics: &[E]) -> H::Output {
extrinsics_data_root::<H>(extrinsics.iter().map(codec::Encode::encode).collect())
pub fn extrinsics_root<H: Hash, E: codec::Encode>(
extrinsics: &[E],
state_version: sp_core::storage::StateVersion,
) -> H::Output {
extrinsics_data_root::<H>(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<H: Hash>(xts: Vec<Vec<u8>>) -> H::Output {
H::ordered_trie_root(xts, sp_core::storage::StateVersion::V0)
pub fn extrinsics_data_root<H: Hash>(
xts: Vec<Vec<u8>>,
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.
Expand Down Expand Up @@ -1753,7 +1759,9 @@ impl<T: Config> Pallet<T> {
let extrinsics = (0..ExtrinsicCount::<T>::take().unwrap_or_default())
.map(ExtrinsicData::<T>::take)
.collect();
let extrinsics_root = extrinsics_data_root::<T::Hashing>(extrinsics);
let extrinsic_state_version = T::Version::get().extrinsic_state_version();
let extrinsics_root =
extrinsics_data_root::<T::Hashing>(extrinsics, extrinsic_state_version);

// move block hash pruning window by one block
let block_hash_count = T::BlockHashCount::get();
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -761,7 +760,8 @@ fn extrinsics_root_is_calculated_correctly() {
System::note_finished_extrinsics();
let header = System::finalize();

let ext_root = extrinsics_data_root::<BlakeTwo256>(vec![vec![1], vec![2]]);
let ext_root =
extrinsics_data_root::<BlakeTwo256>(vec![vec![1], vec![2]], StateVersion::V0);
assert_eq!(ext_root, *header.extrinsics_root());
});
}
Expand Down
3 changes: 2 additions & 1 deletion substrate/primitives/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit b980518

Please sign in to comment.