mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
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:
@@ -579,13 +579,9 @@ mod tests {
|
||||
t.into()
|
||||
}
|
||||
|
||||
fn init_block() {
|
||||
println!("Initializing {}", System::block_number());
|
||||
System::on_initialize(System::block_number());
|
||||
Initializer::on_initialize(System::block_number());
|
||||
}
|
||||
|
||||
fn run_to_block(n: BlockNumber) {
|
||||
// NOTE that this function only simulates modules of interest. Depending on new module may
|
||||
// require adding it here.
|
||||
println!("Running until block {}", n);
|
||||
while System::block_number() < n {
|
||||
let b = System::block_number();
|
||||
@@ -593,9 +589,11 @@ mod tests {
|
||||
if System::block_number() > 1 {
|
||||
println!("Finalizing {}", System::block_number());
|
||||
System::on_finalize(System::block_number());
|
||||
Initializer::on_finalize(System::block_number());
|
||||
}
|
||||
// Session change every 3 blocks.
|
||||
if (b + 1) % 3 == 0 {
|
||||
println!("New session at {}", System::block_number());
|
||||
Initializer::on_new_session(
|
||||
false,
|
||||
Vec::new().into_iter(),
|
||||
@@ -603,7 +601,9 @@ mod tests {
|
||||
);
|
||||
}
|
||||
System::set_block_number(b + 1);
|
||||
init_block();
|
||||
println!("Initializing {}", System::block_number());
|
||||
System::on_initialize(System::block_number());
|
||||
Initializer::on_initialize(System::block_number());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -725,8 +725,9 @@ mod tests {
|
||||
WASM_MAGIC.to_vec().into(),
|
||||
).is_err());
|
||||
|
||||
run_to_block(6);
|
||||
|
||||
// The session will be changed on the 6th block, as part of finalization. The change
|
||||
// will be observed on the 7th.
|
||||
run_to_block(7);
|
||||
assert_ok!(Registrar::register_parachain(
|
||||
1u32.into(),
|
||||
vec![1; 3].into(),
|
||||
|
||||
Reference in New Issue
Block a user