Skip to content

Commit 18d44cf

Browse files
Full Node Streaming - reorder protobuf single length fields before variable length fields (backport #2227) (#2231)
Co-authored-by: Jonathan Fung <121899091+jonfung-dydx@users.noreply.github.com>
1 parent e4327b8 commit 18d44cf

File tree

3 files changed

+297
-299
lines changed

3 files changed

+297
-299
lines changed

indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts

Lines changed: 52 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -293,73 +293,71 @@ export interface StreamOrderbookUpdatesResponseSDKType {
293293
*/
294294

295295
export interface StreamUpdate {
296-
orderbookUpdate?: StreamOrderbookUpdate;
297-
orderFill?: StreamOrderbookFill;
298-
takerOrder?: StreamTakerOrder;
299-
subaccountUpdate?: StreamSubaccountUpdate;
300296
/** Block height of the update. */
301-
302297
blockHeight: number;
303298
/** Exec mode of the update. */
304299

305300
execMode: number;
301+
orderbookUpdate?: StreamOrderbookUpdate;
302+
orderFill?: StreamOrderbookFill;
303+
takerOrder?: StreamTakerOrder;
304+
subaccountUpdate?: StreamSubaccountUpdate;
306305
}
307306
/**
308307
* StreamUpdate is an update that will be pushed through the
309308
* GRPC stream.
310309
*/
311310

312311
export interface StreamUpdateSDKType {
313-
orderbook_update?: StreamOrderbookUpdateSDKType;
314-
order_fill?: StreamOrderbookFillSDKType;
315-
taker_order?: StreamTakerOrderSDKType;
316-
subaccount_update?: StreamSubaccountUpdateSDKType;
317312
/** Block height of the update. */
318-
319313
block_height: number;
320314
/** Exec mode of the update. */
321315

322316
exec_mode: number;
317+
orderbook_update?: StreamOrderbookUpdateSDKType;
318+
order_fill?: StreamOrderbookFillSDKType;
319+
taker_order?: StreamTakerOrderSDKType;
320+
subaccount_update?: StreamSubaccountUpdateSDKType;
323321
}
324322
/**
325323
* StreamOrderbookUpdate provides information on an orderbook update. Used in
326324
* the full node GRPC stream.
327325
*/
328326

329327
export interface StreamOrderbookUpdate {
330-
/**
331-
* Orderbook updates for the clob pair. Can contain order place, removals,
332-
* or updates.
333-
*/
334-
updates: OffChainUpdateV1[];
335328
/**
336329
* Snapshot indicates if the response is from a snapshot of the orderbook.
337330
* All updates should be ignored until snapshot is recieved.
338331
* If the snapshot is true, then all previous entries should be
339332
* discarded and the orderbook should be resynced.
340333
*/
341-
342334
snapshot: boolean;
335+
/**
336+
* Orderbook updates for the clob pair. Can contain order place, removals,
337+
* or updates.
338+
*/
339+
340+
updates: OffChainUpdateV1[];
343341
}
344342
/**
345343
* StreamOrderbookUpdate provides information on an orderbook update. Used in
346344
* the full node GRPC stream.
347345
*/
348346

349347
export interface StreamOrderbookUpdateSDKType {
350-
/**
351-
* Orderbook updates for the clob pair. Can contain order place, removals,
352-
* or updates.
353-
*/
354-
updates: OffChainUpdateV1SDKType[];
355348
/**
356349
* Snapshot indicates if the response is from a snapshot of the orderbook.
357350
* All updates should be ignored until snapshot is recieved.
358351
* If the snapshot is true, then all previous entries should be
359352
* discarded and the orderbook should be resynced.
360353
*/
361-
362354
snapshot: boolean;
355+
/**
356+
* Orderbook updates for the clob pair. Can contain order place, removals,
357+
* or updates.
358+
*/
359+
360+
updates: OffChainUpdateV1SDKType[];
363361
}
364362
/**
365363
* StreamOrderbookFill provides information on an orderbook fill. Used in
@@ -1305,39 +1303,39 @@ export const StreamOrderbookUpdatesResponse = {
13051303

13061304
function createBaseStreamUpdate(): StreamUpdate {
13071305
return {
1306+
blockHeight: 0,
1307+
execMode: 0,
13081308
orderbookUpdate: undefined,
13091309
orderFill: undefined,
13101310
takerOrder: undefined,
1311-
subaccountUpdate: undefined,
1312-
blockHeight: 0,
1313-
execMode: 0
1311+
subaccountUpdate: undefined
13141312
};
13151313
}
13161314

13171315
export const StreamUpdate = {
13181316
encode(message: StreamUpdate, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
1319-
if (message.orderbookUpdate !== undefined) {
1320-
StreamOrderbookUpdate.encode(message.orderbookUpdate, writer.uint32(10).fork()).ldelim();
1317+
if (message.blockHeight !== 0) {
1318+
writer.uint32(8).uint32(message.blockHeight);
13211319
}
13221320

1323-
if (message.orderFill !== undefined) {
1324-
StreamOrderbookFill.encode(message.orderFill, writer.uint32(18).fork()).ldelim();
1321+
if (message.execMode !== 0) {
1322+
writer.uint32(16).uint32(message.execMode);
13251323
}
13261324

1327-
if (message.takerOrder !== undefined) {
1328-
StreamTakerOrder.encode(message.takerOrder, writer.uint32(26).fork()).ldelim();
1325+
if (message.orderbookUpdate !== undefined) {
1326+
StreamOrderbookUpdate.encode(message.orderbookUpdate, writer.uint32(26).fork()).ldelim();
13291327
}
13301328

1331-
if (message.subaccountUpdate !== undefined) {
1332-
StreamSubaccountUpdate.encode(message.subaccountUpdate, writer.uint32(34).fork()).ldelim();
1329+
if (message.orderFill !== undefined) {
1330+
StreamOrderbookFill.encode(message.orderFill, writer.uint32(34).fork()).ldelim();
13331331
}
13341332

1335-
if (message.blockHeight !== 0) {
1336-
writer.uint32(40).uint32(message.blockHeight);
1333+
if (message.takerOrder !== undefined) {
1334+
StreamTakerOrder.encode(message.takerOrder, writer.uint32(42).fork()).ldelim();
13371335
}
13381336

1339-
if (message.execMode !== 0) {
1340-
writer.uint32(48).uint32(message.execMode);
1337+
if (message.subaccountUpdate !== undefined) {
1338+
StreamSubaccountUpdate.encode(message.subaccountUpdate, writer.uint32(50).fork()).ldelim();
13411339
}
13421340

13431341
return writer;
@@ -1353,27 +1351,27 @@ export const StreamUpdate = {
13531351

13541352
switch (tag >>> 3) {
13551353
case 1:
1356-
message.orderbookUpdate = StreamOrderbookUpdate.decode(reader, reader.uint32());
1354+
message.blockHeight = reader.uint32();
13571355
break;
13581356

13591357
case 2:
1360-
message.orderFill = StreamOrderbookFill.decode(reader, reader.uint32());
1358+
message.execMode = reader.uint32();
13611359
break;
13621360

13631361
case 3:
1364-
message.takerOrder = StreamTakerOrder.decode(reader, reader.uint32());
1362+
message.orderbookUpdate = StreamOrderbookUpdate.decode(reader, reader.uint32());
13651363
break;
13661364

13671365
case 4:
1368-
message.subaccountUpdate = StreamSubaccountUpdate.decode(reader, reader.uint32());
1366+
message.orderFill = StreamOrderbookFill.decode(reader, reader.uint32());
13691367
break;
13701368

13711369
case 5:
1372-
message.blockHeight = reader.uint32();
1370+
message.takerOrder = StreamTakerOrder.decode(reader, reader.uint32());
13731371
break;
13741372

13751373
case 6:
1376-
message.execMode = reader.uint32();
1374+
message.subaccountUpdate = StreamSubaccountUpdate.decode(reader, reader.uint32());
13771375
break;
13781376

13791377
default:
@@ -1387,32 +1385,32 @@ export const StreamUpdate = {
13871385

13881386
fromPartial(object: DeepPartial<StreamUpdate>): StreamUpdate {
13891387
const message = createBaseStreamUpdate();
1388+
message.blockHeight = object.blockHeight ?? 0;
1389+
message.execMode = object.execMode ?? 0;
13901390
message.orderbookUpdate = object.orderbookUpdate !== undefined && object.orderbookUpdate !== null ? StreamOrderbookUpdate.fromPartial(object.orderbookUpdate) : undefined;
13911391
message.orderFill = object.orderFill !== undefined && object.orderFill !== null ? StreamOrderbookFill.fromPartial(object.orderFill) : undefined;
13921392
message.takerOrder = object.takerOrder !== undefined && object.takerOrder !== null ? StreamTakerOrder.fromPartial(object.takerOrder) : undefined;
13931393
message.subaccountUpdate = object.subaccountUpdate !== undefined && object.subaccountUpdate !== null ? StreamSubaccountUpdate.fromPartial(object.subaccountUpdate) : undefined;
1394-
message.blockHeight = object.blockHeight ?? 0;
1395-
message.execMode = object.execMode ?? 0;
13961394
return message;
13971395
}
13981396

13991397
};
14001398

14011399
function createBaseStreamOrderbookUpdate(): StreamOrderbookUpdate {
14021400
return {
1403-
updates: [],
1404-
snapshot: false
1401+
snapshot: false,
1402+
updates: []
14051403
};
14061404
}
14071405

14081406
export const StreamOrderbookUpdate = {
14091407
encode(message: StreamOrderbookUpdate, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
1410-
for (const v of message.updates) {
1411-
OffChainUpdateV1.encode(v!, writer.uint32(10).fork()).ldelim();
1408+
if (message.snapshot === true) {
1409+
writer.uint32(8).bool(message.snapshot);
14121410
}
14131411

1414-
if (message.snapshot === true) {
1415-
writer.uint32(16).bool(message.snapshot);
1412+
for (const v of message.updates) {
1413+
OffChainUpdateV1.encode(v!, writer.uint32(18).fork()).ldelim();
14161414
}
14171415

14181416
return writer;
@@ -1428,11 +1426,11 @@ export const StreamOrderbookUpdate = {
14281426

14291427
switch (tag >>> 3) {
14301428
case 1:
1431-
message.updates.push(OffChainUpdateV1.decode(reader, reader.uint32()));
1429+
message.snapshot = reader.bool();
14321430
break;
14331431

14341432
case 2:
1435-
message.snapshot = reader.bool();
1433+
message.updates.push(OffChainUpdateV1.decode(reader, reader.uint32()));
14361434
break;
14371435

14381436
default:
@@ -1446,8 +1444,8 @@ export const StreamOrderbookUpdate = {
14461444

14471445
fromPartial(object: DeepPartial<StreamOrderbookUpdate>): StreamOrderbookUpdate {
14481446
const message = createBaseStreamOrderbookUpdate();
1449-
message.updates = object.updates?.map(e => OffChainUpdateV1.fromPartial(e)) || [];
14501447
message.snapshot = object.snapshot ?? false;
1448+
message.updates = object.updates?.map(e => OffChainUpdateV1.fromPartial(e)) || [];
14511449
return message;
14521450
}
14531451

proto/dydxprotocol/clob/query.proto

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,35 +182,35 @@ message StreamOrderbookUpdatesResponse {
182182
// StreamUpdate is an update that will be pushed through the
183183
// GRPC stream.
184184
message StreamUpdate {
185+
// Block height of the update.
186+
uint32 block_height = 1;
187+
188+
// Exec mode of the update.
189+
uint32 exec_mode = 2;
190+
185191
// Contains one of an StreamOrderbookUpdate,
186192
// StreamOrderbookFill, StreamTakerOrderStatus.
187193
oneof update_message {
188-
StreamOrderbookUpdate orderbook_update = 1;
189-
StreamOrderbookFill order_fill = 2;
190-
StreamTakerOrder taker_order = 3;
191-
dydxprotocol.subaccounts.StreamSubaccountUpdate subaccount_update = 4;
194+
StreamOrderbookUpdate orderbook_update = 3;
195+
StreamOrderbookFill order_fill = 4;
196+
StreamTakerOrder taker_order = 5;
197+
dydxprotocol.subaccounts.StreamSubaccountUpdate subaccount_update = 6;
192198
}
193-
194-
// Block height of the update.
195-
uint32 block_height = 5;
196-
197-
// Exec mode of the update.
198-
uint32 exec_mode = 6;
199199
}
200200

201201
// StreamOrderbookUpdate provides information on an orderbook update. Used in
202202
// the full node GRPC stream.
203203
message StreamOrderbookUpdate {
204-
// Orderbook updates for the clob pair. Can contain order place, removals,
205-
// or updates.
206-
repeated dydxprotocol.indexer.off_chain_updates.OffChainUpdateV1 updates = 1
207-
[ (gogoproto.nullable) = false ];
208-
209204
// Snapshot indicates if the response is from a snapshot of the orderbook.
210205
// All updates should be ignored until snapshot is recieved.
211206
// If the snapshot is true, then all previous entries should be
212207
// discarded and the orderbook should be resynced.
213-
bool snapshot = 2;
208+
bool snapshot = 1;
209+
210+
// Orderbook updates for the clob pair. Can contain order place, removals,
211+
// or updates.
212+
repeated dydxprotocol.indexer.off_chain_updates.OffChainUpdateV1 updates = 2
213+
[ (gogoproto.nullable) = false ];
214214
}
215215

216216
// StreamOrderbookFill provides information on an orderbook fill. Used in

0 commit comments

Comments
 (0)