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 Aug 12, 2024
1 parent de6a7e3 commit 8f35691
Show file tree
Hide file tree
Showing 36 changed files with 82 additions and 11 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
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: 16,
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 @@ -124,6 +124,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 16,
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 @@ -223,6 +223,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 5,
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 @@ -196,6 +196,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 5,
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 @@ -130,6 +130,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 @@ -149,6 +149,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 7,
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 @@ -151,6 +151,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 @@ -150,6 +150,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 @@ -107,6 +107,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 @@ -139,6 +139,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 @@ -139,6 +139,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 @@ -82,6 +82,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 @@ -90,6 +90,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 @@ -243,6 +243,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 @@ -114,6 +114,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 @@ -133,6 +133,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 @@ -147,6 +148,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
extrinsic_state_version: 0,
};

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

/// The signed extensions that are added to the runtime.
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 @@ -171,6 +171,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 26,
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 @@ -122,6 +122,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 @@ -167,6 +167,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
transaction_version: 26,
state_version: 1,
extrinsic_state_version: 0,
};

/// The BABE epoch configuration at genesis.
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 @@ -170,6 +170,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 @@ -508,6 +508,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 @@ -520,14 +521,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 @@ -546,6 +549,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
3 changes: 2 additions & 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,8 @@ 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,\"stateVersion\":1,\
\"extrinsicStateVersion\":0}";

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 @@ -479,7 +479,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,\"stateVersion\":1,\
\"extrinsicStateVersion\":0}";

let runtime_version = api.runtime_version(None.into()).unwrap();
let serialized = serde_json::to_string(&runtime_version).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 @@ -183,16 +183,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 @@ -1847,7 +1853,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 @@ -41,6 +41,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
5 changes: 3 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::{OnRuntimeUpgrade, WhitelistedStorageKeys},
};
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,
Expand Down Expand Up @@ -789,7 +789,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
1 change: 1 addition & 0 deletions substrate/primitives/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,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
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 8f35691

Please sign in to comment.