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 committed Oct 20, 2023
1 parent 7699435 commit 05903d6
Show file tree
Hide file tree
Showing 32 changed files with 67 additions and 9 deletions.
1 change: 1 addition & 0 deletions cumulus/pallets/dmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ mod tests {
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/pallets/parachain-system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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 @@ -135,6 +135,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 13,
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 @@ -145,6 +145,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 13,
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 @@ -128,6 +128,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 13,
state_version: 1,
extrinsic_state_version: 0,
};

#[cfg(not(feature = "state-trie-version-1"))]
Expand All @@ -141,6 +142,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 13,
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 @@ -113,6 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 13,
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 @@ -137,6 +137,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 3,
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 @@ -137,6 +137,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
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 @@ -203,6 +203,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 3,
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 @@ -120,6 +120,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 @@ -134,6 +134,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 @@ -102,6 +102,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 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 @@ -87,6 +87,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 @@ -233,6 +233,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 @@ -109,6 +109,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 = 12000;
Expand Down
1 change: 1 addition & 0 deletions cumulus/test/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,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 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 @@ -138,6 +138,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 22,
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 @@ -145,6 +145,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 22,
state_version: 1,
extrinsic_state_version: 0,
};

/// The BABE epoch configuration at genesis.
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 @@ -110,6 +110,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 @@ -152,6 +152,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
4 changes: 4 additions & 0 deletions substrate/client/executor/src/wasm_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ mod tests {
apis: sp_api::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 @@ -518,11 +519,13 @@ mod tests {
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 4)]),
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 @@ -541,6 +544,7 @@ mod tests {
apis: sp_api::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
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
11 changes: 6 additions & 5 deletions substrate/frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ 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 @@ -1448,7 +1448,8 @@ 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
4 changes: 2 additions & 2 deletions substrate/frame/system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use frame_support::{
traits::WhitelistedStorageKeys,
};
use std::collections::BTreeSet;

use sp_core::storage::StateVersion;
use mock::{RuntimeOrigin, *};
use sp_core::{hexdisplay::HexDisplay, H256};
use sp_runtime::{
Expand Down Expand Up @@ -721,7 +721,7 @@ 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
2 changes: 1 addition & 1 deletion substrate/primitives/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct RuntimeVersion {
apis: u8,
transaction_version: u32,
state_version: u8,
extrinsic_state_version: u8,
}

#[derive(Default, Debug)]
Expand All @@ -75,6 +76,7 @@ struct ParseRuntimeVersion {
impl_version: Option<u32>,
transaction_version: Option<u32>,
state_version: Option<u8>,
extrinsic_state_version: Option<u8>,
}

impl ParseRuntimeVersion {
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -199,6 +203,7 @@ impl ParseRuntimeVersion {
impl_version,
transaction_version,
state_version,
extrinsic_state_version
} = self;

Ok(RuntimeVersion {
Expand All @@ -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),
})
}
}
Expand Down Expand Up @@ -241,6 +247,7 @@ mod tests {
apis: 0,
transaction_version: 2,
state_version: 1,
extrinsic_state_version: 0,
}
.encode();

Expand All @@ -256,6 +263,7 @@ mod tests {
apis: Cow::Owned(vec![]),
transaction_version: 2,
state_version: 1,
extrinsic_state_version: 0
},
);
}
Expand Down
Loading

0 comments on commit 05903d6

Please sign in to comment.