Skip to content

Commit

Permalink
Update RuntimeVerison type and use system_version to derive extri…
Browse files Browse the repository at this point in the history
…nsics root `StateVersion` instead of `V0` (paritytech#4257)

This PR
- Renames `RuntimeVersion::state_version` to `system_version`
- Uses `Runtime::system_version` to derive extrinsics root
`StateVersion` instead of default `StateVersion::V0`

This PR should not be breaking any existing chains so long as they use
same `RuntimeVersion::state_version` for `Runtime::system_version`

Using `RuntimeVersion::system_version = 2` will make the extrinsics root
to use `StateVersion::V1` instead of `V0`

RFC for this change - polkadot-fellows/RFCs#42

---------

Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Koute <[email protected]>
Co-authored-by: Nazar Mokrynskyi <[email protected]>

(cherry picked from commit 9930d21)
  • Loading branch information
vedhavyas authored and nazar-pc committed Sep 27, 2024
1 parent 3f5007c commit 08fa8f5
Show file tree
Hide file tree
Showing 43 changed files with 584 additions and 79 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cumulus/client/network/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl RelayChainInterface for DummyRelayChainInterface {
impl_version: 0,
apis: Cow::Owned(apis),
transaction_version: 5,
state_version: 1,
system_version: 1,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion cumulus/client/pov-recovery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl RelayChainInterface for Relaychain {
impl_version: 0,
apis: Cow::Owned(apis),
transaction_version: 5,
state_version: 1,
system_version: 1,
})
}

Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/parachain-system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ parameter_types! {
impl_version: 1,
apis: sp_version::create_apis_vec!([]),
transaction_version: 1,
state_version: 1,
system_version: 1,
};
pub const ParachainId: ParaId = ParaId::new(200);
pub const ReservedXcmpWeight: Weight = Weight::zero();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 16,
state_version: 1,
system_version: 1,
};

/// 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 @@ -127,7 +127,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 16,
state_version: 1,
system_version: 1,
};

/// 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 @@ -242,7 +242,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 6,
state_version: 1,
system_version: 1,
};

/// 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 @@ -227,7 +227,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 6,
state_version: 1,
system_version: 1,
};

/// 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 @@ -130,7 +130,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 6,
state_version: 1,
system_version: 1,
};

/// 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 @@ -148,7 +148,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 7,
state_version: 1,
system_version: 1,
};

/// 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 @@ -153,7 +153,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
state_version: 1,
system_version: 1,
};

/// 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 @@ -152,7 +152,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
state_version: 1,
system_version: 1,
};

/// 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 @@ -106,7 +106,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
system_version: 1,
};

/// 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 @@ -140,7 +140,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
system_version: 1,
};

/// 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 @@ -140,7 +140,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
system_version: 1,
};

/// The version information used to identify this runtime when compiled natively.
Expand Down
2 changes: 1 addition & 1 deletion cumulus/parachains/runtimes/starters/seedling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
state_version: 0,
system_version: 1,
};

/// The version information used to identify this runtime when compiled natively.
Expand Down
2 changes: 1 addition & 1 deletion cumulus/parachains/runtimes/starters/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 0,
system_version: 1,
};

/// The version information used to identify this runtime when compiled natively.
Expand Down
2 changes: 1 addition & 1 deletion cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
system_version: 1,
};

/// 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,7 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 6,
state_version: 0,
system_version: 0,
};

pub const MILLISECS_PER_BLOCK: u64 = 6000;
Expand Down
4 changes: 2 additions & 2 deletions cumulus/test/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
system_version: 1,
};

#[cfg(feature = "increment-spec-version")]
Expand All @@ -146,7 +146,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
system_version: 1,
};

pub const EPOCH_DURATION_IN_BLOCKS: u32 = 10 * MINUTES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
system_version: 1,
};

/// The signed extensions that are added to the runtime.
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 26,
state_version: 1,
system_version: 1,
};

/// The BABE epoch configuration at genesis.
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
system_version: 1,
};

/// The BABE epoch configuration at genesis.
Expand Down
2 changes: 1 addition & 1 deletion polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 26,
state_version: 1,
system_version: 1,
};

/// The BABE epoch configuration at genesis.
Expand Down
76 changes: 76 additions & 0 deletions prdoc/pr_4257.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Rename `state_version` in `RuntimeVersion` to `system_version`.

doc:
- audience: Runtime Dev
description: |
This PR renames `state_version` in `RuntimeVersion` to `system_version`. `system_version=2` signifies
that extrinsic root derivation uses `StateVersion::V1`.

- audience: Runtime User
description: |
`RuntimeVersion`'s `state_version` is renamed to `system_version`. Applications using that type and its field
must update their code to reflect the changes. For easier migration serde serialization produces both new
`systemVersion` and old `stateVersion` fields and deserialization supports `stateVersion` as an alias as too.

crates:
- name: frame-system
bump: major
- name: sp-api
bump: none
- name: sp-version
bump: major
- name: sp-storage
bump: minor
- name: sp-version-proc-macro
bump: minor
- name: sc-block-builder
bump: major
- name: sc-executor
bump: major
- name: sc-rpc
bump: none
- name: sc-rpc-spec-v2
bump: none
- name: cumulus-pallet-parachain-system
bump: none
- name: cumulus-client-pov-recovery
bump: none
- name: cumulus-client-network
bump: none
- name: rococo-runtime
bump: major
- name: westend-runtime
bump: major
- name: asset-hub-rococo-runtime
bump: major
- name: asset-hub-westend-runtime
bump: major
- name: bridge-hub-rococo-runtime
bump: major
- name: bridge-hub-westend-runtime
bump: major
- name: collectives-westend-runtime
bump: major
- name: coretime-rococo-runtime
bump: major
- name: coretime-westend-runtime
bump: major
- name: people-rococo-runtime
bump: major
- name: people-westend-runtime
bump: major
- name: penpal-runtime
bump: major
- name: contracts-rococo-runtime
bump: major
- name: glutton-westend-runtime
bump: major
- name: seedling-runtime
bump: major
- name: shell-runtime
bump: major
- name: rococo-parachain-runtime
bump: major
2 changes: 1 addition & 1 deletion substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
state_version: 1,
system_version: 1,
};

/// The BABE epoch configuration at genesis.
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ where
header.extrinsics_root().clone(),
HashingFor::<Block>::ordered_trie_root(
self.extrinsics.iter().map(Encode::encode).collect(),
sp_runtime::StateVersion::V0,
self.api.version(self.parent_hash)?.extrinsics_root_state_version(),
),
);

Expand Down
12 changes: 6 additions & 6 deletions substrate/client/executor/src/wasm_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ mod tests {

let version = decode_version(&old_runtime_version.encode()).unwrap();
assert_eq!(1, version.transaction_version);
assert_eq!(0, version.state_version);
assert_eq!(0, version.system_version);
}

#[test]
Expand All @@ -507,12 +507,12 @@ mod tests {
impl_version: 1,
apis: create_apis_vec!([(<dyn Core::<Block>>::ID, 3)]),
transaction_version: 3,
state_version: 4,
system_version: 4,
};

let version = decode_version(&old_runtime_version.encode()).unwrap();
assert_eq!(3, version.transaction_version);
assert_eq!(0, version.state_version);
assert_eq!(0, version.system_version);

let old_runtime_version = RuntimeVersion {
spec_name: "test".into(),
Expand All @@ -522,12 +522,12 @@ mod tests {
impl_version: 1,
apis: create_apis_vec!([(<dyn Core::<Block>>::ID, 4)]),
transaction_version: 3,
state_version: 4,
system_version: 4,
};

let version = decode_version(&old_runtime_version.encode()).unwrap();
assert_eq!(3, version.transaction_version);
assert_eq!(4, version.state_version);
assert_eq!(4, version.system_version);
}

#[test]
Expand All @@ -545,7 +545,7 @@ mod tests {
impl_version: 100,
apis: create_apis_vec!([(<dyn Core::<Block>>::ID, 4)]),
transaction_version: 100,
state_version: 1,
system_version: 1,
};

let embedded = sp_version::embed::embed_runtime_version(&wasm, runtime_version.clone())
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/rpc-spec-v2/src/chain_head/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ async fn follow_with_runtime() {
[\"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\":1}";
[\"0xed99c5acb25eedf5\",3],[\"0xfbc577b9d747efd6\",1]],\"transactionVersion\":1,\"systemVersion\":1}";

let runtime: RuntimeVersion = serde_json::from_str(runtime_str).unwrap();

Expand Down
3 changes: 2 additions & 1 deletion substrate/client/rpc/src/state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ async fn should_return_runtime_version() {
[\"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\":1}";
[\"0xed99c5acb25eedf5\",3],[\"0xfbc577b9d747efd6\",1]],\"transactionVersion\":1,\"systemVersion\":1,\
\"stateVersion\":1}";

let runtime_version = api.runtime_version(None.into()).unwrap();
let serialized = serde_json::to_string(&runtime_version).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/support/test/compile_pass/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: sp_version::create_apis_vec!([]),
transaction_version: 0,
state_version: 0,
system_version: 0,
};

pub type Signature = sr25519::Signature;
Expand Down
Loading

0 comments on commit 08fa8f5

Please sign in to comment.