Skip to content

Commit

Permalink
Fix #387 - Generalize the Event and Error of tasks by separating exec…
Browse files Browse the repository at this point in the history
…ution from triggering and rescheduling (#383)

* If the balance is insufficient, skip the bond

* fixup: auto format Rust code

* Fix tests for auto compound task

* Add test cases of  4 scenarios for auto compound task

* Fix DelegationNotFound typo

* Change the branch of pallet-parachain-staking library to oak-staging

* In the AutoCompoundDelegatorStakeFailed event, the error_message will include details about both the delegator and collator.

* Add non_interrupt_errors to Task attributes

* fixup: auto format Rust code

* Add encoded_call attribute to TaskTriggered event

* fixup: auto format Rust code

* Remove XcmpTaskSucceeded, AutoCompoundDelegatorStakeSucceeded, AutoCompoundDelegatorStakeSkipped, DynamicDispatchResult event

* fixup: auto format Rust code

* Fix tests

* Fix tests. Add comments.

* fixup: auto format Rust code

* Rename cancel_upon_errors to abort_errors

* fixup: auto format Rust code

* Fix tests

* fixup: auto format Rust code

* Add TaskExecuted event

* fixup: auto format Rust code

* Fix tests

* fixup: auto format Rust code

* Remove DynamicDispatchResult in benchmarking

* Rename TaskFailedToReschedule to TaskRescheduleFailed

* Add comments

* Add more checks in tests

* fixup: auto format Rust code

* Check dynamic dispatch error in bechmarking

* Remove abort_errors in TaskTriggered event

* Deposit DelegationIncreased event in MockDelegatorActions

* Rename cancel_errors to abort_errors in mock.rs

* Revert assert_last_event and add  allow(dead_code) annotation on it

* Update parachain-staking library

* Change the type of encoded_call in TaskTriggered event

* Change the type of abort_errors to Vec<Vec<u8>>

---------

Co-authored-by: oak-code-formatter <oak-code-formatter@users.noreply.github.com>
Co-authored-by: Chris Li <chrisli30@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 3, 2023
1 parent 9ad58fb commit 1f62244
Show file tree
Hide file tree
Showing 16 changed files with 1,031 additions and 423 deletions.
55 changes: 28 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "r
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38" }

# Moonbeam Dependencies
pallet-parachain-staking = { git = "https://github.com/OAK-Foundation/moonbeam", branch = "oak-polkadot-v0.9.38" }
pallet-parachain-staking = { git = "https://github.com/OAK-Foundation/moonbeam", branch = "oak-staging" }

# ORML Dependencies
orml-asset-registry = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.38" }
Expand Down
7 changes: 5 additions & 2 deletions pallets/automation-time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ scale-info = { version = "2.1", default-features = false, features = [
"derive",
] }
log = { version = "0.4.17", default-features = false }
hex = { version = "0.4.3", default-features = false, features = [
"alloc",
] }

# Polkadot
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.38" }
Expand All @@ -33,6 +36,7 @@ cumulus-primitives-core = { git = 'https://github.com/paritytech/cumulus', defau
## Substrate Primitive Dependencies
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }

## Substrate FRAME Dependencies
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.38" }
Expand All @@ -46,7 +50,7 @@ pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-fe
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.38" }

## Moonbeam Dependencies
pallet-parachain-staking = { git = "https://github.com/OAK-Foundation/moonbeam", default-features = false, branch = "oak-polkadot-v0.9.38" }
pallet-parachain-staking = { git = "https://github.com/OAK-Foundation/moonbeam", default-features = false, branch = "oak-staging" }

## ORML
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = false, branch = "polkadot-v0.9.38" }
Expand All @@ -62,7 +66,6 @@ primitives = { path = "../../primitives", default-features = false }
rand = { version = "0.7.3" }
serde = { version = "1.0.144" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.38" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.38" }

pallet-xcm = { git = 'https://github.com/paritytech/polkadot', default-features = false, branch = "release-v0.9.38" }
Expand Down
25 changes: 14 additions & 11 deletions pallets/automation-time/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn schedule_notify_tasks<T: Config>(owner: T::AccountId, times: Vec<u64>, count:
task_id.clone(),
times.clone(),
vec![4, 5, 6],
vec![],
)
.unwrap();
let task_id = AutomationTime::<T>::schedule_task(&task).unwrap();
Expand Down Expand Up @@ -92,6 +93,7 @@ fn schedule_xcmp_tasks<T: Config>(owner: T::AccountId, times: Vec<u64>, count: u
Weight::from_ref_time(5_000),
Weight::from_ref_time(10_000),
InstructionSequence::PayThroughSovereignAccount,
vec![],
)
.unwrap();
let task_id = AutomationTime::<T>::schedule_task(&task).unwrap();
Expand Down Expand Up @@ -123,6 +125,7 @@ fn schedule_auto_compound_delegated_stake_tasks<T: Config>(
frequency,
collator,
account_minimum,
vec![],
)
.unwrap();
AutomationTime::<T>::schedule_task(&task).unwrap();
Expand Down Expand Up @@ -316,26 +319,26 @@ benchmarks! {
T::DelegatorActions::setup_delegator(&collator, &delegator)?;

let (task_id, task) = schedule_auto_compound_delegated_stake_tasks::<T>(delegator.clone(), 3600, 1).pop().unwrap();
}: { AutomationTime::<T>::run_auto_compound_delegated_stake_task(delegator, collator, account_minimum, task_id.clone(), &task) }
}: { AutomationTime::<T>::run_auto_compound_delegated_stake_task(delegator, collator, account_minimum, &task) }

run_dynamic_dispatch_action {
let caller: T::AccountId = account("caller", 0, SEED);
let task_id = vec![49, 45, 48, 45, 52];
let call: <T as Config>::Call = frame_system::Call::remark { remark: vec![] }.into();
let encoded_call = call.encode();
}: { AutomationTime::<T>::run_dynamic_dispatch_action(caller.clone(), encoded_call, task_id.clone()) }
verify {
assert_last_event::<T>(Event::DynamicDispatchResult{ who: caller, task_id: task_id.clone(), result: Ok(()) }.into())
}: {
let (_, error) = AutomationTime::<T>::run_dynamic_dispatch_action(caller.clone(), encoded_call);
assert_eq!(error, None);
}

run_dynamic_dispatch_action_fail_decode {
let caller: T::AccountId = account("caller", 0, SEED);
let task_id = vec![49, 45, 48, 45, 52];

let bad_encoded_call: Vec<u8> = vec![1];
}: { AutomationTime::<T>::run_dynamic_dispatch_action(caller.clone(), bad_encoded_call, task_id.clone()) }
verify {
assert_last_event::<T>(Event::CallCannotBeDecoded{ who: caller, task_id: task_id.clone() }.into())
}: {
let (_, error) = AutomationTime::<T>::run_dynamic_dispatch_action(caller.clone(), bad_encoded_call);
assert_eq!(error, Some(DispatchError::from(Error::<T>::CallCannotBeDecoded)));
}

/*
Expand All @@ -355,7 +358,7 @@ benchmarks! {

for i in 0..v {
let task_id: Vec<u8> = vec![i.saturated_into::<u8>()];
let task = TaskOf::<T>::create_event_task::<T>(caller.clone(), task_id.clone(), vec![time.into()], vec![4, 5, 6]).unwrap();
let task = TaskOf::<T>::create_event_task::<T>(caller.clone(), task_id.clone(), vec![time.into()], vec![4, 5, 6], vec![]).unwrap();
AutomationTime::<T>::schedule_task(&task).unwrap();
let missed_task = MissedTaskV2Of::<T>::new(caller.clone(), task_id.clone(), time.into());
<AccountTasks<T>>::insert(caller.clone(), task_id.clone(), task);
Expand Down Expand Up @@ -395,7 +398,7 @@ benchmarks! {

for i in 0..v {
let task_id: Vec<u8> = vec![i.saturated_into::<u8>()];
let task = TaskOf::<T>::create_event_task::<T>(caller.clone(), task_id.clone(), vec![execution_time], vec![65, 65.saturating_add(i as u8)]).unwrap();
let task = TaskOf::<T>::create_event_task::<T>(caller.clone(), task_id.clone(), vec![execution_time], vec![65, 65.saturating_add(i as u8)], vec![]).unwrap();
let task_id = AutomationTime::<T>::schedule_task(&task).unwrap();
<AccountTasks<T>>::insert(caller.clone(), task_id.clone(), task);
task_ids.push((caller.clone(), task_id.clone()))
Expand Down Expand Up @@ -442,7 +445,7 @@ benchmarks! {
for j in 0..1 {
let time = time.saturating_add(3600);
let task_id: Vec<u8> = vec![i.saturated_into::<u8>(), j.saturated_into::<u8>()];
let task = TaskOf::<T>::create_event_task::<T>(caller.clone(), task_id.clone(), vec![time.into()], vec![4, 5, 6]).unwrap();
let task = TaskOf::<T>::create_event_task::<T>(caller.clone(), task_id.clone(), vec![time.into()], vec![4, 5, 6], vec![]).unwrap();
AutomationTime::<T>::schedule_task(&task).unwrap();
<AccountTasks<T>>::insert(caller.clone(), task_id, task);
}
Expand All @@ -458,7 +461,7 @@ benchmarks! {

for i in 0..T::MaxTasksPerSlot::get() {
task_id = increment_task_id(task_id);
let task = TaskOf::<T>::create_event_task::<T>(caller.clone(), task_id.clone(), vec![current_time.into()], vec![4, 5, 6]).unwrap();
let task = TaskOf::<T>::create_event_task::<T>(caller.clone(), task_id.clone(), vec![current_time.into()], vec![4, 5, 6], vec![]).unwrap();
AutomationTime::<T>::schedule_task(&task).unwrap();
<AccountTasks<T>>::insert(caller.clone(), task_id.clone(), task);
}
Expand Down
Loading

0 comments on commit 1f62244

Please sign in to comment.