Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry mechanics to pallet-scheduler #3060

Merged
merged 44 commits into from
Feb 16, 2024
Merged
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
328d0cd
Add option to retry task in scheduler
georgepisaltu Jan 23, 2024
6f56d9f
Add unit tests for retry scheduler
georgepisaltu Jan 23, 2024
22800c5
Add benchmarks for retry scheduler
georgepisaltu Jan 24, 2024
9315c2e
Add some docs to retry functions
georgepisaltu Jan 25, 2024
5bbd31e
Remove redundant clone
georgepisaltu Jan 25, 2024
3eb8016
Add real weights to scheduler pallet
georgepisaltu Jan 25, 2024
9ecae46
Merge remote-tracking branch 'upstream/master' into retry-schedule
georgepisaltu Jan 25, 2024
fcff15c
".git/.scripts/commands/bench-all/bench-all.sh" --pallet=pallet_sched…
Jan 25, 2024
a8fd732
".git/.scripts/commands/bench-all/bench-all.sh" --pallet=pallet_sched…
Jan 25, 2024
3e6e77e
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
Jan 25, 2024
9120d60
".git/.scripts/commands/bench-all/bench-all.sh" --pallet=pallet_sched…
Jan 25, 2024
4167d6f
".git/.scripts/commands/bench-all/bench-all.sh" --pallet=pallet_sched…
Jan 25, 2024
816906a
Use `TaskAddress` in `set_retry`
georgepisaltu Jan 26, 2024
8a28ea5
Merge remote-tracking branch 'upstream/master' into retry-schedule
georgepisaltu Jan 26, 2024
900d2d5
Add prdoc
georgepisaltu Jan 26, 2024
05cbdfc
Refactor agenda query in `set_retry`
georgepisaltu Jan 26, 2024
5fc62f4
Minor renames and fixes
georgepisaltu Jan 26, 2024
5e305e1
Refactor `schedule_retry` return type
georgepisaltu Jan 26, 2024
5943dcc
Implement `ensure_privilege`
georgepisaltu Jan 26, 2024
690f2b8
Add event for setting retry config
georgepisaltu Jan 26, 2024
4a81417
Make retry fail if insufficient weight
georgepisaltu Jan 29, 2024
438effb
Remove redundant weight parameter in `set_retry`
georgepisaltu Jan 29, 2024
d048760
Merge remote-tracking branch 'upstream/master' into retry-schedule
georgepisaltu Jan 29, 2024
3c2b540
Add test for dropping insufficient weight retry
georgepisaltu Jan 29, 2024
7a39a69
Merge remote-tracking branch 'upstream/master' into retry-schedule
georgepisaltu Jan 29, 2024
2e8f954
Clean up retry config on cancel
georgepisaltu Feb 1, 2024
7dfb517
Small refactor
georgepisaltu Feb 1, 2024
2e26707
Merge remote-tracking branch 'upstream/master' into retry-schedule
georgepisaltu Feb 1, 2024
40b567d
Add docs to retry config map
georgepisaltu Feb 1, 2024
2b35465
Add retry count to `RetrySet` event
georgepisaltu Feb 2, 2024
a43df52
Merge remote-tracking branch 'upstream/master' into retry-schedule
georgepisaltu Feb 2, 2024
9da58c6
Make retries independent of periodic runs
georgepisaltu Feb 7, 2024
2976dac
Merge remote-tracking branch 'upstream/master' into retry-schedule
georgepisaltu Feb 7, 2024
8ce66f7
Small refactoring
georgepisaltu Feb 13, 2024
dc9ef2e
Add `cancel_retry` extrinsics
georgepisaltu Feb 13, 2024
945a095
Merge remote-tracking branch 'upstream/master' into retry-schedule
georgepisaltu Feb 13, 2024
39eb209
Add e2e unit test for retry schedule
georgepisaltu Feb 14, 2024
2290240
Merge remote-tracking branch 'upstream/master' into retry-schedule
georgepisaltu Feb 14, 2024
50a2010
Simplify `schedule_retry`
georgepisaltu Feb 15, 2024
e9cc27e
Add docs for `as_retry`
georgepisaltu Feb 15, 2024
497100c
Merge remote-tracking branch 'upstream/master' into retry-schedule
georgepisaltu Feb 15, 2024
863bec7
Update doc comments for `set_retry`
georgepisaltu Feb 16, 2024
7a16648
Merge remote-tracking branch 'upstream/master' into retry-schedule
georgepisaltu Feb 16, 2024
b72da0c
Move common logic under `do_cancel_retry`
georgepisaltu Feb 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement ensure_privilege
Signed-off-by: georgepisaltu <[email protected]>
  • Loading branch information
georgepisaltu committed Jan 26, 2024
commit 5943dcc3a8c9f55cadd1d85c8c74585ea8beff22
42 changes: 18 additions & 24 deletions substrate/frame/scheduler/src/lib.rs
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,7 @@ pub mod pallet {
.get(index as usize)
.and_then(Option::as_ref)
.ok_or(Error::<T>::NotFound)?;
if matches!(
T::OriginPrivilegeCmp::cmp_privilege(origin.caller(), &task.origin),
Some(Ordering::Less) | None
) {
return Err(BadOrigin.into())
}
Self::ensure_privilege(origin.caller(), &task.origin)?;
Retries::<T>::insert(
(when, index),
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
RetryConfig { total_retries: retries, remaining: retries, period },
Expand Down Expand Up @@ -530,12 +525,7 @@ pub mod pallet {
.get(agenda_index as usize)
.and_then(Option::as_ref)
.ok_or(Error::<T>::NotFound)?;
if matches!(
T::OriginPrivilegeCmp::cmp_privilege(origin.caller(), &task.origin),
Some(Ordering::Less) | None
) {
return Err(BadOrigin.into())
}
Self::ensure_privilege(origin.caller(), &task.origin)?;
Retries::<T>::insert(
(when, agenda_index),
RetryConfig { total_retries: retries, remaining: retries, period },
Expand Down Expand Up @@ -940,12 +930,7 @@ impl<T: Config> Pallet<T> {
Ok(None),
|s| -> Result<Option<Scheduled<_, _, _, _, _>>, DispatchError> {
if let (Some(ref o), Some(ref s)) = (origin, s.borrow()) {
if matches!(
T::OriginPrivilegeCmp::cmp_privilege(o, &s.origin),
Some(Ordering::Less) | None
) {
return Err(BadOrigin.into())
}
Self::ensure_privilege(o, &s.origin)?;
};
Ok(s.take())
},
Expand Down Expand Up @@ -1033,12 +1018,7 @@ impl<T: Config> Pallet<T> {
Agenda::<T>::try_mutate(when, |agenda| -> DispatchResult {
if let Some(s) = agenda.get_mut(i) {
if let (Some(ref o), Some(ref s)) = (origin, s.borrow()) {
if matches!(
T::OriginPrivilegeCmp::cmp_privilege(o, &s.origin),
Some(Ordering::Less) | None
) {
return Err(BadOrigin.into())
}
Self::ensure_privilege(o, &s.origin)?;
T::Preimages::drop(&s.call);
}
*s = None;
Expand Down Expand Up @@ -1366,6 +1346,20 @@ impl<T: Config> Pallet<T> {
None => Err(task),
}
}

/// Ensure that `left` has at least the same level of privilege or higher than `right`.
///
/// Returns an error if `left` has a lower level of privilege or the two cannot be compared.
fn ensure_privilege(
left: &<T as Config>::PalletsOrigin,
right: &<T as Config>::PalletsOrigin,
) -> Result<(), DispatchError> {
if matches!(T::OriginPrivilegeCmp::cmp_privilege(left, right), Some(Ordering::Less) | None)
{
return Err(BadOrigin.into());
}
Ok(())
}
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
}

impl<T: Config> schedule::v2::Anon<BlockNumberFor<T>, <T as Config>::RuntimeCall, T::PalletsOrigin>
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
Expand Down