-
Notifications
You must be signed in to change notification settings - Fork 115
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
[IND-402] Have vulcan re-queue cached order updates instead of ender. #688
[IND-402] Have vulcan re-queue cached order updates instead of ender. #688
Conversation
IND-402 Fix Stateful order placement with no fill
Stateful orders that are not filled do not get added to the order book. Issue: Potential Solution:
|
WalkthroughThe changes primarily focus on transitioning from a Redis-based caching system to a Kafka-based messaging system for handling stateful order updates. The code has been refactored to remove Redis dependencies and introduce Kafka message handling. The tests have been updated to reflect these changes. Changes
TipsChat with CodeRabbit Bot (
|
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (11)
- indexer/services/ender/tests/handlers/stateful-order/stateful-order-placement-handler.test.ts (5 hunks)
- indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts (2 hunks)
- indexer/services/vulcan/tests/handlers/order-place-handler.test.ts (8 hunks)
- indexer/services/vulcan/tests/helpers/websocket-helpers.ts (2 hunks)
- indexer/services/vulcan/tests/lib/send-message-helper.test.ts (6 hunks)
- indexer/services/vulcan/src/config.ts (1 hunks)
- indexer/services/vulcan/src/handlers/order-place-handler.ts (5 hunks)
- indexer/services/vulcan/src/handlers/order-remove-handler.ts (4 hunks)
- indexer/services/vulcan/src/handlers/order-update-handler.ts (2 hunks)
- indexer/services/vulcan/src/index.ts (1 hunks)
- indexer/services/vulcan/src/lib/send-message-helper.ts (6 hunks)
Files skipped from review due to trivial changes (6)
- indexer/services/ender/tests/handlers/stateful-order/stateful-order-placement-handler.test.ts
- indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts
- indexer/services/vulcan/tests/lib/send-message-helper.test.ts
- indexer/services/vulcan/src/config.ts
- indexer/services/vulcan/src/handlers/order-update-handler.ts
- indexer/services/vulcan/src/index.ts
Additional comments: 29
indexer/services/vulcan/__tests__/helpers/websocket-helpers.ts (2)
2-2: The import of
OffChainUpdateV1
is new and seems to be used in the new functionexpectOffchainUpdateMessage
. Ensure that this import is used elsewhere in the codebase and that the new function is being called correctly.33-48: The new function
expectOffchainUpdateMessage
is added to handle off-chain update messages. It checks if the topic of the producer record is equal toKafkaTopics.TO_VULCAN
, decodes the message, and checks if the decoded message and key are equal to the expected ones. This function seems to be correctly implemented.indexer/services/vulcan/src/handlers/order-remove-handler.ts (4)
36-40: The import statement for
sendWebsocketWrapper
has been replaced withsendMessageWrapper
. Ensure that the new functionsendMessageWrapper
is compatible with the existing code and performs the same functionality as the oldsendWebsocketWrapper
function.222-229: The
subaccountMessage
object has been updated to use theMessage
type fromkafkajs
instead ofBuffer
. ThesendWebsocketWrapper
function has been replaced withsendMessageWrapper
. Ensure that theMessage
type is compatible with thesendMessageWrapper
function and that the message is correctly sent.279-289: The
subaccountMessage
object has been updated to use theMessage
type fromkafkajs
instead ofBuffer
. ThesendWebsocketWrapper
function has been replaced withsendMessageWrapper
. Ensure that theMessage
type is compatible with thesendMessageWrapper
function and that the message is correctly sent.323-330: The
orderbookMessage
object has been updated to use theMessage
type fromkafkajs
instead ofBuffer
. ThesendWebsocketWrapper
function has been replaced withsendMessageWrapper
. Ensure that theMessage
type is compatible with thesendMessageWrapper
function and that the message is correctly sent.indexer/services/vulcan/src/lib/send-message-helper.ts (6)
9-9: The type of
queuedMessages
has been changed fromBuffer[]
toMessage[]
. Ensure that all usages ofqueuedMessages
throughout the codebase have been updated to handleMessage
objects instead ofBuffer
objects.34-34: The function
sendWebsocketWrapper
has been renamed tosendMessageWrapper
and its parameter type has been changed fromBuffer
toMessage
. Ensure that all calls to this function throughout the codebase have been updated to match the new function signature.51-51: The configuration property
FLUSH_WEBSOCKET_MESSAGES_INTERVAL_MS
has been renamed toFLUSH_KAFKA_MESSAGES_INTERVAL_MS
. Ensure that the configuration files and environment variables have been updated to reflect this change.78-78: The type of
messages
has been changed fromBuffer[]
toMessage[]
. Ensure that all usages ofmessages
throughout the codebase have been updated to handleMessage
objects instead ofBuffer
objects.92-92: The
messages
array is now directly passed toproducer.send()
, whereas previously eachBuffer
in the array was wrapped in an object with avalue
property. Ensure that theproducer.send()
function can handle an array ofMessage
objects.105-105: The function
sendWebsocketWrapper
has been replaced withsendMessageWrapper
. Ensure that thesendMessageWrapper
function can handleMessage
objects.indexer/services/vulcan/src/handlers/order-place-handler.ts (6)
26-28: The new import
StatefulOrderUpdatesCache
andisStatefulOrder
from@dydxprotocol-indexer/redis
and@dydxprotocol-indexer/v4-proto-parser
respectively, are added to handle stateful orders. Ensure that these modules are correctly implemented and tested.53-54: The comment indicates that if the order is a stateful order, it will attempt to remove any cached order update from the
StatefulOrderUpdatesCache
, and then queue the order update to be re-sent and re-processed. This is a new behavior introduced in thehandle
method.131-134: The condition to check if an order is stateful has been updated. Previously, it was checking if
goodTilBlockTime
was defined. Now it uses theisStatefulOrder
function. Ensure that this change is intended and correctly implemented.144:
The new methodsendCachedOrderUpdate
is called for stateful orders. This method is responsible for sending any cached order updates.
- 146-153: The
subaccountMessage
is now an object of typeMessage
instead ofBuffer
. Thevalue
field of theMessage
object is assigned the result ofcreateSubaccountWebsocketMessage
. This change is part of the update to useMessage
objects instead ofBuffer
objects for queued messages.154:
ThesendMessageWrapper
function is used instead ofsendWebsocketWrapper
. This change is part of the update to make the function more generic and usable across multiple handlers.
160-167: Similar to the
subaccountMessage
, theorderbookMessage
is now an object of typeMessage
instead ofBuffer
. Thevalue
field of theMessage
object is assigned the result ofcreateOrderbookWebsocketMessage
. ThesendMessageWrapper
function is used to send the message.363-384: The new method
sendCachedOrderUpdate
is added. This method removes and sends the cached order update for the given order id if it exists. It uses theremoveStatefulOrderUpdate
method fromStatefulOrderUpdatesCache
to remove the cached order update. If a cached order update is found, it creates aMessage
object and sends it using thesendMessageWrapper
function.indexer/services/vulcan/__tests__/handlers/order-place-handler.test.ts (11)
43-43: The import of
StatefulOrderUpdatesCache
from@dydxprotocol-indexer/redis
indicates that the test suite now includes tests for stateful order updates. This is in line with the PR summary which mentions the addition of a new methodsendCachedOrderUpdate
to handle cached order updates for stateful orders.54-55: The import of
OrderUpdateV1
from@dydxprotocol-indexer/v4-protos
suggests that the test suite now includes tests for order updates. This aligns with the PR summary which mentions the addition of a new methodsendCachedOrderUpdate
to handle cached order updates for stateful orders.62-62: The import of
expectOffchainUpdateMessage
from../helpers/websocket-helpers
suggests that the test suite now includes tests for off-chain update messages. This aligns with the PR summary which mentions the addition of a new methodsendCachedOrderUpdate
to handle cached order updates for stateful orders.71-74: The
OffchainUpdateRecord
interface has been added to represent off-chain update records. This aligns with the PR summary which mentions the addition of a new methodsendCachedOrderUpdate
to handle cached order updates for stateful orders.651-687: The test case 'handles order place with OPEN placement status, does not exist initially' has been updated to include scenarios with and without cached order updates. This aligns with the PR summary which mentions the addition of a new method
sendCachedOrderUpdate
to handle cached order updates for stateful orders.699-713: The test case now includes a setup for cached order updates. If a cached order update is provided, it is added to the
StatefulOrderUpdatesCache
and anexpectedOffchainUpdate
is created. This aligns with the PR summary which mentions the addition of a new methodsendCachedOrderUpdate
to handle cached order updates for stateful orders.732-733: The
expectWebsocketMessagesSent
function is now called withexpectedOffchainUpdate
as an argument. This suggests that the function has been updated to check for off-chain update messages.1019-1019: The
expectWebsocketMessagesSent
function now accepts anexpectedOffchainUpdate
parameter. This suggests that the function has been updated to check for off-chain update messages.1030-1044: The test case now includes checks for off-chain update messages. If an
expectedOffchainUpdate
is provided, the test case expects an off-chain update message to be sent and checks the message using theexpectOffchainUpdateMessage
function.1088-1090: The test case now increments the
callIndex
after checking the subaccount message. This suggests that the order of messages being sent has been updated.1092-1092: The test case now checks the orderbook message after checking the subaccount message and off-chain update message. This suggests that the order of messages being sent has been updated.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- indexer/services/vulcan/tests/handlers/order-place-handler.test.ts (8 hunks)
Additional comments: 9
indexer/services/vulcan/__tests__/handlers/order-place-handler.test.ts (9)
43-43: The import of
StatefulOrderUpdatesCache
from@dydxprotocol-indexer/redis
indicates that the test suite now includes tests for the handling of cached order updates. This aligns with the PR summary that mentions the addition of cached order update handling in theOrderPlaceHandler
class.54-55: The import of
OrderUpdateV1
from@dydxprotocol-indexer/v4-protos
is new and is likely used for testing the handling of cached order updates.62-62: The addition of
expectOffchainUpdateMessage
to the import from../helpers/websocket-helpers
indicates that the test suite now includes tests for sending off-chain update messages. This aligns with the PR summary that mentions the replacement of thesendWebsocketWrapper
function withsendMessageWrapper
to send Kafka messages.71-74: The
OffchainUpdateRecord
interface is new and is likely used for testing the handling of cached order updates.651-687: The test case 'handles order place with OPEN placement status, does not exist initially' has been updated to include scenarios with and without cached order updates. This aligns with the PR summary that mentions the addition of cached order update handling in the
OrderPlaceHandler
class.699-713: The addition of code to add a cached order update to the
StatefulOrderUpdatesCache
and setexpectedOffchainUpdate
indicates that the test case now includes a scenario where a cached order update exists. This aligns with the PR summary that mentions the addition of cached order update handling in theOrderPlaceHandler
class.1019-1019: The addition of
expectedOffchainUpdate
to the parameters of theexpectWebsocketMessagesSent
function indicates that the function now checks for the sending of off-chain update messages. This aligns with the PR summary that mentions the replacement of thesendWebsocketWrapper
function withsendMessageWrapper
to send Kafka messages.1030-1044: The addition of code to check for the sending of an off-chain update message indicates that the
expectWebsocketMessagesSent
function now includes a scenario where an off-chain update message is sent. This aligns with the PR summary that mentions the replacement of thesendWebsocketWrapper
function withsendMessageWrapper
to send Kafka messages.1088-1089: The update to increment
callIndex
after checking for a subaccount message indicates that theexpectWebsocketMessagesSent
function now accounts for the possibility of an off-chain update message being sent before a subaccount message. This aligns with the PR summary that mentions the replacement of thesendWebsocketWrapper
function withsendMessageWrapper
to send Kafka messages.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- indexer/services/vulcan/src/handlers/order-place-handler.ts (5 hunks)
Additional comments: 6
indexer/services/vulcan/src/handlers/order-place-handler.ts (6)
26-28: The
StatefulOrderUpdatesCache
andgetOrderIdHash
andisStatefulOrder
are newly imported. Ensure that these are used correctly in the code.53-54: The comment indicates that for stateful orders, the code will attempt to remove any cached order update and then queue the order update to be re-sent and re-processed. This is a new behavior and should be tested thoroughly.
131-134: The condition for checking if an order is stateful has been changed. Previously, it was based on the
goodTilBlockTime
property of the order. Now, it uses theisStatefulOrder
function with theorderFlags
property of the order. Ensure that this change is intentional and correctly reflects the definition of a stateful order.144:
ThesendCachedOrderUpdate
method is called for stateful orders. This is a new behavior and should be tested thoroughly.
146-154: The
sendWebsocketWrapper
function has been replaced withsendMessageWrapper
and now handlesMessage
objects instead ofBuffer
objects. Ensure that this change is compatible with the rest of the codebase and that theMessage
objects are correctly formed.160-167: Similar to the previous comment, the
sendWebsocketWrapper
function has been replaced withsendMessageWrapper
and now handlesMessage
objects instead ofBuffer
objects. Ensure that this change is compatible with the rest of the codebase and that theMessage
objects are correctly formed.363-384: The
sendCachedOrderUpdate
method is a new addition. It removes and sends the cached order update for a given order id if it exists. This method should be tested thoroughly to ensure it behaves as expected.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- indexer/services/ender/tests/handlers/stateful-order/stateful-order-placement-handler.test.ts (5 hunks)
Files skipped from review due to trivial changes (1)
- indexer/services/ender/tests/handlers/stateful-order/stateful-order-placement-handler.test.ts
Changelist
Fixes issue found in testing #683 , where
ender
does not find the cached update. There's a race condition whereender
processes a block beforevulcan
caches the order update. Moved re-queuing logic tovulcan
to fix the issue as the order update will either be cached beforethe order place is received, or the order update will be processed after the order place is received.Other updates:
ender
vulcan
to send both keys and values in Kafka messagesTest Plan
Unit tested, and tested on
dev
.Author/Reviewer Checklist
state-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.