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

Feat/order book add fulfill order partially #1559

Merged
merged 12 commits into from Sep 21, 2023

Conversation

cdamian
Copy link
Contributor

@cdamian cdamian commented Sep 19, 2023

Description

Added a new extrinsic in the order-book pallet that allows for a partial order fulfillment.

Checklist:

  • I have added Rust doc comments to structs, enums, traits and functions
  • I have made corresponding changes to the documentation
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works

@cdamian cdamian force-pushed the feat/order-book-add-fulfill-order-partially branch from 1cb3ac7 to 97c6940 Compare September 19, 2023 17:20
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Clean and nice and fast as always. Got some thoughts about the parameters of the call. But otherwise good.

pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
let partial_fulfillment = !remaining_buy_amount.is_zero();

ensure!(
partial_buy_amount >= order.min_fulfillment_amount,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would mean the min_fullfillment_amount is not a global min but rather a min_per_buy. I am okay with that, just wanted to channel this by you @hieronx .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please let me know if we are OK with this, otherwise we can add a check for the remaining buy amount to ensure that it doesn't go too low, even though I'm not sure if that makes sense ^^

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, I was rather thinking that it is a one-time amount. Like, I wanna get at least x. But it is fine to go with the given solution.

pallets/order-book/src/lib.rs Show resolved Hide resolved
@cdamian cdamian force-pushed the feat/order-book-add-fulfill-order-partially branch from 97c6940 to 6c9421b Compare September 20, 2023 11:39
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

I really appreciate your thoroughness, especially with the unit tests! The logic LGTM but I would like to reduce code duplication (comment). Apart from that a few minor nits which are no blocking.

pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
runtime/altair/src/weights/pallet_order_book.rs Outdated Show resolved Hide resolved
order_id,
placing_account: order.placing_account,
fulfilling_account: ACCOUNT_1,
partial_fulfillment: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICS, the test should fail here if fulfillment_ratio is 100%?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but it doesn't get to 100 in this test. The 100 percent case is handled separately given the different expected events.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah dumb me forgetting that 0..100 != 0..=100 in Rust 🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah, that's on me since I did not find a proper way to have a separate test for each percentage using a macro. If we get a failure here now, one would have to debug and figure out which percentage is problematic, which is awkward to say the least.

Maybe @lemunozm can help ^^

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it's the current test is more than sane. Theoretically, you could add a debug message to the assertion(s) to populate the failure fulfillment_ratio.

Copy link
Contributor

@lemunozm lemunozm Sep 22, 2023

Choose a reason for hiding this comment

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

Sorry, just saw this now.

Does each different value of fulfillment_ratio use a different path in the code? Maybe it's unnecessary to test all values and only do it with corner cases, for example, with 1, 50, 99.

The macro would be cool, but doesn't hurt to leave it as it is and print the ratio on each iteration. To the purists 😄, exists a catch_unwind that can be used in these cases to add some extra information when the test fails. For example, adding the fulfillment_ratio value in the error message used in that iteration. Maybe I will add it to the fuzzer.

pallets/order-book/src/tests.rs Show resolved Hide resolved
pallets/order-book/src/tests.rs Show resolved Hide resolved
pallets/order-book/src/tests.rs Outdated Show resolved Hide resolved
pallets/order-book/src/tests.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Show resolved Hide resolved
@cdamian cdamian force-pushed the feat/order-book-add-fulfill-order-partially branch from c6002c4 to a9b6cfd Compare September 21, 2023 11:14
@cdamian cdamian marked this pull request as ready for review September 21, 2023 11:14
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

LGTM! Great work 🚀

order_id,
placing_account: order.placing_account,
fulfilling_account: ACCOUNT_1,
partial_fulfillment: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it's the current test is more than sane. Theoretically, you could add a debug message to the assertion(s) to populate the failure fulfillment_ratio.

Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

LGTM!

@cdamian cdamian merged commit 71cd8a4 into main Sep 21, 2023
10 checks passed
@cdamian cdamian deleted the feat/order-book-add-fulfill-order-partially branch September 21, 2023 14:57
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