This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
pallet-scheduler: Ensure we request a preimage #13340
Merged
paritytech-processbot
merged 2 commits into
master
from
bkchr-scheduler-request-preimage
Feb 9, 2023
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,9 +58,10 @@ fn scheduling_with_preimages_works() { | |
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(10) }); | ||
let hash = <Test as frame_system::Config>::Hashing::hash_of(&call); | ||
let len = call.using_encoded(|x| x.len()) as u32; | ||
let hashed = Preimage::pick(hash, len); | ||
assert_ok!(Preimage::note_preimage(RuntimeOrigin::signed(0), call.encode())); | ||
// Important to use here `Bounded::Lookup` to ensure that we request the hash. | ||
let hashed = Bounded::Lookup { hash, len }; | ||
assert_ok!(Scheduler::do_schedule(DispatchTime::At(4), None, 127, root(), hashed)); | ||
assert_ok!(Preimage::note_preimage(RuntimeOrigin::signed(0), call.encode())); | ||
assert!(Preimage::is_requested(&hash)); | ||
run_to_block(3); | ||
assert!(logger::log().is_empty()); | ||
|
@@ -479,8 +480,9 @@ fn scheduler_handles_periodic_unavailable_preimage() { | |
let call = RuntimeCall::Logger(LoggerCall::log { i: 42, weight: (max_weight / 3) * 2 }); | ||
let hash = <Test as frame_system::Config>::Hashing::hash_of(&call); | ||
let len = call.using_encoded(|x| x.len()) as u32; | ||
let bound = Preimage::pick(hash, len); | ||
assert_ok!(Preimage::note(call.encode().into())); | ||
let bound = Bounded::Lookup { hash, len }; | ||
// The preimage isn't requested yet. | ||
assert!(!Preimage::is_requested(&hash)); | ||
|
||
assert_ok!(Scheduler::do_schedule( | ||
DispatchTime::At(4), | ||
|
@@ -489,19 +491,23 @@ fn scheduler_handles_periodic_unavailable_preimage() { | |
root(), | ||
bound.clone(), | ||
)); | ||
|
||
// The preimage is requested. | ||
assert!(Preimage::is_requested(&hash)); | ||
|
||
// Note the preimage. | ||
assert_ok!(Preimage::note_preimage(RuntimeOrigin::signed(1), call.encode())); | ||
|
||
// Executes 1 times till block 4. | ||
run_to_block(4); | ||
assert_eq!(logger::log().len(), 1); | ||
|
||
// Unnote the preimage. | ||
// Unnote the preimage | ||
Preimage::unnote(&hash); | ||
|
||
// Does not ever execute again. | ||
run_to_block(100); | ||
assert_eq!(logger::log().len(), 1); | ||
|
||
// The preimage is not requested anymore. | ||
assert!(!Preimage::is_requested(&hash)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can keep this check to assert that a periodic job wont re-request it. |
||
}); | ||
} | ||
|
||
|
@@ -1129,7 +1135,8 @@ fn postponed_named_task_cannot_be_rescheduled() { | |
RuntimeCall::Logger(LoggerCall::log { i: 42, weight: Weight::from_ref_time(1000) }); | ||
let hash = <Test as frame_system::Config>::Hashing::hash_of(&call); | ||
let len = call.using_encoded(|x| x.len()) as u32; | ||
let hashed = Preimage::pick(hash, len); | ||
// Important to use here `Bounded::Lookup` to ensure that we request the hash. | ||
let hashed = Bounded::Lookup { hash, len }; | ||
let name: [u8; 32] = hash.as_ref().try_into().unwrap(); | ||
|
||
let address = Scheduler::do_schedule_named( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.