Do not use rely on the block initialization when calling runtime APIs (#2123)

* Don't initialize block when calling runtime APIs

* Adapt check_validation_outputs

We split the code path for the inclusion and for the commitments checking.

* Slap #[skip_initialize_block] on safe runtime APIs

That is, those that should not be affected by this attribute

* Make `Scheduled` not ephemeral

So that it is persisted in the storage and ready to be inspected
by the runtime APIs. This is in contrast to what was before, where we
would remove the storage entry and then rely on the scheduling performed
by `on_initialize` again.

* Add a big fat comment

* Typos

Co-authored-by: Robert Habermeier <rphmeier@gmail.com>

* Move session change to the end of the current block

Previously, it was the beginning of the next block. This allows us to
put #[skip_initialize_block]

* Update tests

* Fix a test in paras registrar

Also refactor it a bit so the next time there are more chances this kind
of issue is diagnosed quicker.

* Add for_runtime_api to inclusion's check_validation_outputs

Co-authored-by: Robert Habermeier <rphmeier@gmail.com>
This commit is contained in:
Sergei Shulepov
2020-12-22 00:02:22 +01:00
committed by GitHub
parent 01d271caeb
commit 4405f52e2d
8 changed files with 114 additions and 77 deletions
+8 -9
View File
@@ -182,7 +182,7 @@ decl_storage! {
ParathreadClaimIndex: Vec<ParaId>;
/// The block number where the session start occurred. Used to track how many group rotations have occurred.
SessionStartBlock get(fn session_start_block): T::BlockNumber;
/// Currently scheduled cores - free but up to be occupied. Ephemeral storage item that's wiped on finalization.
/// Currently scheduled cores - free but up to be occupied.
///
/// Bounded by the number of cores: one for each parachain and parathread multiplexer.
Scheduled get(fn scheduled): Vec<CoreAssignment>; // sorted ascending by CoreIndex.
@@ -203,13 +203,6 @@ decl_module! {
impl<T: Config> Module<T> {
/// Called by the initializer to initialize the scheduler module.
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
Self::schedule(Vec::new());
0
}
/// Called by the initializer to finalize the scheduler module.
pub(crate) fn initializer_finalize() {
// Free all scheduled cores and return parathread claims to queue, with retries incremented.
let config = <configuration::Module<T>>::config();
ParathreadQueue::mutate(|queue| {
@@ -225,10 +218,16 @@ impl<T: Config> Module<T> {
}
}
}
})
});
Self::schedule(Vec::new());
0
}
/// Called by the initializer to finalize the scheduler module.
pub(crate) fn initializer_finalize() {}
/// Called by the initializer to note that a new session has started.
pub(crate) fn initializer_on_new_session(notification: &SessionChangeNotification<T::BlockNumber>) {
let &SessionChangeNotification {