-
Notifications
You must be signed in to change notification settings - Fork 123
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
Orderbook Fills emission #1448
Orderbook Fills emission #1448
Changes from 10 commits
a622df9
2d0ed2f
a0ee1e1
5b1a471
cec38f7
06c842c
9c34203
657c23e
cc0d888
1183240
6e95ca9
34c2527
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -518,3 +518,9 @@ func (f *FakeMemClobKeeper) SendOrderbookUpdates( | |
snapshot bool, | ||
) { | ||
} | ||
|
||
func (f *FakeMemClobKeeper) SendOrderbookFillUpdates( | ||
ctx sdk.Context, | ||
orderbookFills []types.StreamOrderbookFill, | ||
) { | ||
} | ||
Comment on lines
+522
to
+526
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method This method is defined but does not contain any implementation. If this is intentional (e.g., for a mock or placeholder), it should be documented clearly. Otherwise, it should be implemented or removed if not needed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,45 +175,6 @@ func PrepareCheckState( | |
offchainUpdates, | ||
) | ||
|
||
// For orders that are filled in the last block, send an orderbook update to the grpc streams. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Axed this whole section to send out order updates.
|
||
if keeper.GetGrpcStreamingManager().Enabled() { | ||
allUpdates := types.NewOffchainUpdates() | ||
orderIdsToSend := make(map[types.OrderId]bool) | ||
|
||
// Send an update for reverted local operations. | ||
for _, operation := range localValidatorOperationsQueue { | ||
if match := operation.GetMatch(); match != nil { | ||
// For normal order matches, we send an update for the taker and maker orders. | ||
if matchedOrders := match.GetMatchOrders(); matchedOrders != nil { | ||
orderIdsToSend[matchedOrders.TakerOrderId] = true | ||
for _, fill := range matchedOrders.Fills { | ||
orderIdsToSend[fill.MakerOrderId] = true | ||
} | ||
} | ||
// For liquidation matches, we send an update for the maker orders. | ||
if matchedLiquidation := match.GetMatchPerpetualLiquidation(); matchedLiquidation != nil { | ||
for _, fill := range matchedLiquidation.Fills { | ||
orderIdsToSend[fill.MakerOrderId] = true | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Send an update for orders that were proposed. | ||
for _, orderId := range processProposerMatchesEvents.OrderIdsFilledInLastBlock { | ||
orderIdsToSend[orderId] = true | ||
} | ||
|
||
// Send update. | ||
for orderId := range orderIdsToSend { | ||
if _, exists := keeper.MemClob.GetOrder(ctx, orderId); exists { | ||
orderbookUpdate := keeper.MemClob.GetOrderbookUpdatesForOrderUpdate(ctx, orderId) | ||
allUpdates.Append(orderbookUpdate) | ||
} | ||
} | ||
keeper.SendOrderbookUpdates(ctx, allUpdates, false) | ||
} | ||
|
||
// 3. Place all stateful order placements included in the last block on the memclob. | ||
// Note telemetry is measured outside of the function call because `PlaceStatefulOrdersFromLastBlock` | ||
// is called within `PlaceConditionalOrdersTriggeredInLastBlock`. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,6 +276,19 @@ func (k Keeper) RemoveOrderFillAmount(ctx sdk.Context, orderId types.OrderId) { | |
[]byte(types.OrderAmountFilledKeyPrefix), | ||
) | ||
memStore.Delete(orderId.ToStateKey()) | ||
|
||
// If grpc stream is on, zero out the fill amount. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Zero'ing out fill amounts when fill amounts are removed. I added this to the innermost statewrite/remove method. I could have added it to each of the 3-4 callsites but this might be cleaner. Let me know if the other approach is preferred. |
||
if k.GetGrpcStreamingManager().Enabled() { | ||
allUpdates := types.NewOffchainUpdates() | ||
if message, success := off_chain_updates.CreateOrderUpdateMessage( | ||
ctx, | ||
orderId, | ||
0, // Total filled quantums is zero because it's been pruned from state. | ||
); success { | ||
allUpdates.AddUpdateMessage(orderId, message) | ||
} | ||
k.SendOrderbookUpdates(ctx, allUpdates, false) | ||
} | ||
} | ||
|
||
// PruneStateFillAmountsForShortTermOrders prunes Short-Term order fill amounts from state that are pruneable | ||
|
@@ -286,27 +299,5 @@ func (k Keeper) PruneStateFillAmountsForShortTermOrders( | |
blockHeight := lib.MustConvertIntegerToUint32(ctx.BlockHeight()) | ||
|
||
// Prune all fill amounts from state which have a pruneable block height of the current `blockHeight`. | ||
prunedOrderIds := k.PruneOrdersForBlockHeight(ctx, blockHeight) | ||
|
||
// Send an orderbook update for each pruned order for grpc streams. | ||
// This is needed because short term orders are pruned in PrepareCheckState using | ||
// keeper.MemClob.openOrders.blockExpirationsForOrders, which can fall out of sync with state fill amount | ||
// pruning when there's replacement. | ||
// Long-term fix would be to add logic to keep them in sync. | ||
// TODO(CT-722): add logic to keep state fill amount pruning and order pruning in sync. | ||
if k.GetGrpcStreamingManager().Enabled() { | ||
allUpdates := types.NewOffchainUpdates() | ||
for _, orderId := range prunedOrderIds { | ||
if _, exists := k.MemClob.GetOrder(ctx, orderId); exists { | ||
if message, success := off_chain_updates.CreateOrderUpdateMessage( | ||
ctx, | ||
orderId, | ||
0, // Total filled quantums is zero because it's been pruned from state. | ||
); success { | ||
allUpdates.AddUpdateMessage(orderId, message) | ||
} | ||
} | ||
} | ||
k.SendOrderbookUpdates(ctx, allUpdates, false) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need since this zero'ing out fills is punted to the innermost state remove method |
||
k.PruneOrdersForBlockHeight(ctx, blockHeight) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar looking functions - worth to create helper?
nbd - will let you make the call