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(orderbook): prevent stuck replace order holds #1842

Merged
merged 1 commit into from
Aug 27, 2020

Conversation

sangaman
Copy link
Collaborator

This fixes a bug whereby an order could be placed on hold without that hold ever being removed.

When replacing an order, we place the existing order on hold until the replacement order has finished matching, and only then do we remove the original order. However, the order was being placed on hold before the checks for sufficient balance to fill this order, and in case those checks failed the remainder of the placeOrder routine would be skipped including the part that removes the original order. In such a case, the original order would be put on hold indefinitely.

Instead, we place the existing order on hold immediately before we begin matching and after any checks on the validity of the new order are passed. If the checks fail, then the new order is rejected and the order it was intended to replace remains in the order book without a hold, allowing it to be replaced or removed again by a future call.

Fixes #1835.

This fixes a bug whereby an order could be placed on hold without that
hold ever being removed.

When replacing an order, we place the existing order on hold until the
replacement order has finished matching, and only then do we remove the
original order. However, the order was being placed on hold before the
checks for sufficient balance to fill this order, and in case those
checks failed the remainder of the `placeOrder` routine would be skipped
including the part that removes the original order. In such a case, the
original order would be put on hold indefinitely.

Instead, we place the existing order on hold immediately before we
begin matching and after any checks on the validity of the new order
are passed. If the checks fail, then the new order is rejected and the
order it was intended to replace remains in the order book without a
hold, allowing it to be replaced or removed again by a future call.

Fixes #1835.
@sangaman sangaman added bug Something isn't working order book labels Aug 27, 2020
@sangaman sangaman requested review from a user, kilrau and raladev August 27, 2020 04:15
@sangaman sangaman self-assigned this Aug 27, 2020
@kilrau
Copy link
Contributor

kilrau commented Aug 27, 2020

Do you have a way to test this? Otherwise I have a node that regularly gets itself into such a situation and can run this branch there @raladev

@sangaman
Copy link
Collaborator Author

Do you have a way to test this? Otherwise I have a node that regularly gets itself into such a situation and can run this branch there @raladev

The way to test (and reproduce the issue on master) would be to place an order that replaces another order but exceeds your channel capacity, more than your L2 balance in other words. The replaced order would become permanently on hold. On this branch there should be no hold.

@kilrau
Copy link
Contributor

kilrau commented Aug 27, 2020

Ok, but why would xud allow me to place an order exceeding my L2 balance in the first place?

EDIT: got it

the order was being placed on hold before the checks for sufficient balance to fill this order

This PR should fix it.

@kilrau kilrau added the P1 top priority label Aug 27, 2020
@raladev raladev merged commit 984e064 into master Aug 27, 2020
@raladev raladev deleted the fix/stuck-order-holds branch August 27, 2020 14:53
rsercano pushed a commit that referenced this pull request Sep 11, 2020
This fixes a bug whereby an order could be placed on hold without that
hold ever being removed.

When replacing an order, we place the existing order on hold until the
replacement order has finished matching, and only then do we remove the
original order. However, the order was being placed on hold before the
checks for sufficient balance to fill this order, and in case those
checks failed the remainder of the `placeOrder` routine would be skipped
including the part that removes the original order. In such a case, the
original order would be put on hold indefinitely.

Instead, we place the existing order on hold immediately before we
begin matching and after any checks on the validity of the new order
are passed. If the checks fail, then the new order is rejected and the
order it was intended to replace remains in the order book without a
hold, allowing it to be replaced or removed again by a future call.

Fixes #1835.

added currency check to walletwithdraw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working order book P1 top priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Order stuck on-hold (arby exits with Unrecoverable error)
3 participants