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

handle price confirmation when running tasks #449

Merged
merged 12 commits into from
Oct 11, 2023

Conversation

v9n
Copy link
Member

@v9n v9n commented Oct 10, 2023

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

@v9n v9n marked this pull request as draft October 10, 2023 08:27
@v9n v9n marked this pull request as ready for review October 10, 2023 16:17
@@ -501,7 +501,7 @@ fn test_shift_tasks_movement_through_price_changes() {
asset2.to_vec(),
1000u128,
"gt".as_bytes().to_vec(),
vec!(100),
vec!(10100),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update mock price so adjust these accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we leverage variables to make these numbers more readable? For example, instead of 10100, we could use something like target_price_1 + 100.

Basically we just need to know how much higher or lower these numbers are compared to a target number in mock, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, agree. let me update

pallets/automation-price/src/mock.rs Show resolved Hide resolved
@@ -501,7 +501,7 @@ fn test_shift_tasks_movement_through_price_changes() {
asset2.to_vec(),
1000u128,
"gt".as_bytes().to_vec(),
vec!(100),
vec!(10100),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we leverage variables to make these numbers more readable? For example, instead of 10100, we could use something like target_price_1 + 100.

Basically we just need to know how much higher or lower these numbers are compared to a target number in mock, right?

Copy link
Member

@imstar15 imstar15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

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
@v9n v9n force-pushed the handle-price-move-before-task-run branch from 5c41a00 to d59d488 Compare October 11, 2023 15:32
@v9n
Copy link
Member Author

v9n commented Oct 11, 2023

@chrisli30 I refactor with the new var and add more comments to explain the test idea

Base automatically changed from restructure-task-storage to master October 11, 2023 17:06
Copy link
Member

@chrisli30 chrisli30 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more comments regarding task events for discussion.

let mut consumed_task_index: usize = 0;
// Check whether a task can run or not based on its expiration and price.
//
// A task can be queued but got expired when it's about to run, in that case, we don't want
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A task can be queued but got expired when it's about to run, in that case, we don't want it to be run.
While there may be different opinions on whether it should be executed or not, we can keep the behavior as-is. This comment is crucial for reviewing the design decision later. 👌

pallets/automation-price/src/lib.rs Show resolved Hide resolved
} else {
Self::deposit_event(Event::PriceAlreadyMoved {
who: task.owner_id.clone(),
task_id: task.task_id.clone(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same reasoning as the above,
{ taskId, price, actual}

Another way is to wrap all conditions into a condition object, so at the top level they all look the same
{taskId, condition, value}

Then for the expiration event, the event becomes {taskId, condition: {expireAt}, value: now_value }, and for the price moved event, {taskId, condition: {price: {chain, exchange, asset1, asset2, price} }, value: new_price }. Please see which way makes more sense is Rust implementation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code is updated with the new condition layout. Condition can be applied for multiple type of Error to add extra information later on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this looks cleaner and readable in code.

Copy link
Member

@chrisli30 chrisli30 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event definitions look good 👍

@v9n v9n merged commit 5e5f4d0 into master Oct 11, 2023
3 checks passed
@v9n v9n deleted the handle-price-move-before-task-run branch October 14, 2023 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants