-
Notifications
You must be signed in to change notification settings - Fork 70
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
Sweep expired tasks, fixed #442 #451
Conversation
71b63f9
to
89b5bac
Compare
5c41a00
to
d59d488
Compare
The price may have changed in extreme case by the time we run the tasks, if so, we adjust accordingly and emit an event. Task won't be put back to the queue but will be removed from the queue as if it has run succesfully, but we emit the event about stale price instead of executing the task
3e4b3af
to
c0fe578
Compare
06e5b39
to
d4ccd48
Compare
Hi @chrisli30 @imstar15 This is ready to review. Please help check. Thanks. |
// TaskStats: decrease task count | ||
// AccountStats: decrease task count | ||
// SortedTasksIndex | ||
pub fn remove_task(task: &Task<T>, event: Option<Event<T>>) { |
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.
Yea definitely needs this encapsulation of remove tasks.
pallets/automation-price/src/lib.rs
Outdated
// TaskQueue if the task is alreayd queue | ||
// TaskStats: decrease task count | ||
// AccountStats: decrease task count | ||
// SortedTasksIndex |
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.
Let’s add comments.
SortedTasksIndex - sorted by price
Sorted TaskIds by expiration?
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.
comment are added now.
BTreeMap::<u128, TaskIdList<T>>::new() | ||
} | ||
#[pallet::storage] | ||
#[pallet::getter(fn get_sorted_tasks_by_expiration)] |
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.
@chrisli30 This is the SortedTaskByExpiration where we store a tasks sorted by expired epoch
When block has idle time, we will run task sweep to delete expired tasks. We will run as long as we still have weight left leverage
on_idle
block https://paritytech.github.io/polkadot-sdk/master/frame_support/traits/trait.Hooks.html#method.on_idleI had a few test cases to test this extensively. When removing tasks, we also update our stat such as total task count and task count of user that has task being removed.