-
Notifications
You must be signed in to change notification settings - Fork 135
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
[CT-700] separate indexer and grpc streaming events #1209
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -994,9 +994,8 @@ func New( | |
clobFlags := clobflags.GetClobFlagValuesFromOptions(appOpts) | ||
logger.Info("Parsed CLOB flags", "Flags", clobFlags) | ||
|
||
memClob := clobmodulememclob.NewMemClobPriceTimePriority( | ||
app.IndexerEventManager.Enabled() || app.GrpcStreamingManager.Enabled(), | ||
) | ||
memClob := clobmodulememclob.NewMemClobPriceTimePriority(app.IndexerEventManager.Enabled()) | ||
memClob.SetGenerateOrderbookUpdates(app.GrpcStreamingManager.Enabled()) | ||
|
||
app.ClobKeeper = clobmodulekeeper.NewKeeper( | ||
appCodec, | ||
Comment on lines
994
to
1001
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 gRPC server is initialized without specifying SSL/TLS credentials, which could expose the server to security vulnerabilities such as man-in-the-middle attacks. It's crucial to secure the gRPC connection by including credentials derived from an SSL certificate. You can create credentials using - app.Server = daemonserver.NewServer(logger, grpc.NewServer(), &daemontypes.FileHandlerImpl{}, daemonFlags.Shared.SocketAddress)
+ creds, err := credentials.NewServerTLSFromFile("cert.pem", "cert.key")
+ if err != nil {
+ panic(err)
+ }
+ app.Server = daemonserver.NewServer(logger, grpc.NewServer(grpc.Creds(creds)), &daemontypes.FileHandlerImpl{}, daemonFlags.Shared.SocketAddress) |
||
|
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 |
---|---|---|
|
@@ -103,19 +103,21 @@ func (sm *GrpcStreamingManagerImpl) SendOrderbookUpdates( | |
// Send updates to subscribers. | ||
idsToRemove := make([]uint32, 0) | ||
for id, subscription := range sm.orderbookSubscriptions { | ||
updatesToSend := make([]ocutypes.OffChainUpdateV1, 0) | ||
for _, clobPairId := range subscription.clobPairIds { | ||
if updates, ok := v1updates[clobPairId]; ok { | ||
if err := subscription.srv.Send( | ||
&clobtypes.StreamOrderbookUpdatesResponse{ | ||
Updates: updates, | ||
Snapshot: snapshot, | ||
}, | ||
); err != nil { | ||
idsToRemove = append(idsToRemove, id) | ||
break | ||
} | ||
updatesToSend = append(updatesToSend, updates...) | ||
} | ||
} | ||
|
||
if err := subscription.srv.Send( | ||
&clobtypes.StreamOrderbookUpdatesResponse{ | ||
Updates: updatesToSend, | ||
Snapshot: snapshot, | ||
}, | ||
); err != nil { | ||
idsToRemove = append(idsToRemove, id) | ||
} | ||
Comment on lines
+113
to
+120
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. send one snapshot for all updates instead of one snapshot / clob pair |
||
} | ||
|
||
// Clean up subscriptions that have been closed. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,18 @@ func PrepareCheckState( | |
offchainUpdates, | ||
) | ||
|
||
// For orders that are filled in the last block, send an orderbook update to the grpc streams. | ||
if keeper.GetGrpcStreamingManager().Enabled() { | ||
allUpdates := types.NewOffchainUpdates() | ||
for _, orderId := range processProposerMatchesEvents.OrderIdsFilledInLastBlock { | ||
if _, exists := keeper.MemClob.GetOrder(ctx, orderId); exists { | ||
orderbookUpdate := keeper.MemClob.GetOrderbookUpdatesForOrderUpdate(ctx, orderId) | ||
allUpdates.Append(orderbookUpdate) | ||
} | ||
} | ||
keeper.SendOrderbookUpdates(allUpdates, false) | ||
} | ||
Comment on lines
+169
to
+179
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 changes from lines 169 to 179 introduce a loop to send orderbook updates for orders filled in the last block. Consider the following improvements:
|
||
|
||
// 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 |
---|---|---|
|
@@ -1310,8 +1310,6 @@ func (k Keeper) SendOffchainMessages( | |
} | ||
k.GetIndexerEventManager().SendOffchainData(update) | ||
} | ||
|
||
k.GetGrpcStreamingManager().SendOrderbookUpdates(offchainUpdates, false) | ||
Comment on lines
-1313
to
-1314
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. decouple grpc events and indexer events |
||
} | ||
|
||
// getFillQuoteQuantums returns the total fillAmount price in quote quantums based on the maker subticks. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ package memclob | |
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/indexer/off_chain_updates" | ||
ocutypes "github.com/dydxprotocol/v4-chain/protocol/indexer/off_chain_updates/types" | ||
indexersharedtypes "github.com/dydxprotocol/v4-chain/protocol/indexer/shared/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/lib" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/clob/types" | ||
) | ||
|
@@ -27,7 +29,7 @@ func (m *MemClobPriceTimePriority) GetOffchainUpdatesForOrderbookSnapshot( | |
level.LevelOrders.Front.Each( | ||
func(order types.ClobOrder) { | ||
offchainUpdates.Append( | ||
m.GetOffchainUpdatesForOrder(ctx, order.Order), | ||
m.GetOrderbookUpdatesForOrderPlacement(ctx, order.Order), | ||
) | ||
}, | ||
) | ||
|
@@ -44,7 +46,7 @@ func (m *MemClobPriceTimePriority) GetOffchainUpdatesForOrderbookSnapshot( | |
level.LevelOrders.Front.Each( | ||
func(order types.ClobOrder) { | ||
offchainUpdates.Append( | ||
m.GetOffchainUpdatesForOrder(ctx, order.Order), | ||
m.GetOrderbookUpdatesForOrderPlacement(ctx, order.Order), | ||
) | ||
}, | ||
) | ||
|
@@ -54,10 +56,10 @@ func (m *MemClobPriceTimePriority) GetOffchainUpdatesForOrderbookSnapshot( | |
return offchainUpdates | ||
} | ||
|
||
// GetOffchainUpdatesForOrder returns a place order offchain message and | ||
// a update order offchain message used to construct an order for | ||
// the orderbook snapshot grpc stream. | ||
func (m *MemClobPriceTimePriority) GetOffchainUpdatesForOrder( | ||
// GetOrderbookUpdatesForOrderPlacement returns a place order offchain message and | ||
// a update order offchain message used to add an order for | ||
// the orderbook grpc stream. | ||
func (m *MemClobPriceTimePriority) GetOrderbookUpdatesForOrderPlacement( | ||
ctx sdk.Context, | ||
order types.Order, | ||
) (offchainUpdates *types.OffchainUpdates) { | ||
|
@@ -86,3 +88,43 @@ func (m *MemClobPriceTimePriority) GetOffchainUpdatesForOrder( | |
|
||
return offchainUpdates | ||
} | ||
|
||
// GetOrderbookUpdatesForOrderRemoval returns a remove order offchain message | ||
// used to remove an order for the orderbook grpc stream. | ||
func (m *MemClobPriceTimePriority) GetOrderbookUpdatesForOrderRemoval( | ||
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. In
Can we do the same for orderbook updates? It would be nice to have all these no-op if this isn't a full node with streaming turned on. |
||
ctx sdk.Context, | ||
orderId types.OrderId, | ||
) (offchainUpdates *types.OffchainUpdates) { | ||
offchainUpdates = types.NewOffchainUpdates() | ||
if message, success := off_chain_updates.CreateOrderRemoveMessageWithReason( | ||
ctx, | ||
orderId, | ||
indexersharedtypes.OrderRemovalReason_ORDER_REMOVAL_REASON_UNSPECIFIED, | ||
ocutypes.OrderRemoveV1_ORDER_REMOVAL_STATUS_BEST_EFFORT_CANCELED, | ||
); success { | ||
offchainUpdates.AddRemoveMessage(orderId, message) | ||
} | ||
return offchainUpdates | ||
} | ||
|
||
// GetOrderbookUpdatesForOrderUpdate returns an update order offchain message | ||
// used to update an order for the orderbook grpc stream. | ||
func (m *MemClobPriceTimePriority) GetOrderbookUpdatesForOrderUpdate( | ||
ctx sdk.Context, | ||
orderId types.OrderId, | ||
) (offchainUpdates *types.OffchainUpdates) { | ||
offchainUpdates = types.NewOffchainUpdates() | ||
|
||
// Get the current fill amount of the order. | ||
fillAmount := m.GetOrderFilledAmount(ctx, orderId) | ||
|
||
// Generate an update message updating the total filled amount of order. | ||
if message, success := off_chain_updates.CreateOrderUpdateMessage( | ||
ctx, | ||
orderId, | ||
fillAmount, | ||
); success { | ||
offchainUpdates.AddUpdateMessage(orderId, message) | ||
} | ||
return offchainUpdates | ||
} |
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.
we should probably also get rid to the
app.IndexerEventManager.Enabled()
in the builder method and use theSet...
method insteadThere 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.
hard to add arguments to the constructor method since we have a ton of tests that need to be modified