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

Actions queue overflow in dealer::process_queue #22

Closed
unboxedtype opened this issue Nov 11, 2021 · 2 comments
Closed

Actions queue overflow in dealer::process_queue #22

unboxedtype opened this issue Nov 11, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@unboxedtype
Copy link

unboxedtype commented Nov 11, 2021

In Flex, orders of opposite direction get matched in the dealer::process_queue() function.

This function contains the while loop that traverses the order queues of opposite direction, matching orders with each other.
It is quite message-intensive function: for example, it generates at least 3 new messages for each partially matched order
(see dealer::make_deal), and on each loop iteration, it generates a message for every expired order found in the queue
(see dealer::extract_active_order).

The proposition of this issue is that in some circumstances, the process_queue() function may generate more messages
than allowed by the node, i.e. MAX_ACTIONS = 255.
(see https://github.com/tonlabs/ton-labs-executor/blob/e20b16b4d92cee8261e96916b118c344483e0013/src/transaction_executor.rs#L488)
If this happens, most probably, the Price smart-contract will not be able to match orders of this price level any further :
all future calls will run into the same transaction abort, leaving all the funds locked and this Price level locked.

Before doing the formal analysis, we thought that the number of generated messages is bounded by at least the deals_limit_
constant, but, it turns out, the loop iteration counter may go well beyond that value. And the reason is that the break statement is located under conditional that might not hold, leading to another loop iterations:
https://github.com/tonlabs/flex/blob/3aaa20eb73e7498d08d39191d693f1efa7d016eb/flex/Price.cpp#L139

It is proposed to introduce some definitional bound for the number of iterations this loop may process, hence protecting
the action queue from possible overflow / deadlock condition.

The same holds for PriceXchg::process_queue().

@unboxedtype
Copy link
Author

@azhogin azhogin added the bug Something isn't working label Dec 1, 2021
@azhogin
Copy link
Contributor

azhogin commented May 25, 2022

in the new version added calculation of out messages and overlimit checks.

@azhogin azhogin closed this as completed May 25, 2022
gitbook-com bot pushed a commit that referenced this issue Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants