reset events before apply runtime upgrade (#10620)

* reset events before apply runtime upgrade

* fix tests

* add test

* update comment

* Update frame/system/src/lib.rs

* trigger CI

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Xiliang Chen
2022-01-12 21:22:29 +13:00
committed by GitHub
parent 79cab81364
commit d346028a9d
11 changed files with 79 additions and 83 deletions
+5 -37
View File
@@ -944,27 +944,6 @@ where
}
}
/// A type of block initialization to perform.
pub enum InitKind {
/// Leave inspectable storage entries in state.
///
/// i.e. `Events` are not being reset.
/// Should only be used for off-chain calls,
/// regular block execution should clear those.
Inspection,
/// Reset also inspectable storage entries.
///
/// This should be used for regular block execution.
Full,
}
impl Default for InitKind {
fn default() -> Self {
InitKind::Full
}
}
/// Reference status; can be either referenced or unreferenced.
#[derive(RuntimeDebug)]
pub enum RefStatus {
@@ -1302,12 +1281,7 @@ impl<T: Config> Pallet<T> {
}
/// Start the execution of a particular block.
pub fn initialize(
number: &T::BlockNumber,
parent_hash: &T::Hash,
digest: &generic::Digest,
kind: InitKind,
) {
pub fn initialize(number: &T::BlockNumber, parent_hash: &T::Hash, digest: &generic::Digest) {
// populate environment
ExecutionPhase::<T>::put(Phase::Initialization);
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &0u32);
@@ -1318,13 +1292,6 @@ impl<T: Config> Pallet<T> {
// Remove previous block data from storage
BlockWeight::<T>::kill();
// Kill inspectable storage entries in state when `InitKind::Full`.
if let InitKind::Full = kind {
<Events<T>>::kill();
EventCount::<T>::kill();
<EventTopics<T>>::remove_all(None);
}
}
/// Remove temporary "environment" entries in storage, compute the storage root and return the
@@ -1444,9 +1411,10 @@ impl<T: Config> Pallet<T> {
AllExtrinsicsLen::<T>::put(len as u32);
}
/// Reset events. Can be used as an alternative to
/// `initialize` for tests that don't need to bother with the other environment entries.
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
/// Reset events.
///
/// This needs to be used in prior calling [`initialize`](Self::initialize) for each new block
/// to clear events from previous block.
pub fn reset_events() {
<Events<T>>::kill();
EventCount::<T>::kill();