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

[r2r] API call optimization #1279

Merged
merged 24 commits into from Jun 27, 2022
Merged

[r2r] API call optimization #1279

merged 24 commits into from Jun 27, 2022

Conversation

caglaryucekaya
Copy link

Requests current balance only for coins with an active maker order, as part of #1269.

@caglaryucekaya caglaryucekaya changed the title API call optimization [wip] API call optimization May 6, 2022
@caglaryucekaya caglaryucekaya changed the title [wip] API call optimization [r2r] API call optimization May 6, 2022
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! It's the first review iteration.

mm2src/lp_ordermatch.rs Outdated Show resolved Hide resolved
mm2src/lp_ordermatch.rs Outdated Show resolved Hide resolved
@caglaryucekaya caglaryucekaya changed the title [r2r] API call optimization [wip] API call optimization May 6, 2022
@caglaryucekaya caglaryucekaya changed the title [wip] API call optimization [r2r] API call optimization May 6, 2022
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

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

Second review iteration.

@@ -4263,6 +4275,37 @@ async fn get_max_volume(ctx: &MmArc, my_coin: &MmCoinEnum, other_coin: &MmCoinEn
))
}

pub async fn check_balance_update_loop(ctx: MmWeak, ticker: String) {
let mut current_balance = None;
Copy link
Member

Choose a reason for hiding this comment

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

Current balance is known when order is created. You can add it to fn arguments and simplify it a bit as Option won’t be used.

mm2src/lp_ordermatch.rs Outdated Show resolved Hide resolved
mm2src/lp_ordermatch/my_orders_storage.rs Outdated Show resolved Hide resolved
mm2src/lp_ordermatch.rs Outdated Show resolved Hide resolved
@caglaryucekaya caglaryucekaya changed the title [r2r] API call optimization [wip] API call optimization May 9, 2022
@caglaryucekaya caglaryucekaya changed the title [wip] API call optimization [r2r] API call optimization May 10, 2022
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

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

Next review iteration.

mm2src/lp_ordermatch.rs Outdated Show resolved Hide resolved
@artemii235
Copy link
Member

@caglaryucekaya WASM build and test MM2_WASM_Linux CI stage fails now. Please track statuses and fix errors if they occur.

Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

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

One change.

mm2src/lp_ordermatch.rs Outdated Show resolved Hide resolved
@artemii235
Copy link
Member

@caglaryucekaya Also, there are 4 tests failing that have been stable:

docker_tests::docker_ordermatch_tests::test_zombie_order_after_balance_reduce_and_mm_restart
docker_tests::order_should_be_cancelled_when_entire_balance_is_withdrawn
docker_tests::order_should_be_updated_when_balance_is_decreased_alice_subscribes_after_update
docker_tests::order_should_be_updated_when_balance_is_decreased_alice_subscribes_before_update

And these should be related to this PR changes. Please check them and fix.

@caglaryucekaya caglaryucekaya changed the title [r2r] API call optimization [wip] API call optimization May 11, 2022
@caglaryucekaya caglaryucekaya changed the title [wip] API call optimization [r2r] API call optimization May 11, 2022
@artemii235
Copy link
Member

@caglaryucekaya rustfmt check is failing.

Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

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

Next review iteration.

mm2src/lp_ordermatch.rs Outdated Show resolved Hide resolved
mm2src/lp_ordermatch.rs Outdated Show resolved Hide resolved
@caglaryucekaya caglaryucekaya changed the title [r2r] API call optimization [wip] API call optimization May 12, 2022
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

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

Last note :)

mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
@caglaryucekaya caglaryucekaya changed the title [r2r] API call optimization [wip] API call optimization Jun 21, 2022
@caglaryucekaya caglaryucekaya changed the title [wip] API call optimization [r2r] API call optimization Jun 21, 2022
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

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

One more note.

mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
@caglaryucekaya caglaryucekaya changed the title [r2r] API call optimization [wip] API call optimization Jun 22, 2022
@caglaryucekaya caglaryucekaya changed the title [wip] API call optimization [r2r] API call optimization Jun 22, 2022
artemii235
artemii235 previously approved these changes Jun 22, 2022
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

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

Great work! 🙂 @sergeyboyko0791 @shamardy Please take a look too.

Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

I think we need to add balance loop if it doesn't exist for taker orders that get converted to maker in handle_timed_out_taker_orders, it would be good to also add a test case for this to not forget about it in the future if we were to change anything.

@caglaryucekaya caglaryucekaya changed the title [r2r] API call optimization [wip] API call optimization Jun 22, 2022
@caglaryucekaya caglaryucekaya changed the title [wip] API call optimization [r2r] API call optimization Jun 22, 2022
}
ordermatch_ctx
.makerorders_ctx
.lock()
Copy link
Author

Choose a reason for hiding this comment

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

@artemii235 here's the lock inside the loop

Copy link
Member

Choose a reason for hiding this comment

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

It's not a problem here as Taker->Maker order conversion is not that frequent :)

@artemii235
Copy link
Member

@sergeyboyko0791 Waiting for your review 🙂

shamardy
shamardy previously approved these changes Jun 23, 2022
Copy link
Collaborator

@shamardy shamardy left a comment

Choose a reason for hiding this comment

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

Amazing Work 🚀 !

Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

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

Great progress!
Please consider my suggestions

mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
if !orderbook.order_set.contains_key(uuid) {
missing_uuids.push(*uuid);
}
}
}

for uuid in missing_uuids {
let order_mutex = match ordermatch_ctx.my_maker_orders.lock().get(&uuid) {
let order_mutex = match ordermatch_ctx.makerorders_ctx.lock().orders.get(&uuid) {

Choose a reason for hiding this comment

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

I think it's better to add MakerOrdersContext::get_order method

mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
mm2src/mm2_main/src/lp_ordermatch.rs Outdated Show resolved Hide resolved
Copy link

@sergeyboyko0791 sergeyboyko0791 left a comment

Choose a reason for hiding this comment

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

Only one non-critical comment. If you have time, you can fix it, otherwise we can merge this PR

self.balance_loops.insert(ticker.to_string(), handle);
}

fn spawn_balance_loop(&mut self, ctx: MmWeak, order_base: &str, balance: Option<BigDecimal>) {

Choose a reason for hiding this comment

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

It's better to take order_base: String by value.

Copy link
Author

Choose a reason for hiding this comment

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

Sure I'll fix it

Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

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

🔥

@artemii235 artemii235 merged commit 7203a05 into dev Jun 27, 2022
@artemii235 artemii235 deleted the api-call-optimization branch June 27, 2022 07:59
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.

None yet

4 participants