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

Prune orders might be compute inefficient #222

Open
Henry-E opened this issue Mar 15, 2022 · 0 comments
Open

Prune orders might be compute inefficient #222

Henry-E opened this issue Mar 15, 2022 · 0 comments

Comments

@Henry-E
Copy link

Henry-E commented Mar 15, 2022

In the prune orders function, there's a remove all function that iterates over both the bid and ask queues to find orders owned by a particular open orders account. The issue with this is that if you have an orderbook with a lot of orders the function can run out compute units. While the solution to this in the function is to lower the limit parameter, I was wondering about the design of the function. Is there a reason why it's necessary to iterate over the bid and ask queues to get the order ids when the open orders account already stores the order ids?

// Removes all orders belonging to the given open orders account.
pub fn remove_all(
&mut self,
open_orders: [u64; 4],
mut limit: u16,
) -> DexResult<(Vec<LeafNode>, Vec<LeafNode>)> {
let asks_matching_open_orders = self
.asks
.find_by(&mut limit, |order| order.owner().eq(&open_orders));
let bids_matching_open_orders = self
.bids
.find_by(&mut limit, |order| order.owner().eq(&open_orders));
let bids_removed: Vec<LeafNode> = bids_matching_open_orders
.iter()
.filter_map(|order_to_remove| self.bids.remove_by_key(*order_to_remove))
.collect();
let asks_removed: Vec<LeafNode> = asks_matching_open_orders
.iter()
.filter_map(|order_to_remove| self.asks.remove_by_key(*order_to_remove))
.collect();
Ok((bids_removed, asks_removed))
}
}

vs. how just passing the order id to remove the leaf node, like in the cancel order function?
pub(crate) fn cancel_order_v2(
&mut self,
side: Side,
open_orders_address: [u64; 4],
open_orders: &mut OpenOrders,
order_id: u128,
event_q: &mut EventQueue,
) -> DexResult {
let leaf_node = self
.orders_mut(side)
.remove_by_key(order_id)
.ok_or(DexErrorCode::OrderNotFound)?;

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

No branches or pull requests

1 participant