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

Fix: zero amount order bug #1816

Merged
merged 3 commits into from
Apr 18, 2024
Merged

Fix: zero amount order bug #1816

merged 3 commits into from
Apr 18, 2024

Conversation

lemunozm
Copy link
Contributor

@lemunozm lemunozm commented Apr 17, 2024

Description

There are two casuistics where an order can contain a zero amount. Such an order can not be closed, and theoretically, it should not exist.

  • Added test cases that generate the error. All newly added tests fail without the fix.
  • Added fix bypassing creating orders when they have 0 amount.

Q: Should we allow to close zero orders even though they should not be possible now?

@lemunozm lemunozm added I2-bug The code fails to follow expected behaviour. crcl-protocol Circle protocol related. labels Apr 17, 2024
@lemunozm lemunozm self-assigned this Apr 17, 2024
}

#[test]
fn when_apply_over_smaller_inverse_swap_but_math_precission() {
Copy link
Contributor Author

@lemunozm lemunozm Apr 17, 2024

Choose a reason for hiding this comment

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

We do not really need this test if we have the pallet-swaps tests. But I wanted to force a use case from FI PoV. We can finally remove it once we're sure it's fully solved.

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.

Thanks!! @lemunozm do you think this fix has to live here or we could think about fixing it on the pallet-order-book side?

I am also not sure why having a zero order lead to a missing FI state. Do you know the reason for that or in general explain what the issue was? I mean pallet-order-book does fulfill zero orders, right?

Copy link

codecov bot commented Apr 17, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 48.56%. Comparing base (da63bf1) to head (c21a170).

❗ Current head c21a170 differs from pull request most recent head 00229e4. Consider uploading reports for the commit 00229e4 to get more accurate results

Files Patch % Lines
pallets/swaps/src/lib.rs 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1816      +/-   ##
==========================================
+ Coverage   48.53%   48.56%   +0.03%     
==========================================
  Files         167      167              
  Lines       13314    13320       +6     
==========================================
+ Hits         6462     6469       +7     
+ Misses       6852     6851       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lemunozm
Copy link
Contributor Author

lemunozm commented Apr 18, 2024

do you think this fix has to live here or we could think about fixing it on the pallet-order-book side?

I've added a couple of test for cancel zero amount orders and fulfill zero amount orders and they work fine. So from order-book perspective I think everything is fine.

My reason for putting this in pallet-swaps was: if you do not need nothing to swap, you do not need to create an empty order, so pallet swaps should check those cases.

I am also not sure why having a zero order lead to a missing FI state.

Do you mean to this error right? I'm pretty sure it is because when creating a zero-order, from FI PoV, the swap is fully done, and it detects it can clean the associated info. So later, when you fulfill the zero order, you can not find such a state. This should no longer happen because we're blocking the creation of zero-amount orders now.

@mustermeiszer
Copy link
Collaborator

Makes sense! Thanks

@lemunozm lemunozm merged commit 2eebc49 into main Apr 18, 2024
10 checks passed
@lemunozm lemunozm deleted the fix/zero-amount-order branch April 18, 2024 07:21
wischli pushed a commit that referenced this pull request Apr 18, 2024
* add tests that fail and shouldn't

* add fix

* add extra tests
wischli added a commit that referenced this pull request Apr 18, 2024
* fix: looser is_local_representation

* tests: fix after changing setup

* Fix: zero amount order bug (#1816)

* add tests that fail and shouldn't

* add fix

* add extra tests

---------

Co-authored-by: Luis Enrique Muñoz Martín <lemunozm@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crcl-protocol Circle protocol related. I2-bug The code fails to follow expected behaviour.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants