From ec32bd37d5122acdd44cbc0facd8ff08104605b3 Mon Sep 17 00:00:00 2001 From: Jonathan Fung Date: Mon, 6 May 2024 13:40:16 -0400 Subject: [PATCH] cleanup --- protocol/x/clob/memclob/memclob.go | 76 +++++------------------------- 1 file changed, 13 insertions(+), 63 deletions(-) diff --git a/protocol/x/clob/memclob/memclob.go b/protocol/x/clob/memclob/memclob.go index 8e56297916..1a11d63e25 100644 --- a/protocol/x/clob/memclob/memclob.go +++ b/protocol/x/clob/memclob/memclob.go @@ -390,25 +390,6 @@ func (m *MemClobPriceTimePriority) mustUpdateMemclobStateWithMatches( // If orderbook updates are on, send an orderbook update with the fill to grpc streams. if m.generateOrderbookUpdates { - if takerOrder.IsLiquidation() { - log.InfoLog( - ctx, - "emitting a match", - "order", takerOrder, - "liquidation", true, - "mode", ctx.ExecMode(), - ) - } else { - order := takerOrder.MustGetOrder() - log.InfoLog( - ctx, - "emitting a match", - "order", takerOrder.MustGetOrder(), - "orderId", order.OrderId.String(), - "mode", ctx.ExecMode(), - ) - } - // Collect all maker orders. makerOrders := lib.MapSlice( makerFillWithOrders, @@ -910,36 +891,19 @@ func (m *MemClobPriceTimePriority) matchOrder( offchainUpdates.Append(matchOffchainUpdates) writeCache() } else { - // allUpdates := types.NewOffchainUpdates() - // // try sending updates for all things involved since state reverted - // if order.IsLiquidation() { - // log.InfoLog( - // ctx, - // "reverted state", - // "order", order, - // "liquidation", true, - // "mode", ctx.ExecMode(), - // ) - // } else { - // normalOrder := order.MustGetOrder() - // log.InfoLog( - // ctx, - // "reverted state", - // "order", normalOrder, - // "orderId", normalOrder.OrderId.String(), - // "mode", ctx.ExecMode(), - // "matching_err", matchingErr, - // "len_maker_fills", len(newMakerFills), - // ) - // updates := m.GetOrderbookUpdatesForOrderUpdate(ctx, normalOrder.OrderId) - // allUpdates.Append(updates) - // } - // // revert all maker fills - // for _, fill := range newMakerFills { - // updates := m.GetOrderbookUpdatesForOrderUpdate(ctx, fill.MakerOrderId) - // allUpdates.Append(updates) - // } - // m.clobKeeper.SendOrderbookUpdates(ctx, allUpdates, false) + // If state was not written to, re-send grpc stream updates for all orders + // involved in the match to "reset" fill amounts. + allUpdates := types.NewOffchainUpdates() + if !order.IsLiquidation() { + normalOrder := order.MustGetOrder() + updates := m.GetOrderbookUpdatesForOrderUpdate(ctx, normalOrder.OrderId) + allUpdates.Append(updates) + } + for _, fill := range newMakerFills { + updates := m.GetOrderbookUpdatesForOrderUpdate(ctx, fill.MakerOrderId) + allUpdates.Append(updates) + } + m.clobKeeper.SendOrderbookUpdates(ctx, allUpdates, false) } return takerOrderStatus, offchainUpdates, makerOrdersToRemove, matchingErr @@ -1585,12 +1549,6 @@ func (m *MemClobPriceTimePriority) mustAddOrderToOrderbook( if m.generateOrderbookUpdates { // Send an orderbook update to grpc streams. - log.InfoLog( - ctx, - "emitting updates loc 1", - "orderId", newOrder.OrderId.String(), - "order", newOrder, - ) orderbookUpdate := m.GetOrderbookUpdatesForOrderPlacement(ctx, newOrder) m.clobKeeper.SendOrderbookUpdates(ctx, orderbookUpdate, false) } @@ -2034,8 +1992,6 @@ func (m *MemClobPriceTimePriority) mustRemoveOrder( // Send an orderbook update to grpc streams. orderbookUpdate := m.GetOrderbookUpdatesForOrderRemoval(ctx, order.OrderId) allUpdates.Append(orderbookUpdate) - // orderbookUpdate = m.GetOrderbookUpdatesForOrderUpdate(ctx, order.OrderId) - // allUpdates.Append(orderbookUpdate) m.clobKeeper.SendOrderbookUpdates(ctx, orderbookUpdate, false) } } @@ -2055,12 +2011,6 @@ func (m *MemClobPriceTimePriority) mustUpdateOrderbookStateWithMatchedMakerOrder panic("Total filled size of maker order greater than the order size") } - // // Send an orderbook update for the order's new total filled amount. - // if m.generateOrderbookUpdates { - // orderbookUpdate := m.GetOrderbookUpdatesForOrderUpdate(ctx, makerOrder.OrderId) - // m.clobKeeper.SendOrderbookUpdates(ctx, orderbookUpdate, false) - // } - // If the order is fully filled, remove it from the orderbook. // Note we shouldn't remove Short-Term order hashes from `ShortTermOrderTxBytes` here since // the order was matched.