From 5b49c903e02f6d667bf36510953f5a6bb61297d1 Mon Sep 17 00:00:00 2001 From: dydxwill <119354122+dydxwill@users.noreply.github.com> Date: Fri, 1 Dec 2023 12:15:41 -0500 Subject: [PATCH 1/6] [IND-520] Add more pnl stats (#826) --- .../src/helpers/pnl-ticks-helper.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/indexer/services/roundtable/src/helpers/pnl-ticks-helper.ts b/indexer/services/roundtable/src/helpers/pnl-ticks-helper.ts index 6642e4732e..221bd22550 100644 --- a/indexer/services/roundtable/src/helpers/pnl-ticks-helper.ts +++ b/indexer/services/roundtable/src/helpers/pnl-ticks-helper.ts @@ -1,4 +1,4 @@ -import { logger } from '@dydxprotocol-indexer/base'; +import { logger, stats } from '@dydxprotocol-indexer/base'; import { AssetPositionTable, FundingIndexMap, @@ -36,6 +36,7 @@ export async function getPnlTicksCreateObjects( blockTime: IsoString, txId: number, ): Promise { + const startGetPnlTicksCreateObjects: number = Date.now(); const pnlTicksToBeCreatedAt: DateTime = DateTime.utc(); const [ mostRecentPnlTicks, @@ -47,6 +48,10 @@ export async function getPnlTicksCreateObjects( getMostRecentPnlTicksForEachAccount(), SubaccountTable.getSubaccountsWithTransfers(blockHeight, { readReplica: true, txId }), ]); + stats.timing( + `${config.SERVICE_NAME}_get_ticks_relevant_accounts`, + new Date().getTime() - startGetPnlTicksCreateObjects, + ); const accountToLastUpdatedBlockTime: _.Dictionary = _.mapValues( mostRecentPnlTicks, (pnlTick: PnlTicksCreateObject) => pnlTick.blockTime, @@ -66,17 +71,27 @@ export async function getPnlTicksCreateObjects( ), ...newSubaccountIds, ]; + stats.gauge( + `${config.SERVICE_NAME}_get_ticks_accounts_to_update`, + accountsToUpdate.length, + ); const idToSubaccount: _.Dictionary = _.keyBy( subaccountsWithTransfers, 'id', ); + const getFundingIndexStart: number = Date.now(); const blockHeightToFundingIndexMap: _.Dictionary = await getBlockHeightToFundingIndexMap( subaccountsWithTransfers, accountsToUpdate, txId, ); + stats.timing( + `${config.SERVICE_NAME}_get_ticks_funding_indices`, + new Date().getTime() - getFundingIndexStart, + ); + const getAccountInfoStart: number = Date.now(); const [ subaccountTotalTransfersMap, openPerpetualPositions, @@ -122,7 +137,12 @@ export async function getPnlTicksCreateObjects( OraclePriceTable.findLatestPrices(blockHeight), FundingIndexUpdatesTable.findFundingIndexMap(blockHeight), ]); + stats.timing( + `${config.SERVICE_NAME}_get_ticks_account_info`, + new Date().getTime() - getAccountInfoStart, + ); + const computePnlStart: number = Date.now(); const newTicksToCreate: PnlTicksCreateObject[] = accountsToUpdate.map( (account: string) => getNewPnlTick( account, @@ -139,6 +159,10 @@ export async function getPnlTicksCreateObjects( currentFundingIndexMap, ), ); + stats.timing( + `${config.SERVICE_NAME}_get_ticks_compute_pnl`, + new Date().getTime() - computePnlStart, + ); return newTicksToCreate; } From 5901af412b8f0b50b667a267799f175299978039 Mon Sep 17 00:00:00 2001 From: Lukasz Cwik <126621805+lcwik@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:39:03 -0800 Subject: [PATCH 2/6] [IND-481] Use a single SQL function to process a block. (#827) * [IND-481] Use a single SQL function to process a block. --- .../kafka/src/batch-kafka-producer.ts | 6 +- .../postgres/src/helpers/stores-helpers.ts | 26 +- .../postgres/src/types/utility-types.ts | 5 + .../services/bazooka/src/vulcan-helpers.ts | 2 + .../__tests__/handlers/asset-handler.test.ts | 1 + .../handlers/funding-handler.test.ts | 1 + .../handlers/liquidity-tier-handler.test.ts | 1 + .../markets/market-create-handler.test.ts | 14 +- .../markets/market-modify-handler.test.ts | 15 +- .../market-price-update-handler.test.ts | 14 +- .../order-fills/deleveraging-handler.test.ts | 1 + .../order-fills/liquidation-handler.test.ts | 1 + .../order-fills/order-handler.test.ts | 1 + .../handlers/perpetual-market-handler.test.ts | 1 + ...onditional-order-placement-handler.test.ts | 1 + ...onditional-order-triggered-handler.test.ts | 1 + .../stateful-order-placement-handler.test.ts | 1 + .../stateful-order-removal-handler.test.ts | 1 + .../subaccount-update-handler.test.ts | 1 + .../handlers/transfer-handler.test.ts | 1 + .../handlers/update-clob-pair-handler.test.ts | 1 + .../handlers/update-perpetual-handler.test.ts | 1 + .../__tests__/lib/batched-handler.test.ts | 1 + .../__tests__/lib/block-processor.test.ts | 14 +- .../ender/__tests__/lib/on-message.test.ts | 315 ++++-------------- .../ender/__tests__/lib/sync-handlers.test.ts | 167 ++-------- .../ender/__tests__/scripts/scripts.test.ts | 2 +- .../validators/asset-validator.test.ts | 1 + .../validators/deleveraging-validator.test.ts | 2 + .../validators/funding-validator.test.ts | 2 + .../liquidity-tier-validator.test.ts | 3 + .../validators/market-validator.test.ts | 2 + .../validators/order-fill-validator.test.ts | 2 + .../perpetual-market-validator.test.ts | 3 + .../stateful-order-validator.test.ts | 2 + .../subaccount-update-validator.test.ts | 2 + .../validators/transfer-validator.test.ts | 2 + .../update-clob-pair-validator.test.ts | 2 + .../update-perpetual-validator.test.ts | 2 + .../abstract-stateful-order-handler.ts | 46 --- .../ender/src/handlers/asset-handler.ts | 22 +- .../ender/src/handlers/funding-handler.ts | 33 +- .../services/ender/src/handlers/handler.ts | 22 +- .../src/handlers/liquidity-tier-handler.ts | 22 +- .../handlers/markets/market-create-handler.ts | 33 +- .../handlers/markets/market-modify-handler.ts | 38 +-- .../markets/market-price-update-handler.ts | 37 +- .../order-fills/deleveraging-handler.ts | 36 +- .../order-fills/liquidation-handler.ts | 48 +-- .../src/handlers/order-fills/order-handler.ts | 64 +--- .../src/handlers/perpetual-market-handler.ts | 22 +- .../conditional-order-placement-handler.ts | 17 +- .../conditional-order-triggered-handler.ts | 21 +- .../stateful-order-placement-handler.ts | 5 +- .../stateful-order-removal-handler.ts | 4 +- .../src/handlers/subaccount-update-handler.ts | 28 +- .../ender/src/handlers/transfer-handler.ts | 33 +- .../src/handlers/update-clob-pair-handler.ts | 22 +- .../src/handlers/update-perpetual-handler.ts | 22 +- .../helpers/postgres/postgres-functions.ts | 3 + .../ender/src/lib/batched-handlers.ts | 11 +- .../services/ender/src/lib/block-processor.ts | 94 +++++- indexer/services/ender/src/lib/helper.ts | 16 +- .../services/ender/src/lib/kafka-publisher.ts | 1 + indexer/services/ender/src/lib/on-message.ts | 38 --- .../services/ender/src/lib/sync-handlers.ts | 8 +- indexer/services/ender/src/lib/types.ts | 13 + .../src/scripts/dydx_block_processor.sql | 43 +++ .../dydx_block_processor_ordered_handlers.sql | 63 ++++ ...ydx_block_processor_unordered_handlers.sql | 70 ++++ ...eate_initial_rows_for_tendermint_block.sql | 16 +- .../scripts/dydx_create_tendermint_event.sql | 4 +- .../src/scripts/dydx_create_transaction.sql | 6 +- .../scripts/dydx_stateful_order_handler.sql | 2 +- .../dydx_uuid_from_transaction_parts.sql | 2 +- .../ender/src/validators/asset-validator.ts | 1 + .../src/validators/deleveraging-validator.ts | 1 + .../ender/src/validators/funding-validator.ts | 1 + .../validators/liquidity-tier-validator.ts | 1 + .../ender/src/validators/market-validator.ts | 1 + .../src/validators/order-fill-validator.ts | 35 +- .../validators/perpetual-market-validator.ts | 1 + .../validators/stateful-order-validator.ts | 1 + .../validators/subaccount-update-validator.ts | 1 + .../src/validators/transfer-validator.ts | 1 + .../validators/update-clob-pair-validator.ts | 1 + .../validators/update-perpetual-validator.ts | 1 + .../ender/src/validators/validator.ts | 17 +- .../src/tasks/remove-expired-orders.ts | 1 + 89 files changed, 657 insertions(+), 993 deletions(-) create mode 100644 indexer/services/ender/src/scripts/dydx_block_processor.sql create mode 100644 indexer/services/ender/src/scripts/dydx_block_processor_ordered_handlers.sql create mode 100644 indexer/services/ender/src/scripts/dydx_block_processor_unordered_handlers.sql diff --git a/indexer/packages/kafka/src/batch-kafka-producer.ts b/indexer/packages/kafka/src/batch-kafka-producer.ts index 7e70ff4b05..6885e29ae9 100644 --- a/indexer/packages/kafka/src/batch-kafka-producer.ts +++ b/indexer/packages/kafka/src/batch-kafka-producer.ts @@ -2,7 +2,6 @@ import { logger } from '@dydxprotocol-indexer/base'; import { Producer, RecordMetadata } from 'kafkajs'; import _ from 'lodash'; -import config from './config'; import { KafkaTopics } from './types'; /** @@ -28,7 +27,10 @@ export class BatchKafkaProducer { constructor( topic: KafkaTopics, producer: Producer, - maxBatchSizeBytes: number = config.KAFKA_MAX_BATCH_WEBSOCKET_MESSAGE_SIZE_BYTES, + // Note that default parameters are bound during module load time making it difficult + // to modify the parameter during a test so we explicitly require callers to pass in + // config.KAFKA_MAX_BATCH_WEBSOCKET_MESSAGE_SIZE_BYTES. + maxBatchSizeBytes: number, ) { this.maxBatchSizeBytes = maxBatchSizeBytes; this.producer = producer; diff --git a/indexer/packages/postgres/src/helpers/stores-helpers.ts b/indexer/packages/postgres/src/helpers/stores-helpers.ts index 7fd583d843..da31ea2e25 100644 --- a/indexer/packages/postgres/src/helpers/stores-helpers.ts +++ b/indexer/packages/postgres/src/helpers/stores-helpers.ts @@ -64,25 +64,19 @@ export async function rawQuery( options: Options, // eslint-disable-next-line @typescript-eslint/no-explicit-any ): Promise> { - if (options.readReplica) { - if (options.txId) { - return knexReadReplica.getConnection().raw(queryString).transacting( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - >Transaction.get(options.txId), - ); - } else { - return knexReadReplica.getConnection().raw(queryString); - } - } else { - if (options.txId) { - return knexPrimary.raw(queryString).transacting( + const connection = options.readReplica ? knexReadReplica.getConnection() : knexPrimary; + let queryBuilder = options.bindings === undefined + ? connection.raw(queryString) : connection.raw(queryString, options.bindings); + if (options.txId) { + queryBuilder = queryBuilder.transacting( // eslint-disable-next-line @typescript-eslint/no-explicit-any >Transaction.get(options.txId), - ); - } else { - return knexPrimary.raw(queryString); - } + ); + } + if (options.sqlOptions) { + queryBuilder = queryBuilder.options(options.sqlOptions); } + return queryBuilder; } /* ------- Bulk Helpers ------- */ diff --git a/indexer/packages/postgres/src/types/utility-types.ts b/indexer/packages/postgres/src/types/utility-types.ts index b22cd58d7f..f0eecb4397 100644 --- a/indexer/packages/postgres/src/types/utility-types.ts +++ b/indexer/packages/postgres/src/types/utility-types.ts @@ -1,4 +1,6 @@ /* ------- UTILITY TYPES ------- */ +import { RawBinding } from 'knex'; + export type IsoString = string; export type RegexPattern = string; @@ -17,6 +19,9 @@ export interface Options { orderBy?: [string, Ordering][]; readReplica?: boolean, random?: boolean; + bindings?: readonly RawBinding[]; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + sqlOptions?: Readonly<{ [key: string]: any }>; } export enum Ordering { diff --git a/indexer/services/bazooka/src/vulcan-helpers.ts b/indexer/services/bazooka/src/vulcan-helpers.ts index 16f33cab1f..eacbaedb37 100644 --- a/indexer/services/bazooka/src/vulcan-helpers.ts +++ b/indexer/services/bazooka/src/vulcan-helpers.ts @@ -24,6 +24,7 @@ import { Long } from '@dydxprotocol-indexer/v4-protos/build/codegen/helpers'; import Big from 'big.js'; import _ from 'lodash'; +import config from './config'; import { ZERO } from './constants'; interface VulcanMessage { @@ -134,6 +135,7 @@ export async function sendStatefulOrderMessages() { const batchProducer: BatchKafkaProducer = new BatchKafkaProducer( KafkaTopics.TO_VULCAN, producer, + config.KAFKA_MAX_BATCH_WEBSOCKET_MESSAGE_SIZE_BYTES, ); for (const message of messages) { batchProducer.addMessageAndMaybeFlush(message); diff --git a/indexer/services/ender/__tests__/handlers/asset-handler.test.ts b/indexer/services/ender/__tests__/handlers/asset-handler.test.ts index 75f210031d..1982e07c08 100644 --- a/indexer/services/ender/__tests__/handlers/asset-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/asset-handler.test.ts @@ -85,6 +85,7 @@ describe('assetHandler', () => { const handler: AssetCreationHandler = new AssetCreationHandler( block, + 0, indexerTendermintEvent, 0, defaultAssetCreateEvent, diff --git a/indexer/services/ender/__tests__/handlers/funding-handler.test.ts b/indexer/services/ender/__tests__/handlers/funding-handler.test.ts index 8a5bb2883a..f676a88eaa 100644 --- a/indexer/services/ender/__tests__/handlers/funding-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/funding-handler.test.ts @@ -89,6 +89,7 @@ describe('fundingHandler', () => { const handler: FundingHandler = new FundingHandler( block, + 0, indexerTendermintEvent, 0, defaultFundingUpdateSampleEvent, diff --git a/indexer/services/ender/__tests__/handlers/liquidity-tier-handler.test.ts b/indexer/services/ender/__tests__/handlers/liquidity-tier-handler.test.ts index ff86a71d69..a9353d03c0 100644 --- a/indexer/services/ender/__tests__/handlers/liquidity-tier-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/liquidity-tier-handler.test.ts @@ -90,6 +90,7 @@ describe('liquidityTierHandler', () => { const handler: LiquidityTierHandler = new LiquidityTierHandler( block, + 0, indexerTendermintEvent, 0, defaultLiquidityTierUpsertEvent, diff --git a/indexer/services/ender/__tests__/handlers/markets/market-create-handler.test.ts b/indexer/services/ender/__tests__/handlers/markets/market-create-handler.test.ts index 839626cdd5..5ce1a88233 100644 --- a/indexer/services/ender/__tests__/handlers/markets/market-create-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/markets/market-create-handler.test.ts @@ -1,4 +1,4 @@ -import { logger, ParseMessageError } from '@dydxprotocol-indexer/base'; +import { logger } from '@dydxprotocol-indexer/base'; import { dbHelpers, MarketFromDatabase, MarketTable, testMocks, } from '@dydxprotocol-indexer/postgres'; @@ -46,7 +46,6 @@ describe('marketCreateHandler', () => { }); const loggerCrit = jest.spyOn(logger, 'crit'); - const loggerError = jest.spyOn(logger, 'error'); const producerSendMock: jest.SpyInstance = jest.spyOn(producer, 'send'); describe('getParallelizationIds', () => { @@ -75,6 +74,7 @@ describe('marketCreateHandler', () => { const handler: MarketCreateHandler = new MarketCreateHandler( block, + 0, indexerTendermintEvent, 0, marketEvent, @@ -128,7 +128,7 @@ describe('marketCreateHandler', () => { txHash: defaultTxHash, }); await expect(onMessage(kafkaMessage)).rejects.toThrowError( - new ParseMessageError('Market in MarketCreate already exists'), + 'Market in MarketCreate already exists', ); // Check that market in database is the old market. @@ -137,13 +137,9 @@ describe('marketCreateHandler', () => { ) as MarketFromDatabase; expect(market.minPriceChangePpm).toEqual(50); - expect(loggerError).toHaveBeenCalledWith(expect.objectContaining({ - at: 'MarketCreateHandler#logAndThrowParseMessageError', - message: 'Market in MarketCreate already exists', - })); expect(loggerCrit).toHaveBeenCalledWith(expect.objectContaining({ - at: 'onMessage#onMessage', - message: 'Error: Unable to parse message, this must be due to a bug in V4 node', + at: expect.stringContaining('PL/pgSQL function dydx_market_create_handler('), + message: expect.stringContaining('Market in MarketCreate already exists'), })); expect(producerSendMock.mock.calls.length).toEqual(0); }); diff --git a/indexer/services/ender/__tests__/handlers/markets/market-modify-handler.test.ts b/indexer/services/ender/__tests__/handlers/markets/market-modify-handler.test.ts index c80d4a1a7f..cf2a2d1c58 100644 --- a/indexer/services/ender/__tests__/handlers/markets/market-modify-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/markets/market-modify-handler.test.ts @@ -1,4 +1,4 @@ -import { logger, ParseMessageError } from '@dydxprotocol-indexer/base'; +import { logger } from '@dydxprotocol-indexer/base'; import { dbHelpers, MarketFromDatabase, MarketTable, testMocks, } from '@dydxprotocol-indexer/postgres'; @@ -40,7 +40,6 @@ describe('marketModifyHandler', () => { }); const loggerCrit = jest.spyOn(logger, 'crit'); - const loggerError = jest.spyOn(logger, 'error'); const producerSendMock: jest.SpyInstance = jest.spyOn(producer, 'send'); describe('getParallelizationIds', () => { @@ -69,6 +68,7 @@ describe('marketModifyHandler', () => { const handler: MarketModifyHandler = new MarketModifyHandler( block, + 0, indexerTendermintEvent, 0, marketEvent, @@ -115,16 +115,11 @@ describe('marketModifyHandler', () => { }); await expect(onMessage(kafkaMessage)).rejects.toThrowError( - new ParseMessageError('Market in MarketModify doesn\'t exist'), + 'Market in MarketModify doesn\'t exist', ); - - expect(loggerError).toHaveBeenCalledWith(expect.objectContaining({ - at: 'MarketModifyHandler#logAndThrowParseMessageError', - message: 'Market in MarketModify doesn\'t exist', - })); expect(loggerCrit).toHaveBeenCalledWith(expect.objectContaining({ - at: 'onMessage#onMessage', - message: 'Error: Unable to parse message, this must be due to a bug in V4 node', + at: expect.stringContaining('PL/pgSQL function dydx_market_modify_handler('), + message: expect.stringContaining('Market in MarketModify doesn\'t exist'), })); expect(producerSendMock.mock.calls.length).toEqual(0); }); diff --git a/indexer/services/ender/__tests__/handlers/markets/market-price-update-handler.test.ts b/indexer/services/ender/__tests__/handlers/markets/market-price-update-handler.test.ts index 77eb916dbe..6c85845032 100644 --- a/indexer/services/ender/__tests__/handlers/markets/market-price-update-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/markets/market-price-update-handler.test.ts @@ -1,4 +1,4 @@ -import { logger, ParseMessageError } from '@dydxprotocol-indexer/base'; +import { logger } from '@dydxprotocol-indexer/base'; import { dbHelpers, MarketFromDatabase, @@ -54,7 +54,6 @@ describe('marketPriceUpdateHandler', () => { jest.resetAllMocks(); }); const loggerCrit = jest.spyOn(logger, 'crit'); - const loggerError = jest.spyOn(logger, 'error'); const producerSendMock: jest.SpyInstance = jest.spyOn(producer, 'send'); describe('getParallelizationIds', () => { @@ -83,6 +82,7 @@ describe('marketPriceUpdateHandler', () => { const handler: MarketPriceUpdateHandler = new MarketPriceUpdateHandler( block, + 0, indexerTendermintEvent, 0, marketEvent, @@ -111,16 +111,12 @@ describe('marketPriceUpdateHandler', () => { }); await expect(onMessage(kafkaMessage)).rejects.toThrowError( - new ParseMessageError('MarketPriceUpdateEvent contains a non-existent market id'), + 'MarketPriceUpdateEvent contains a non-existent market id', ); - expect(loggerError).toHaveBeenCalledWith(expect.objectContaining({ - at: 'MarketPriceUpdateHandler#logAndThrowParseMessageError', - message: 'MarketPriceUpdateEvent contains a non-existent market id', - })); expect(loggerCrit).toHaveBeenCalledWith(expect.objectContaining({ - at: 'onMessage#onMessage', - message: 'Error: Unable to parse message, this must be due to a bug in V4 node', + at: expect.stringContaining('PL/pgSQL function dydx_market_price_update_handler('), + message: expect.stringContaining('MarketPriceUpdateEvent contains a non-existent market id'), })); expect(producerSendMock.mock.calls.length).toEqual(0); }); diff --git a/indexer/services/ender/__tests__/handlers/order-fills/deleveraging-handler.test.ts b/indexer/services/ender/__tests__/handlers/order-fills/deleveraging-handler.test.ts index fbe6950292..8c06ba595b 100644 --- a/indexer/services/ender/__tests__/handlers/order-fills/deleveraging-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/order-fills/deleveraging-handler.test.ts @@ -143,6 +143,7 @@ describe('DeleveragingHandler', () => { const handler: DeleveragingHandler = new DeleveragingHandler( block, + 0, indexerTendermintEvent, 0, defaultDeleveragingEvent, diff --git a/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts b/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts index ee139e5347..1b7f3ddb0f 100644 --- a/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/order-fills/liquidation-handler.test.ts @@ -178,6 +178,7 @@ describe('LiquidationHandler', () => { const handler: LiquidationHandler = new LiquidationHandler( block, + 0, indexerTendermintEvent, 0, { diff --git a/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts b/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts index 9e4867b1d1..46b005c841 100644 --- a/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/order-fills/order-handler.test.ts @@ -180,6 +180,7 @@ describe('OrderHandler', () => { const handler: OrderHandler = new OrderHandler( block, + 0, indexerTendermintEvent, 0, { diff --git a/indexer/services/ender/__tests__/handlers/perpetual-market-handler.test.ts b/indexer/services/ender/__tests__/handlers/perpetual-market-handler.test.ts index 336ced9392..50cc4e4681 100644 --- a/indexer/services/ender/__tests__/handlers/perpetual-market-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/perpetual-market-handler.test.ts @@ -90,6 +90,7 @@ describe('perpetualMarketHandler', () => { const handler: PerpetualMarketCreationHandler = new PerpetualMarketCreationHandler( block, + 0, indexerTendermintEvent, 0, defaultPerpetualMarketCreateEvent, diff --git a/indexer/services/ender/__tests__/handlers/stateful-order/conditional-order-placement-handler.test.ts b/indexer/services/ender/__tests__/handlers/stateful-order/conditional-order-placement-handler.test.ts index 3f7c2d2fe1..0f3b55b0bb 100644 --- a/indexer/services/ender/__tests__/handlers/stateful-order/conditional-order-placement-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/stateful-order/conditional-order-placement-handler.test.ts @@ -108,6 +108,7 @@ describe('conditionalOrderPlacementHandler', () => { const handler: ConditionalOrderPlacementHandler = new ConditionalOrderPlacementHandler( block, + 0, indexerTendermintEvent, 0, defaultStatefulOrderEvent, diff --git a/indexer/services/ender/__tests__/handlers/stateful-order/conditional-order-triggered-handler.test.ts b/indexer/services/ender/__tests__/handlers/stateful-order/conditional-order-triggered-handler.test.ts index fa234c9a38..e9a02dc164 100644 --- a/indexer/services/ender/__tests__/handlers/stateful-order/conditional-order-triggered-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/stateful-order/conditional-order-triggered-handler.test.ts @@ -94,6 +94,7 @@ describe('conditionalOrderTriggeredHandler', () => { const handler: ConditionalOrderTriggeredHandler = new ConditionalOrderTriggeredHandler( block, + 0, indexerTendermintEvent, 0, defaultStatefulOrderEvent, diff --git a/indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-placement-handler.test.ts b/indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-placement-handler.test.ts index ae5a38d00c..dd0ca482c4 100644 --- a/indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-placement-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-placement-handler.test.ts @@ -119,6 +119,7 @@ describe('statefulOrderPlacementHandler', () => { const handler: StatefulOrderPlacementHandler = new StatefulOrderPlacementHandler( block, + 0, indexerTendermintEvent, 0, statefulOrderEvent, diff --git a/indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-removal-handler.test.ts b/indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-removal-handler.test.ts index e860242e38..68aa0b226b 100644 --- a/indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-removal-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-removal-handler.test.ts @@ -88,6 +88,7 @@ describe('statefulOrderRemovalHandler', () => { const handler: StatefulOrderRemovalHandler = new StatefulOrderRemovalHandler( block, + 0, indexerTendermintEvent, 0, defaultStatefulOrderEvent, diff --git a/indexer/services/ender/__tests__/handlers/subaccount-update-handler.test.ts b/indexer/services/ender/__tests__/handlers/subaccount-update-handler.test.ts index a94556b195..6c41322434 100644 --- a/indexer/services/ender/__tests__/handlers/subaccount-update-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/subaccount-update-handler.test.ts @@ -127,6 +127,7 @@ describe('subaccountUpdateHandler', () => { const handler: SubaccountUpdateHandler = new SubaccountUpdateHandler( block, + 0, indexerTendermintEvent, 0, defaultEmptySubaccountUpdate, diff --git a/indexer/services/ender/__tests__/handlers/transfer-handler.test.ts b/indexer/services/ender/__tests__/handlers/transfer-handler.test.ts index 608c4bab1c..55bea45627 100644 --- a/indexer/services/ender/__tests__/handlers/transfer-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/transfer-handler.test.ts @@ -120,6 +120,7 @@ describe('transferHandler', () => { const handler: TransferHandler = new TransferHandler( block, + 0, indexerTendermintEvent, 0, defaultTransferEvent, diff --git a/indexer/services/ender/__tests__/handlers/update-clob-pair-handler.test.ts b/indexer/services/ender/__tests__/handlers/update-clob-pair-handler.test.ts index 0c4f307fff..f66c1d68c5 100644 --- a/indexer/services/ender/__tests__/handlers/update-clob-pair-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/update-clob-pair-handler.test.ts @@ -78,6 +78,7 @@ describe('update-clob-pair-handler', () => { const handler: UpdateClobPairHandler = new UpdateClobPairHandler( block, + 0, indexerTendermintEvent, 0, defaultUpdateClobPairEvent, diff --git a/indexer/services/ender/__tests__/handlers/update-perpetual-handler.test.ts b/indexer/services/ender/__tests__/handlers/update-perpetual-handler.test.ts index 6dba0779ba..f6d67cfcdc 100644 --- a/indexer/services/ender/__tests__/handlers/update-perpetual-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/update-perpetual-handler.test.ts @@ -77,6 +77,7 @@ describe('update-perpetual-handler', () => { const handler: UpdatePerpetualHandler = new UpdatePerpetualHandler( block, + 0, indexerTendermintEvent, 0, defaultUpdatePerpetualEvent, diff --git a/indexer/services/ender/__tests__/lib/batched-handler.test.ts b/indexer/services/ender/__tests__/lib/batched-handler.test.ts index 27f148eb95..dce139356c 100644 --- a/indexer/services/ender/__tests__/lib/batched-handler.test.ts +++ b/indexer/services/ender/__tests__/lib/batched-handler.test.ts @@ -48,6 +48,7 @@ function generateFakeHandler(parallelizationIds: string[]): FakeHandler { const handler: FakeHandler = new FakeHandler( block, + 0, defaultEvent, fakeTxId, {}, diff --git a/indexer/services/ender/__tests__/lib/block-processor.test.ts b/indexer/services/ender/__tests__/lib/block-processor.test.ts index a5217a49c3..d0ea660cdb 100644 --- a/indexer/services/ender/__tests__/lib/block-processor.test.ts +++ b/indexer/services/ender/__tests__/lib/block-processor.test.ts @@ -23,6 +23,7 @@ import { BlockProcessor } from '../../src/lib/block-processor'; import { BatchedHandlers } from '../../src/lib/batched-handlers'; import { SyncHandlers } from '../../src/lib/sync-handlers'; import { mock, MockProxy } from 'jest-mock-extended'; +import { createPostgresFunctions } from '../../src/helpers/postgres/postgres-functions'; describe('block-processor', () => { let batchedHandlers: MockProxy; @@ -36,6 +37,7 @@ describe('block-processor', () => { beforeAll(async () => { await dbHelpers.migrate(); + await createPostgresFunctions(); }); afterEach(async () => { @@ -90,18 +92,18 @@ describe('block-processor', () => { transactionIndex0, eventIndex0, ), - createIndexerTendermintEvent( - DydxIndexerSubtypes.ASSET, - defaultAssetEventBinary, - transactionIndex0, - eventIndex1, - ), createIndexerTendermintEvent( DydxIndexerSubtypes.MARKET, defaultMarketEventBinary, transactionIndex1, eventIndex0, ), + createIndexerTendermintEvent( + DydxIndexerSubtypes.ASSET, + defaultAssetEventBinary, + transactionIndex0, + eventIndex1, + ), ]; it('batched handlers called before sync handlers for normal blocks', async () => { diff --git a/indexer/services/ender/__tests__/lib/on-message.test.ts b/indexer/services/ender/__tests__/lib/on-message.test.ts index 5a8e287969..a447e90542 100644 --- a/indexer/services/ender/__tests__/lib/on-message.test.ts +++ b/indexer/services/ender/__tests__/lib/on-message.test.ts @@ -1,6 +1,7 @@ import { DateTime } from 'luxon'; import { assetRefresher, + AssetTable, BlockFromDatabase, BlockTable, dbHelpers, @@ -17,7 +18,6 @@ import { TransactionTable, } from '@dydxprotocol-indexer/postgres'; import { - DeleveragingEventV1, FundingEventV1, IndexerTendermintBlock, IndexerTendermintEvent, @@ -30,16 +30,14 @@ import { import { createIndexerTendermintBlock, createIndexerTendermintEvent } from '../helpers/indexer-proto-helpers'; import { onMessage } from '../../src/lib/on-message'; import { KafkaMessage } from 'kafkajs'; -import { createKafkaMessage, KafkaTopics, producer } from '@dydxprotocol-indexer/kafka'; +import { + createKafkaMessage, KafkaTopics, producer, +} from '@dydxprotocol-indexer/kafka'; import { MILLIS_IN_NANOS, SECONDS_IN_MILLIS } from '../../src/constants'; import { ConsolidatedKafkaEvent, DydxIndexerSubtypes } from '../../src/lib/types'; -import { SubaccountUpdateHandler } from '../../src/handlers/subaccount-update-handler'; import config from '../../src/config'; import { logger, stats } from '@dydxprotocol-indexer/base'; -import { TransferHandler } from '../../src/handlers/transfer-handler'; -import { FundingHandler } from '../../src/handlers/funding-handler'; import { - defaultDeleveragingEvent, defaultFundingUpdateSampleEvent, defaultHeight, defaultMarketModify, @@ -47,47 +45,14 @@ import { defaultSubaccountMessage, } from '../helpers/constants'; import { updateBlockCache } from '../../src/caches/block-cache'; -import { MarketModifyHandler } from '../../src/handlers/markets/market-modify-handler'; import Long from 'long'; import { createPostgresFunctions } from '../../src/helpers/postgres/postgres-functions'; -import { DeleveragingHandler } from '../../src/handlers/order-fills/deleveraging-handler'; - -jest.mock('../../src/handlers/subaccount-update-handler'); -jest.mock('../../src/handlers/transfer-handler'); -jest.mock('../../src/handlers/funding-handler'); -jest.mock('../../src/handlers/order-fills/deleveraging-handler'); -jest.mock('../../src/handlers/markets/market-modify-handler'); describe('on-message', () => { let producerSendMock: jest.SpyInstance; const loggerError = jest.spyOn(logger, 'error'); beforeEach(() => { - (SubaccountUpdateHandler as jest.Mock).mockReturnValue({ - handle: () => [], - validate: () => null, - getParallelizationIds: () => [], - }); - (TransferHandler as jest.Mock).mockReturnValue({ - handle: () => [], - validate: () => null, - getParallelizationIds: () => [], - }); - (MarketModifyHandler as jest.Mock).mockReturnValue({ - handle: () => [], - validate: () => null, - getParallelizationIds: () => [], - }); - (FundingHandler as jest.Mock).mockReturnValue({ - handle: () => [], - validate: () => null, - getParallelizationIds: () => [], - }); - (DeleveragingHandler as jest.Mock).mockReturnValue({ - handle: () => [], - validate: () => null, - getParallelizationIds: () => [], - }); producerSendMock = jest.spyOn(producer, 'send'); producerSendMock.mockImplementation(() => { }); @@ -161,10 +126,6 @@ describe('on-message', () => { defaultMarketModify, ).finish()); - const defaultDeleveragingEventBinary: Uint8Array = Uint8Array.from(DeleveragingEventV1.encode( - defaultDeleveragingEvent, - ).finish()); - it('successfully processes block with transaction event', async () => { const transactionIndex: number = 0; const eventIndex: number = 0; @@ -193,14 +154,6 @@ describe('on-message', () => { expectBlock(defaultHeight.toString(), defaultDateTime.toISO()), ]); - expect((SubaccountUpdateHandler as jest.Mock)).toHaveBeenCalledTimes(1); - expect((SubaccountUpdateHandler as jest.Mock)).toHaveBeenNthCalledWith( - 1, - block, - events[0], - expect.any(Number), - defaultSubaccountUpdateEvent, - ); expect(stats.increment).toHaveBeenCalledWith('ender.received_kafka_message', 1); expect(stats.timing).toHaveBeenCalledWith( 'ender.message_time_in_queue', expect.any(Number), 1, { topic: KafkaTopics.TO_ENDER }); @@ -209,16 +162,7 @@ describe('on-message', () => { expect.any(Number), 1, { success: 'true' }); }); - it.each([ - [ - 'via knex', - false, - ], - [ - 'via SQL function', - true, - ], - ])('successfully processes block with transaction event with unset version', async () => { + it('successfully processes block with transaction event with unset version', async () => { const transactionIndex: number = 0; const eventIndex: number = 0; const events: IndexerTendermintEvent[] = [ @@ -247,14 +191,6 @@ describe('on-message', () => { expectBlock(defaultHeight.toString(), defaultDateTime.toISO()), ]); - expect((SubaccountUpdateHandler as jest.Mock)).toHaveBeenCalledTimes(1); - expect((SubaccountUpdateHandler as jest.Mock)).toHaveBeenNthCalledWith( - 1, - block, - events[0], - expect.any(Number), - defaultSubaccountUpdateEvent, - ); expect(stats.increment).toHaveBeenCalledWith('ender.received_kafka_message', 1); expect(stats.timing).toHaveBeenCalledWith( 'ender.message_time_in_queue', expect.any(Number), 1, { topic: KafkaTopics.TO_ENDER }); @@ -264,6 +200,10 @@ describe('on-message', () => { }); it('successfully processes block with transfer event', async () => { + await Promise.all([ + MarketTable.create(testConstants.defaultMarket), + AssetTable.create(testConstants.defaultAsset), + ]); const transactionIndex: number = 0; const eventIndex: number = 0; const events: IndexerTendermintEvent[] = [ @@ -291,14 +231,6 @@ describe('on-message', () => { expectBlock(defaultHeight.toString(), defaultDateTime.toISO()), ]); - expect((TransferHandler as jest.Mock)).toHaveBeenCalledTimes(1); - expect((TransferHandler as jest.Mock)).toHaveBeenNthCalledWith( - 1, - block, - events[0], - expect.any(Number), - defaultTransferEvent, - ); expect(stats.increment).toHaveBeenCalledWith('ender.received_kafka_message', 1); expect(stats.timing).toHaveBeenCalledWith( 'ender.message_time_in_queue', expect.any(Number), 1, { topic: KafkaTopics.TO_ENDER }); @@ -348,71 +280,6 @@ describe('on-message', () => { expectBlock(defaultHeight.toString(), defaultDateTime.toISO()), ]); - expect((FundingHandler as jest.Mock)).toHaveBeenCalledTimes(1); - expect((FundingHandler as jest.Mock)).toHaveBeenNthCalledWith( - 1, - block, - events[0], - expect.any(Number), - defaultFundingUpdateSampleEvent, - ); - expect(stats.increment).toHaveBeenCalledWith('ender.received_kafka_message', 1); - expect(stats.timing).toHaveBeenCalledWith( - 'ender.message_time_in_queue', expect.any(Number), 1, { topic: KafkaTopics.TO_ENDER }); - expect(stats.gauge).toHaveBeenCalledWith('ender.processing_block_height', expect.any(Number)); - expect(stats.timing).toHaveBeenCalledWith('ender.processed_block.timing', - expect.any(Number), 1, { success: 'true' }); - }); - - it('successfully processes block with deleveraging event', async () => { - await Promise.all([ - MarketTable.create(testConstants.defaultMarket), - MarketTable.create(testConstants.defaultMarket2), - ]); - await Promise.all([ - LiquidityTiersTable.create(testConstants.defaultLiquidityTier), - LiquidityTiersTable.create(testConstants.defaultLiquidityTier2), - ]); - await Promise.all([ - PerpetualMarketTable.create(testConstants.defaultPerpetualMarket), - PerpetualMarketTable.create(testConstants.defaultPerpetualMarket2), - ]); - await perpetualMarketRefresher.updatePerpetualMarkets(); - - const transactionIndex: number = 0; - const eventIndex: number = 0; - const events: IndexerTendermintEvent[] = [ - createIndexerTendermintEvent( - DydxIndexerSubtypes.DELEVERAGING, - defaultDeleveragingEventBinary, - transactionIndex, - eventIndex, - ), - ]; - - const block: IndexerTendermintBlock = createIndexerTendermintBlock( - defaultHeight, - defaultTime, - events, - [defaultTxHash], - ); - const binaryBlock: Uint8Array = Uint8Array.from(IndexerTendermintBlock.encode(block).finish()); - const kafkaMessage: KafkaMessage = createKafkaMessage(Buffer.from(binaryBlock)); - - await onMessage(kafkaMessage); - await Promise.all([ - expectTendermintEvent(defaultHeight.toString(), transactionIndex, eventIndex), - expectBlock(defaultHeight.toString(), defaultDateTime.toISO()), - ]); - - expect((DeleveragingHandler as jest.Mock)).toHaveBeenCalledTimes(1); - expect((DeleveragingHandler as jest.Mock)).toHaveBeenNthCalledWith( - 1, - block, - events[0], - expect.any(Number), - defaultDeleveragingEvent, - ); expect(stats.increment).toHaveBeenCalledWith('ender.received_kafka_message', 1); expect(stats.timing).toHaveBeenCalledWith( 'ender.message_time_in_queue', expect.any(Number), 1, { topic: KafkaTopics.TO_ENDER }); @@ -448,6 +315,10 @@ describe('on-message', () => { }); it('skips over unknown events while processing', async () => { + await Promise.all([ + MarketTable.create(testConstants.defaultMarket), + AssetTable.create(testConstants.defaultAsset), + ]); const transactionIndex: number = 0; const eventIndex: number = 0; const eventIndex1: number = 1; @@ -482,14 +353,6 @@ describe('on-message', () => { expectBlock(defaultHeight.toString(), defaultDateTime.toISO()), ]); - expect((TransferHandler as jest.Mock)).toHaveBeenCalledTimes(1); - expect((TransferHandler as jest.Mock)).toHaveBeenNthCalledWith( - 1, - block, - events[0], - expect.any(Number), - defaultTransferEvent, - ); expect(loggerError).toHaveBeenCalledWith(expect.objectContaining({ at: 'helpers#indexerTendermintEventToEventWithType', message: 'Unable to parse event subtype: unknown', @@ -500,6 +363,9 @@ describe('on-message', () => { }); it('successfully processes block with market event', async () => { + await Promise.all([ + MarketTable.create(testConstants.defaultMarket), + ]); const transactionIndex: number = 0; const eventIndex: number = 0; const events: IndexerTendermintEvent[] = [ @@ -527,14 +393,6 @@ describe('on-message', () => { expectBlock(defaultHeight.toString(), defaultDateTime.toISO()), ]); - expect((MarketModifyHandler as jest.Mock)).toHaveBeenCalledTimes(1); - expect((MarketModifyHandler as jest.Mock)).toHaveBeenNthCalledWith( - 1, - block, - events[0], - expect.any(Number), - defaultMarketModify, - ); expect(stats.increment).toHaveBeenCalledWith('ender.received_kafka_message', 1); expect(stats.timing).toHaveBeenCalledWith( 'ender.message_time_in_queue', expect.any(Number), 1, { topic: KafkaTopics.TO_ENDER }); @@ -544,13 +402,26 @@ describe('on-message', () => { }); it('successfully processes block with block event', async () => { - // -1 so that createIndexerTendermintEvent creates a block event + await Promise.all([ + MarketTable.create(testConstants.defaultMarket), + MarketTable.create(testConstants.defaultMarket2), + ]); + await Promise.all([ + LiquidityTiersTable.create(testConstants.defaultLiquidityTier), + LiquidityTiersTable.create(testConstants.defaultLiquidityTier2), + ]); + await Promise.all([ + PerpetualMarketTable.create(testConstants.defaultPerpetualMarket), + PerpetualMarketTable.create(testConstants.defaultPerpetualMarket2), + ]); + await perpetualMarketRefresher.updatePerpetualMarkets(); + const transactionIndex: number = -1; const eventIndex: number = 0; const events: IndexerTendermintEvent[] = [ createIndexerTendermintEvent( - DydxIndexerSubtypes.SUBACCOUNT_UPDATE, - defaultSubaccountUpdateEventBinary, + DydxIndexerSubtypes.FUNDING, + defaultFundingEventBinary, transactionIndex, eventIndex, ), @@ -571,12 +442,6 @@ describe('on-message', () => { expectBlock(defaultHeight.toString(), defaultDateTime.toISO()), ]); - const transactions: TransactionFromDatabase[] = await - TransactionTable.findAll({}, [], { readReplica: true }); - - expect(transactions.length).toEqual(0); - - expect((SubaccountUpdateHandler as jest.Mock)).toHaveBeenCalledTimes(0); expect(stats.increment).toHaveBeenCalledWith('ender.received_kafka_message', 1); expect(stats.timing).toHaveBeenCalledWith( 'ender.message_time_in_queue', expect.any(Number), 1, { topic: KafkaTopics.TO_ENDER }); @@ -586,20 +451,35 @@ describe('on-message', () => { }); it('successfully processes block with transaction event and block event', async () => { - const transactionIndex: number = 0; - const eventIndex: number = 0; + await Promise.all([ + MarketTable.create(testConstants.defaultMarket), + MarketTable.create(testConstants.defaultMarket2), + ]); + await Promise.all([ + LiquidityTiersTable.create(testConstants.defaultLiquidityTier), + LiquidityTiersTable.create(testConstants.defaultLiquidityTier2), + ]); + await Promise.all([ + PerpetualMarketTable.create(testConstants.defaultPerpetualMarket), + PerpetualMarketTable.create(testConstants.defaultPerpetualMarket2), + ]); + await perpetualMarketRefresher.updatePerpetualMarkets(); const blockTransactionIndex: number = -1; + const transactionIndex: number = 0; + const eventIndex: number = 0; const events: IndexerTendermintEvent[] = [ + // MARKET is a transaction event. createIndexerTendermintEvent( - DydxIndexerSubtypes.SUBACCOUNT_UPDATE, - defaultSubaccountUpdateEventBinary, + DydxIndexerSubtypes.MARKET, + defaultMarketEventBinary, transactionIndex, eventIndex, ), + // FUNDING is a block event. createIndexerTendermintEvent( - DydxIndexerSubtypes.SUBACCOUNT_UPDATE, - defaultSubaccountUpdateEventBinary, + DydxIndexerSubtypes.FUNDING, + defaultFundingEventBinary, blockTransactionIndex, eventIndex, ), @@ -621,21 +501,6 @@ describe('on-message', () => { expectTransactionWithHash([defaultTxHash]), expectBlock(defaultHeight.toString(), defaultDateTime.toISO()), ]); - - expect((SubaccountUpdateHandler as jest.Mock)).toHaveBeenCalledTimes(1); - expect((SubaccountUpdateHandler as jest.Mock)).toHaveBeenNthCalledWith( - 1, - block, - events[0], - expect.any(Number), - defaultSubaccountUpdateEvent, - ); - expect(stats.increment).toHaveBeenCalledWith('ender.received_kafka_message', 1); - expect(stats.timing).toHaveBeenCalledWith( - 'ender.message_time_in_queue', expect.any(Number), 1, { topic: KafkaTopics.TO_ENDER }); - expect(stats.gauge).toHaveBeenCalledWith('ender.processing_block_height', expect.any(Number)); - expect(stats.timing).toHaveBeenCalledWith('ender.processed_block.timing', - expect.any(Number), 1, { success: 'true' }); }); it('successfully processes block with multiple transactions', async () => { @@ -686,28 +551,6 @@ describe('on-message', () => { expectBlock(defaultHeight.toString(), defaultDateTime.toISO()), ]); - expect((SubaccountUpdateHandler as jest.Mock)).toHaveBeenCalledTimes(3); - expect((SubaccountUpdateHandler as jest.Mock)).toHaveBeenNthCalledWith( - 1, - block, - events[0], - expect.any(Number), - defaultSubaccountUpdateEvent, - ); - expect((SubaccountUpdateHandler as jest.Mock)).toHaveBeenNthCalledWith( - 2, - block, - events[1], - expect.any(Number), - defaultSubaccountUpdateEvent, - ); - expect((SubaccountUpdateHandler as jest.Mock)).toHaveBeenNthCalledWith( - 3, - block, - events[2], - expect.any(Number), - defaultSubaccountUpdateEvent, - ); expect(stats.increment).toHaveBeenCalledWith('ender.received_kafka_message', 1); expect(stats.timing).toHaveBeenCalledWith( 'ender.message_time_in_queue', expect.any(Number), 1, { topic: KafkaTopics.TO_ENDER }); @@ -715,14 +558,17 @@ describe('on-message', () => { expect(stats.timing).toHaveBeenCalledWith('ender.processed_block.timing', expect.any(Number), 1, { success: 'true' }); }); - it('successfully batches up kafka messages', async () => { + await Promise.all([ + MarketTable.create(testConstants.defaultMarket), + AssetTable.create(testConstants.defaultAsset), + ]); const transactionIndex: number = 0; const eventIndex: number = 0; const events: IndexerTendermintEvent[] = [ createIndexerTendermintEvent( - DydxIndexerSubtypes.SUBACCOUNT_UPDATE, - defaultSubaccountUpdateEventBinary, + DydxIndexerSubtypes.TRANSFER, + defaultTransferEventBinary, transactionIndex, eventIndex, ), @@ -737,26 +583,7 @@ describe('on-message', () => { const binaryBlock: Uint8Array = Uint8Array.from(IndexerTendermintBlock.encode(block).finish()); const kafkaMessage: KafkaMessage = createKafkaMessage(Buffer.from(binaryBlock)); - // Mock the return of kafka messages that in total have size > max message size in bytes - const kafkaMessages: ConsolidatedKafkaEvent[] = []; - let totalSizeBytes: number = 0; - const subaccountByteChange: number = Buffer.from( - Uint8Array.from(SubaccountMessage.encode(defaultSubaccountMessage).finish()), - ).byteLength; - while (totalSizeBytes <= config.KAFKA_MAX_BATCH_WEBSOCKET_MESSAGE_SIZE_BYTES) { - kafkaMessages.push({ - topic: KafkaTopics.TO_WEBSOCKETS_SUBACCOUNTS, - message: defaultSubaccountMessage, - }); - totalSizeBytes += subaccountByteChange; - } - - (SubaccountUpdateHandler as jest.Mock).mockReturnValue({ - handle: () => kafkaMessages, - validate: () => null, - getParallelizationIds: () => [], - }); - + config.KAFKA_MAX_BATCH_WEBSOCKET_MESSAGE_SIZE_BYTES = 1; await onMessage(kafkaMessage); await Promise.all([ expectTendermintEvent(defaultHeight.toString(), transactionIndex, eventIndex), @@ -765,9 +592,9 @@ describe('on-message', () => { ]); expect(producerSendMock).toHaveBeenCalledTimes(2); - // First message sent should contain all but 1 of the message buffers - expect(producerSendMock.mock.calls[0][0].messages).toHaveLength(kafkaMessages.length - 1); - // Second message sent should contain just a single message buffer + // First message batch sent should contain the first message + expect(producerSendMock.mock.calls[0][0].messages).toHaveLength(1); + // Second message batch should contain the second message expect(producerSendMock.mock.calls[1][0].messages).toHaveLength(1); expect(stats.increment).toHaveBeenCalledWith('ender.received_kafka_message', 1); @@ -810,12 +637,6 @@ describe('on-message', () => { totalSizeBytes += subaccountByteChange; } - (SubaccountUpdateHandler as jest.Mock).mockReturnValue({ - handle: () => kafkaMessages, - validate: () => null, - getParallelizationIds: () => [], - }); - config.SEND_WEBSOCKET_MESSAGES = false; await onMessage(kafkaMessage); await Promise.all([ @@ -892,16 +713,6 @@ describe('on-message', () => { // Initialize assetRefresher await assetRefresher.updateAssets(); await perpetualMarketRefresher.updatePerpetualMarkets(); - (SubaccountUpdateHandler as jest.Mock).mockReturnValue({ - handle: () => { - // clear cache so we can confirm that the cache is updated after the error - assetRefresher.clear(); - perpetualMarketRefresher.clear(); - throw new Error(); - }, - validate: () => null, - getParallelizationIds: () => [], - }); await onMessage(kafkaMessage); expect(assetRefresher.getAssetsMap()).not.toEqual({}); diff --git a/indexer/services/ender/__tests__/lib/sync-handlers.test.ts b/indexer/services/ender/__tests__/lib/sync-handlers.test.ts index f68f6a0f97..a3ebc6761c 100644 --- a/indexer/services/ender/__tests__/lib/sync-handlers.test.ts +++ b/indexer/services/ender/__tests__/lib/sync-handlers.test.ts @@ -1,155 +1,42 @@ import { SyncHandlers } from '../../src/lib/sync-handlers'; -import { - AssetCreateEventV1, - IndexerTendermintBlock, - IndexerTendermintEvent, - MarketEventV1, -} from '@dydxprotocol-indexer/v4-protos'; -import { createIndexerTendermintBlock, createIndexerTendermintEvent } from '../helpers/indexer-proto-helpers'; -import { - defaultAssetCreateEvent, - defaultDateTime, - defaultMarketCreate, - defaultTime, - defaultTxHash, -} from '../helpers/constants'; import { DydxIndexerSubtypes } from '../../src/lib/types'; -import { AssetCreationHandler } from '../../src/handlers/asset-handler'; -import { MarketCreateHandler } from '../../src/handlers/markets/market-create-handler'; -import { - AssetColumns, - AssetFromDatabase, - AssetTable, - BlockTable, - dbHelpers, - MarketColumns, - MarketFromDatabase, - MarketTable, - Ordering, - TendermintEventTable, - Transaction, -} from '@dydxprotocol-indexer/postgres'; import { KafkaPublisher } from '../../src/lib/kafka-publisher'; -import { createPostgresFunctions } from '../../src/helpers/postgres/postgres-functions'; - -const defaultMarketEventBinary: Uint8Array = Uint8Array.from(MarketEventV1.encode( - defaultMarketCreate, -).finish()); - -const defaultAssetEventBinary: Uint8Array = Uint8Array.from(AssetCreateEventV1.encode( - defaultAssetCreateEvent, -).finish()); +import * as pg from 'pg'; +import { mock, MockProxy } from 'jest-mock-extended'; +import { Handler } from '../../src/handlers/handler'; describe('syncHandler', () => { - const defaultTransactionIndex: number = 0; - const defaultMarketEvent: IndexerTendermintEvent = createIndexerTendermintEvent( - DydxIndexerSubtypes.MARKET, - defaultMarketEventBinary, - defaultTransactionIndex, - 0, - ); - - const defaultAssetEvent: IndexerTendermintEvent = createIndexerTendermintEvent( - DydxIndexerSubtypes.ASSET, - defaultAssetEventBinary, - defaultTransactionIndex, - 1, - ); - - const block: IndexerTendermintBlock = createIndexerTendermintBlock( - 1, - defaultTime, - [defaultMarketEvent, defaultAssetEvent], - [defaultTxHash], - ); - describe('addHandler/process', () => { - beforeAll(async () => { - await createPostgresFunctions(); - }); - - beforeEach(async () => { - await BlockTable.create({ - blockHeight: '1', - time: defaultDateTime.toISO(), - }); - await Promise.all([ - TendermintEventTable.create({ - blockHeight: '1', - transactionIndex: defaultTransactionIndex, - eventIndex: 0, - }), - TendermintEventTable.create({ - blockHeight: '1', - transactionIndex: defaultTransactionIndex, - eventIndex: 1, - }), - ]); - }); - - afterEach(async () => { - await dbHelpers.clearData(); - }); - - afterAll(async () => { - await dbHelpers.teardown(); - }); - it('successfully adds handler', async () => { - const synchHandlers: SyncHandlers = new SyncHandlers(); - const txId: number = await Transaction.start(); - const assetHandler = new AssetCreationHandler( - block, - defaultAssetEvent, - txId, - defaultAssetCreateEvent, - ); + const firstHandler: MockProxy> = mock>(); + firstHandler.blockEventIndex = 0; + const secondHandler: MockProxy> = mock>(); + secondHandler.blockEventIndex = 1; + const handlerNotInvoked: MockProxy> = mock>(); + handlerNotInvoked.blockEventIndex = 2; + const syncHandlers: SyncHandlers = new SyncHandlers(); - const marketHandler = new MarketCreateHandler( - block, - defaultMarketEvent, - txId, - defaultMarketCreate, - ); // handlers are processed in the order in which they are received. - synchHandlers.addHandler(DydxIndexerSubtypes.MARKET, marketHandler); - synchHandlers.addHandler(DydxIndexerSubtypes.ASSET, assetHandler); + syncHandlers.addHandler(DydxIndexerSubtypes.MARKET, firstHandler); + syncHandlers.addHandler(DydxIndexerSubtypes.ASSET, secondHandler); // should be ignored, because transfers are not handled by syncHandlers - synchHandlers.addHandler(DydxIndexerSubtypes.TRANSFER, assetHandler); - - const assets: AssetFromDatabase[] = await AssetTable.findAll( - {}, - [], { - orderBy: [[AssetColumns.id, Ordering.ASC]], - }); + syncHandlers.addHandler(DydxIndexerSubtypes.TRANSFER, handlerNotInvoked); - expect(assets.length).toEqual(0); - const markets: MarketFromDatabase[] = await MarketTable.findAll( - {}, - [], { - orderBy: [[MarketColumns.id, Ordering.ASC]], - }); - - expect(markets.length).toEqual(0); + const resultRow: pg.QueryResultRow = [ + 'forFirstHandler', + 'forSecondHandler', + 'forNotInvokedHandler', + ]; const kafkaPublisher: KafkaPublisher = new KafkaPublisher(); - await synchHandlers.process(kafkaPublisher); - await Transaction.commit(txId); - - // check that assets/markets are populated - const newAssets: AssetFromDatabase[] = await AssetTable.findAll( - {}, - [], { - orderBy: [[AssetColumns.id, Ordering.ASC]], - }); - - expect(newAssets.length).toEqual(1); - const newMarkets: MarketFromDatabase[] = await MarketTable.findAll( - {}, - [], { - orderBy: [[MarketColumns.id, Ordering.ASC]], - }); - - expect(newMarkets.length).toEqual(1); + await syncHandlers.process(kafkaPublisher, resultRow); + + expect(firstHandler.handle).toHaveBeenCalledWith('forFirstHandler'); + expect(firstHandler.handle).toHaveBeenCalledTimes(1); + expect(secondHandler.handle).toHaveBeenCalledWith('forSecondHandler'); + expect(secondHandler.handle).toHaveBeenCalledTimes(1); + expect(firstHandler.handle.mock.invocationCallOrder[0]).toBeLessThan( + secondHandler.handle.mock.invocationCallOrder[0]); + expect(handlerNotInvoked.handle).toHaveBeenCalledTimes(0); }); }); }); diff --git a/indexer/services/ender/__tests__/scripts/scripts.test.ts b/indexer/services/ender/__tests__/scripts/scripts.test.ts index 37957a6405..d365dcbf17 100644 --- a/indexer/services/ender/__tests__/scripts/scripts.test.ts +++ b/indexer/services/ender/__tests__/scripts/scripts.test.ts @@ -527,7 +527,7 @@ describe('SQL Function Tests', () => { const txHashes = [defaultTxHash, defaultTxHash2]; const dateTimeIso = '2020-01-01T00:00:00.000Z'; await getSingleRawQueryResultRow( - `SELECT dydx_create_initial_rows_for_tendermint_block('${blockHeight}'::text, '${dateTimeIso}'::text, ARRAY['${txHashes.join("','")}']::text[], ARRAY['${events.map((event) => JSON.stringify(event)).join("','")}']::jsonb[])`, + `SELECT dydx_create_initial_rows_for_tendermint_block(${blockHeight}, '${dateTimeIso}', '${JSON.stringify(txHashes)}', '${JSON.stringify(events)}')`, ); // Validate blocks table const blocks = await BlockTable.findAll({}, [], { readReplica: true }); diff --git a/indexer/services/ender/__tests__/validators/asset-validator.test.ts b/indexer/services/ender/__tests__/validators/asset-validator.test.ts index c093150713..20ebf73945 100644 --- a/indexer/services/ender/__tests__/validators/asset-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/asset-validator.test.ts @@ -28,6 +28,7 @@ describe('asset-validator', () => { const validator: AssetValidator = new AssetValidator( defaultAssetCreateEvent, createBlock(defaultAssetCreateEvent), + 0, ); validator.validate(); diff --git a/indexer/services/ender/__tests__/validators/deleveraging-validator.test.ts b/indexer/services/ender/__tests__/validators/deleveraging-validator.test.ts index 93dc4347d6..5529a45aca 100644 --- a/indexer/services/ender/__tests__/validators/deleveraging-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/deleveraging-validator.test.ts @@ -22,6 +22,7 @@ describe('deleveraging-validator', () => { const validator: DeleveragingValidator = new DeleveragingValidator( defaultDeleveragingEvent, createBlock(defaultDeleveragingEvent), + 0, ); validator.validate(); @@ -49,6 +50,7 @@ describe('deleveraging-validator', () => { const validator: DeleveragingValidator = new DeleveragingValidator( event, createBlock(event), + 0, ); expect(() => validator.validate()).toThrow(new ParseMessageError(message)); diff --git a/indexer/services/ender/__tests__/validators/funding-validator.test.ts b/indexer/services/ender/__tests__/validators/funding-validator.test.ts index 907e8140b6..3d91fbe009 100644 --- a/indexer/services/ender/__tests__/validators/funding-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/funding-validator.test.ts @@ -42,6 +42,7 @@ describe('funding-validator', () => { const validator: FundingValidator = new FundingValidator( event, createBlock(event), + 0, ); validator.validate(); @@ -83,6 +84,7 @@ describe('funding-validator', () => { const validator: FundingValidator = new FundingValidator( event, createBlock(event), + 0, ); expect(() => validator.validate()).toThrow(new ParseMessageError(message)); diff --git a/indexer/services/ender/__tests__/validators/liquidity-tier-validator.test.ts b/indexer/services/ender/__tests__/validators/liquidity-tier-validator.test.ts index 9c7443b617..c1af377c40 100644 --- a/indexer/services/ender/__tests__/validators/liquidity-tier-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/liquidity-tier-validator.test.ts @@ -33,6 +33,7 @@ describe('liquidity-tier-validator', () => { const validator: LiquidityTierValidator = new LiquidityTierValidator( defaultLiquidityTierUpsertEvent, createBlock(defaultLiquidityTierUpsertEvent), + 0, ); validator.validate(); @@ -60,6 +61,7 @@ describe('liquidity-tier-validator', () => { const validator: LiquidityTierValidator = new LiquidityTierValidator( event, createBlock(event), + 0, ); expect(() => validator.validate()).toThrow(new ParseMessageError(expectedMessage)); }); @@ -89,6 +91,7 @@ describe('liquidity-tier-validator', () => { const validator: LiquidityTierValidator = new LiquidityTierValidator( event, createBlock(event), + 0, ); validator.validate(); expect(loggerError).toHaveBeenCalledWith(expect.objectContaining({ diff --git a/indexer/services/ender/__tests__/validators/market-validator.test.ts b/indexer/services/ender/__tests__/validators/market-validator.test.ts index 0f9abaa443..4742b95abe 100644 --- a/indexer/services/ender/__tests__/validators/market-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/market-validator.test.ts @@ -37,6 +37,7 @@ describe('market-validator', () => { const validator: MarketValidator = new MarketValidator( event, createBlock(event), + 0, ); validator.validate(); @@ -153,6 +154,7 @@ describe('market-validator', () => { const validator: MarketValidator = new MarketValidator( event, createBlock(event), + 0, ); expect(() => validator.validate()).toThrow(new ParseMessageError(message)); diff --git a/indexer/services/ender/__tests__/validators/order-fill-validator.test.ts b/indexer/services/ender/__tests__/validators/order-fill-validator.test.ts index 46e52c4e19..3cb81896b3 100644 --- a/indexer/services/ender/__tests__/validators/order-fill-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/order-fill-validator.test.ts @@ -46,6 +46,7 @@ describe('order-fill-validator', () => { const validator: OrderFillValidator = new OrderFillValidator( event, createBlock(event), + 0, ); validator.validate(); @@ -173,6 +174,7 @@ describe('order-fill-validator', () => { const validator: OrderFillValidator = new OrderFillValidator( event, createBlock(event), + 0, ); expect(() => validator.validate()).toThrow(new ParseMessageError(message)); diff --git a/indexer/services/ender/__tests__/validators/perpetual-market-validator.test.ts b/indexer/services/ender/__tests__/validators/perpetual-market-validator.test.ts index 8f6a569c43..95848824d2 100644 --- a/indexer/services/ender/__tests__/validators/perpetual-market-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/perpetual-market-validator.test.ts @@ -32,6 +32,7 @@ describe('perpetual-market-validator', () => { const validator: PerpetualMarketValidator = new PerpetualMarketValidator( defaultPerpetualMarketCreateEvent, createBlock(defaultPerpetualMarketCreateEvent), + 0, ); validator.validate(); @@ -43,6 +44,7 @@ describe('perpetual-market-validator', () => { const validator: PerpetualMarketValidator = new PerpetualMarketValidator( defaultPerpetualMarketCreateEvent, createBlock(defaultPerpetualMarketCreateEvent), + 0, ); const message: string = 'PerpetualMarketCreateEvent id already exists'; expect(() => validator.validate()).toThrow(new ParseMessageError(message)); @@ -77,6 +79,7 @@ describe('perpetual-market-validator', () => { const validator: PerpetualMarketValidator = new PerpetualMarketValidator( event, createBlock(event), + 0, ); expect(() => validator.validate()).toThrow(new ParseMessageError(expectedMessage)); }); diff --git a/indexer/services/ender/__tests__/validators/stateful-order-validator.test.ts b/indexer/services/ender/__tests__/validators/stateful-order-validator.test.ts index 38092de371..b6d074706f 100644 --- a/indexer/services/ender/__tests__/validators/stateful-order-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/stateful-order-validator.test.ts @@ -46,6 +46,7 @@ describe('stateful-order-validator', () => { const validator: StatefulOrderValidator = new StatefulOrderValidator( event, createBlock(event), + 0, ); validator.validate(); @@ -346,6 +347,7 @@ describe('stateful-order-validator', () => { const validator: StatefulOrderValidator = new StatefulOrderValidator( event, createBlock(event), + 0, ); expect(() => validator.validate()).toThrow(new ParseMessageError(message)); diff --git a/indexer/services/ender/__tests__/validators/subaccount-update-validator.test.ts b/indexer/services/ender/__tests__/validators/subaccount-update-validator.test.ts index a851a96bb1..bac021ef47 100644 --- a/indexer/services/ender/__tests__/validators/subaccount-update-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/subaccount-update-validator.test.ts @@ -27,6 +27,7 @@ describe('subaccount-update-validator', () => { const validator: SubaccountUpdateValidator = new SubaccountUpdateValidator( defaultEmptySubaccountUpdateEvent, createBlock(defaultEmptySubaccountUpdateEvent), + 0, ); validator.validate(); @@ -41,6 +42,7 @@ describe('subaccount-update-validator', () => { const validator: SubaccountUpdateValidator = new SubaccountUpdateValidator( invalidEvent, createBlock(invalidEvent), + 0, ); const message: string = 'SubaccountUpdateEvent must contain a subaccountId'; diff --git a/indexer/services/ender/__tests__/validators/transfer-validator.test.ts b/indexer/services/ender/__tests__/validators/transfer-validator.test.ts index 4d5085ba37..ca27198281 100644 --- a/indexer/services/ender/__tests__/validators/transfer-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/transfer-validator.test.ts @@ -31,6 +31,7 @@ describe('transfer-validator', () => { const validator: TransferValidator = new TransferValidator( defaultTransferEvent, createBlock(defaultTransferEvent), + 0, ); validator.validate(); @@ -93,6 +94,7 @@ describe('transfer-validator', () => { const validator: TransferValidator = new TransferValidator( event, createBlock(event), + 0, ); expect(() => validator.validate()).toThrow(new ParseMessageError(message)); diff --git a/indexer/services/ender/__tests__/validators/update-clob-pair-validator.test.ts b/indexer/services/ender/__tests__/validators/update-clob-pair-validator.test.ts index 4fe4fe46e4..7b2b841f44 100644 --- a/indexer/services/ender/__tests__/validators/update-clob-pair-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/update-clob-pair-validator.test.ts @@ -47,6 +47,7 @@ describe('update-clob-pair-validator', () => { const validator: UpdateClobPairValidator = new UpdateClobPairValidator( defaultUpdateClobPairEvent, createBlock(defaultUpdateClobPairEvent), + 0, ); validator.validate(); @@ -60,6 +61,7 @@ describe('update-clob-pair-validator', () => { clobPairId: 20, }, createBlock(defaultUpdateClobPairEvent), + 0, ); expect(() => validator.validate()).toThrow(new ParseMessageError( diff --git a/indexer/services/ender/__tests__/validators/update-perpetual-validator.test.ts b/indexer/services/ender/__tests__/validators/update-perpetual-validator.test.ts index c7ca30bb80..8ba7128494 100644 --- a/indexer/services/ender/__tests__/validators/update-perpetual-validator.test.ts +++ b/indexer/services/ender/__tests__/validators/update-perpetual-validator.test.ts @@ -47,6 +47,7 @@ describe('update-perpetual-validator', () => { const validator: UpdatePerpetualValidator = new UpdatePerpetualValidator( defaultUpdatePerpetualEvent, createBlock(defaultUpdatePerpetualEvent), + 0, ); validator.validate(); @@ -60,6 +61,7 @@ describe('update-perpetual-validator', () => { id: 20, }, createBlock(defaultUpdatePerpetualEvent), + 0, ); expect(() => validator.validate()).toThrow(new ParseMessageError( diff --git a/indexer/services/ender/src/handlers/abstract-stateful-order-handler.ts b/indexer/services/ender/src/handlers/abstract-stateful-order-handler.ts index e2dfb35283..7d275d5743 100644 --- a/indexer/services/ender/src/handlers/abstract-stateful-order-handler.ts +++ b/indexer/services/ender/src/handlers/abstract-stateful-order-handler.ts @@ -1,18 +1,3 @@ -import { logger } from '@dydxprotocol-indexer/base'; -import { - OrderFromDatabase, - PerpetualMarketFromDatabase, - storeHelpers, - OrderModel, - PerpetualMarketModel, - SubaccountFromDatabase, -} from '@dydxprotocol-indexer/postgres'; -import SubaccountModel from '@dydxprotocol-indexer/postgres/build/src/models/subaccount-model'; -import { - StatefulOrderEventV1, -} from '@dydxprotocol-indexer/v4-protos'; -import * as pg from 'pg'; - import { STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE } from '../constants'; import { Handler } from './handler'; @@ -25,35 +10,4 @@ export abstract class AbstractStatefulOrderHandler extends Handler { `${STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE}_${orderId}`, ]; } - - protected async handleEventViaSqlFunction(): - Promise<[OrderFromDatabase, - PerpetualMarketFromDatabase, - SubaccountFromDatabase | undefined]> { - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const result: pg.QueryResult = await storeHelpers.rawQuery( - `SELECT dydx_stateful_order_handler( - ${this.block.height}, - '${this.block.time?.toISOString()}', - '${JSON.stringify(StatefulOrderEventV1.decode(eventDataBinary))}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'AbstractStatefulOrderHandler#handleEventViaSqlFunction', - message: 'Failed to handle StatefulOrderEventV1', - error, - }); - throw error; - }); - - return [ - OrderModel.fromJson(result.rows[0].result.order) as OrderFromDatabase, - PerpetualMarketModel.fromJson( - result.rows[0].result.perpetual_market) as PerpetualMarketFromDatabase, - result.rows[0].result.subaccount - ? SubaccountModel.fromJson(result.rows[0].result.subaccount) as SubaccountFromDatabase - : undefined, - ]; - } } diff --git a/indexer/services/ender/src/handlers/asset-handler.ts b/indexer/services/ender/src/handlers/asset-handler.ts index 70c488e9d5..b505f6af5c 100644 --- a/indexer/services/ender/src/handlers/asset-handler.ts +++ b/indexer/services/ender/src/handlers/asset-handler.ts @@ -1,9 +1,7 @@ -import { logger } from '@dydxprotocol-indexer/base'; import { AssetFromDatabase, AssetModel, assetRefresher, - storeHelpers, } from '@dydxprotocol-indexer/postgres'; import { AssetCreateEventV1 } from '@dydxprotocol-indexer/v4-protos'; import * as pg from 'pg'; @@ -19,25 +17,9 @@ export class AssetCreationHandler extends Handler { } // eslint-disable-next-line @typescript-eslint/require-await - public async internalHandle(): Promise { - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const result: pg.QueryResult = await storeHelpers.rawQuery( - `SELECT dydx_asset_create_handler( - '${JSON.stringify(AssetCreateEventV1.decode(eventDataBinary))}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'AssetCreationHandler#internalHandle', - message: 'Failed to handle AssetCreateEventV1', - error, - }); - - throw error; - }); - + public async internalHandle(resultRow: pg.QueryResultRow): Promise { const asset: AssetFromDatabase = AssetModel.fromJson( - result.rows[0].result.asset) as AssetFromDatabase; + resultRow.asset) as AssetFromDatabase; assetRefresher.addAsset(asset); return []; } diff --git a/indexer/services/ender/src/handlers/funding-handler.ts b/indexer/services/ender/src/handlers/funding-handler.ts index 454c91223c..772ae562a0 100644 --- a/indexer/services/ender/src/handlers/funding-handler.ts +++ b/indexer/services/ender/src/handlers/funding-handler.ts @@ -4,12 +4,10 @@ import { PerpetualMarketFromDatabase, TendermintEventTable, protocolTranslations, - storeHelpers, PerpetualMarketModel, } from '@dydxprotocol-indexer/postgres'; import { NextFundingCache } from '@dydxprotocol-indexer/redis'; import { - FundingEventV1, FundingEventV1_Type, FundingUpdateV1, } from '@dydxprotocol-indexer/v4-protos'; @@ -49,33 +47,10 @@ export class FundingHandler extends Handler { } // eslint-disable-next-line @typescript-eslint/require-await - public async internalHandle(): Promise { - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const transactionIndex: number = indexerTendermintEventToTransactionIndex( - this.indexerTendermintEvent, - ); - const result: pg.QueryResult = await storeHelpers.rawQuery( - `SELECT dydx_funding_handler( - ${this.block.height}, - '${this.block.time?.toISOString()}', - '${JSON.stringify(FundingEventV1.decode(eventDataBinary))}', - ${this.indexerTendermintEvent.eventIndex}, - ${transactionIndex} - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'FundingHandler#internalHandle', - message: 'Failed to handle FundingEventV1', - error, - }); - - throw error; - }); - + public async internalHandle(resultRow: pg.QueryResultRow): Promise { const perpetualMarkets: Map = new Map(); - for (const [key, perpetualMarket] of Object.entries(result.rows[0].result.perpetual_markets)) { + for (const [key, perpetualMarket] of Object.entries(resultRow.perpetual_markets)) { perpetualMarkets.set( key, PerpetualMarketModel.fromJson(perpetualMarket as object) as PerpetualMarketFromDatabase, @@ -86,10 +61,10 @@ export class FundingHandler extends Handler { for (let i: number = 0; i < this.event.updates.length; i++) { const update: FundingUpdateV1 = this.event.updates[i]; - if (result.rows[0].result.errors[i] != null) { + if (resultRow.errors[i] != null) { logger.error({ at: 'FundingHandler#handleFundingSample', - message: result.rows[0].result.errors[i], + message: resultRow.errors[i], update, }); continue; diff --git a/indexer/services/ender/src/handlers/handler.ts b/indexer/services/ender/src/handlers/handler.ts index 95fa0a54a7..51362c9965 100644 --- a/indexer/services/ender/src/handlers/handler.ts +++ b/indexer/services/ender/src/handlers/handler.ts @@ -19,6 +19,7 @@ import { SubaccountId, } from '@dydxprotocol-indexer/v4-protos'; import { DateTime } from 'luxon'; +import * as pg from 'pg'; import config from '../config'; import { indexerTendermintEventToTransactionIndex } from '../lib/helper'; @@ -28,6 +29,7 @@ import { export type HandlerInitializer = new ( block: IndexerTendermintBlock, + blockEventIndex: number, indexerTendermintEvent: IndexerTendermintEvent, txId: number, event: EventMessage, @@ -43,16 +45,20 @@ export abstract class Handler { indexerTendermintEvent: IndexerTendermintEvent; timestamp: DateTime; txId: number; + // The index of the event in the block. + blockEventIndex: number; event: T; abstract eventType: string; constructor( block: IndexerTendermintBlock, + blockEventIndex: number, indexerTendermintEvent: IndexerTendermintEvent, txId: number, event: T, ) { this.block = block; + this.blockEventIndex = blockEventIndex; this.indexerTendermintEvent = indexerTendermintEvent; this.timestamp = DateTime.fromJSDate(block.time!); this.txId = txId; @@ -66,19 +72,21 @@ export abstract class Handler { public abstract getParallelizationIds(): string[]; /** - * Processes the event and updates Postgres in the transaction specified by - * txId provided in the constructor, then returns all consolidated kafka events to be - * written to Kafka. + * Performs side effects based upon the results returned from the SQL based handler + * implementations and then returns all consolidated Kafka events to be written to Kafka. */ - public abstract internalHandle(): Promise; + public abstract internalHandle(resultRow: pg.QueryResultRow): Promise; /** - * Handle the event and export timing stats + * Performs side effects based upon the results returned from the SQL based handler + * implementations and then returns all consolidated Kafka events to be written to Kafka. + * + * Wraps internalHandle with timing information. */ - public async handle(): Promise { + public async handle(resultRow: pg.QueryResultRow): Promise { const start: number = Date.now(); try { - return await this.internalHandle(); + return await this.internalHandle(resultRow); } finally { stats.timing( `${config.SERVICE_NAME}.handle_event.timing`, diff --git a/indexer/services/ender/src/handlers/liquidity-tier-handler.ts b/indexer/services/ender/src/handlers/liquidity-tier-handler.ts index 1e77d46b2b..2c89d9f66f 100644 --- a/indexer/services/ender/src/handlers/liquidity-tier-handler.ts +++ b/indexer/services/ender/src/handlers/liquidity-tier-handler.ts @@ -1,11 +1,9 @@ -import { logger } from '@dydxprotocol-indexer/base'; import { LiquidityTiersFromDatabase, LiquidityTiersModel, PerpetualMarketFromDatabase, liquidityTierRefresher, perpetualMarketRefresher, - storeHelpers, } from '@dydxprotocol-indexer/postgres'; import { LiquidityTierUpsertEventV1 } from '@dydxprotocol-indexer/v4-protos'; import _ from 'lodash'; @@ -23,25 +21,9 @@ export class LiquidityTierHandler extends Handler { } // eslint-disable-next-line @typescript-eslint/require-await - public async internalHandle(): Promise { - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const result: pg.QueryResult = await storeHelpers.rawQuery( - `SELECT dydx_liquidity_tier_handler( - '${JSON.stringify(LiquidityTierUpsertEventV1.decode(eventDataBinary))}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'LiquidityTierHandler#internalHandle', - message: 'Failed to handle LiquidityTierUpsertEventV1', - error, - }); - - throw error; - }); - + public async internalHandle(resultRow: pg.QueryResultRow): Promise { const liquidityTier: LiquidityTiersFromDatabase = LiquidityTiersModel.fromJson( - result.rows[0].result.liquidity_tier) as LiquidityTiersFromDatabase; + resultRow.liquidity_tier) as LiquidityTiersFromDatabase; liquidityTierRefresher.upsertLiquidityTier(liquidityTier); return this.generateWebsocketEventsForLiquidityTier(liquidityTier); } diff --git a/indexer/services/ender/src/handlers/markets/market-create-handler.ts b/indexer/services/ender/src/handlers/markets/market-create-handler.ts index 77be14834e..6f539e3665 100644 --- a/indexer/services/ender/src/handlers/markets/market-create-handler.ts +++ b/indexer/services/ender/src/handlers/markets/market-create-handler.ts @@ -1,10 +1,8 @@ import { logger } from '@dydxprotocol-indexer/base'; -import { - storeHelpers, -} from '@dydxprotocol-indexer/postgres'; import { MarketEventV1 } from '@dydxprotocol-indexer/v4-protos'; +import * as pg from 'pg'; -import { ConsolidatedKafkaEvent, MarketCreateEventMessage } from '../../lib/types'; +import { ConsolidatedKafkaEvent } from '../../lib/types'; import { Handler } from '../handler'; export class MarketCreateHandler extends Handler { @@ -15,37 +13,14 @@ export class MarketCreateHandler extends Handler { return [`${this.eventType}_${this.event.marketId}`]; } - public async internalHandle(): Promise { + // eslint-disable-next-line @typescript-eslint/require-await + public async internalHandle(_: pg.QueryResultRow): Promise { logger.info({ at: 'MarketCreateHandler#handle', message: 'Received MarketEvent with MarketCreate.', event: this.event, }); - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - await storeHelpers.rawQuery( - `SELECT dydx_market_create_handler( - '${JSON.stringify(MarketEventV1.decode(eventDataBinary))}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'MarketCreateHandler#internalHandle', - message: 'Failed to handle MarketEventV1', - error, - }); - - if (error.message.includes('Market in MarketCreate already exists')) { - const marketCreate: MarketCreateEventMessage = this.event as MarketCreateEventMessage; - this.logAndThrowParseMessageError( - 'Market in MarketCreate already exists', - { marketCreate }, - ); - } - - throw error; - }); - return []; } } diff --git a/indexer/services/ender/src/handlers/markets/market-modify-handler.ts b/indexer/services/ender/src/handlers/markets/market-modify-handler.ts index 33f5c963c3..eeee9188e3 100644 --- a/indexer/services/ender/src/handlers/markets/market-modify-handler.ts +++ b/indexer/services/ender/src/handlers/markets/market-modify-handler.ts @@ -1,8 +1,8 @@ import { logger } from '@dydxprotocol-indexer/base'; -import { storeHelpers } from '@dydxprotocol-indexer/postgres'; import { MarketEventV1 } from '@dydxprotocol-indexer/v4-protos'; +import * as pg from 'pg'; -import { ConsolidatedKafkaEvent, MarketModifyEventMessage } from '../../lib/types'; +import { ConsolidatedKafkaEvent } from '../../lib/types'; import { Handler } from '../handler'; export class MarketModifyHandler extends Handler { @@ -13,42 +13,14 @@ export class MarketModifyHandler extends Handler { return [`${this.eventType}_${this.event.marketId}`]; } - public async internalHandle(): Promise { + // eslint-disable-next-line @typescript-eslint/require-await + public async internalHandle(_: pg.QueryResultRow): Promise { logger.info({ at: 'MarketModifyHandler#handle', - message: 'Received MarketEvent with MarketCreate.', + message: 'Received MarketEvent with MarketModify.', event: this.event, }); - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - await storeHelpers.rawQuery( - `SELECT dydx_market_modify_handler( - '${JSON.stringify(MarketEventV1.decode(eventDataBinary))}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'MarketModifyHandler#internalHandle', - message: 'Failed to handle MarketEventV1', - error, - }); - - const castedMarketModifyMessage: - MarketModifyEventMessage = this.event as MarketModifyEventMessage; - - if (error.message.includes('Market in MarketModify doesn\'t exist')) { - this.logAndThrowParseMessageError( - 'Market in MarketModify doesn\'t exist', - { castedMarketModifyMessage }, - ); - } - - this.logAndThrowParseMessageError( - 'Failed to update market in markets table', - { castedMarketModifyMessage }, - ); - }); - return []; } } diff --git a/indexer/services/ender/src/handlers/markets/market-price-update-handler.ts b/indexer/services/ender/src/handlers/markets/market-price-update-handler.ts index 4e3ddfd9dd..56c9978fd9 100644 --- a/indexer/services/ender/src/handlers/markets/market-price-update-handler.ts +++ b/indexer/services/ender/src/handlers/markets/market-price-update-handler.ts @@ -3,7 +3,7 @@ import { MarketFromDatabase, OraclePriceFromDatabase, OraclePriceModel, - MarketMessageContents, storeHelpers, MarketModel, + MarketMessageContents, MarketModel, } from '@dydxprotocol-indexer/postgres'; import { MarketEventV1 } from '@dydxprotocol-indexer/v4-protos'; import * as pg from 'pg'; @@ -11,7 +11,6 @@ import * as pg from 'pg'; import { generateOraclePriceContents } from '../../helpers/kafka-helper'; import { ConsolidatedKafkaEvent, - MarketPriceUpdateEventMessage, } from '../../lib/types'; import { Handler } from '../handler'; @@ -23,44 +22,18 @@ export class MarketPriceUpdateHandler extends Handler { return [`${this.eventType}_${this.event.marketId}`]; } - public async internalHandle(): Promise { + // eslint-disable-next-line @typescript-eslint/require-await + public async internalHandle(resultRow: pg.QueryResultRow): Promise { logger.info({ at: 'MarketPriceUpdateHandler#handle', message: 'Received MarketEvent with MarketPriceUpdate.', event: this.event, }); - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const result: pg.QueryResult = await storeHelpers.rawQuery( - `SELECT dydx_market_price_update_handler( - ${this.block.height}, - '${this.block.time?.toISOString()}', - '${JSON.stringify(MarketEventV1.decode(eventDataBinary))}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'MarketPriceUpdateHandler#internalHandle', - message: 'Failed to handle MarketEventV1', - error, - }); - - if (error.message.includes('MarketPriceUpdateEvent contains a non-existent market id')) { - const castedMarketPriceUpdateMessage: - MarketPriceUpdateEventMessage = this.event as MarketPriceUpdateEventMessage; - this.logAndThrowParseMessageError( - 'MarketPriceUpdateEvent contains a non-existent market id', - { castedMarketPriceUpdateMessage }, - ); - } - - throw error; - }); - const market: MarketFromDatabase = MarketModel.fromJson( - result.rows[0].result.market) as MarketFromDatabase; + resultRow.market) as MarketFromDatabase; const oraclePrice: OraclePriceFromDatabase = OraclePriceModel.fromJson( - result.rows[0].result.oracle_price) as OraclePriceFromDatabase; + resultRow.oracle_price) as OraclePriceFromDatabase; return [ this.generateKafkaEvent( diff --git a/indexer/services/ender/src/handlers/order-fills/deleveraging-handler.ts b/indexer/services/ender/src/handlers/order-fills/deleveraging-handler.ts index 2c8dbd2dc1..712779a6a7 100644 --- a/indexer/services/ender/src/handlers/order-fills/deleveraging-handler.ts +++ b/indexer/services/ender/src/handlers/order-fills/deleveraging-handler.ts @@ -7,14 +7,12 @@ import { perpetualMarketRefresher, PerpetualPositionFromDatabase, PerpetualPositionModel, - storeHelpers, SubaccountTable, } from '@dydxprotocol-indexer/postgres'; import { DeleveragingEventV1 } from '@dydxprotocol-indexer/v4-protos'; import * as pg from 'pg'; import { SUBACCOUNT_ORDER_FILL_EVENT_TYPE } from '../../constants'; -import { indexerTendermintEventToTransactionIndex } from '../../lib/helper'; import { ConsolidatedKafkaEvent } from '../../lib/types'; import { AbstractOrderFillHandler } from './abstract-order-fill-handler'; @@ -48,41 +46,19 @@ export class DeleveragingHandler extends AbstractOrderFillHandler { - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const transactionIndex: number = indexerTendermintEventToTransactionIndex( - this.indexerTendermintEvent, - ); - const result: pg.QueryResult = await storeHelpers.rawQuery( - `SELECT dydx_deleveraging_handler( - ${this.block.height}, - '${this.block.time?.toISOString()}', - '${JSON.stringify(DeleveragingEventV1.decode(eventDataBinary))}', - ${this.indexerTendermintEvent.eventIndex}, - ${transactionIndex}, - '${this.block.txHashes[transactionIndex]}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'DeleveragingHandler#internalHandle', - message: 'Failed to handle DeleveragingEventV1', - error, - }); - throw error; - }); + public async internalHandle(resultRow: pg.QueryResultRow): Promise { const liquidatedFill: FillFromDatabase = FillModel.fromJson( - result.rows[0].result.liquidated_fill) as FillFromDatabase; + resultRow.liquidated_fill) as FillFromDatabase; const offsettingFill: FillFromDatabase = FillModel.fromJson( - result.rows[0].result.offsetting_fill) as FillFromDatabase; + resultRow.offsetting_fill) as FillFromDatabase; const perpetualMarket: PerpetualMarketFromDatabase = PerpetualMarketModel.fromJson( - result.rows[0].result.perpetual_market) as PerpetualMarketFromDatabase; + resultRow.perpetual_market) as PerpetualMarketFromDatabase; const liquidatedPerpetualPosition: PerpetualPositionFromDatabase = PerpetualPositionModel.fromJson( - result.rows[0].result.liquidated_perpetual_position) as PerpetualPositionFromDatabase; + resultRow.liquidated_perpetual_position) as PerpetualPositionFromDatabase; const offsettingPerpetualPosition: PerpetualPositionFromDatabase = PerpetualPositionModel.fromJson( - result.rows[0].result.offsetting_perpetual_position) as PerpetualPositionFromDatabase; + resultRow.offsetting_perpetual_position) as PerpetualPositionFromDatabase; const kafkaEvents: ConsolidatedKafkaEvent[] = [ this.generateConsolidatedKafkaEvent( this.event.liquidated!, diff --git a/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts b/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts index 83bf565f6f..4b9b7efb99 100644 --- a/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts +++ b/indexer/services/ender/src/handlers/order-fills/liquidation-handler.ts @@ -1,4 +1,3 @@ -import { logger } from '@dydxprotocol-indexer/base'; import { FillFromDatabase, FillModel, @@ -10,15 +9,13 @@ import { PerpetualMarketModel, PerpetualPositionFromDatabase, PerpetualPositionModel, - storeHelpers, SubaccountTable, - USDC_ASSET_ID, - OrderStatus, FillType, + OrderStatus, } from '@dydxprotocol-indexer/postgres'; import { StateFilledQuantumsCache } from '@dydxprotocol-indexer/redis'; import { isStatefulOrder } from '@dydxprotocol-indexer/v4-proto-parser'; import { - LiquidationOrderV1, IndexerOrderId, OrderFillEventV1, + LiquidationOrderV1, IndexerOrderId, } from '@dydxprotocol-indexer/v4-protos'; import Long from 'long'; import * as pg from 'pg'; @@ -29,7 +26,6 @@ import { redisClient } from '../../helpers/redis/redis-controller'; import { orderFillWithLiquidityToOrderFillEventWithLiquidation, } from '../../helpers/translation-helper'; -import { indexerTendermintEventToTransactionIndex } from '../../lib/helper'; import { OrderFillWithLiquidity } from '../../lib/translated-types'; import { ConsolidatedKafkaEvent, @@ -84,56 +80,26 @@ export class LiquidationHandler extends AbstractOrderFillHandler { - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const transactionIndex: number = indexerTendermintEventToTransactionIndex( - this.indexerTendermintEvent, - ); - + public async internalHandle(resultRow: pg.QueryResultRow): Promise { const castedLiquidationFillEventMessage: OrderFillEventWithLiquidation = orderFillWithLiquidityToOrderFillEventWithLiquidation( this.event, ); const field: string = this.event.liquidity === Liquidity.MAKER ? 'makerOrder' : 'liquidationOrder'; - const fillType: string = this.event.liquidity === Liquidity.MAKER - ? FillType.LIQUIDATION : FillType.LIQUIDATED; - - const result: pg.QueryResult = await storeHelpers.rawQuery( - `SELECT dydx_liquidation_fill_handler_per_order( - '${field}', - ${this.block.height}, - '${this.block.time?.toISOString()}', - '${JSON.stringify(OrderFillEventV1.decode(eventDataBinary))}', - ${this.indexerTendermintEvent.eventIndex}, - ${transactionIndex}, - '${this.block.txHashes[transactionIndex]}', - '${this.event.liquidity}', - '${fillType}', - '${USDC_ASSET_ID}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'liquidationHandler#internalHandle', - message: 'Failed to handle OrderFillEventV1', - error, - }); - throw error; - }); const fill: FillFromDatabase = FillModel.fromJson( - result.rows[0].result.fill) as FillFromDatabase; + resultRow[field].fill) as FillFromDatabase; const perpetualMarket: PerpetualMarketFromDatabase = PerpetualMarketModel.fromJson( - result.rows[0].result.perpetual_market) as PerpetualMarketFromDatabase; + resultRow[field].perpetual_market) as PerpetualMarketFromDatabase; const position: PerpetualPositionFromDatabase = PerpetualPositionModel.fromJson( - result.rows[0].result.perpetual_position) as PerpetualPositionFromDatabase; + resultRow[field].perpetual_position) as PerpetualPositionFromDatabase; if (this.event.liquidity === Liquidity.MAKER) { // Must be done in this order, because fills refer to an order // We do not create a taker order for liquidations. const makerOrder: OrderFromDatabase = OrderModel.fromJson( - result.rows[0].result.order) as OrderFromDatabase; + resultRow[field].order) as OrderFromDatabase; // Update the cache tracking the state-filled amount per order for use in vulcan await StateFilledQuantumsCache.updateStateFilledQuantums( diff --git a/indexer/services/ender/src/handlers/order-fills/order-handler.ts b/indexer/services/ender/src/handlers/order-fills/order-handler.ts index c3be2a5b41..5b0e6198bd 100644 --- a/indexer/services/ender/src/handlers/order-fills/order-handler.ts +++ b/indexer/services/ender/src/handlers/order-fills/order-handler.ts @@ -1,4 +1,3 @@ -import { logger } from '@dydxprotocol-indexer/base'; import { FillFromDatabase, FillModel, @@ -10,15 +9,13 @@ import { PerpetualMarketModel, PerpetualPositionFromDatabase, PerpetualPositionModel, - storeHelpers, SubaccountTable, - USDC_ASSET_ID, OrderStatus, } from '@dydxprotocol-indexer/postgres'; -import { CanceledOrderStatus, CanceledOrdersCache, StateFilledQuantumsCache } from '@dydxprotocol-indexer/redis'; +import { StateFilledQuantumsCache } from '@dydxprotocol-indexer/redis'; import { isStatefulOrder } from '@dydxprotocol-indexer/v4-proto-parser'; import { - OrderFillEventV1, IndexerOrderId, IndexerSubaccountId, IndexerOrder, + IndexerOrderId, IndexerSubaccountId, IndexerOrder, } from '@dydxprotocol-indexer/v4-protos'; import Long from 'long'; import * as pg from 'pg'; @@ -27,7 +24,6 @@ import { STATEFUL_ORDER_ORDER_FILL_EVENT_TYPE, SUBACCOUNT_ORDER_FILL_EVENT_TYPE import { convertPerpetualPosition } from '../../helpers/kafka-helper'; import { redisClient } from '../../helpers/redis/redis-controller'; import { orderFillWithLiquidityToOrderFillEventWithOrder } from '../../helpers/translation-helper'; -import { indexerTendermintEventToTransactionIndex } from '../../lib/helper'; import { OrderFillWithLiquidity } from '../../lib/translated-types'; import { ConsolidatedKafkaEvent, OrderFillEventWithOrder } from '../../lib/types'; import { AbstractOrderFillHandler } from './abstract-order-fill-handler'; @@ -58,17 +54,7 @@ export class OrderHandler extends AbstractOrderFillHandler { - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const transactionIndex: number = indexerTendermintEventToTransactionIndex( - this.indexerTendermintEvent, - ); + public async internalHandle(resultRow: pg.QueryResultRow): Promise { const kafkaEvents: ConsolidatedKafkaEvent[] = []; const castedOrderFillEventMessage: @@ -78,44 +64,14 @@ export class OrderHandler extends AbstractOrderFillHandler { - logger.error({ - at: 'orderHandler#internalHandle', - message: 'Failed to handle OrderFillEventV1', - error, - }); - throw error; - }); const order: OrderFromDatabase = OrderModel.fromJson( - result.rows[0].result.order) as OrderFromDatabase; + resultRow[field].order) as OrderFromDatabase; const fill: FillFromDatabase = FillModel.fromJson( - result.rows[0].result.fill) as FillFromDatabase; + resultRow[field].fill) as FillFromDatabase; const perpetualMarket: PerpetualMarketFromDatabase = PerpetualMarketModel.fromJson( - result.rows[0].result.perpetual_market) as PerpetualMarketFromDatabase; + resultRow[field].perpetual_market) as PerpetualMarketFromDatabase; const position: PerpetualPositionFromDatabase = PerpetualPositionModel.fromJson( - result.rows[0].result.perpetual_position) as PerpetualPositionFromDatabase; + resultRow[field].perpetual_position) as PerpetualPositionFromDatabase; let subaccountId: IndexerSubaccountId; if (this.event.liquidity === Liquidity.MAKER) { @@ -162,4 +118,10 @@ export class OrderHandler extends AbstractOrderFillHandler { - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const result: pg.QueryResult = await storeHelpers.rawQuery( - `SELECT dydx_perpetual_market_handler( - '${JSON.stringify(PerpetualMarketCreateEventV1.decode(eventDataBinary))}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'PerpetualMarketCreationHandler#internalHandle', - message: 'Failed to handle PerpetualMarketCreateEventV1', - error, - }); - - throw error; - }); - + public async internalHandle(resultRow: pg.QueryResultRow): Promise { const perpetualMarket: PerpetualMarketFromDatabase = PerpetualMarketModel.fromJson( - result.rows[0].result.perpetual_market) as PerpetualMarketFromDatabase; + resultRow.perpetual_market) as PerpetualMarketFromDatabase; perpetualMarketRefresher.upsertPerpetualMarket(perpetualMarket); return [ diff --git a/indexer/services/ender/src/handlers/stateful-order/conditional-order-placement-handler.ts b/indexer/services/ender/src/handlers/stateful-order/conditional-order-placement-handler.ts index dadc145cd9..83d0971884 100644 --- a/indexer/services/ender/src/handlers/stateful-order/conditional-order-placement-handler.ts +++ b/indexer/services/ender/src/handlers/stateful-order/conditional-order-placement-handler.ts @@ -1,14 +1,14 @@ import { - OrderFromDatabase, + OrderFromDatabase, OrderModel, OrderTable, - PerpetualMarketFromDatabase, - SubaccountFromDatabase, + PerpetualMarketFromDatabase, PerpetualMarketModel, SubaccountMessageContents, } from '@dydxprotocol-indexer/postgres'; import { IndexerSubaccountId, StatefulOrderEventV1, } from '@dydxprotocol-indexer/v4-protos'; +import * as pg from 'pg'; import { generateOrderSubaccountMessage } from '../../helpers/kafka-helper'; import { ConsolidatedKafkaEvent } from '../../lib/types'; @@ -26,15 +26,14 @@ export class ConditionalOrderPlacementHandler extends } // eslint-disable-next-line @typescript-eslint/require-await - public async internalHandle(): Promise { - const result: - [OrderFromDatabase, - PerpetualMarketFromDatabase, - SubaccountFromDatabase | undefined] = await this.handleEventViaSqlFunction(); + public async internalHandle(resultRow: pg.QueryResultRow): Promise { + const order: OrderFromDatabase = OrderModel.fromJson(resultRow.order) as OrderFromDatabase; + const perpetualMarket: PerpetualMarketFromDatabase = PerpetualMarketModel.fromJson( + resultRow.perpetual_market) as PerpetualMarketFromDatabase; const subaccountId: IndexerSubaccountId = this.event.conditionalOrderPlacement!.order!.orderId!.subaccountId!; - return this.createKafkaEvents(subaccountId, result[0], result[1]); + return this.createKafkaEvents(subaccountId, order, perpetualMarket); } private createKafkaEvents( diff --git a/indexer/services/ender/src/handlers/stateful-order/conditional-order-triggered-handler.ts b/indexer/services/ender/src/handlers/stateful-order/conditional-order-triggered-handler.ts index 99a3521a08..0cab1392da 100644 --- a/indexer/services/ender/src/handlers/stateful-order/conditional-order-triggered-handler.ts +++ b/indexer/services/ender/src/handlers/stateful-order/conditional-order-triggered-handler.ts @@ -3,8 +3,9 @@ import { OrderTable, PerpetualMarketFromDatabase, orderTranslations, - SubaccountFromDatabase, + SubaccountFromDatabase, OrderModel, PerpetualMarketModel, } from '@dydxprotocol-indexer/postgres'; +import SubaccountModel from '@dydxprotocol-indexer/postgres/build/src/models/subaccount-model'; import { getOrderIdHash } from '@dydxprotocol-indexer/v4-proto-parser'; import { IndexerOrder, @@ -12,6 +13,7 @@ import { OrderPlaceV1_OrderPlacementStatus, StatefulOrderEventV1, } from '@dydxprotocol-indexer/v4-protos'; +import * as pg from 'pg'; import { ConsolidatedKafkaEvent } from '../../lib/types'; import { AbstractStatefulOrderHandler } from '../abstract-stateful-order-handler'; @@ -28,15 +30,16 @@ export class ConditionalOrderTriggeredHandler extends } // eslint-disable-next-line @typescript-eslint/require-await - public async internalHandle(): Promise { - const result: - [OrderFromDatabase, - PerpetualMarketFromDatabase, - SubaccountFromDatabase | undefined] = await this.handleEventViaSqlFunction(); + public async internalHandle(resultRow: pg.QueryResultRow): Promise { + const order: OrderFromDatabase = OrderModel.fromJson(resultRow.order) as OrderFromDatabase; + const perpetualMarket: PerpetualMarketFromDatabase = PerpetualMarketModel.fromJson( + resultRow.perpetual_market) as PerpetualMarketFromDatabase; + const subaccount: SubaccountFromDatabase = SubaccountModel.fromJson( + resultRow.subaccount) as SubaccountFromDatabase; - const order: IndexerOrder = orderTranslations.convertToIndexerOrderWithSubaccount( - result[0], result[1], result[2]!); - return this.createKafkaEvents(order); + const indexerOrder: IndexerOrder = orderTranslations.convertToIndexerOrderWithSubaccount( + order, perpetualMarket, subaccount); + return this.createKafkaEvents(indexerOrder); } private createKafkaEvents(order: IndexerOrder): ConsolidatedKafkaEvent[] { diff --git a/indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts b/indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts index aea4b59152..a2ea67f578 100644 --- a/indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts +++ b/indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts @@ -8,6 +8,7 @@ import { IndexerOrder, StatefulOrderEventV1, } from '@dydxprotocol-indexer/v4-protos'; +import * as pg from 'pg'; import { ConsolidatedKafkaEvent } from '../../lib/types'; import { AbstractStatefulOrderHandler } from '../abstract-stateful-order-handler'; @@ -30,9 +31,7 @@ export class StatefulOrderPlacementHandler extends } // eslint-disable-next-line @typescript-eslint/require-await - public async internalHandle(): Promise { - await this.handleEventViaSqlFunction(); - + public async internalHandle(_: pg.QueryResultRow): Promise { let order: IndexerOrder; // TODO(IND-334): Remove after deprecating StatefulOrderPlacementEvent if (this.event.orderPlace !== undefined) { diff --git a/indexer/services/ender/src/handlers/stateful-order/stateful-order-removal-handler.ts b/indexer/services/ender/src/handlers/stateful-order/stateful-order-removal-handler.ts index 69a11bdded..5a162c850a 100644 --- a/indexer/services/ender/src/handlers/stateful-order/stateful-order-removal-handler.ts +++ b/indexer/services/ender/src/handlers/stateful-order/stateful-order-removal-handler.ts @@ -8,6 +8,7 @@ import { OrderRemoveV1_OrderRemovalStatus, StatefulOrderEventV1, } from '@dydxprotocol-indexer/v4-protos'; +import * as pg from 'pg'; import { ConsolidatedKafkaEvent } from '../../lib/types'; import { AbstractStatefulOrderHandler } from '../abstract-stateful-order-handler'; @@ -23,9 +24,8 @@ export class StatefulOrderRemovalHandler extends } // eslint-disable-next-line @typescript-eslint/require-await - public async internalHandle(): Promise { + public async internalHandle(_: pg.QueryResultRow): Promise { const orderIdProto: IndexerOrderId = this.event.orderRemoval!.removedOrderId!; - await this.handleEventViaSqlFunction(); return this.createKafkaEvents(orderIdProto); } diff --git a/indexer/services/ender/src/handlers/subaccount-update-handler.ts b/indexer/services/ender/src/handlers/subaccount-update-handler.ts index 43fac7a6d9..44443799cc 100644 --- a/indexer/services/ender/src/handlers/subaccount-update-handler.ts +++ b/indexer/services/ender/src/handlers/subaccount-update-handler.ts @@ -1,4 +1,3 @@ -import { logger } from '@dydxprotocol-indexer/base'; import { AssetPositionFromDatabase, AssetPositionModel, @@ -11,7 +10,6 @@ import { perpetualMarketRefresher, PerpetualMarketsMap, PerpetualPositionModel, - storeHelpers, SubaccountMessageContents, SubaccountTable, UpdatedPerpetualPositionSubaccountKafkaObject, @@ -21,7 +19,6 @@ import * as pg from 'pg'; import { SUBACCOUNT_ORDER_FILL_EVENT_TYPE } from '../constants'; import { addPositionsToContents, annotateWithPnl } from '../helpers/kafka-helper'; -import { indexerTendermintEventToTransactionIndex } from '../lib/helper'; import { SubaccountUpdate } from '../lib/translated-types'; import { ConsolidatedKafkaEvent } from '../lib/types'; import { Handler } from './handler'; @@ -39,33 +36,14 @@ export class SubaccountUpdateHandler extends Handler { ]; } - public async internalHandle(): Promise { - const transactionIndex: number = indexerTendermintEventToTransactionIndex( - this.indexerTendermintEvent, - ); - - const result: pg.QueryResult = await storeHelpers.rawQuery(`SELECT dydx_subaccount_update_handler( - ${this.block.height}, - '${this.block.time?.toISOString()}', - '${JSON.stringify(this.event)}', - ${this.indexerTendermintEvent.eventIndex}, - ${transactionIndex}) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'subaccountUpdateHandler#internalHandle', - message: 'Failed to handle SubaccountUpdateEventV1', - error, - }); - throw error; - }); + public async internalHandle(resultRow: pg.QueryResultRow): Promise { const updateObjects: UpdatedPerpetualPositionSubaccountKafkaObject[] = _.map( - result.rows[0].result.perpetual_positions, + resultRow.perpetual_positions, (value) => PerpetualPositionModel.fromJson( value) as UpdatedPerpetualPositionSubaccountKafkaObject, ); const updatedAssetPositions: AssetPositionFromDatabase[] = _.map( - result.rows[0].result.asset_positions, + resultRow.asset_positions, (value) => AssetPositionModel.fromJson(value) as AssetPositionFromDatabase, ); const markets: MarketFromDatabase[] = await MarketTable.findAll( diff --git a/indexer/services/ender/src/handlers/transfer-handler.ts b/indexer/services/ender/src/handlers/transfer-handler.ts index 975a7eb9cb..dcd24ad38f 100644 --- a/indexer/services/ender/src/handlers/transfer-handler.ts +++ b/indexer/services/ender/src/handlers/transfer-handler.ts @@ -1,8 +1,6 @@ -import { logger } from '@dydxprotocol-indexer/base'; import { AssetFromDatabase, AssetModel, - storeHelpers, SubaccountMessageContents, TransferFromDatabase, TransferModel, @@ -11,7 +9,6 @@ import { TransferEventV1 } from '@dydxprotocol-indexer/v4-protos'; import * as pg from 'pg'; import { generateTransferContents } from '../helpers/kafka-helper'; -import { indexerTendermintEventToTransactionIndex } from '../lib/helper'; import { ConsolidatedKafkaEvent } from '../lib/types'; import { Handler } from './handler'; @@ -24,35 +21,11 @@ export class TransferHandler extends Handler { } // eslint-disable-next-line @typescript-eslint/require-await - public async internalHandle(): Promise { - const transactionIndex: number = indexerTendermintEventToTransactionIndex( - this.indexerTendermintEvent, - ); - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const result: pg.QueryResult = await storeHelpers.rawQuery( - `SELECT dydx_transfer_handler( - ${this.block.height}, - '${this.block.time?.toISOString()}', - '${JSON.stringify(TransferEventV1.decode(eventDataBinary))}', - ${this.indexerTendermintEvent.eventIndex}, - ${transactionIndex}, - '${this.block.txHashes[transactionIndex]}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'TransferHandler#internalHandle', - message: 'Failed to handle TransferEventV1', - error, - }); - - throw error; - }); - + public async internalHandle(resultRow: pg.QueryResultRow): Promise { const asset: AssetFromDatabase = AssetModel.fromJson( - result.rows[0].result.asset) as AssetFromDatabase; + resultRow.asset) as AssetFromDatabase; const transfer: TransferFromDatabase = TransferModel.fromJson( - result.rows[0].result.transfer) as TransferFromDatabase; + resultRow.transfer) as TransferFromDatabase; return this.generateKafkaEvents( transfer, asset, diff --git a/indexer/services/ender/src/handlers/update-clob-pair-handler.ts b/indexer/services/ender/src/handlers/update-clob-pair-handler.ts index 18217fc78f..0840835227 100644 --- a/indexer/services/ender/src/handlers/update-clob-pair-handler.ts +++ b/indexer/services/ender/src/handlers/update-clob-pair-handler.ts @@ -1,9 +1,7 @@ -import { logger } from '@dydxprotocol-indexer/base'; import { PerpetualMarketFromDatabase, PerpetualMarketModel, perpetualMarketRefresher, - storeHelpers, } from '@dydxprotocol-indexer/postgres'; import { UpdateClobPairEventV1 } from '@dydxprotocol-indexer/v4-protos'; import * as pg from 'pg'; @@ -20,25 +18,9 @@ export class UpdateClobPairHandler extends Handler { } // eslint-disable-next-line @typescript-eslint/require-await - public async internalHandle(): Promise { - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const result: pg.QueryResult = await storeHelpers.rawQuery( - `SELECT dydx_update_clob_pair_handler( - '${JSON.stringify(UpdateClobPairEventV1.decode(eventDataBinary))}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'UpdateClobPairHandler#internalHandle', - message: 'Failed to handle UpdateClobPairEventV1', - error, - }); - - throw error; - }); - + public async internalHandle(resultRow: pg.QueryResultRow): Promise { const perpetualMarket: PerpetualMarketFromDatabase = PerpetualMarketModel.fromJson( - result.rows[0].result.perpetual_market) as PerpetualMarketFromDatabase; + resultRow.perpetual_market) as PerpetualMarketFromDatabase; perpetualMarketRefresher.upsertPerpetualMarket(perpetualMarket); diff --git a/indexer/services/ender/src/handlers/update-perpetual-handler.ts b/indexer/services/ender/src/handlers/update-perpetual-handler.ts index 5e7df33559..c3a9175b21 100644 --- a/indexer/services/ender/src/handlers/update-perpetual-handler.ts +++ b/indexer/services/ender/src/handlers/update-perpetual-handler.ts @@ -1,8 +1,6 @@ -import { logger } from '@dydxprotocol-indexer/base'; import { PerpetualMarketFromDatabase, perpetualMarketRefresher, - storeHelpers, PerpetualMarketModel, } from '@dydxprotocol-indexer/postgres'; import { UpdatePerpetualEventV1 } from '@dydxprotocol-indexer/v4-protos'; @@ -20,25 +18,9 @@ export class UpdatePerpetualHandler extends Handler { } // eslint-disable-next-line @typescript-eslint/require-await - public async internalHandle(): Promise { - const eventDataBinary: Uint8Array = this.indexerTendermintEvent.dataBytes; - const result: pg.QueryResult = await storeHelpers.rawQuery( - `SELECT dydx_update_perpetual_handler( - '${JSON.stringify(UpdatePerpetualEventV1.decode(eventDataBinary))}' - ) AS result;`, - { txId: this.txId }, - ).catch((error: Error) => { - logger.error({ - at: 'UpdatePerpetualHandler#internalHandle', - message: 'Failed to handle UpdatePerpetualEventV1', - error, - }); - - throw error; - }); - + public async internalHandle(resultRow: pg.QueryResultRow): Promise { const perpetualMarket: PerpetualMarketFromDatabase = PerpetualMarketModel.fromJson( - result.rows[0].result.perpetual_market) as PerpetualMarketFromDatabase; + resultRow.perpetual_market) as PerpetualMarketFromDatabase; await perpetualMarketRefresher.upsertPerpetualMarket(perpetualMarket); diff --git a/indexer/services/ender/src/helpers/postgres/postgres-functions.ts b/indexer/services/ender/src/helpers/postgres/postgres-functions.ts index fe5abaa1ce..94024ee20f 100644 --- a/indexer/services/ender/src/helpers/postgres/postgres-functions.ts +++ b/indexer/services/ender/src/helpers/postgres/postgres-functions.ts @@ -30,6 +30,9 @@ const scripts: string[] = [ 'create_extension_pg_stat_statements.sql', 'create_extension_uuid_ossp.sql', 'dydx_asset_create_handler.sql', + 'dydx_block_processor.sql', + 'dydx_block_processor_ordered_handlers.sql', + 'dydx_block_processor_unordered_handlers.sql', 'dydx_clob_pair_status_to_market_status.sql', 'dydx_deleveraging_handler.sql', 'dydx_market_create_handler.sql', diff --git a/indexer/services/ender/src/lib/batched-handlers.ts b/indexer/services/ender/src/lib/batched-handlers.ts index e5e33bf63a..88e174e64c 100644 --- a/indexer/services/ender/src/lib/batched-handlers.ts +++ b/indexer/services/ender/src/lib/batched-handlers.ts @@ -1,5 +1,6 @@ import { logger, stats } from '@dydxprotocol-indexer/base'; import _ from 'lodash'; +import * as pg from 'pg'; import config from '../config'; import { Handler } from '../handlers/handler'; @@ -9,9 +10,11 @@ import { ConsolidatedKafkaEvent, EventMessage } from './types'; // type alias for an array of handlers, handlers in a `HandlerBatch` can be processed in parallel. type HandlerBatch = Handler[]; +// TODO(IND-514): Remove the batch and sync handlers completely by moving all redis updates into +// a pipeline similar to how we return kafka events and then batch and emit them. export class BatchedHandlers { // An array of `HandlerBatch`s. Handlers in a `HandlerBatch` can be processed in parallel, and - // `HandlerBatch`s are processed in a sequential order following the order in `bartchedHandlers`. + // `HandlerBatch`s are processed in a sequential order following the order in `batchedHandlers`. batchedHandlers: HandlerBatch[]; // An array of sets of parallization ids. Each array of ids is the parallelization ids for the // corresponding array of handlers in this.batchedHandlers as well as all the parallelization ids @@ -71,7 +74,9 @@ export class BatchedHandlers { * and ensuring that handlers with overlapping parallelization ids are not processed in parallel. * Adds events to the kafkaPublisher. */ - public async process(kafkaPublisher: KafkaPublisher): Promise { + public async process( + kafkaPublisher: KafkaPublisher, + resultRow: pg.QueryResultRow): Promise { for (let batchIndex = 0; batchIndex < this.batchedHandlers.length; batchIndex++) { const start: number = Date.now(); const handlerCountMapping: { [key: string]: number } = {}; @@ -87,7 +92,7 @@ export class BatchedHandlers { Date.now() - this.initializationTime, { eventType: handler.eventType }, ); - return handler.handle(); + return handler.handle(resultRow[handler.blockEventIndex]); }), ); diff --git a/indexer/services/ender/src/lib/block-processor.ts b/indexer/services/ender/src/lib/block-processor.ts index c284966c15..27f60a2e1c 100644 --- a/indexer/services/ender/src/lib/block-processor.ts +++ b/indexer/services/ender/src/lib/block-processor.ts @@ -1,8 +1,17 @@ /* eslint-disable max-len */ -import { logger } from '@dydxprotocol-indexer/base'; -import { IndexerTendermintBlock, IndexerTendermintEvent } from '@dydxprotocol-indexer/v4-protos'; +import { logger, stats, STATS_NO_SAMPLING } from '@dydxprotocol-indexer/base'; +import { + storeHelpers, +} from '@dydxprotocol-indexer/postgres'; +import { + IndexerTendermintBlock, + IndexerTendermintEvent, +} from '@dydxprotocol-indexer/v4-protos'; import _ from 'lodash'; +import * as pg from 'pg'; +import { DatabaseError } from 'pg'; +import config from '../config'; import { Handler } from '../handlers/handler'; import { AssetValidator } from '../validators/asset-validator'; import { DeleveragingValidator } from '../validators/deleveraging-validator'; @@ -50,8 +59,19 @@ function serializeSubtypeAndVersion( return `${subtype}-${version}`; } +type DecodedIndexerTendermintBlock = Omit & { + events: DecodedIndexerTendermintEvent[]; +}; + +type DecodedIndexerTendermintEvent = Omit & { + /** Decoded tendermint event. */ + dataBytes: object; +}; + export class BlockProcessor { block: IndexerTendermintBlock; + sqlEventPromises: Promise[]; + sqlBlock: DecodedIndexerTendermintBlock; txId: number; batchedHandlers: BatchedHandlers; syncHandlers: SyncHandlers; @@ -62,6 +82,11 @@ export class BlockProcessor { ) { this.block = block; this.txId = txId; + this.sqlBlock = { + ...this.block, + events: new Array(this.block.events.length), + }; + this.sqlEventPromises = new Array(this.block.events.length); this.batchedHandlers = new BatchedHandlers(); this.syncHandlers = new SyncHandlers(); } @@ -81,6 +106,7 @@ export class BlockProcessor { * @returns the kafka publisher which contains all the events to be published to the kafka */ public async process(): Promise { + const groupedEvents: GroupedEvents = this.groupEvents(); this.validateAndOrganizeEvents(groupedEvents); return this.processEvents(); @@ -101,22 +127,24 @@ export class BlockProcessor { groupedEvents.transactionEvents.push([]); } - _.forEach(this.block.events, (event: IndexerTendermintEvent) => { + for (let i: number = 0; i < this.block.events.length; i++) { + const event: IndexerTendermintEvent = this.block.events[i]; const transactionIndex: number = indexerTendermintEventToTransactionIndex(event); const eventProtoWithType: EventProtoWithTypeAndVersion | undefined = indexerTendermintEventToEventProtoWithType( + i, event, ); if (eventProtoWithType === undefined) { - return; + continue; } if (transactionIndex === -1) { groupedEvents.blockEvents.push(eventProtoWithType); - return; + continue; } groupedEvents.transactionEvents[transactionIndex].push(eventProtoWithType); - }); + } return groupedEvents; } @@ -168,9 +196,11 @@ export class BlockProcessor { const validator: Validator = new Initializer( eventProto.eventProto, this.block, + eventProto.blockEventIndex, ); validator.validate(); + this.sqlEventPromises[eventProto.blockEventIndex] = validator.getEventForBlockProcessor(); const handlers: Handler[] = validator.createHandlers( eventProto.indexerTendermintEvent, this.txId, @@ -187,14 +217,58 @@ export class BlockProcessor { private async processEvents(): Promise { const kafkaPublisher: KafkaPublisher = new KafkaPublisher(); + + await Promise.all(this.sqlEventPromises).then((values) => { + for (let i: number = 0; i < this.block.events.length; i++) { + const event: IndexerTendermintEvent = this.block.events[i]; + this.sqlBlock.events[i] = { + ...event, + // Specifically use the decoded version of the event instead of the bytes + // since the SQL block processor doesn't know how to decode protobuf + // natively. + dataBytes: values[i], + }; + } + }); + + const start: number = Date.now(); + let success = false; + let resultRow: pg.QueryResultRow; + try { + const result: pg.QueryResult = await storeHelpers.rawQuery( + 'SELECT dydx_block_processor(?) AS result;', + { + txId: this.txId, + bindings: [JSON.stringify(this.sqlBlock)], + sqlOptions: { name: 'dydx_block_processor' }, + }, + ).catch((error: DatabaseError) => { + logger.crit({ + at: `BlockProcessor#processEvents\n${error.where}`, + message: error.message, + error, + }); + throw error; + }); + resultRow = result.rows[0].result; + success = true; + } finally { + stats.timing( + `${config.SERVICE_NAME}.processed_block_sql.timing`, + Date.now() - start, + STATS_NO_SAMPLING, + { success: success.toString() }, + ); + } + // in genesis, handle sync events first, then batched events. // in other blocks, handle batched events first, then sync events. if (this.block.height === 0) { - await this.syncHandlers.process(kafkaPublisher); - await this.batchedHandlers.process(kafkaPublisher); + await this.syncHandlers.process(kafkaPublisher, resultRow); + await this.batchedHandlers.process(kafkaPublisher, resultRow); } else { - await this.batchedHandlers.process(kafkaPublisher); - await this.syncHandlers.process(kafkaPublisher); + await this.batchedHandlers.process(kafkaPublisher, resultRow); + await this.syncHandlers.process(kafkaPublisher, resultRow); } return kafkaPublisher; } diff --git a/indexer/services/ender/src/lib/helper.ts b/indexer/services/ender/src/lib/helper.ts index d1ee2f9a9c..1e4b3ffc91 100644 --- a/indexer/services/ender/src/lib/helper.ts +++ b/indexer/services/ender/src/lib/helper.ts @@ -87,10 +87,12 @@ export function dateToDateTime( /** * Determines the event subtype and parses the IndexerTendermintEvent * to the correct EventProto and returns it all in an object. - * @param event + * @param blockEventIndex - the index of the event in the block. + * @param event - the event. * @returns */ export function indexerTendermintEventToEventProtoWithType( + blockEventIndex: number, event: IndexerTendermintEvent, ): EventProtoWithTypeAndVersion | undefined { const eventDataBinary: Uint8Array = event.dataBytes; @@ -103,6 +105,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: OrderFillEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } case (DydxIndexerSubtypes.SUBACCOUNT_UPDATE.toString()): { @@ -111,6 +114,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: SubaccountUpdateEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } case (DydxIndexerSubtypes.TRANSFER.toString()): { @@ -119,6 +123,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: TransferEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } case (DydxIndexerSubtypes.MARKET.toString()): { @@ -127,6 +132,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: MarketEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } case (DydxIndexerSubtypes.STATEFUL_ORDER.toString()): { @@ -135,6 +141,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: StatefulOrderEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } case (DydxIndexerSubtypes.FUNDING.toString()): { @@ -143,6 +150,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: FundingEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } case (DydxIndexerSubtypes.ASSET.toString()): { @@ -151,6 +159,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: AssetCreateEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } case (DydxIndexerSubtypes.PERPETUAL_MARKET.toString()): { @@ -159,6 +168,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: PerpetualMarketCreateEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } case (DydxIndexerSubtypes.LIQUIDITY_TIER.toString()): { @@ -167,6 +177,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: LiquidityTierUpsertEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } case (DydxIndexerSubtypes.UPDATE_PERPETUAL.toString()): { @@ -175,6 +186,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: UpdatePerpetualEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } case (DydxIndexerSubtypes.UPDATE_CLOB_PAIR.toString()): { @@ -183,6 +195,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: UpdateClobPairEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } case (DydxIndexerSubtypes.DELEVERAGING.toString()): { @@ -191,6 +204,7 @@ export function indexerTendermintEventToEventProtoWithType( eventProto: DeleveragingEventV1.decode(eventDataBinary), indexerTendermintEvent: event, version, + blockEventIndex, }; } default: { diff --git a/indexer/services/ender/src/lib/kafka-publisher.ts b/indexer/services/ender/src/lib/kafka-publisher.ts index 36aa302d15..e1d7b018f4 100644 --- a/indexer/services/ender/src/lib/kafka-publisher.ts +++ b/indexer/services/ender/src/lib/kafka-publisher.ts @@ -186,6 +186,7 @@ export class KafkaPublisher { const batchProducer: BatchKafkaProducer = new BatchKafkaProducer( topicKafkaMessages.topic, producer, + config.KAFKA_MAX_BATCH_WEBSOCKET_MESSAGE_SIZE_BYTES, ); for (const message of topicKafkaMessages.messages) { batchProducer.addMessageAndMaybeFlush(message); diff --git a/indexer/services/ender/src/lib/on-message.ts b/indexer/services/ender/src/lib/on-message.ts index eda6e31a4e..c33be095d7 100644 --- a/indexer/services/ender/src/lib/on-message.ts +++ b/indexer/services/ender/src/lib/on-message.ts @@ -4,14 +4,12 @@ import { ParseMessageError, wrapBackgroundTask, STATS_NO_SAMPLING, - runFuncWithTimingStat, } from '@dydxprotocol-indexer/base'; import { KafkaTopics } from '@dydxprotocol-indexer/kafka'; import { Transaction, IsolationLevel, CandleFromDatabase, - storeHelpers, } from '@dydxprotocol-indexer/postgres'; import { IndexerTendermintBlock, @@ -74,15 +72,6 @@ export async function onMessage(message: KafkaMessage): Promise { try { validateIndexerTendermintBlock(indexerTendermintBlock); - await runFuncWithTimingStat( - createInitialRows( - blockHeight, - txId, - indexerTendermintBlock, - ), - {}, - 'create_initial_rows', - ); const blockProcessor: BlockProcessor = new BlockProcessor( indexerTendermintBlock, txId, @@ -220,30 +209,3 @@ function validateIndexerTendermintBlock( ); } } - -async function createInitialRows( - blockHeight: string, - txId: number, - block: IndexerTendermintBlock, -): Promise { - const txHashesString = block.txHashes.length > 0 ? `ARRAY['${block.txHashes.join("','")}']::text[]` : 'null'; - const eventsString = block.events.length > 0 ? `ARRAY['${block.events.map((event) => JSON.stringify(event)).join("','")}']::jsonb[]` : 'null'; - - const queryString: string = `SELECT dydx_create_initial_rows_for_tendermint_block( - '${blockHeight}'::text, - '${block.time!.toISOString()}'::text, - ${txHashesString}, - ${eventsString} - ) AS result;`; - await storeHelpers.rawQuery( - queryString, - { txId }, - ).catch((error: Error) => { - logger.error({ - at: 'on-message#createInitialRowsViaSqlFunction', - message: 'Failed to create initial rows', - error, - }); - throw error; - }); -} diff --git a/indexer/services/ender/src/lib/sync-handlers.ts b/indexer/services/ender/src/lib/sync-handlers.ts index 3562fe4544..1359973a45 100644 --- a/indexer/services/ender/src/lib/sync-handlers.ts +++ b/indexer/services/ender/src/lib/sync-handlers.ts @@ -1,5 +1,6 @@ import { logger, stats } from '@dydxprotocol-indexer/base'; import _ from 'lodash'; +import * as pg from 'pg'; import config from '../config'; import { Handler } from '../handlers/handler'; @@ -24,6 +25,8 @@ export const SYNCHRONOUS_SUBTYPES: DydxIndexerSubtypes[] = [ * After genesis block, these events should be handled after events in BatchedHandlers. * It is used for processing asset and market events. */ +// TODO(IND-514): Remove the batch and sync handlers completely by moving all redis updates into +// a pipeline similar to how we return kafka events and then batch and emit them. export class SyncHandlers { handlerBatch: HandlerBatch; initializationTime: number; @@ -60,7 +63,7 @@ export class SyncHandlers { * Adds events to the kafkaPublisher. */ public async process( - kafkaPublisher: KafkaPublisher, + kafkaPublisher: KafkaPublisher, resultRow: pg.QueryResultRow, ): Promise { const start: number = Date.now(); const handlerCountMapping: { [key: string]: number } = {}; @@ -71,7 +74,8 @@ export class SyncHandlers { handlerCountMapping[handlerName] = 0; } handlerCountMapping[handlerName] += 1; - const events: ConsolidatedKafkaEvent[] = await handler.handle(); + const events: ConsolidatedKafkaEvent[] = await handler.handle( + resultRow[handler.blockEventIndex]); consolidatedKafkaEventGroup.push(events); } diff --git a/indexer/services/ender/src/lib/types.ts b/indexer/services/ender/src/lib/types.ts index 5984f8fa61..969d24b38b 100644 --- a/indexer/services/ender/src/lib/types.ts +++ b/indexer/services/ender/src/lib/types.ts @@ -60,66 +60,79 @@ export type EventProtoWithTypeAndVersion = { eventProto: EventMessage, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } & ({ type: DydxIndexerSubtypes.ORDER_FILL, eventProto: OrderFillEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } | { type: DydxIndexerSubtypes.SUBACCOUNT_UPDATE, eventProto: SubaccountUpdateEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } | { type: DydxIndexerSubtypes.TRANSFER, eventProto: TransferEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } | { type: DydxIndexerSubtypes.MARKET, eventProto: MarketEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } | { type: DydxIndexerSubtypes.STATEFUL_ORDER, eventProto: StatefulOrderEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } | { type: DydxIndexerSubtypes.FUNDING, eventProto: FundingEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } | { type: DydxIndexerSubtypes.ASSET, eventProto: AssetCreateEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } | { type: DydxIndexerSubtypes.PERPETUAL_MARKET, eventProto: PerpetualMarketCreateEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } | { type: DydxIndexerSubtypes.LIQUIDITY_TIER, eventProto: LiquidityTierUpsertEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } | { type: DydxIndexerSubtypes.UPDATE_PERPETUAL, eventProto: UpdatePerpetualEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } | { type: DydxIndexerSubtypes.UPDATE_CLOB_PAIR, eventProto: UpdateClobPairEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, } | { type: DydxIndexerSubtypes.DELEVERAGING, eventProto: DeleveragingEventV1, indexerTendermintEvent: IndexerTendermintEvent, version: number, + blockEventIndex: number, }); // Events grouped into events block events and events for each transactionIndex diff --git a/indexer/services/ender/src/scripts/dydx_block_processor.sql b/indexer/services/ender/src/scripts/dydx_block_processor.sql new file mode 100644 index 0000000000..c944c0adec --- /dev/null +++ b/indexer/services/ender/src/scripts/dydx_block_processor.sql @@ -0,0 +1,43 @@ +CREATE OR REPLACE FUNCTION dydx_block_processor(block jsonb) RETURNS jsonb AS $$ +/** + Processes an entire block by creating the initial tendermint rows for the block and then processes each event + individually through their respective handlers. + + Parameters: + - block: A 'DecodedIndexerTendermintBlock' converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. + + Returns: + An array containing the results for each event or NULL if this event is not handled by this block processor. + See each individual handler function for a description of the the inputs and outputs. + + (Note that no text should exist before the function declaration to ensure that exception line numbers are correct.) +*/ +DECLARE + block_height int = (block->'height')::int; + block_time timestamp = (block->>'time')::timestamp; + rval jsonb[]; + rval_to_merge jsonb[]; +BEGIN + PERFORM dydx_create_initial_rows_for_tendermint_block(block_height, block_time, block->'txHashes', block->'events'); + + /** In genesis, handle ordered events first, then unordered events. In other blocks, handle unordered events first, then ordered events. */ + IF NOT block_height = 0 THEN + rval = dydx_block_processor_unordered_handlers(block); + rval_to_merge = dydx_block_processor_ordered_handlers(block); + ELSE + rval = dydx_block_processor_ordered_handlers(block); + rval_to_merge = dydx_block_processor_unordered_handlers(block); + END IF; + + /** + Merge the results of the two handlers together by taking the first non-null result of each. + + Note that arrays are 1-indexed in PostgreSQL and empty arrays return NULL for array_length. + */ + FOR i in 1..coalesce(array_length(rval, 1), 0) LOOP + rval[i] = coalesce(rval[i], rval_to_merge[i]); + END LOOP; + + RETURN to_jsonb(rval); +END; +$$ LANGUAGE plpgsql; diff --git a/indexer/services/ender/src/scripts/dydx_block_processor_ordered_handlers.sql b/indexer/services/ender/src/scripts/dydx_block_processor_ordered_handlers.sql new file mode 100644 index 0000000000..94d0ea30e0 --- /dev/null +++ b/indexer/services/ender/src/scripts/dydx_block_processor_ordered_handlers.sql @@ -0,0 +1,63 @@ +CREATE OR REPLACE FUNCTION dydx_block_processor_ordered_handlers(block jsonb) RETURNS jsonb[] AS $$ +/** + Processes each event that should be handled by the batched handler. This includes all synchronous types + (https://github.com/dydxprotocol/v4-chain/blob/b5d4e8a7c5cc48c460731b21c47f22eabef8b2b7/indexer/services/ender/src/lib/sync-handlers.ts#L11). + + Parameters: + - block: A 'DecodedIndexerTendermintBlock' converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. + + Returns: + An array containing the results for each event or NULL if this event is not handled by this block processor. + See each individual handler function for a description of the the inputs and outputs. + + (Note that no text should exist before the function declaration to ensure that exception line numbers are correct.) + + TODO(IND-514): Remove the batch and sync handlers completely by moving all redis updates into + a pipeline similar to how we return kafka events and then batch and emit them. +*/ +DECLARE + block_height int = (block->'height')::int; + block_time timestamp = (block->>'time')::timestamp; + event_ jsonb; + rval jsonb[]; + event_index int; + transaction_index int; + event_data jsonb; +BEGIN + rval = array_fill(NULL::jsonb, ARRAY[coalesce(jsonb_array_length(block->'events'), 0)]::integer[]); + + /** Note that arrays are 1-indexed in PostgreSQL and empty arrays return NULL for array_length. */ + FOR i in 1..coalesce(array_length(rval, 1), 0) LOOP + event_ = jsonb_array_element(block->'events', i-1); + transaction_index = dydx_tendermint_event_to_transaction_index(event_); + event_index = (event_->'eventIndex')::int; + event_data = event_->'dataBytes'; + CASE event_->'subtype' + WHEN '"market"'::jsonb THEN + IF event_data->'priceUpdate' IS NOT NULL THEN + rval[i] = dydx_market_price_update_handler(block_height, block_time, event_data); + ELSIF event_data->'marketCreate' IS NOT NULL THEN + rval[i] = dydx_market_create_handler(event_data); + ELSIF event_data->'marketModify' IS NOT NULL THEN + rval[i] = dydx_market_modify_handler(event_data); + ELSE + RAISE EXCEPTION 'Unknown market event %', event_; + END IF; + WHEN '"asset"'::jsonb THEN + rval[i] = dydx_asset_create_handler(event_data); + WHEN '"perpetual_market"'::jsonb THEN + rval[i] = dydx_perpetual_market_handler(event_data); + WHEN '"liquidity_tier"'::jsonb THEN + rval[i] = dydx_liquidity_tier_handler(event_data); + WHEN '"update_perpetual"'::jsonb THEN + rval[i] = dydx_update_perpetual_handler(event_data); + WHEN '"update_clob_pair"'::jsonb THEN + rval[i] = dydx_update_clob_pair_handler(event_data); + ELSE + NULL; + END CASE; + END LOOP; + + RETURN rval; +END; +$$ LANGUAGE plpgsql; diff --git a/indexer/services/ender/src/scripts/dydx_block_processor_unordered_handlers.sql b/indexer/services/ender/src/scripts/dydx_block_processor_unordered_handlers.sql new file mode 100644 index 0000000000..da9bb87b88 --- /dev/null +++ b/indexer/services/ender/src/scripts/dydx_block_processor_unordered_handlers.sql @@ -0,0 +1,70 @@ +CREATE OR REPLACE FUNCTION dydx_block_processor_unordered_handlers(block jsonb) RETURNS jsonb[] AS $$ +/** + Processes each event that should be handled by the batched handler. This includes all supported non synchronous types + (https://github.com/dydxprotocol/v4-chain/blob/b5d4e8a7c5cc48c460731b21c47f22eabef8b2b7/indexer/services/ender/src/lib/sync-handlers.ts#L11). + + Parameters: + - block: A 'DecodedIndexerTendermintBlock' converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. + + Returns: + An array containing the results for each event or NULL if this event is not handled by this block processor. + See each individual handler function for a description of the the inputs and outputs. + + (Note that no text should exist before the function declaration to ensure that exception line numbers are correct.) + + TODO(IND-514): Remove the batch and sync handlers completely by moving all redis updates into + a pipeline similar to how we return kafka events and then batch and emit them. +*/ +DECLARE + USDC_ASSET_ID constant text = '0'; + + block_height int = (block->'height')::int; + block_time timestamp = (block->>'time')::timestamp; + event_ jsonb; + rval jsonb[]; + event_index int; + transaction_index int; + event_data jsonb; +BEGIN + rval = array_fill(NULL::jsonb, ARRAY[coalesce(jsonb_array_length(block->'events'), 0)]::integer[]); + + /** Note that arrays are 1-indexed in PostgreSQL and empty arrays return NULL for array_length. */ + FOR i in 1..coalesce(array_length(rval, 1), 0) LOOP + event_ = jsonb_array_element(block->'events', i-1); + transaction_index = dydx_tendermint_event_to_transaction_index(event_); + event_index = (event_->'eventIndex')::int; + event_data = event_->'dataBytes'; + CASE event_->'subtype' + WHEN '"order_fill"'::jsonb THEN + /** If event_data.order is populated then this means it is not a liquidation order. */ + IF event_data->'order' IS NOT NULL THEN + rval[i] = jsonb_build_object( + 'makerOrder', + dydx_order_fill_handler_per_order('makerOrder', block_height, block_time, event_data, event_index, transaction_index, jsonb_array_element_text(block->'txHashes', transaction_index), 'MAKER', 'LIMIT', USDC_ASSET_ID, event_data->>'makerCanceledOrderStatus'), + 'order', + dydx_order_fill_handler_per_order('order', block_height, block_time, event_data, event_index, transaction_index, jsonb_array_element_text(block->'txHashes', transaction_index), 'TAKER', 'LIMIT', USDC_ASSET_ID, event_data->>'takerCanceledOrderStatus')); + ELSE + rval[i] = jsonb_build_object( + 'makerOrder', + dydx_liquidation_fill_handler_per_order('makerOrder', block_height, block_time, event_data, event_index, transaction_index, jsonb_array_element_text(block->'txHashes', transaction_index), 'MAKER', 'LIQUIDATION', USDC_ASSET_ID), + 'liquidationOrder', + dydx_liquidation_fill_handler_per_order('liquidationOrder', block_height, block_time, event_data, event_index, transaction_index, jsonb_array_element_text(block->'txHashes', transaction_index), 'TAKER', 'LIQUIDATED', USDC_ASSET_ID)); + END IF; + WHEN '"subaccount_update"'::jsonb THEN + rval[i] = dydx_subaccount_update_handler(block_height, block_time, event_data, event_index, transaction_index); + WHEN '"transfer"'::jsonb THEN + rval[i] = dydx_transfer_handler(block_height, block_time, event_data, event_index, transaction_index, jsonb_array_element_text(block->'txHashes', transaction_index)); + WHEN '"stateful_order"'::jsonb THEN + rval[i] = dydx_stateful_order_handler(block_height, block_time, event_data); + WHEN '"funding_values"'::jsonb THEN + rval[i] = dydx_funding_handler(block_height, block_time, event_data, event_index, transaction_index); + WHEN '"deleveraging"'::jsonb THEN + rval[i] = dydx_deleveraging_handler(block_height, block_time, event_data, event_index, transaction_index, jsonb_array_element_text(block->'txHashes', transaction_index)); + ELSE + NULL; + END CASE; + END LOOP; + + RETURN rval; +END; +$$ LANGUAGE plpgsql; diff --git a/indexer/services/ender/src/scripts/dydx_create_initial_rows_for_tendermint_block.sql b/indexer/services/ender/src/scripts/dydx_create_initial_rows_for_tendermint_block.sql index 11fd91ba08..58e717d887 100644 --- a/indexer/services/ender/src/scripts/dydx_create_initial_rows_for_tendermint_block.sql +++ b/indexer/services/ender/src/scripts/dydx_create_initial_rows_for_tendermint_block.sql @@ -1,5 +1,5 @@ CREATE OR REPLACE FUNCTION dydx_create_initial_rows_for_tendermint_block( - block_height text, block_time text, tx_hashes text[], events jsonb[]) RETURNS void AS $$ + block_height int, block_time timestamp, tx_hashes jsonb, events jsonb) RETURNS void AS $$ /** Parameters: - block_height: the height of the block being processed. @@ -12,19 +12,19 @@ CREATE OR REPLACE FUNCTION dydx_create_initial_rows_for_tendermint_block( */ BEGIN -- Create block. - INSERT INTO blocks ("blockHeight", "time") VALUES (block_height::bigint, block_time::timestamp); + INSERT INTO blocks ("blockHeight", "time") VALUES (block_height, block_time); -- Create transactions. - IF tx_hashes IS NOT NULL AND array_length(tx_hashes, 1) > 0 THEN - FOR i IN 1..array_length(tx_hashes, 1) LOOP - PERFORM dydx_create_transaction(tx_hashes[i], block_height, i); + IF tx_hashes IS NOT NULL AND jsonb_array_length(tx_hashes) > 0 THEN + FOR i IN 0..jsonb_array_length(tx_hashes)-1 LOOP + PERFORM dydx_create_transaction(jsonb_array_element_text(tx_hashes, i), block_height, i); END LOOP; END IF; -- Create tendermint events. - IF events IS NOT NULL AND array_length(events, 1) > 0 THEN - FOR i IN 1..array_length(events, 1) LOOP - PERFORM dydx_create_tendermint_event(events[i], block_height); + IF events IS NOT NULL AND jsonb_array_length(events) > 0 THEN + FOR i IN 0..jsonb_array_length(events)-1 LOOP + PERFORM dydx_create_tendermint_event(jsonb_array_element(events, i), block_height); END LOOP; END IF; END; diff --git a/indexer/services/ender/src/scripts/dydx_create_tendermint_event.sql b/indexer/services/ender/src/scripts/dydx_create_tendermint_event.sql index b720be1057..d5c6742cf7 100644 --- a/indexer/services/ender/src/scripts/dydx_create_tendermint_event.sql +++ b/indexer/services/ender/src/scripts/dydx_create_tendermint_event.sql @@ -1,5 +1,5 @@ CREATE OR REPLACE FUNCTION dydx_create_tendermint_event( - event jsonb, block_height text + event jsonb, block_height int ) RETURNS jsonb AS $$ /** Parameters: @@ -18,7 +18,7 @@ BEGIN event_id := dydx_event_id_from_parts(CAST(block_height AS int), transaction_idx, CAST(event->>'eventIndex' AS int)); INSERT INTO tendermint_events ("id", "blockHeight", "transactionIndex", "eventIndex") - VALUES (event_id, block_height::bigint, transaction_idx, CAST(event->>'eventIndex' AS int)) + VALUES (event_id, block_height, transaction_idx, (event->'eventIndex')::int) RETURNING to_jsonb(tendermint_events.*) INTO inserted_event; RETURN inserted_event; diff --git a/indexer/services/ender/src/scripts/dydx_create_transaction.sql b/indexer/services/ender/src/scripts/dydx_create_transaction.sql index 989667d746..4723d69c23 100644 --- a/indexer/services/ender/src/scripts/dydx_create_transaction.sql +++ b/indexer/services/ender/src/scripts/dydx_create_transaction.sql @@ -1,5 +1,5 @@ CREATE OR REPLACE FUNCTION dydx_create_transaction( - transaction_hash text, block_height text, transaction_index int + transaction_hash text, block_height int, transaction_index int ) RETURNS jsonb AS $$ /** Parameters: @@ -14,8 +14,8 @@ DECLARE inserted_transaction jsonb; BEGIN INSERT INTO transactions ("blockHeight", "transactionIndex", "transactionHash", "id") - VALUES (block_height::bigint, transaction_index, transaction_hash, - dydx_uuid_from_transaction_parts(block_height, transaction_index::text)) + VALUES (block_height, transaction_index, transaction_hash, + dydx_uuid_from_transaction_parts(block_height, transaction_index)) RETURNING to_jsonb(transactions.*) INTO inserted_transaction; RETURN inserted_transaction; diff --git a/indexer/services/ender/src/scripts/dydx_stateful_order_handler.sql b/indexer/services/ender/src/scripts/dydx_stateful_order_handler.sql index b8a4b108a8..e4962c07a3 100644 --- a/indexer/services/ender/src/scripts/dydx_stateful_order_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_stateful_order_handler.sql @@ -24,7 +24,7 @@ DECLARE BEGIN /** TODO(IND-334): Remove after deprecating StatefulOrderPlacementEvent. */ IF event_data->'orderPlace' IS NOT NULL OR event_data->'longTermOrderPlacement' IS NOT NULL OR event_data->'conditionalOrderPlacement' IS NOT NULL THEN - order_ = COALESCE(event_data->'orderPlace'->'order', event_data->'longTermOrderPlacement'->'order', event_data->'conditionalOrderPlacement'->'order'); + order_ = coalesce(event_data->'orderPlace'->'order', event_data->'longTermOrderPlacement'->'order', event_data->'conditionalOrderPlacement'->'order'); clob_pair_id = (order_->'orderId'->'clobPairId')::bigint; perpetual_market_record = dydx_get_perpetual_market_for_clob_pair(clob_pair_id); diff --git a/indexer/services/ender/src/scripts/dydx_uuid_from_transaction_parts.sql b/indexer/services/ender/src/scripts/dydx_uuid_from_transaction_parts.sql index cdbd16d71e..8bd3438e59 100644 --- a/indexer/services/ender/src/scripts/dydx_uuid_from_transaction_parts.sql +++ b/indexer/services/ender/src/scripts/dydx_uuid_from_transaction_parts.sql @@ -1,4 +1,4 @@ -CREATE OR REPLACE FUNCTION dydx_uuid_from_transaction_parts(block_height text, transaction_index text) RETURNS uuid AS $$ +CREATE OR REPLACE FUNCTION dydx_uuid_from_transaction_parts(block_height int, transaction_index int) RETURNS uuid AS $$ /** Returns a UUID using the parts of a transaction. diff --git a/indexer/services/ender/src/validators/asset-validator.ts b/indexer/services/ender/src/validators/asset-validator.ts index 7bcc2422fc..0bf140e322 100644 --- a/indexer/services/ender/src/validators/asset-validator.ts +++ b/indexer/services/ender/src/validators/asset-validator.ts @@ -13,6 +13,7 @@ export class AssetValidator extends Validator { ): Handler[] { const handler: Handler = new AssetCreationHandler( this.block, + this.blockEventIndex, indexerTendermintEvent, txId, this.event, diff --git a/indexer/services/ender/src/validators/deleveraging-validator.ts b/indexer/services/ender/src/validators/deleveraging-validator.ts index c722b68159..7a75557977 100644 --- a/indexer/services/ender/src/validators/deleveraging-validator.ts +++ b/indexer/services/ender/src/validators/deleveraging-validator.ts @@ -29,6 +29,7 @@ export class DeleveragingValidator extends Validator { return [ new DeleveragingHandler( this.block, + this.blockEventIndex, indexerTendermintEvent, txId, this.event, diff --git a/indexer/services/ender/src/validators/funding-validator.ts b/indexer/services/ender/src/validators/funding-validator.ts index 0429aa5204..894a69bf41 100644 --- a/indexer/services/ender/src/validators/funding-validator.ts +++ b/indexer/services/ender/src/validators/funding-validator.ts @@ -42,6 +42,7 @@ export class FundingValidator extends Validator { ): Handler[] { const handler: Handler = new FundingHandler( this.block, + this.blockEventIndex, indexerTendermintEvent, txId, this.event as FundingEventMessage, diff --git a/indexer/services/ender/src/validators/liquidity-tier-validator.ts b/indexer/services/ender/src/validators/liquidity-tier-validator.ts index 5db8d771fc..3c6417e0f9 100644 --- a/indexer/services/ender/src/validators/liquidity-tier-validator.ts +++ b/indexer/services/ender/src/validators/liquidity-tier-validator.ts @@ -47,6 +47,7 @@ export class LiquidityTierValidator extends Validator[] { const handler: Handler = new LiquidityTierHandler( this.block, + this.blockEventIndex, indexerTendermintEvent, txId, this.event, diff --git a/indexer/services/ender/src/validators/market-validator.ts b/indexer/services/ender/src/validators/market-validator.ts index 665aa58921..fef4dbd787 100644 --- a/indexer/services/ender/src/validators/market-validator.ts +++ b/indexer/services/ender/src/validators/market-validator.ts @@ -116,6 +116,7 @@ export class MarketValidator extends Validator { // @ts-ignore const handler: Handler = new Initializer( this.block, + this.blockEventIndex, indexerTendermintEvent, txId, this.event, diff --git a/indexer/services/ender/src/validators/order-fill-validator.ts b/indexer/services/ender/src/validators/order-fill-validator.ts index cc4aabbbeb..d25eb6421d 100644 --- a/indexer/services/ender/src/validators/order-fill-validator.ts +++ b/indexer/services/ender/src/validators/order-fill-validator.ts @@ -1,4 +1,8 @@ -import { Liquidity } from '@dydxprotocol-indexer/postgres'; +import { + Liquidity, + OrderTable, +} from '@dydxprotocol-indexer/postgres'; +import { CanceledOrdersCache } from '@dydxprotocol-indexer/redis'; import { IndexerTendermintEvent, LiquidationOrderV1, @@ -9,6 +13,7 @@ import _ from 'lodash'; import { Handler, HandlerInitializer } from '../handlers/handler'; import { LiquidationHandler } from '../handlers/order-fills/liquidation-handler'; import { OrderHandler } from '../handlers/order-fills/order-handler'; +import { redisClient } from '../helpers/redis/redis-controller'; import { orderFillEventV1ToOrderFill } from '../helpers/translation-helper'; import { OrderFillWithLiquidity } from '../lib/translated-types'; import { OrderFillEventWithLiquidity } from '../lib/types'; @@ -32,6 +37,33 @@ export class OrderFillValidator extends Validator { } } + public async getEventForBlockProcessor(): Promise { + // If event.order is populated then this means it is not a liquidation + // order, and therefore we need to know the canceled order status stored + // in redis to correctly update the database. + if (this.event.order) { + return Promise.all([ + CanceledOrdersCache.getOrderCanceledStatus( + OrderTable.orderIdToUuid(this.event.makerOrder!.orderId!), + redisClient, + ), + CanceledOrdersCache.getOrderCanceledStatus( + OrderTable.orderIdToUuid(this.event.order.orderId!), + redisClient, + ), + ], + ).then((canceledOrderStatuses) => { + return { + makerCanceledOrderStatus: canceledOrderStatuses[0], + takerCanceledOrderstatus: canceledOrderStatuses[1], + ...this.event, + }; + }); + } + + return this.event; + } + private validateOrder( order: IndexerOrder, liquidity: Liquidity, @@ -82,6 +114,7 @@ export class OrderFillValidator extends Validator { (orderFillEventWithLiquidity: OrderFillEventWithLiquidity) => { return new Initializer( this.block, + this.blockEventIndex, indexerTendermintEvent, txId, orderFillEventV1ToOrderFill(orderFillEventWithLiquidity), diff --git a/indexer/services/ender/src/validators/perpetual-market-validator.ts b/indexer/services/ender/src/validators/perpetual-market-validator.ts index 2ea504c35c..93531c835b 100644 --- a/indexer/services/ender/src/validators/perpetual-market-validator.ts +++ b/indexer/services/ender/src/validators/perpetual-market-validator.ts @@ -41,6 +41,7 @@ export class PerpetualMarketValidator extends Validator[] { const handler: Handler = new PerpetualMarketCreationHandler( this.block, + this.blockEventIndex, indexerTendermintEvent, txId, this.event, diff --git a/indexer/services/ender/src/validators/stateful-order-validator.ts b/indexer/services/ender/src/validators/stateful-order-validator.ts index e2e6bd5cd3..066b7fbb20 100644 --- a/indexer/services/ender/src/validators/stateful-order-validator.ts +++ b/indexer/services/ender/src/validators/stateful-order-validator.ts @@ -223,6 +223,7 @@ export class StatefulOrderValidator extends Validator { // @ts-ignore const handler: Handler = new Initializer( this.block, + this.blockEventIndex, indexerTendermintEvent, txId, this.event, diff --git a/indexer/services/ender/src/validators/subaccount-update-validator.ts b/indexer/services/ender/src/validators/subaccount-update-validator.ts index 7c1de9fdad..a747a43716 100644 --- a/indexer/services/ender/src/validators/subaccount-update-validator.ts +++ b/indexer/services/ender/src/validators/subaccount-update-validator.ts @@ -23,6 +23,7 @@ export class SubaccountUpdateValidator extends Validator { return [ new TransferHandler( this.block, + this.blockEventIndex, indexerTendermintEvent, txId, this.event, diff --git a/indexer/services/ender/src/validators/update-clob-pair-validator.ts b/indexer/services/ender/src/validators/update-clob-pair-validator.ts index 07bd892a82..315075da3f 100644 --- a/indexer/services/ender/src/validators/update-clob-pair-validator.ts +++ b/indexer/services/ender/src/validators/update-clob-pair-validator.ts @@ -23,6 +23,7 @@ export class UpdateClobPairValidator extends Validator { ): Handler[] { const handler: Handler = new UpdateClobPairHandler( this.block, + this.blockEventIndex, indexerTendermintEvent, txId, this.event, diff --git a/indexer/services/ender/src/validators/update-perpetual-validator.ts b/indexer/services/ender/src/validators/update-perpetual-validator.ts index 2f2f5586e6..b0511d7e48 100644 --- a/indexer/services/ender/src/validators/update-perpetual-validator.ts +++ b/indexer/services/ender/src/validators/update-perpetual-validator.ts @@ -21,6 +21,7 @@ export class UpdatePerpetualValidator extends Validator ): Handler[] { const handler: Handler = new UpdatePerpetualHandler( this.block, + this.blockEventIndex, indexerTendermintEvent, txId, this.event, diff --git a/indexer/services/ender/src/validators/validator.ts b/indexer/services/ender/src/validators/validator.ts index 7808fa5ae3..3db9fe9b5a 100644 --- a/indexer/services/ender/src/validators/validator.ts +++ b/indexer/services/ender/src/validators/validator.ts @@ -7,14 +7,17 @@ import { EventMessage } from '../lib/types'; export type ValidatorInitializer = new ( event: EventMessage, block: IndexerTendermintBlock, + eventBlockIndex: number, ) => Validator; -export abstract class Validator { +export abstract class Validator { event: T; block: IndexerTendermintBlock; + blockEventIndex: number; - constructor(event: T, block: IndexerTendermintBlock) { + constructor(event: T, block: IndexerTendermintBlock, blockEventIndex: number) { this.event = event; + this.blockEventIndex = blockEventIndex; this.block = block; } @@ -23,6 +26,16 @@ export abstract class Validator { */ public abstract validate(): void; + /** + * Returns the decoded event and any additional details the SQL function needs to process. + */ + // TODO(IND-513): Convert handlers to have a 1-1 relationship with each validator by merging + // the order fill handlers together into a single handler (and the respective SQL function) + // and push this method down into the handler itself. + public getEventForBlockProcessor(): Promise { + return Promise.resolve(this.event); + } + protected logAndThrowParseMessageError( message: string, // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/indexer/services/roundtable/src/tasks/remove-expired-orders.ts b/indexer/services/roundtable/src/tasks/remove-expired-orders.ts index 8fd19a9022..45c8e7f64b 100644 --- a/indexer/services/roundtable/src/tasks/remove-expired-orders.ts +++ b/indexer/services/roundtable/src/tasks/remove-expired-orders.ts @@ -49,6 +49,7 @@ export default async function runTask(): Promise { const batchKafkaProducer: BatchKafkaProducer = new BatchKafkaProducer( KafkaTopics.TO_VULCAN, producer, + config.KAFKA_MAX_BATCH_WEBSOCKET_MESSAGE_SIZE_BYTES, ); const allPromises: Promise[] = _.map(orderUuids, (orderUuid: string) => { From 9e08e81b9f6f198ee0a10b99f4981fb7e0c3970f Mon Sep 17 00:00:00 2001 From: Jonathan Fung <121899091+jonfung-dydx@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:29:18 -0700 Subject: [PATCH 3/6] [CLOB-1014] [CLOB-1004] Unify metrics library, un-modularize metrics keys (#792) * add new unified metrics library * migrate clob/abci.go and deleveraging * liquidations file * delete dupe'd function * clean out mev.go * clean up * touchup * one more thing * add TODO for module measure since * disable lll linter for metrics_keys.go --- protocol/lib/metrics/constants.go | 1 - protocol/lib/metrics/lib.go | 92 ++++++++++++++++++++++++++ protocol/lib/metrics/metric_keys.go | 42 ++++++++++++ protocol/lib/metrics/util.go | 20 ------ protocol/x/clob/abci.go | 12 ++-- protocol/x/clob/keeper/deleveraging.go | 83 ++++++++++++----------- protocol/x/clob/keeper/liquidations.go | 54 +++++++-------- protocol/x/clob/keeper/mev.go | 60 +++++++++++------ protocol/x/clob/types/order_id.go | 5 +- 9 files changed, 246 insertions(+), 123 deletions(-) create mode 100644 protocol/lib/metrics/lib.go create mode 100644 protocol/lib/metrics/metric_keys.go diff --git a/protocol/lib/metrics/constants.go b/protocol/lib/metrics/constants.go index dff52b62c0..c988e626aa 100644 --- a/protocol/lib/metrics/constants.go +++ b/protocol/lib/metrics/constants.go @@ -302,7 +302,6 @@ const ( // Liquidation. ConstructLiquidationOrder = "construct_liquidation_order" - InsuranceFundBalance = "insurance_fund_balance" InsuranceFundDelta = "insurance_fund_delta" Liquidations = "liquidations" MaybeGetLiquidationOrder = "maybe_get_liquidation_order" diff --git a/protocol/lib/metrics/lib.go b/protocol/lib/metrics/lib.go new file mode 100644 index 0000000000..bd67d1c41e --- /dev/null +++ b/protocol/lib/metrics/lib.go @@ -0,0 +1,92 @@ +package metrics + +import ( + "time" + + gometrics "github.com/armon/go-metrics" + "github.com/cosmos/cosmos-sdk/telemetry" +) + +// This file provides a main entrypoint for logging in the v4 protocol. +// TODO(CLOB-1013) Drop both metrics libraries above for a library +// that supports float64 (i.e hashicorp go-metrics) + +type Label = gometrics.Label + +// IncrCounterWithLabels provides a wrapper functionality for emitting a counter +// metric with global labels (if any) along with the provided labels. +func IncrCounterWithLabels(key string, val float32, labels ...Label) { + telemetry.IncrCounterWithLabels([]string{key}, val, labels) +} + +// IncrCounter provides a wrapper functionality for emitting a counter +// metric with global labels (if any). +func IncrCounter(key string, val float32) { + telemetry.IncrCounterWithLabels([]string{key}, val, []gometrics.Label{}) +} + +// SetGaugeWithLabels provides a wrapper functionality for emitting a gauge +// metric with global labels (if any) along with the provided labels. +func SetGaugeWithLabels(key string, val float32, labels ...gometrics.Label) { + telemetry.SetGaugeWithLabels([]string{key}, val, labels) +} + +// SetGauge provides a wrapper functionality for emitting a gauge +// metric with global labels (if any). +func SetGauge(key string, val float32) { + telemetry.SetGaugeWithLabels([]string{key}, val, []gometrics.Label{}) +} + +// AddSampleWithLabels provides a wrapper functionality for emitting a sample +// metric with the provided labels. +func AddSampleWithLabels(key string, val float32, labels ...gometrics.Label) { + gometrics.AddSampleWithLabels( + []string{key}, + val, + labels, + ) +} + +// AddSample provides a wrapper functionality for emitting a sample +// metric. +func AddSample(key string, val float32) { + gometrics.AddSampleWithLabels( + []string{key}, + val, + []gometrics.Label{}, + ) +} + +// ModuleMeasureSince provides a wrapper functionality for emitting a time measure +// metric with global labels (if any). +// Please try to use `AddSample` instead. +// TODO(CLOB-1022) Roll our own calculations for timing on top of AddSample instead +// of using MeasureSince. +func ModuleMeasureSince(module string, key string, start time.Time) { + telemetry.ModuleMeasureSince( + module, + start, + key, + ) +} + +// ModuleMeasureSinceWithLabels provides a short hand method for emitting a time measure +// metric for a module with labels. Global labels are not included in this metric. +// Please try to use `AddSampleWithLabels` instead. +// TODO(CLOB-1022) Roll our own calculations for timing on top of AddSample instead +// of using MeasureSince. +func ModuleMeasureSinceWithLabels( + module string, + keys []string, + start time.Time, + labels []gometrics.Label, +) { + gometrics.MeasureSinceWithLabels( + keys, + start.UTC(), + append( + []gometrics.Label{telemetry.NewLabel(telemetry.MetricLabelNameModule, module)}, + labels..., + ), + ) +} diff --git a/protocol/lib/metrics/metric_keys.go b/protocol/lib/metrics/metric_keys.go new file mode 100644 index 0000000000..1be6e8f717 --- /dev/null +++ b/protocol/lib/metrics/metric_keys.go @@ -0,0 +1,42 @@ +// nolint:lll +package metrics + +// Metrics Keys Guidelines +// 1. Be wary of length +// 2. Prefix by module +// 3. Suffix keys with a unit of measurement +// 4. Delimit with '_' +// 5. Information such as callback type should be added as tags, not in key names. +// Example: clob_place_order_count, clob_msg_place_order_latency_ms, clob_operations_queue_length +// clob_expired_stateful_orders_count, clob_processed_orders_ms_total + +// Clob Metrics Keys +const ( + // Stats + ClobExpiredStatefulOrders = "clob_expired_stateful_order_removed" + ClobPrepareCheckStateCannotDeleverageSubaccount = "clob_prepare_check_state_cannot_deleverage_subaccount" + ClobDeleverageSubaccountTotalQuoteQuantums = "clob_deleverage_subaccount_total_quote_quantums" + ClobDeleverageSubaccount = "clob_deleverage_subaccount" + LiquidationsPlacePerpetualLiquidationQuoteQuantums = "liquidations_place_perpetual_liquidation_quote_quantums" + LiquidationsLiquidationMatchNegativeTNC = "liquidations_liquidation_match_negative_tnc" + ClobMevErrorCount = "clob_mev_error_count" + + // Gauges + InsuranceFundBalance = "insurance_fund_balance" + ClobMev = "clob_mev" + + // Samples + ClobDeleverageSubaccountTotalQuoteQuantumsDistribution = "clob_deleverage_subaccount_total_quote_quantums_distribution" + DeleveragingPercentFilledDistribution = "deleveraging_percent_filled_distribution" + ClobDeleveragingNumSubaccountsIteratedCount = "clob_deleveraging_num_subaccounts_iterated_count" + ClobDeleveragingNonOverlappingBankrupcyPricesCount = "clob_deleveraging_non_overlapping_bankruptcy_prices_count" + ClobDeleveragingNoOpenPositionOnOppositeSideCount = "clob_deleveraging_no_open_position_on_opposite_side_count" + ClobDeleverageSubaccountFilledQuoteQuantums = "clob_deleverage_subaccount_filled_quote_quantums" + LiquidationsLiquidatableSubaccountIdsCount = "liquidations_liquidatable_subaccount_ids_count" + LiquidationsPercentFilledDistribution = "liquidations_percent_filled_distribution" + LiquidationsPlacePerpetualLiquidationQuoteQuantumsDistribution = "liquidations_place_perpetual_liquidation_quote_quantums_distribution" + + // Measure Since + ClobOffsettingSubaccountPerpetualPosition = "clob_offsetting_subaccount_perpetual_position" + MevLatency = "mev_latency" +) diff --git a/protocol/lib/metrics/util.go b/protocol/lib/metrics/util.go index 3d7d71682b..cd16b4261b 100644 --- a/protocol/lib/metrics/util.go +++ b/protocol/lib/metrics/util.go @@ -3,7 +3,6 @@ package metrics import ( "math/big" "strconv" - "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -68,25 +67,6 @@ func GetMetricValueFromBigInt(i *big.Int) float32 { return r } -// ModuleMeasureSinceWithLabels provides a short hand method for emitting a time measure -// metric for a module with a given set of keys and labels. -// NOTE: global labels are not included in this metric. -func ModuleMeasureSinceWithLabels( - module string, - keys []string, - start time.Time, - labels []gometrics.Label, -) { - gometrics.MeasureSinceWithLabels( - keys, - start.UTC(), - append( - []gometrics.Label{telemetry.NewLabel(telemetry.MetricLabelNameModule, module)}, - labels..., - ), - ) -} - // GetCallbackMetricFromCtx determines the callback metric based on the context. Note that DeliverTx is implied // if the context is not CheckTx or ReCheckTx. This function is unable to account for other callbacks like // PrepareCheckState or EndBlocker. diff --git a/protocol/x/clob/abci.go b/protocol/x/clob/abci.go index f8e89134ce..b22303d983 100644 --- a/protocol/x/clob/abci.go +++ b/protocol/x/clob/abci.go @@ -4,7 +4,6 @@ import ( "fmt" "time" - gometrics "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" liquidationtypes "github.com/dydxprotocol/v4-chain/protocol/daemons/server/types/liquidations" @@ -63,10 +62,10 @@ func EndBlocker( ), ), ) - telemetry.IncrCounterWithLabels( - []string{types.ModuleName, metrics.Expired, metrics.StatefulOrderRemoved, metrics.Count}, + metrics.IncrCounterWithLabels( + metrics.ClobExpiredStatefulOrders, 1, - orderId.GetOrderIdLabels(), + orderId.GetOrderIdLabels()..., ) } @@ -108,10 +107,9 @@ func EndBlocker( keeper.PruneRateLimits(ctx) // Emit relevant metrics at the end of every block. - telemetry.SetGaugeWithLabels( - []string{metrics.InsuranceFundBalance}, + metrics.SetGauge( + metrics.InsuranceFundBalance, metrics.GetMetricValueFromBigInt(keeper.GetInsuranceFundBalance(ctx)), - []gometrics.Label{}, ) } diff --git a/protocol/x/clob/keeper/deleveraging.go b/protocol/x/clob/keeper/deleveraging.go index 50e055e3ab..794d2ff835 100644 --- a/protocol/x/clob/keeper/deleveraging.go +++ b/protocol/x/clob/keeper/deleveraging.go @@ -3,15 +3,14 @@ package keeper import ( "errors" "fmt" - indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" - "github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager" "math/big" "time" + indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" + "github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager" + errorsmod "cosmossdk.io/errors" - gometrics "github.com/armon/go-metrics" - "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/dydxprotocol/v4-chain/protocol/lib" "github.com/dydxprotocol/v4-chain/protocol/lib/metrics" @@ -41,11 +40,9 @@ func (k Keeper) MaybeDeleverageSubaccount( // Early return to skip deleveraging if the subaccount can't be deleveraged. if !canPerformDeleveraging { - telemetry.IncrCounter( + metrics.IncrCounter( + metrics.ClobPrepareCheckStateCannotDeleverageSubaccount, 1, - types.ModuleName, - metrics.PrepareCheckState, - metrics.CannotDeleverageSubaccount, ) return new(big.Int), nil } @@ -67,7 +64,7 @@ func (k Keeper) MaybeDeleverageSubaccount( deltaQuantums := new(big.Int).Neg(position.GetBigQuantums()) quantumsDeleveraged, err = k.MemClob.DeleverageSubaccount(ctx, subaccountId, perpetualId, deltaQuantums) - labels := []gometrics.Label{ + labels := []metrics.Label{ metrics.GetLabelForIntValue(metrics.PerpetualId, int(perpetualId)), metrics.GetLabelForBoolValue(metrics.IsLong, deltaQuantums.Sign() == -1), } @@ -79,22 +76,27 @@ func (k Keeper) MaybeDeleverageSubaccount( labels = append(labels, metrics.GetLabelForStringValue(metrics.Status, metrics.PartiallyFilled)) } // Record the status of the deleveraging operation. - telemetry.IncrCounterWithLabels([]string{types.ModuleName, metrics.DeleverageSubaccount}, 1, labels) + metrics.IncrCounterWithLabels( + metrics.ClobDeleverageSubaccount, + 1, + labels..., + ) if quoteQuantums, err := k.perpetualsKeeper.GetNetNotional( ctx, perpetualId, new(big.Int).Abs(deltaQuantums), ); err == nil { - telemetry.IncrCounterWithLabels( - []string{types.ModuleName, metrics.DeleverageSubaccount, metrics.TotalQuoteQuantums}, + metrics.IncrCounterWithLabels( + metrics.ClobDeleverageSubaccountTotalQuoteQuantums, metrics.GetMetricValueFromBigInt(quoteQuantums), - labels, + labels..., ) - gometrics.AddSampleWithLabels( - []string{types.ModuleName, metrics.DeleverageSubaccount, metrics.TotalQuoteQuantums, metrics.Distribution}, + + metrics.AddSampleWithLabels( + metrics.ClobDeleverageSubaccountTotalQuoteQuantumsDistribution, metrics.GetMetricValueFromBigInt(quoteQuantums), - labels, + labels..., ) } @@ -103,10 +105,11 @@ func (k Keeper) MaybeDeleverageSubaccount( new(big.Float).SetInt(new(big.Int).Abs(quantumsDeleveraged)), new(big.Float).SetInt(new(big.Int).Abs(deltaQuantums)), ).Float32() - gometrics.AddSampleWithLabels( - []string{metrics.Deleveraging, metrics.PercentFilled, metrics.Distribution}, + + metrics.AddSampleWithLabels( + metrics.DeleveragingPercentFilledDistribution, percentFilled, - labels, + labels..., ) return quantumsDeleveraged, err @@ -195,11 +198,10 @@ func (k Keeper) OffsetSubaccountPerpetualPosition( fills []types.MatchPerpetualDeleveraging_Fill, deltaQuantumsRemaining *big.Int, ) { - defer telemetry.ModuleMeasureSince( + defer metrics.ModuleMeasureSince( types.ModuleName, + metrics.ClobOffsettingSubaccountPerpetualPosition, time.Now(), - types.ModuleName, - metrics.OffsettingSubaccountPerpetualPosition, ) numSubaccountsIterated := uint32(0) @@ -280,29 +282,25 @@ func (k Keeper) OffsetSubaccountPerpetualPosition( k.GetPseudoRand(ctx), ) - labels := []gometrics.Label{ + labels := []metrics.Label{ metrics.GetLabelForIntValue(metrics.PerpetualId, int(perpetualId)), } - gometrics.AddSampleWithLabels( - []string{ - types.ModuleName, metrics.Deleveraging, metrics.NumSubaccountsIterated, metrics.Count, - }, + + metrics.AddSampleWithLabels( + metrics.ClobDeleveragingNumSubaccountsIteratedCount, float32(numSubaccountsIterated), - labels, + labels..., ) - gometrics.AddSampleWithLabels( - []string{ - types.ModuleName, metrics.Deleveraging, metrics.NonOverlappingBankruptcyPrices, metrics.Count, - }, + + metrics.AddSampleWithLabels( + metrics.ClobDeleveragingNonOverlappingBankrupcyPricesCount, float32(numSubaccountsWithNonOverlappingBankruptcyPrices), - labels, + labels..., ) - gometrics.AddSampleWithLabels( - []string{ - types.ModuleName, metrics.Deleveraging, metrics.NoOpenPositionOnOppositeSide, metrics.Count, - }, + metrics.AddSampleWithLabels( + metrics.ClobDeleveragingNoOpenPositionOnOppositeSideCount, float32(numSubaccountsWithNoOpenPositionOnOppositeSide), - labels, + labels..., ) return fills, deltaQuantumsRemaining } @@ -423,15 +421,16 @@ func (k Keeper) ProcessDeleveraging( perpetualId, new(big.Int).Abs(deltaQuantums), ); err == nil { - labels := []gometrics.Label{ + labels := []metrics.Label{ metrics.GetLabelForIntValue(metrics.PerpetualId, int(perpetualId)), metrics.GetLabelForBoolValue(metrics.CheckTx, ctx.IsCheckTx()), metrics.GetLabelForBoolValue(metrics.IsLong, deltaQuantums.Sign() == -1), } - gometrics.AddSampleWithLabels( - []string{types.ModuleName, metrics.DeleverageSubaccount, metrics.Filled, metrics.QuoteQuantums}, + + metrics.AddSampleWithLabels( + metrics.ClobDeleverageSubaccountFilledQuoteQuantums, metrics.GetMetricValueFromBigInt(deleveragedQuoteQuantums), - labels, + labels..., ) } diff --git a/protocol/x/clob/keeper/liquidations.go b/protocol/x/clob/keeper/liquidations.go index eb5d4190b8..8017370cfa 100644 --- a/protocol/x/clob/keeper/liquidations.go +++ b/protocol/x/clob/keeper/liquidations.go @@ -10,7 +10,6 @@ import ( errorsmod "cosmossdk.io/errors" - gometrics "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/dydxprotocol/v4-chain/protocol/lib" @@ -28,12 +27,8 @@ func (k Keeper) LiquidateSubaccountsAgainstOrderbook( ) error { lib.AssertCheckTxMode(ctx) - gometrics.AddSample( - []string{ - metrics.Liquidations, - metrics.LiquidatableSubaccountIds, - metrics.Count, - }, + metrics.AddSample( + metrics.LiquidationsLiquidatableSubaccountIdsCount, float32(len(subaccountIds)), ) @@ -284,7 +279,7 @@ func (k Keeper) PlacePerpetualLiquidation( perpetualId, ) - labels := []gometrics.Label{ + labels := []metrics.Label{ metrics.GetLabelForIntValue(metrics.PerpetualId, int(perpetualId)), } if liquidationOrder.IsBuy() { @@ -298,10 +293,11 @@ func (k Keeper) PlacePerpetualLiquidation( new(big.Float).SetUint64(orderSizeOptimisticallyFilledFromMatchingQuantums.ToUint64()), new(big.Float).SetUint64(liquidationOrder.GetBaseQuantums().ToUint64()), ).Float32() - gometrics.AddSampleWithLabels( - []string{metrics.Liquidations, metrics.PercentFilled, metrics.Distribution}, + + metrics.AddSampleWithLabels( + metrics.LiquidationsPercentFilledDistribution, percentFilled, - labels, + labels..., ) if orderSizeOptimisticallyFilledFromMatchingQuantums == 0 { @@ -324,15 +320,16 @@ func (k Keeper) PlacePerpetualLiquidation( perpetualId, liquidationOrder.GetBaseQuantums().ToBigInt(), ); err == nil { - telemetry.IncrCounterWithLabels( - []string{metrics.Liquidations, metrics.PlacePerpetualLiquidation, metrics.QuoteQuantums}, + metrics.IncrCounterWithLabels( + metrics.LiquidationsPlacePerpetualLiquidationQuoteQuantums, metrics.GetMetricValueFromBigInt(totalQuoteQuantums), - labels, + labels..., ) - gometrics.AddSampleWithLabels( - []string{metrics.Liquidations, metrics.PlacePerpetualLiquidation, metrics.QuoteQuantums, metrics.Distribution}, + + metrics.AddSampleWithLabels( + metrics.LiquidationsPlacePerpetualLiquidationQuoteQuantumsDistribution, metrics.GetMetricValueFromBigInt(totalQuoteQuantums), - labels, + labels..., ) } @@ -581,19 +578,18 @@ func (k Keeper) GetFillablePrice( if !ctx.IsCheckTx() && !ctx.IsReCheckTx() { callback = metrics.DeliverTx } - telemetry.IncrCounterWithLabels( - []string{metrics.Liquidations, metrics.LiquidationMatchNegativeTNC}, + + metrics.IncrCounterWithLabels( + metrics.LiquidationsLiquidationMatchNegativeTNC, 1, - []gometrics.Label{ - metrics.GetLabelForIntValue( - metrics.PerpetualId, - int(perpetualId), - ), - metrics.GetLabelForStringValue( - metrics.Callback, - callback, - ), - }, + metrics.GetLabelForIntValue( + metrics.PerpetualId, + int(perpetualId), + ), + metrics.GetLabelForStringValue( + metrics.Callback, + callback, + ), ) ctx.Logger().Info( diff --git a/protocol/x/clob/keeper/mev.go b/protocol/x/clob/keeper/mev.go index f1015c4ecb..870dc0e0f1 100644 --- a/protocol/x/clob/keeper/mev.go +++ b/protocol/x/clob/keeper/mev.go @@ -6,8 +6,6 @@ import ( "runtime/debug" "time" - gometrics "github.com/armon/go-metrics" - "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/dydxprotocol/v4-chain/protocol/app/process" "github.com/dydxprotocol/v4-chain/protocol/lib" @@ -60,7 +58,11 @@ func (k Keeper) RecordMevMetrics( perpetualKeeper process.ProcessPerpetualKeeper, msgProposedOperations *types.MsgProposedOperations, ) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), metrics.Mev, metrics.Latency) + defer metrics.ModuleMeasureSince( + types.ModuleName, + metrics.MevLatency, + time.Now(), + ) // Recover from any panics that occur during MEV calculation. defer func() { @@ -99,7 +101,10 @@ func (k Keeper) RecordMevMetrics( msgProposedOperations.GetOperationsQueue(), ), ) - telemetry.IncrCounter(1, types.ModuleName, metrics.Mev, metrics.Error, metrics.Count) + metrics.IncrCounter( + metrics.ClobMevErrorCount, + 1, + ) return } if err := k.CalculateSubaccountPnLForMevMatches( @@ -114,7 +119,10 @@ func (k Keeper) RecordMevMetrics( blockProposerMevMatches, ), ) - telemetry.IncrCounter(1, types.ModuleName, metrics.Mev, metrics.Error, metrics.Count) + metrics.IncrCounter( + metrics.ClobMevErrorCount, + 1, + ) return } @@ -132,7 +140,10 @@ func (k Keeper) RecordMevMetrics( k.GetOperations(ctx).GetOperationsQueue(), ), ) - telemetry.IncrCounter(1, types.ModuleName, metrics.Mev, metrics.Error, metrics.Count) + metrics.IncrCounter( + metrics.ClobMevErrorCount, + 1, + ) return } if err := k.CalculateSubaccountPnLForMevMatches( @@ -147,7 +158,10 @@ func (k Keeper) RecordMevMetrics( validatorMevMatches, ), ) - telemetry.IncrCounter(1, types.ModuleName, metrics.Mev, metrics.Error, metrics.Count) + metrics.IncrCounter( + metrics.ClobMevErrorCount, + 1, + ) return } @@ -220,7 +234,10 @@ func (k Keeper) RecordMevMetrics( consensusRound, ok := ctx.Value(process.ConsensusRound).(int64) if !ok { k.Logger(ctx).Error("Failed to get consensus round") - telemetry.IncrCounter(1, types.ModuleName, metrics.Mev, metrics.Error, metrics.Count) + metrics.IncrCounter( + metrics.ClobMevErrorCount, + 1, + ) return } @@ -233,7 +250,10 @@ func (k Keeper) RecordMevMetrics( "proposer", proposerConsAddress.String(), ) - telemetry.IncrCounter(1, types.ModuleName, metrics.Mev, metrics.Error, metrics.Count) + metrics.IncrCounter( + metrics.ClobMevErrorCount, + 1, + ) return } @@ -280,19 +300,17 @@ func (k Keeper) RecordMevMetrics( ).String(), ) - telemetry.SetGaugeWithLabels( - []string{types.ModuleName, metrics.Mev}, + metrics.SetGaugeWithLabels( + metrics.ClobMev, mev, - []gometrics.Label{ - metrics.GetLabelForStringValue( - metrics.Proposer, - proposer.Description.Moniker, - ), - metrics.GetLabelForIntValue( - metrics.ClobPairId, - int(clobPairId.ToUint32()), - ), - }, + metrics.GetLabelForStringValue( + metrics.Proposer, + proposer.Description.Moniker, + ), + metrics.GetLabelForIntValue( + metrics.ClobPairId, + int(clobPairId.ToUint32()), + ), ) validatorVolumeQuoteQuantumsPerMarket[clobPairId] = new(big.Int).Div( diff --git a/protocol/x/clob/types/order_id.go b/protocol/x/clob/types/order_id.go index ee74f7aacf..8f629a1236 100644 --- a/protocol/x/clob/types/order_id.go +++ b/protocol/x/clob/types/order_id.go @@ -6,7 +6,6 @@ import ( errorsmod "cosmossdk.io/errors" - gometrics "github.com/armon/go-metrics" "github.com/dydxprotocol/v4-chain/protocol/lib/metrics" ) @@ -174,8 +173,8 @@ func MustSortAndHaveNoDuplicates(orderIds []OrderId) { } // GetOrderIdLabels returns the telemetry labels of this order ID. -func (o *OrderId) GetOrderIdLabels() []gometrics.Label { - return []gometrics.Label{ +func (o *OrderId) GetOrderIdLabels() []metrics.Label { + return []metrics.Label{ metrics.GetLabelForIntValue(metrics.OrderFlag, int(o.GetOrderFlags())), metrics.GetLabelForIntValue(metrics.ClobPairId, int(o.GetClobPairId())), } From f2e78ba7842b03f653284e5e8fc6c6e39f8c44d7 Mon Sep 17 00:00:00 2001 From: Jakob Herlitz <125316911+jakob-dydx@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:54:03 -0800 Subject: [PATCH 4/6] [CLOB-1007] add protos for final settlement clob pair status and removal reason (#828) * add protos for final settlement clob pair status and final settlement removal reason * add missing indexer constants * update proto formatting * fix indexer test * update comment and panic string * update broken test --- indexer/packages/postgres/src/constants.ts | 1 + .../src/types/perpetual-market-types.ts | 1 + .../codegen/dydxprotocol/clob/clob_pair.ts | 23 ++++ .../dydxprotocol/indexer/protocol/v1/clob.ts | 23 ++++ .../indexer/shared/removal_reason.ts | 13 ++ .../comlink/public/api-documentation.md | 1 + indexer/services/comlink/public/swagger.json | 3 +- ...dydx_clob_pair_status_to_market_status.sql | 1 + proto/dydxprotocol/clob/clob_pair.proto | 5 + .../indexer/protocol/v1/clob.proto | 5 + .../indexer/shared/removal_reason.proto | 2 + protocol/indexer/protocol/v1/clob.pb.go | 122 ++++++++++-------- protocol/indexer/protocol/v1/v1_mappers.go | 9 +- .../indexer/protocol/v1/v1_mappers_test.go | 5 +- protocol/indexer/shared/removal_reason.pb.go | 63 ++++----- protocol/x/clob/types/clob_pair.pb.go | 88 +++++++------ 16 files changed, 236 insertions(+), 129 deletions(-) diff --git a/indexer/packages/postgres/src/constants.ts b/indexer/packages/postgres/src/constants.ts index 900c2e6038..97846f3f37 100644 --- a/indexer/packages/postgres/src/constants.ts +++ b/indexer/packages/postgres/src/constants.ts @@ -110,6 +110,7 @@ Record = { [ClobPairStatus.CLOB_PAIR_STATUS_PAUSED]: PerpetualMarketStatus.PAUSED, [ClobPairStatus.CLOB_PAIR_STATUS_POST_ONLY]: PerpetualMarketStatus.POST_ONLY, [ClobPairStatus.CLOB_PAIR_STATUS_INITIALIZING]: PerpetualMarketStatus.INITIALIZING, + [ClobPairStatus.CLOB_PAIR_STATUS_FINAL_SETTLEMENT]: PerpetualMarketStatus.FINAL_SETTLEMENT, }; export const DEFAULT_POSTGRES_OPTIONS : Options = config.USE_READ_REPLICA diff --git a/indexer/packages/postgres/src/types/perpetual-market-types.ts b/indexer/packages/postgres/src/types/perpetual-market-types.ts index 65962fb655..13318b3c68 100644 --- a/indexer/packages/postgres/src/types/perpetual-market-types.ts +++ b/indexer/packages/postgres/src/types/perpetual-market-types.ts @@ -60,4 +60,5 @@ export enum PerpetualMarketStatus { CANCEL_ONLY = 'CANCEL_ONLY', POST_ONLY = 'POST_ONLY', INITIALIZING = 'INITIALIZING', + FINAL_SETTLEMENT = 'FINAL_SETTLEMENT', } diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/clob_pair.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/clob_pair.ts index d0bba0007e..f0c6ab0c2b 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/clob_pair.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/clob_pair.ts @@ -33,6 +33,14 @@ export enum ClobPair_Status { * both short-term and post-only. */ STATUS_INITIALIZING = 5, + + /** + * STATUS_FINAL_SETTLEMENT - STATUS_FINAL_SETTLEMENT represents a clob pair which is deactivated + * and trading has ceased. All open positions will be closed by the + * protocol. Open stateful orders will be cancelled. Open short-term + * orders will be left to expire. + */ + STATUS_FINAL_SETTLEMENT = 6, UNRECOGNIZED = -1, } /** Status of the CLOB. */ @@ -68,6 +76,14 @@ export enum ClobPair_StatusSDKType { * both short-term and post-only. */ STATUS_INITIALIZING = 5, + + /** + * STATUS_FINAL_SETTLEMENT - STATUS_FINAL_SETTLEMENT represents a clob pair which is deactivated + * and trading has ceased. All open positions will be closed by the + * protocol. Open stateful orders will be cancelled. Open short-term + * orders will be left to expire. + */ + STATUS_FINAL_SETTLEMENT = 6, UNRECOGNIZED = -1, } export function clobPair_StatusFromJSON(object: any): ClobPair_Status { @@ -96,6 +112,10 @@ export function clobPair_StatusFromJSON(object: any): ClobPair_Status { case "STATUS_INITIALIZING": return ClobPair_Status.STATUS_INITIALIZING; + case 6: + case "STATUS_FINAL_SETTLEMENT": + return ClobPair_Status.STATUS_FINAL_SETTLEMENT; + case -1: case "UNRECOGNIZED": default: @@ -122,6 +142,9 @@ export function clobPair_StatusToJSON(object: ClobPair_Status): string { case ClobPair_Status.STATUS_INITIALIZING: return "STATUS_INITIALIZING"; + case ClobPair_Status.STATUS_FINAL_SETTLEMENT: + return "STATUS_FINAL_SETTLEMENT"; + case ClobPair_Status.UNRECOGNIZED: default: return "UNRECOGNIZED"; diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/clob.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/clob.ts index e25b4b9767..92995bc19d 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/clob.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/protocol/v1/clob.ts @@ -307,6 +307,14 @@ export enum ClobPairStatus { * both short-term and post-only. */ CLOB_PAIR_STATUS_INITIALIZING = 5, + + /** + * CLOB_PAIR_STATUS_FINAL_SETTLEMENT - CLOB_PAIR_STATUS_FINAL_SETTLEMENT represents a clob pair that has been + * deactivated. Clob pairs in this state do not accept new orders and trading + * is blocked. All open positions are closed by the protocol when the clob + * pair gains this status. + */ + CLOB_PAIR_STATUS_FINAL_SETTLEMENT = 6, UNRECOGNIZED = -1, } /** @@ -348,6 +356,14 @@ export enum ClobPairStatusSDKType { * both short-term and post-only. */ CLOB_PAIR_STATUS_INITIALIZING = 5, + + /** + * CLOB_PAIR_STATUS_FINAL_SETTLEMENT - CLOB_PAIR_STATUS_FINAL_SETTLEMENT represents a clob pair that has been + * deactivated. Clob pairs in this state do not accept new orders and trading + * is blocked. All open positions are closed by the protocol when the clob + * pair gains this status. + */ + CLOB_PAIR_STATUS_FINAL_SETTLEMENT = 6, UNRECOGNIZED = -1, } export function clobPairStatusFromJSON(object: any): ClobPairStatus { @@ -376,6 +392,10 @@ export function clobPairStatusFromJSON(object: any): ClobPairStatus { case "CLOB_PAIR_STATUS_INITIALIZING": return ClobPairStatus.CLOB_PAIR_STATUS_INITIALIZING; + case 6: + case "CLOB_PAIR_STATUS_FINAL_SETTLEMENT": + return ClobPairStatus.CLOB_PAIR_STATUS_FINAL_SETTLEMENT; + case -1: case "UNRECOGNIZED": default: @@ -402,6 +422,9 @@ export function clobPairStatusToJSON(object: ClobPairStatus): string { case ClobPairStatus.CLOB_PAIR_STATUS_INITIALIZING: return "CLOB_PAIR_STATUS_INITIALIZING"; + case ClobPairStatus.CLOB_PAIR_STATUS_FINAL_SETTLEMENT: + return "CLOB_PAIR_STATUS_FINAL_SETTLEMENT"; + case ClobPairStatus.UNRECOGNIZED: default: return "UNRECOGNIZED"; diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/shared/removal_reason.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/shared/removal_reason.ts index bd787a70e8..970a5c8e2c 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/shared/removal_reason.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/shared/removal_reason.ts @@ -75,6 +75,9 @@ export enum OrderRemovalReason { * equity tier requirements. */ ORDER_REMOVAL_REASON_EQUITY_TIER = 13, + + /** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed since its ClobPair has entered final settlement. */ + ORDER_REMOVAL_REASON_FINAL_SETTLEMENT = 14, UNRECOGNIZED = -1, } /** OrderRemovalReason is an enum of all the reasons an order was removed. */ @@ -155,6 +158,9 @@ export enum OrderRemovalReasonSDKType { * equity tier requirements. */ ORDER_REMOVAL_REASON_EQUITY_TIER = 13, + + /** ORDER_REMOVAL_REASON_FINAL_SETTLEMENT - The order has been removed since its ClobPair has entered final settlement. */ + ORDER_REMOVAL_REASON_FINAL_SETTLEMENT = 14, UNRECOGNIZED = -1, } export function orderRemovalReasonFromJSON(object: any): OrderRemovalReason { @@ -215,6 +221,10 @@ export function orderRemovalReasonFromJSON(object: any): OrderRemovalReason { case "ORDER_REMOVAL_REASON_EQUITY_TIER": return OrderRemovalReason.ORDER_REMOVAL_REASON_EQUITY_TIER; + case 14: + case "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT": + return OrderRemovalReason.ORDER_REMOVAL_REASON_FINAL_SETTLEMENT; + case -1: case "UNRECOGNIZED": default: @@ -265,6 +275,9 @@ export function orderRemovalReasonToJSON(object: OrderRemovalReason): string { case OrderRemovalReason.ORDER_REMOVAL_REASON_EQUITY_TIER: return "ORDER_REMOVAL_REASON_EQUITY_TIER"; + case OrderRemovalReason.ORDER_REMOVAL_REASON_FINAL_SETTLEMENT: + return "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT"; + case OrderRemovalReason.UNRECOGNIZED: default: return "UNRECOGNIZED"; diff --git a/indexer/services/comlink/public/api-documentation.md b/indexer/services/comlink/public/api-documentation.md index f499988468..bd09dc6402 100644 --- a/indexer/services/comlink/public/api-documentation.md +++ b/indexer/services/comlink/public/api-documentation.md @@ -2816,6 +2816,7 @@ or |*anonymous*|CANCEL_ONLY| |*anonymous*|POST_ONLY| |*anonymous*|INITIALIZING| +|*anonymous*|FINAL_SETTLEMENT| ## PerpetualMarketResponseObject diff --git a/indexer/services/comlink/public/swagger.json b/indexer/services/comlink/public/swagger.json index 888773a9d4..fc2e3db6be 100644 --- a/indexer/services/comlink/public/swagger.json +++ b/indexer/services/comlink/public/swagger.json @@ -686,7 +686,8 @@ "PAUSED", "CANCEL_ONLY", "POST_ONLY", - "INITIALIZING" + "INITIALIZING", + "FINAL_SETTLEMENT" ], "type": "string" }, diff --git a/indexer/services/ender/src/scripts/dydx_clob_pair_status_to_market_status.sql b/indexer/services/ender/src/scripts/dydx_clob_pair_status_to_market_status.sql index a4ea28e715..fe6f2be178 100644 --- a/indexer/services/ender/src/scripts/dydx_clob_pair_status_to_market_status.sql +++ b/indexer/services/ender/src/scripts/dydx_clob_pair_status_to_market_status.sql @@ -17,6 +17,7 @@ BEGIN WHEN '3'::jsonb THEN RETURN 'CANCEL_ONLY'; /** CLOB_PAIR_STATUS_CANCEL_ONLY */ WHEN '4'::jsonb THEN RETURN 'POST_ONLY'; /** CLOB_PAIR_STATUS_POST_ONLY */ WHEN '5'::jsonb THEN RETURN 'INITIALIZING'; /** CLOB_PAIR_STATUS_INITIALIZING */ + WHEN '6'::jsonb THEN RETURN 'FINAL_SETTLEMENT'; /** CLOB_PAIR_STATUS_FINAL_SETTLEMENT */ ELSE RAISE EXCEPTION 'Invalid clob pair status: %', status; END CASE; END; diff --git a/proto/dydxprotocol/clob/clob_pair.proto b/proto/dydxprotocol/clob/clob_pair.proto index 4668851dea..2ad28d4281 100644 --- a/proto/dydxprotocol/clob/clob_pair.proto +++ b/proto/dydxprotocol/clob/clob_pair.proto @@ -65,6 +65,11 @@ message ClobPair { // Clob pairs in this state only accept orders which are // both short-term and post-only. STATUS_INITIALIZING = 5; + // STATUS_FINAL_SETTLEMENT represents a clob pair which is deactivated + // and trading has ceased. All open positions will be closed by the + // protocol. Open stateful orders will be cancelled. Open short-term + // orders will be left to expire. + STATUS_FINAL_SETTLEMENT = 6; } Status status = 7; diff --git a/proto/dydxprotocol/indexer/protocol/v1/clob.proto b/proto/dydxprotocol/indexer/protocol/v1/clob.proto index 7c30fbcf87..b7b52b0a69 100644 --- a/proto/dydxprotocol/indexer/protocol/v1/clob.proto +++ b/proto/dydxprotocol/indexer/protocol/v1/clob.proto @@ -173,4 +173,9 @@ enum ClobPairStatus { // Clob pairs in this state only accept orders which are // both short-term and post-only. CLOB_PAIR_STATUS_INITIALIZING = 5; + // CLOB_PAIR_STATUS_FINAL_SETTLEMENT represents a clob pair that has been + // deactivated. Clob pairs in this state do not accept new orders and trading + // is blocked. All open positions are closed by the protocol when the clob + // pair gains this status. + CLOB_PAIR_STATUS_FINAL_SETTLEMENT = 6; } diff --git a/proto/dydxprotocol/indexer/shared/removal_reason.proto b/proto/dydxprotocol/indexer/shared/removal_reason.proto index 7787e6571a..be81d025d2 100644 --- a/proto/dydxprotocol/indexer/shared/removal_reason.proto +++ b/proto/dydxprotocol/indexer/shared/removal_reason.proto @@ -51,4 +51,6 @@ enum OrderRemovalReason { // The order has been removed since the subaccount does not satisfy the // equity tier requirements. ORDER_REMOVAL_REASON_EQUITY_TIER = 13; + // The order has been removed since its ClobPair has entered final settlement. + ORDER_REMOVAL_REASON_FINAL_SETTLEMENT = 14; } diff --git a/protocol/indexer/protocol/v1/clob.pb.go b/protocol/indexer/protocol/v1/clob.pb.go index ba1ea7a6d9..6e17da3336 100644 --- a/protocol/indexer/protocol/v1/clob.pb.go +++ b/protocol/indexer/protocol/v1/clob.pb.go @@ -47,6 +47,11 @@ const ( // Clob pairs in this state only accept orders which are // both short-term and post-only. ClobPairStatus_CLOB_PAIR_STATUS_INITIALIZING ClobPairStatus = 5 + // CLOB_PAIR_STATUS_FINAL_SETTLEMENT represents a clob pair that has been + // deactivated. Clob pairs in this state do not accept new orders and trading + // is blocked. All open positions are closed by the protocol when the clob + // pair gains this status. + ClobPairStatus_CLOB_PAIR_STATUS_FINAL_SETTLEMENT ClobPairStatus = 6 ) var ClobPairStatus_name = map[int32]string{ @@ -56,15 +61,17 @@ var ClobPairStatus_name = map[int32]string{ 3: "CLOB_PAIR_STATUS_CANCEL_ONLY", 4: "CLOB_PAIR_STATUS_POST_ONLY", 5: "CLOB_PAIR_STATUS_INITIALIZING", + 6: "CLOB_PAIR_STATUS_FINAL_SETTLEMENT", } var ClobPairStatus_value = map[string]int32{ - "CLOB_PAIR_STATUS_UNSPECIFIED": 0, - "CLOB_PAIR_STATUS_ACTIVE": 1, - "CLOB_PAIR_STATUS_PAUSED": 2, - "CLOB_PAIR_STATUS_CANCEL_ONLY": 3, - "CLOB_PAIR_STATUS_POST_ONLY": 4, - "CLOB_PAIR_STATUS_INITIALIZING": 5, + "CLOB_PAIR_STATUS_UNSPECIFIED": 0, + "CLOB_PAIR_STATUS_ACTIVE": 1, + "CLOB_PAIR_STATUS_PAUSED": 2, + "CLOB_PAIR_STATUS_CANCEL_ONLY": 3, + "CLOB_PAIR_STATUS_POST_ONLY": 4, + "CLOB_PAIR_STATUS_INITIALIZING": 5, + "CLOB_PAIR_STATUS_FINAL_SETTLEMENT": 6, } func (x ClobPairStatus) String() string { @@ -479,58 +486,59 @@ func init() { } var fileDescriptor_fac8923e70f7ca3c = []byte{ - // 809 bytes of a gzipped FileDescriptorProto + // 830 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0x4d, 0x73, 0xdb, 0x54, - 0x14, 0xb5, 0x1c, 0xb7, 0x71, 0xae, 0x3f, 0x10, 0x8f, 0x32, 0x15, 0x49, 0xeb, 0x18, 0x2f, 0x20, - 0x03, 0x83, 0x4d, 0x5a, 0x58, 0xc0, 0xc0, 0xc2, 0x56, 0xe4, 0xf6, 0x4d, 0x54, 0x49, 0x48, 0x0a, - 0x4c, 0xba, 0xe0, 0x21, 0x4b, 0x2f, 0xee, 0x9b, 0xca, 0x7a, 0x41, 0x96, 0x32, 0xf5, 0x8e, 0x9f, - 0xc0, 0xcf, 0xea, 0xb2, 0xb0, 0x60, 0x58, 0x31, 0x4c, 0xf2, 0x47, 0x98, 0x27, 0x09, 0x55, 0x8e, - 0x3b, 0x94, 0xec, 0x74, 0xcf, 0x3d, 0xf7, 0xcc, 0x3d, 0xe7, 0xca, 0x32, 0x7c, 0x1a, 0xac, 0x82, - 0x17, 0xe7, 0x31, 0x4f, 0xb8, 0xcf, 0xc3, 0x11, 0x8b, 0x02, 0xfa, 0x82, 0xc6, 0xa3, 0x12, 0xb8, - 0x38, 0x1c, 0xf9, 0x21, 0x9f, 0x0d, 0x33, 0x00, 0xf5, 0xab, 0xe4, 0x61, 0x41, 0x1e, 0x96, 0xc0, - 0xc5, 0xe1, 0xee, 0xe1, 0x5b, 0xe5, 0x96, 0xe9, 0xcc, 0xf3, 0x7d, 0x9e, 0x46, 0x49, 0x3e, 0xb8, - 0x7b, 0x67, 0xce, 0xe7, 0x3c, 0x7b, 0x1c, 0x89, 0xa7, 0x1c, 0x1d, 0xfc, 0x2e, 0x41, 0x17, 0xe7, - 0xe3, 0x66, 0x1c, 0xd0, 0x18, 0x07, 0xe8, 0x27, 0xe8, 0xbc, 0x1e, 0x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} func (m *IndexerOrderId) Marshal() (dAtA []byte, err error) { diff --git a/protocol/indexer/protocol/v1/v1_mappers.go b/protocol/indexer/protocol/v1/v1_mappers.go index 275263257c..b404d3435c 100644 --- a/protocol/indexer/protocol/v1/v1_mappers.go +++ b/protocol/indexer/protocol/v1/v1_mappers.go @@ -176,7 +176,14 @@ func ConvertToClobPairStatus(status clobtypes.ClobPair_Status) ClobPairStatus { return ClobPairStatus_CLOB_PAIR_STATUS_POST_ONLY case clobtypes.ClobPair_STATUS_INITIALIZING: return ClobPairStatus_CLOB_PAIR_STATUS_INITIALIZING + case clobtypes.ClobPair_STATUS_FINAL_SETTLEMENT: + return ClobPairStatus_CLOB_PAIR_STATUS_FINAL_SETTLEMENT default: - panic("invalid clob pair status") + panic( + fmt.Sprintf( + "ConvertToClobPairStatus: invalid clob pair status: %+v", + status, + ), + ) } } diff --git a/protocol/indexer/protocol/v1/v1_mappers_test.go b/protocol/indexer/protocol/v1/v1_mappers_test.go index 66a4a70f1f..af79807302 100644 --- a/protocol/indexer/protocol/v1/v1_mappers_test.go +++ b/protocol/indexer/protocol/v1/v1_mappers_test.go @@ -398,7 +398,10 @@ func TestConvertToClobPairStatus(t *testing.T) { expectedStatus: v1.ClobPairStatus(clobtypes.ClobPair_Status_value[name]), } if value == int32(clobtypes.ClobPair_STATUS_UNSPECIFIED) { - testCase.expectedPanic = "invalid clob pair status" + testCase.expectedPanic = fmt.Sprintf( + "ConvertToClobPairStatus: invalid clob pair status: %+v", + clobtypes.ClobPair_STATUS_UNSPECIFIED, + ) } tests[testName] = testCase } diff --git a/protocol/indexer/shared/removal_reason.pb.go b/protocol/indexer/shared/removal_reason.pb.go index 99a9bf9daf..480302a924 100644 --- a/protocol/indexer/shared/removal_reason.pb.go +++ b/protocol/indexer/shared/removal_reason.pb.go @@ -68,6 +68,8 @@ const ( // The order has been removed since the subaccount does not satisfy the // equity tier requirements. OrderRemovalReason_ORDER_REMOVAL_REASON_EQUITY_TIER OrderRemovalReason = 13 + // The order has been removed since its ClobPair has entered final settlement. + OrderRemovalReason_ORDER_REMOVAL_REASON_FINAL_SETTLEMENT OrderRemovalReason = 14 ) var OrderRemovalReason_name = map[int32]string{ @@ -85,6 +87,7 @@ var OrderRemovalReason_name = map[int32]string{ 11: "ORDER_REMOVAL_REASON_REPLACED", 12: "ORDER_REMOVAL_REASON_FULLY_FILLED", 13: "ORDER_REMOVAL_REASON_EQUITY_TIER", + 14: "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT", } var OrderRemovalReason_value = map[string]int32{ @@ -102,6 +105,7 @@ var OrderRemovalReason_value = map[string]int32{ "ORDER_REMOVAL_REASON_REPLACED": 11, "ORDER_REMOVAL_REASON_FULLY_FILLED": 12, "ORDER_REMOVAL_REASON_EQUITY_TIER": 13, + "ORDER_REMOVAL_REASON_FINAL_SETTLEMENT": 14, } func (x OrderRemovalReason) String() string { @@ -121,33 +125,34 @@ func init() { } var fileDescriptor_0d5eea5cab8c58ba = []byte{ - // 446 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0xcf, 0x6e, 0xd3, 0x40, - 0x10, 0xc6, 0x13, 0xa0, 0x05, 0x16, 0x90, 0x56, 0x7b, 0x05, 0xac, 0x16, 0x5a, 0x5a, 0xfe, 0xc5, - 0x48, 0x20, 0x54, 0x01, 0x12, 0xda, 0x78, 0x27, 0xd2, 0x2a, 0x1b, 0x6f, 0x18, 0xdb, 0xd0, 0xe4, - 0x32, 0x72, 0x63, 0x8b, 0x44, 0x6a, 0x63, 0xe4, 0x96, 0xaa, 0xbc, 0x01, 0x47, 0x1e, 0x8b, 0x63, - 0x8e, 0x1c, 0x51, 0xf2, 0x22, 0x48, 0x76, 0x40, 0x54, 0x5a, 0x5f, 0x7c, 0xf1, 0xef, 0xf7, 0xcd, - 0x67, 0xef, 0x2c, 0x7b, 0x91, 0x7d, 0xcb, 0x2e, 0xbe, 0x94, 0xc5, 0x59, 0x31, 0x29, 0x8e, 0xfd, - 0xd9, 0x3c, 0xcb, 0x2f, 0xf2, 0xd2, 0x3f, 0x9d, 0xa6, 0x65, 0x9e, 0xf9, 0x65, 0x7e, 0x52, 0x9c, - 0xa7, 0xc7, 0x54, 0xe6, 0xe9, 0x69, 0x31, 0xef, 0x54, 0x98, 0xb8, 0xfb, 0xbf, 0xd1, 0x59, 0x1b, - 0x9d, 0xda, 0x78, 0xf2, 0x7d, 0x83, 0x09, 0x5b, 0x66, 0x79, 0x89, 0xb5, 0x8a, 0x95, 0x29, 0x76, - 0xd8, 0x96, 0x45, 0x05, 0x48, 0x08, 0x03, 0xfb, 0x51, 0x1a, 0x42, 0x90, 0x91, 0x0d, 0x29, 0x09, - 0xa3, 0x21, 0x04, 0xba, 0xa7, 0x41, 0xf1, 0x96, 0xd8, 0x62, 0xf7, 0x9c, 0x14, 0x1c, 0x0e, 0x35, - 0x82, 0xe2, 0x6d, 0xf1, 0x88, 0x3d, 0x70, 0xe7, 0x44, 0x80, 0x14, 0xc8, 0x30, 0x00, 0x03, 0x8a, - 0x5f, 0x11, 0xcf, 0xd8, 0x7e, 0xc3, 0x3c, 0x05, 0x18, 0x58, 0x63, 0x64, 0x0c, 0x28, 0x8d, 0x1e, - 0x83, 0xe2, 0x57, 0xc5, 0x1e, 0x7b, 0xe8, 0xa4, 0x75, 0x18, 0x03, 0x86, 0xd2, 0x10, 0x20, 0x5a, - 0xe4, 0xd7, 0xc4, 0x63, 0xb6, 0xeb, 0x04, 0x23, 0x30, 0x3d, 0x8a, 0x51, 0x2a, 0x58, 0xa3, 0x1b, - 0xe2, 0x0d, 0x7b, 0xed, 0x44, 0x87, 0x36, 0x8a, 0xc9, 0x86, 0x66, 0x44, 0x9f, 0x6c, 0x62, 0x14, - 0x05, 0x68, 0xa3, 0x88, 0x06, 0xb2, 0x0f, 0x48, 0x95, 0xc0, 0x37, 0xc5, 0x7b, 0xf6, 0xd6, 0xdd, - 0x67, 0x30, 0x00, 0xa5, 0x65, 0x0c, 0x64, 0xff, 0x7e, 0xed, 0x3a, 0x05, 0xa1, 0x4a, 0xa5, 0xae, - 0xb5, 0x7d, 0x7e, 0x5d, 0xbc, 0x63, 0x07, 0xce, 0x80, 0x9e, 0xed, 0xd7, 0x43, 0x28, 0xa8, 0xb4, - 0xd0, 0xc6, 0xd4, 0x05, 0xea, 0x25, 0xc6, 0x8c, 0xaa, 0x27, 0x28, 0x7e, 0x43, 0x3c, 0x65, 0x7b, - 0x4e, 0x1b, 0x41, 0x25, 0x01, 0xd4, 0xe5, 0x11, 0x22, 0x3d, 0x06, 0x7e, 0x53, 0xec, 0xb3, 0x9d, - 0x86, 0x7f, 0xa7, 0xe0, 0x10, 0xf0, 0xdf, 0xd9, 0x31, 0xb1, 0xcd, 0xee, 0x37, 0xc4, 0x0e, 0x8d, - 0x0c, 0x40, 0xf1, 0x5b, 0x62, 0x97, 0x6d, 0xbb, 0x7b, 0xd7, 0x05, 0x75, 0x55, 0xf0, 0x76, 0xe3, - 0x36, 0xc1, 0x87, 0x44, 0xc7, 0x23, 0x8a, 0x35, 0x20, 0xbf, 0xd3, 0xc5, 0x9f, 0x4b, 0xaf, 0xbd, - 0x58, 0x7a, 0xed, 0xdf, 0x4b, 0xaf, 0xfd, 0x63, 0xe5, 0xb5, 0x16, 0x2b, 0xaf, 0xf5, 0x6b, 0xe5, - 0xb5, 0xc6, 0x07, 0x9f, 0x67, 0x67, 0xd3, 0xaf, 0x47, 0x9d, 0x49, 0x71, 0xe2, 0x5f, 0x5a, 0xff, - 0xf3, 0x57, 0xcf, 0x27, 0xd3, 0x74, 0x36, 0xf7, 0x1b, 0x2e, 0xc4, 0xd1, 0x66, 0xf5, 0xe2, 0xe5, - 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc1, 0x84, 0xfa, 0x05, 0x36, 0x03, 0x00, 0x00, + // 461 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0xcd, 0x6e, 0xd3, 0x40, + 0x14, 0x85, 0x13, 0xa0, 0x05, 0x86, 0x1f, 0x8d, 0x66, 0x0b, 0x58, 0x2d, 0xb4, 0xb4, 0xfc, 0x25, + 0x48, 0x20, 0x54, 0x01, 0x12, 0x9a, 0x78, 0xae, 0xa5, 0x51, 0xc6, 0x9e, 0x70, 0x3d, 0x86, 0x26, + 0x9b, 0xab, 0x34, 0xb6, 0x48, 0xa4, 0x36, 0x46, 0x6e, 0xa9, 0xca, 0x5b, 0xf0, 0x2e, 0xbc, 0x04, + 0xcb, 0x2e, 0x59, 0xa2, 0xe4, 0x45, 0x10, 0x76, 0x40, 0x54, 0xb2, 0x37, 0xde, 0xf8, 0x7c, 0xe7, + 0x9e, 0x99, 0x33, 0x97, 0x3d, 0x4f, 0xbf, 0xa6, 0x67, 0x9f, 0x8b, 0xfc, 0x24, 0x9f, 0xe4, 0x87, + 0xdd, 0xd9, 0x3c, 0xcd, 0xce, 0xb2, 0xa2, 0x7b, 0x3c, 0x1d, 0x17, 0x59, 0xda, 0x2d, 0xb2, 0xa3, + 0xfc, 0x74, 0x7c, 0x48, 0x45, 0x36, 0x3e, 0xce, 0xe7, 0x9d, 0x52, 0x26, 0xee, 0xfc, 0x4f, 0x74, + 0x56, 0x44, 0xa7, 0x22, 0x1e, 0x7f, 0x5f, 0x63, 0xc2, 0x16, 0x69, 0x56, 0x60, 0x85, 0x62, 0x49, + 0x8a, 0x2d, 0xb6, 0x61, 0x51, 0x01, 0x12, 0x42, 0x68, 0x3f, 0x48, 0x43, 0x08, 0x32, 0xb6, 0x11, + 0x25, 0x51, 0x3c, 0x00, 0x5f, 0x07, 0x1a, 0x14, 0x6f, 0x89, 0x0d, 0x76, 0xb7, 0x56, 0x05, 0xfb, + 0x03, 0x8d, 0xa0, 0x78, 0x5b, 0x3c, 0x64, 0xf7, 0xeb, 0x7d, 0x62, 0x40, 0xf2, 0x65, 0xe4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 0x27, 0xda, 0x0d, 0xc9, 0x69, 0x40, 0x7e, 0xab, 0xb1, 0xac, 0x40, 0xff, + 0xa9, 0x34, 0x06, 0xe7, 0x0c, 0x84, 0x10, 0x39, 0x7e, 0xbb, 0x87, 0x3f, 0x16, 0x5e, 0xfb, 0x7c, + 0xe1, 0xb5, 0x7f, 0x2d, 0xbc, 0xf6, 0xb7, 0xa5, 0xd7, 0x3a, 0x5f, 0x7a, 0xad, 0x9f, 0x4b, 0xaf, + 0x35, 0xda, 0xfb, 0x34, 0x3b, 0x99, 0x7e, 0x39, 0xe8, 0x4c, 0xf2, 0xa3, 0xee, 0x85, 0x4d, 0x39, + 0x7d, 0xf9, 0x6c, 0x32, 0x1d, 0xcf, 0xe6, 0xdd, 0x86, 0xdd, 0x39, 0x58, 0x2f, 0x7f, 0xbc, 0xf8, + 0x1d, 0x00, 0x00, 0xff, 0xff, 0x80, 0x93, 0x47, 0x03, 0x61, 0x03, 0x00, 0x00, } diff --git a/protocol/x/clob/types/clob_pair.pb.go b/protocol/x/clob/types/clob_pair.pb.go index 46f2ee4077..49eab1563e 100644 --- a/protocol/x/clob/types/clob_pair.pb.go +++ b/protocol/x/clob/types/clob_pair.pb.go @@ -43,6 +43,11 @@ const ( // Clob pairs in this state only accept orders which are // both short-term and post-only. ClobPair_STATUS_INITIALIZING ClobPair_Status = 5 + // STATUS_FINAL_SETTLEMENT represents a clob pair which is deactivated + // and trading has ceased. All open positions will be closed by the + // protocol. Open stateful orders will be cancelled. Open short-term + // orders will be left to expire. + ClobPair_STATUS_FINAL_SETTLEMENT ClobPair_Status = 6 ) var ClobPair_Status_name = map[int32]string{ @@ -52,15 +57,17 @@ var ClobPair_Status_name = map[int32]string{ 3: "STATUS_CANCEL_ONLY", 4: "STATUS_POST_ONLY", 5: "STATUS_INITIALIZING", + 6: "STATUS_FINAL_SETTLEMENT", } var ClobPair_Status_value = map[string]int32{ - "STATUS_UNSPECIFIED": 0, - "STATUS_ACTIVE": 1, - "STATUS_PAUSED": 2, - "STATUS_CANCEL_ONLY": 3, - "STATUS_POST_ONLY": 4, - "STATUS_INITIALIZING": 5, + "STATUS_UNSPECIFIED": 0, + "STATUS_ACTIVE": 1, + "STATUS_PAUSED": 2, + "STATUS_CANCEL_ONLY": 3, + "STATUS_POST_ONLY": 4, + "STATUS_INITIALIZING": 5, + "STATUS_FINAL_SETTLEMENT": 6, } func (x ClobPair_Status) String() string { @@ -323,40 +330,41 @@ func init() { func init() { proto.RegisterFile("dydxprotocol/clob/clob_pair.proto", fileDescriptor_178b475635886947) } var fileDescriptor_178b475635886947 = []byte{ - // 521 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x93, 0xd1, 0x6b, 0xd3, 0x40, - 0x1c, 0xc7, 0x93, 0xae, 0xab, 0xe3, 0xb6, 0xd6, 0xf4, 0x74, 0xae, 0x22, 0x84, 0x2e, 0xfa, 0x50, - 0x44, 0x53, 0x98, 0xe2, 0xc3, 0x1e, 0x84, 0x34, 0x8b, 0x2e, 0x50, 0xbb, 0x98, 0xa4, 0x82, 0x43, - 0x08, 0x97, 0xe4, 0x70, 0x61, 0x6d, 0xee, 0x96, 0xbb, 0x8c, 0xee, 0x8f, 0x10, 0xfc, 0xa7, 0x04, - 0x1f, 0xf7, 0xe8, 0xa3, 0xb4, 0xff, 0x88, 0xe4, 0x9a, 0xd6, 0xae, 0xeb, 0x4b, 0x08, 0x9f, 0xdf, - 0xe7, 0xf7, 0xe5, 0x7e, 0xbf, 0xe3, 0xc0, 0x61, 0x7c, 0x13, 0x4f, 0x68, 0x46, 0x38, 0x89, 0xc8, - 0xa8, 0x1b, 0x8d, 0x48, 0x28, 0x3e, 0x01, 0x45, 0x49, 0xa6, 0x0b, 0x0e, 0x9b, 0xab, 0x8a, 0x5e, - 0x54, 0xb5, 0x63, 0xb0, 0xef, 0xe0, 0x8c, 0x62, 0x9e, 0xa3, 0x91, 0x39, 0x22, 0xe1, 0x27, 0xcc, - 0x51, 0x8c, 0x38, 0x82, 0x87, 0x60, 0x8f, 0x2e, 0x0a, 0x41, 0x12, 0xb7, 0xe4, 0xb6, 0xdc, 0xa9, - 0xbb, 0xbb, 0x4b, 0x66, 0xc7, 0xda, 0x37, 0xa0, 0x78, 0x94, 0xf0, 0x3b, 0x6d, 0x1a, 0xa8, 0x87, - 0x88, 0xe1, 0x00, 0x31, 0x86, 0xf9, 0x4a, 0x5f, 0x01, 0x8d, 0x82, 0xd9, 0x31, 0x7c, 0x01, 0x1a, - 0x57, 0x39, 0xe1, 0x2b, 0x52, 0x45, 0x48, 0x7b, 0x82, 0x96, 0x96, 0xf6, 0xab, 0x0a, 0x76, 0x8a, - 0x68, 0x07, 0x25, 0x19, 0x6c, 0x80, 0xca, 0x32, 0xab, 0x92, 0xc4, 0x30, 0x04, 0x07, 0xff, 0x4f, - 0x27, 0xc6, 0x1c, 0x97, 0x27, 0x10, 0x59, 0xbb, 0x47, 0x1d, 0xfd, 0xde, 0xac, 0xfa, 0xc6, 0x41, - 0x4f, 0x25, 0x77, 0x9f, 0x6e, 0xdc, 0x80, 0x07, 0x20, 0xa3, 0x84, 0xaf, 0xc5, 0x6f, 0x89, 0xf8, - 0xe7, 0x1b, 0xe2, 0xd7, 0x77, 0x71, 0x2a, 0xb9, 0x0a, 0x5b, 0xdf, 0xcf, 0x2b, 0x00, 0x19, 0xc7, - 0x34, 0x10, 0x4b, 0xba, 0xca, 0x51, 0xca, 0xf3, 0x31, 0x6b, 0x55, 0xdb, 0x72, 0xa7, 0xea, 0x2a, - 0x45, 0xa5, 0x87, 0x18, 0xfe, 0x5c, 0x72, 0xf8, 0x12, 0x34, 0x59, 0x1e, 0xf2, 0x24, 0xba, 0x64, - 0x01, 0xc5, 0x59, 0x50, 0xfc, 0xb5, 0xb6, 0xc5, 0x16, 0x1e, 0x2e, 0x0a, 0x0e, 0xce, 0xfc, 0x24, - 0xba, 0x84, 0xef, 0xc1, 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, 0xe8, 0x02, 0x25, 0x69, 0x77, 0x49, - 0x26, 0xf3, 0x07, 0xc5, 0x6f, 0x28, 0x66, 0x61, 0x4d, 0xe0, 0x37, 0xff, 0x02, 0x00, 0x00, 0xff, - 0xff, 0xc5, 0xb8, 0x66, 0x12, 0x72, 0x03, 0x00, 0x00, + // 540 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x93, 0xc1, 0x6a, 0xdb, 0x30, + 0x1c, 0xc6, 0xed, 0x34, 0xcd, 0x8a, 0xda, 0x64, 0x8e, 0xb6, 0x2e, 0x19, 0x05, 0x93, 0x7a, 0x3b, + 0x84, 0xb1, 0x39, 0xd0, 0x8d, 0x1d, 0x7a, 0x18, 0x38, 0xae, 0xbb, 0x1a, 0x52, 0xd7, 0xb3, 0x9d, + 0xc1, 0xca, 0xc0, 0xc8, 0xb6, 0x58, 0x4d, 0x13, 0xcb, 0xb5, 0xe4, 0x92, 0xbe, 0xc5, 0x9e, 0x63, + 0x4f, 0xb2, 0x63, 0x8f, 0x3b, 0x8e, 0xe4, 0x45, 0x86, 0x15, 0x27, 0x4b, 0xd3, 0x5c, 0x8c, 0xf9, + 0x7d, 0xdf, 0xff, 0x43, 0xff, 0x4f, 0x08, 0x1c, 0x46, 0x77, 0xd1, 0x24, 0xcd, 0x08, 0x23, 0x21, + 0x19, 0xf5, 0xc2, 0x11, 0x09, 0xf8, 0xc7, 0x4f, 0x51, 0x9c, 0xa9, 0x9c, 0xc3, 0xe6, 0xaa, 0x45, + 0x2d, 0x54, 0xe5, 0x18, 0xec, 0xdb, 0x38, 0x4b, 0x31, 0xcb, 0xd1, 0x48, 0x1f, 0x91, 0xe0, 0x1c, + 0x33, 0x14, 0x21, 0x86, 0xe0, 0x21, 0xd8, 0x4b, 0x17, 0x82, 0x1f, 0x47, 0x6d, 0xb1, 0x23, 0x76, + 0xeb, 0xce, 0xee, 0x92, 0x99,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0x14, + 0x27, 0xbd, 0x25, 0x99, 0xcc, 0x5f, 0x1b, 0xbb, 0x4b, 0x31, 0x0d, 0x6a, 0x1c, 0xbf, 0xff, 0x17, + 0x00, 0x00, 0xff, 0xff, 0x96, 0xa7, 0xc6, 0x50, 0x8f, 0x03, 0x00, 0x00, } func (m *PerpetualClobMetadata) Marshal() (dAtA []byte, err error) { From 11fd8a0f434e8920c925d620f09a124a01830620 Mon Sep 17 00:00:00 2001 From: Jakob Herlitz <125316911+jakob-dydx@users.noreply.github.com> Date: Tue, 5 Dec 2023 12:30:38 -0800 Subject: [PATCH 5/6] [CLOB-1015][CLOB-1016] Update MatchPerpetualDeleveraging and DeleveragingEventV1 to have final settlement flag (#833) * add protos for final settlement clob pair status and final settlement removal reason * add missing indexer constants * update proto formatting * update proto formatting * fix indexer test * fix indexer constant which requires all fields of proto to be specified * update comment and panic string * update proto comments --- .../src/codegen/dydxprotocol/clob/matches.ts | 28 +- .../dydxprotocol/indexer/events/events.ts | 32 +- .../ender/__tests__/helpers/constants.ts | 1 + proto/dydxprotocol/clob/matches.proto | 6 + .../dydxprotocol/indexer/events/events.proto | 7 +- protocol/indexer/events/events.pb.go | 298 ++++++++++-------- protocol/x/clob/types/matches.pb.go | 123 +++++--- 7 files changed, 326 insertions(+), 169 deletions(-) diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/matches.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/matches.ts index 3d0f19d5c0..462654af4e 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/matches.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/matches.ts @@ -128,6 +128,14 @@ export interface MatchPerpetualDeleveraging { /** An ordered list of fills created by this liquidation. */ fills: MatchPerpetualDeleveraging_Fill[]; + /** + * Flag denoting whether the deleveraging operation was for the purpose + * of final settlement. Final settlement matches are at the oracle price, + * whereas deleveraging happens at the bankruptcy price of the deleveraged + * subaccount. + */ + + isFinalSettlement: boolean; } /** * MatchPerpetualDeleveraging is an injected message used for deleveraging a @@ -143,6 +151,14 @@ export interface MatchPerpetualDeleveragingSDKType { /** An ordered list of fills created by this liquidation. */ fills: MatchPerpetualDeleveraging_FillSDKType[]; + /** + * Flag denoting whether the deleveraging operation was for the purpose + * of final settlement. Final settlement matches are at the oracle price, + * whereas deleveraging happens at the bankruptcy price of the deleveraged + * subaccount. + */ + + is_final_settlement: boolean; } /** Fill represents a fill between the liquidated and offsetting subaccount. */ @@ -451,7 +467,8 @@ function createBaseMatchPerpetualDeleveraging(): MatchPerpetualDeleveraging { return { liquidated: undefined, perpetualId: 0, - fills: [] + fills: [], + isFinalSettlement: false }; } @@ -469,6 +486,10 @@ export const MatchPerpetualDeleveraging = { MatchPerpetualDeleveraging_Fill.encode(v!, writer.uint32(26).fork()).ldelim(); } + if (message.isFinalSettlement === true) { + writer.uint32(32).bool(message.isFinalSettlement); + } + return writer; }, @@ -493,6 +514,10 @@ export const MatchPerpetualDeleveraging = { message.fills.push(MatchPerpetualDeleveraging_Fill.decode(reader, reader.uint32())); break; + case 4: + message.isFinalSettlement = reader.bool(); + break; + default: reader.skipType(tag & 7); break; @@ -507,6 +532,7 @@ export const MatchPerpetualDeleveraging = { message.liquidated = object.liquidated !== undefined && object.liquidated !== null ? SubaccountId.fromPartial(object.liquidated) : undefined; message.perpetualId = object.perpetualId ?? 0; message.fills = object.fills?.map(e => MatchPerpetualDeleveraging_Fill.fromPartial(e)) || []; + message.isFinalSettlement = object.isFinalSettlement ?? false; return message; } diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts index 1c11aa4faa..4665d3fbc6 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/events/events.ts @@ -465,12 +465,20 @@ export interface DeleveragingEventV1 { */ fillAmount: Long; - /** Bankruptcy price of liquidated subaccount, in USDC quote quantums. */ + /** Fill price of deleveraging event, in USDC quote quantums. */ price: Long; /** `true` if liquidating a short position, `false` otherwise. */ isBuy: boolean; + /** + * `true` if the deleveraging event is for final settlement, indicating + * the match occurred at the oracle price rather than bankruptcy price. + * When this flag is `false`, the fill price is the bankruptcy price + * of the liquidated subaccount. + */ + + isFinalSettlement: boolean; } /** * DeleveragingEvent message contains all the information for a deleveraging @@ -493,12 +501,20 @@ export interface DeleveragingEventV1SDKType { */ fill_amount: Long; - /** Bankruptcy price of liquidated subaccount, in USDC quote quantums. */ + /** Fill price of deleveraging event, in USDC quote quantums. */ price: Long; /** `true` if liquidating a short position, `false` otherwise. */ is_buy: boolean; + /** + * `true` if the deleveraging event is for final settlement, indicating + * the match occurred at the oracle price rather than bankruptcy price. + * When this flag is `false`, the fill price is the bankruptcy price + * of the liquidated subaccount. + */ + + is_final_settlement: boolean; } /** * LiquidationOrder represents the liquidation taker order to be included in a @@ -1782,7 +1798,8 @@ function createBaseDeleveragingEventV1(): DeleveragingEventV1 { perpetualId: 0, fillAmount: Long.UZERO, price: Long.UZERO, - isBuy: false + isBuy: false, + isFinalSettlement: false }; } @@ -1812,6 +1829,10 @@ export const DeleveragingEventV1 = { writer.uint32(48).bool(message.isBuy); } + if (message.isFinalSettlement === true) { + writer.uint32(56).bool(message.isFinalSettlement); + } + return writer; }, @@ -1848,6 +1869,10 @@ export const DeleveragingEventV1 = { message.isBuy = reader.bool(); break; + case 7: + message.isFinalSettlement = reader.bool(); + break; + default: reader.skipType(tag & 7); break; @@ -1865,6 +1890,7 @@ export const DeleveragingEventV1 = { message.fillAmount = object.fillAmount !== undefined && object.fillAmount !== null ? Long.fromValue(object.fillAmount) : Long.UZERO; message.price = object.price !== undefined && object.price !== null ? Long.fromValue(object.price) : Long.UZERO; message.isBuy = object.isBuy ?? false; + message.isFinalSettlement = object.isFinalSettlement ?? false; return message; } diff --git a/indexer/services/ender/__tests__/helpers/constants.ts b/indexer/services/ender/__tests__/helpers/constants.ts index cd583a6ac3..1beaf05399 100644 --- a/indexer/services/ender/__tests__/helpers/constants.ts +++ b/indexer/services/ender/__tests__/helpers/constants.ts @@ -288,6 +288,7 @@ export const defaultDeleveragingEvent: DeleveragingEventV1 = { fillAmount: Long.fromValue(10_000, true), price: Long.fromValue(1_000_000_000, true), isBuy: true, + isFinalSettlement: false, }; export const defaultDepositEvent: TransferEventV1 = { assetId: 0, diff --git a/proto/dydxprotocol/clob/matches.proto b/proto/dydxprotocol/clob/matches.proto index f9a51b6a78..8b7b299f61 100644 --- a/proto/dydxprotocol/clob/matches.proto +++ b/proto/dydxprotocol/clob/matches.proto @@ -75,4 +75,10 @@ message MatchPerpetualDeleveraging { } // An ordered list of fills created by this liquidation. repeated Fill fills = 3 [ (gogoproto.nullable) = false ]; + + // Flag denoting whether the deleveraging operation was for the purpose + // of final settlement. Final settlement matches are at the oracle price, + // whereas deleveraging happens at the bankruptcy price of the deleveraged + // subaccount. + bool is_final_settlement = 4; } diff --git a/proto/dydxprotocol/indexer/events/events.proto b/proto/dydxprotocol/indexer/events/events.proto index c7a55a1bc8..be1d96dd84 100644 --- a/proto/dydxprotocol/indexer/events/events.proto +++ b/proto/dydxprotocol/indexer/events/events.proto @@ -180,10 +180,15 @@ message DeleveragingEventV1 { // The amount filled between the liquidated and offsetting position, in // base quantums. uint64 fill_amount = 4; - // Bankruptcy price of liquidated subaccount, in USDC quote quantums. + // Fill price of deleveraging event, in USDC quote quantums. uint64 price = 5; // `true` if liquidating a short position, `false` otherwise. bool is_buy = 6; + // `true` if the deleveraging event is for final settlement, indicating + // the match occurred at the oracle price rather than bankruptcy price. + // When this flag is `false`, the fill price is the bankruptcy price + // of the liquidated subaccount. + bool is_final_settlement = 7; } // LiquidationOrder represents the liquidation taker order to be included in a diff --git a/protocol/indexer/events/events.pb.go b/protocol/indexer/events/events.pb.go index e9bb3e3dfd..0ddbfd4bca 100644 --- a/protocol/indexer/events/events.pb.go +++ b/protocol/indexer/events/events.pb.go @@ -856,10 +856,15 @@ type DeleveragingEventV1 struct { // The amount filled between the liquidated and offsetting position, in // base quantums. FillAmount uint64 `protobuf:"varint,4,opt,name=fill_amount,json=fillAmount,proto3" json:"fill_amount,omitempty"` - // Bankruptcy price of liquidated subaccount, in USDC quote quantums. + // Fill price of deleveraging event, in USDC quote quantums. Price uint64 `protobuf:"varint,5,opt,name=price,proto3" json:"price,omitempty"` // `true` if liquidating a short position, `false` otherwise. IsBuy bool `protobuf:"varint,6,opt,name=is_buy,json=isBuy,proto3" json:"is_buy,omitempty"` + // `true` if the deleveraging event is for final settlement, indicating + // the match occurred at the oracle price rather than bankruptcy price. + // When this flag is `false`, the fill price is the bankruptcy price + // of the liquidated subaccount. + IsFinalSettlement bool `protobuf:"varint,7,opt,name=is_final_settlement,json=isFinalSettlement,proto3" json:"is_final_settlement,omitempty"` } func (m *DeleveragingEventV1) Reset() { *m = DeleveragingEventV1{} } @@ -937,6 +942,13 @@ func (m *DeleveragingEventV1) GetIsBuy() bool { return false } +func (m *DeleveragingEventV1) GetIsFinalSettlement() bool { + if m != nil { + return m.IsFinalSettlement + } + return false +} + // LiquidationOrder represents the liquidation taker order to be included in a // liquidation order fill event. type LiquidationOrderV1 struct { @@ -2025,131 +2037,132 @@ func init() { } var fileDescriptor_6331dfb59c6fd2bb = []byte{ - // 1971 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x59, 0xcd, 0x4f, 0x23, 0xc9, - 0x15, 0xc7, 0x76, 0x63, 0xe0, 0x81, 0x19, 0xbb, 0x06, 0x18, 0x03, 0x09, 0x43, 0x5a, 0x8a, 0x84, - 0xf6, 0xc3, 0x0c, 0x93, 0x49, 0xb4, 0xca, 0x21, 0x0a, 0x06, 0xb3, 0x78, 0x04, 0x8c, 0xd3, 0x98, - 0xd9, 0xdd, 0x49, 0xb4, 0x9d, 0xa2, 0xbb, 0x6c, 0x4a, 0xf4, 0xd7, 0x76, 0x95, 0xc9, 0x30, 0x52, - 0xce, 0xc9, 0x2d, 0x91, 0x72, 0xce, 0x21, 0x87, 0x5c, 0x22, 0xe5, 0x10, 0x29, 0xd7, 0x95, 0x22, - 0xe5, 0xb2, 0xb7, 0xac, 0x72, 0x49, 0x94, 0xc3, 0x28, 0x9a, 0x39, 0xe4, 0xdf, 0x88, 0xea, 0xa3, - 0xdb, 0x36, 0xb6, 0x19, 0xcf, 0xc0, 0x9e, 0x70, 0xbd, 0x57, 0xef, 0xf7, 0x3e, 0xab, 0xde, 0xab, - 0x06, 0x36, 0xdc, 0x4b, 0xf7, 0x79, 0x14, 0x87, 0x3c, 0x74, 0x42, 0x6f, 0x93, 0x06, 0x2e, 0x79, - 0x4e, 0xe2, 0x4d, 0x72, 0x41, 0x02, 0xce, 0xf4, 0x9f, 0x8a, 0x64, 0xa3, 0xd5, 0xde, 0x9d, 0x15, - 0xbd, 0xb3, 0xa2, 0xb6, 0xac, 0x2c, 0x3b, 0x21, 0xf3, 0x43, 0x66, 0x4b, 0xfe, 0xa6, 0x5a, 0x28, - 0xb9, 0x95, 0x85, 0x76, 0xd8, 0x0e, 0x15, 0x5d, 0xfc, 0xd2, 0xd4, 0x07, 0x43, 0xf5, 0xb2, 0x33, - 0x1c, 0x13, 0x77, 0x33, 0x26, 0x7e, 0x78, 0x81, 0x3d, 0x3b, 0x26, 0x98, 0x85, 0x81, 0x96, 0x78, - 0x7f, 0xa8, 0x44, 0x4a, 0xb8, 0xd8, 0xda, 0x74, 0xbc, 0xf0, 0x54, 0x6f, 0xde, 0x7a, 0xe3, 0x66, - 0xd6, 0x39, 0xc5, 0x8e, 0x13, 0x76, 0x02, 0xae, 0x44, 0xcc, 0x7f, 0x64, 0xe0, 0xce, 0x5e, 0x27, - 0x70, 0x69, 0xd0, 0x3e, 0x89, 0x5c, 0xcc, 0xc9, 0xd3, 0x2d, 0xf4, 0x1d, 0x98, 0x8b, 0x48, 0x1c, - 0x11,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 0x1e, 0x85, - 0x01, 0x09, 0xb8, 0x8c, 0xac, 0x61, 0x95, 0x24, 0xeb, 0x13, 0xca, 0xcf, 0x6a, 0x9a, 0x61, 0x7e, - 0x0a, 0x25, 0x85, 0x55, 0xc5, 0x2c, 0x05, 0x41, 0x60, 0x44, 0x98, 0xc6, 0x52, 0x6a, 0xc6, 0x92, - 0xbf, 0xd1, 0x26, 0x2c, 0xf8, 0x34, 0xb0, 0x15, 0xb8, 0x73, 0x86, 0x83, 0x76, 0xf7, 0xb8, 0x15, - 0xac, 0x92, 0x4f, 0x03, 0x69, 0xcd, 0x8e, 0xe4, 0x34, 0x22, 0xdf, 0xec, 0xc0, 0xdd, 0x21, 0xe1, - 0x42, 0x55, 0x30, 0x4e, 0x31, 0x23, 0x12, 0x7b, 0xf6, 0x61, 0x65, 0x8c, 0xa8, 0xf4, 0x58, 0x66, - 0x49, 0x59, 0xb4, 0x02, 0xd3, 0xa9, 0x67, 0x42, 0x7f, 0xc9, 0x4a, 0xd7, 0xe6, 0x67, 0x89, 0xda, - 0xbe, 0x60, 0xde, 0x86, 0x5a, 0xf3, 0xcf, 0x19, 0x28, 0x1c, 0x87, 0x9d, 0xd8, 0x21, 0x4f, 0x5a, - 0xe2, 0x48, 0x31, 0xf4, 0x33, 0x28, 0x74, 0xef, 0xb2, 0xa4, 0x82, 0x47, 0x56, 0x68, 0x4a, 0xb8, - 0xd8, 0xaa, 0xd4, 0x15, 0xed, 0x38, 0x95, 0xae, 0xbb, 0x22, 0xe1, 0xac, 0x67, 0x8d, 0x1e, 0xc1, - 0x14, 0x76, 0xdd, 0x98, 0x30, 0x26, 0xbd, 0x9c, 0xa9, 0x96, 0xff, 0xf9, 0xd7, 0x0f, 0x17, 0xf4, - 0x05, 0xbf, 0xad, 0x38, 0xc7, 0x3c, 0xa6, 0x41, 0x7b, 0x7f, 0xc2, 0x4a, 0xb6, 0x56, 0xa7, 0x21, - 0xcf, 0xa4, 0x91, 0xe6, 0x9f, 0x72, 0x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, 0x4b, 0x06, 0x96, - 0x54, 0x7c, 0xd2, 0x63, 0x7c, 0xcd, 0x65, 0xa3, 0x0f, 0x66, 0x76, 0xf4, 0xc1, 0xcc, 0x8d, 0x73, - 0x9b, 0x18, 0x23, 0x8e, 0xc3, 0x60, 0xd1, 0x4e, 0x0e, 0x29, 0xda, 0xaa, 0xf5, 0xd5, 0xab, 0xb5, - 0xcc, 0xd7, 0xaf, 0xd6, 0x32, 0xff, 0x7d, 0xb5, 0x96, 0xf9, 0xed, 0xeb, 0xb5, 0x89, 0xaf, 0x5f, - 0xaf, 0x4d, 0xfc, 0xfb, 0xf5, 0xda, 0xc4, 0xb3, 0x8f, 0xc6, 0xff, 0xda, 0xdc, 0xff, 0x6f, 0x81, - 0xd3, 0xbc, 0x64, 0x7c, 0xef, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0xf7, 0x9d, 0xde, 0x80, 0x3c, - 0x18, 0x00, 0x00, + // 1997 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x59, 0xcd, 0x6f, 0x23, 0x49, + 0x15, 0x8f, 0x3f, 0xe2, 0x38, 0x2f, 0x71, 0xc6, 0xae, 0x49, 0x32, 0x4e, 0x02, 0x99, 0xd0, 0x12, + 0x52, 0xb4, 0x1f, 0xce, 0x64, 0x18, 0xd0, 0x8a, 0x03, 0x22, 0x4e, 0x9c, 0x8d, 0x47, 0x49, 0xc6, + 0xb4, 0x9d, 0xd9, 0xdd, 0x01, 0x6d, 0x53, 0xe9, 0x2e, 0x3b, 0xa5, 0xf4, 0xd7, 0x76, 0x95, 0xc3, + 0x64, 0x24, 0xce, 0x70, 0x03, 0x89, 0x33, 0x07, 0x0e, 0x5c, 0x90, 0x38, 0x20, 0x71, 0xdd, 0x13, + 0x97, 0xbd, 0xb1, 0xe2, 0x02, 0xe2, 0x30, 0x42, 0x33, 0x07, 0xae, 0xfc, 0x09, 0x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, 0x8e, 0xf1, 0x35, + 0x97, 0x8d, 0x3e, 0x98, 0xe9, 0xf1, 0x07, 0x33, 0x33, 0xc9, 0x6d, 0x92, 0x1d, 0x73, 0x1c, 0x86, + 0x8b, 0x76, 0x7a, 0x44, 0xd1, 0x56, 0xcd, 0xaf, 0x5e, 0xad, 0xa7, 0xbe, 0x7e, 0xb5, 0x9e, 0xfa, + 0xcf, 0xab, 0xf5, 0xd4, 0x6f, 0x5f, 0xaf, 0x4f, 0x7d, 0xfd, 0x7a, 0x7d, 0xea, 0x5f, 0xaf, 0xd7, + 0xa7, 0x9e, 0x7d, 0x34, 0xf9, 0xd7, 0xe9, 0xc1, 0x7f, 0x23, 0x9c, 0xe6, 0x24, 0xe3, 0x7b, 0xff, + 0x0f, 0x00, 0x00, 0xff, 0xff, 0xeb, 0x35, 0x70, 0xc0, 0x6c, 0x18, 0x00, 0x00, } func (m *FundingUpdateV1) Marshal() (dAtA []byte, err error) { @@ -2752,6 +2765,16 @@ func (m *DeleveragingEventV1) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.IsFinalSettlement { + i-- + if m.IsFinalSettlement { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x38 + } if m.IsBuy { i-- if m.IsBuy { @@ -3815,6 +3838,9 @@ func (m *DeleveragingEventV1) Size() (n int) { if m.IsBuy { n += 2 } + if m.IsFinalSettlement { + n += 2 + } return n } @@ -5688,6 +5714,26 @@ func (m *DeleveragingEventV1) Unmarshal(dAtA []byte) error { } } m.IsBuy = bool(v != 0) + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsFinalSettlement", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsFinalSettlement = bool(v != 0) default: iNdEx = preIndex skippy, err := skipEvents(dAtA[iNdEx:]) diff --git a/protocol/x/clob/types/matches.pb.go b/protocol/x/clob/types/matches.pb.go index 4ccfd0ebee..7eb76a91c3 100644 --- a/protocol/x/clob/types/matches.pb.go +++ b/protocol/x/clob/types/matches.pb.go @@ -339,6 +339,11 @@ type MatchPerpetualDeleveraging struct { PerpetualId uint32 `protobuf:"varint,2,opt,name=perpetual_id,json=perpetualId,proto3" json:"perpetual_id,omitempty"` // An ordered list of fills created by this liquidation. Fills []MatchPerpetualDeleveraging_Fill `protobuf:"bytes,3,rep,name=fills,proto3" json:"fills"` + // Flag denoting whether the deleveraging operation was for the purpose + // of final settlement. Final settlement matches are at the oracle price, + // whereas deleveraging happens at the bankruptcy price of the deleveraged + // subaccount. + IsFinalSettlement bool `protobuf:"varint,4,opt,name=is_final_settlement,json=isFinalSettlement,proto3" json:"is_final_settlement,omitempty"` } func (m *MatchPerpetualDeleveraging) Reset() { *m = MatchPerpetualDeleveraging{} } @@ -395,6 +400,13 @@ func (m *MatchPerpetualDeleveraging) GetFills() []MatchPerpetualDeleveraging_Fil return nil } +func (m *MatchPerpetualDeleveraging) GetIsFinalSettlement() bool { + if m != nil { + return m.IsFinalSettlement + } + return false +} + // Fill represents a fill between the liquidated and offsetting subaccount. type MatchPerpetualDeleveraging_Fill struct { // ID of the subaccount that was used to offset the liquidated subaccount's @@ -465,44 +477,46 @@ func init() { func init() { proto.RegisterFile("dydxprotocol/clob/matches.proto", fileDescriptor_a5aa660bc05a1de4) } var fileDescriptor_a5aa660bc05a1de4 = []byte{ - // 592 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcf, 0x6e, 0xd3, 0x4e, - 0x10, 0xb6, 0xdd, 0x24, 0xbf, 0x5f, 0xc6, 0x29, 0x12, 0x16, 0x20, 0xd7, 0xb4, 0x4e, 0xc8, 0x01, - 0x05, 0x89, 0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07, 0x00, 0x00, 0xff, 0xff, 0x86, 0x7f, 0x34, 0xa0, 0xc8, 0x05, 0x00, 0x00, + // 615 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xcd, 0x4e, 0xdb, 0x40, + 0x10, 0xb6, 0xf3, 0x43, 0x61, 0x1c, 0x2a, 0xb1, 0xfd, 0x91, 0x71, 0xc1, 0xa4, 0x39, 0x54, 0x54, + 0x2a, 0x8e, 0x44, 0xab, 0xaa, 0xd7, 0x86, 0x0a, 0x81, 0x04, 0x2d, 0x32, 0xb7, 0x5e, 0x2c, 0xff, + 0x6c, 0xcc, 0xaa, 0x6b, 0x6f, 0xb0, 0xd7, 0x88, 0xf0, 0x12, 0xf4, 0x09, 0xda, 0x17, 0xe9, 0x03, + 0x70, 0xe4, 0xd8, 0x53, 0x55, 0xc1, 0x8b, 0x54, 0xbb, 0x4e, 0x6c, 0x27, 0x21, 0x6a, 0x91, 0x7a, + 0x5b, 0x7f, 0x33, 0xf3, 0xed, 0x7c, 0xdf, 0xce, 0x18, 0x36, 0x82, 0x61, 0x70, 0x3e, 0x48, 0x18, + 0x67, 0x3e, 0xa3, 0x5d, 0x9f, 0x32, 0xaf, 0x1b, 0xb9, 0xdc, 0x3f, 0xc1, 0xa9, 0x25, 0x51, 0xb4, + 0x52, 0x4d, 0xb0, 0x44, 0x82, 0xf1, 0x38, 0x64, 0x21, 0x93, 0x50, 0x57, 0x9c, 0xf2, 0x44, 0xe3, + 0xe5, 0x04, 0x53, 0x9a, 0x79, 0xae, 0xef, 0xb3, 0x2c, 0xe6, 0x69, 0xe5, 0x3c, 0x4a, 0x5d, 0x9f, + 0xbd, 0x94, 0x25, 0x01, 0x4e, 0xf2, 0x70, 0xe7, 0x47, 0x0d, 0x96, 0x76, 0x28, 0xf3, 0x0e, 0x45, + 0x23, 0x68, 0x07, 0x5a, 0xb2, 0x23, 0x47, 0xa6,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x78, 0x5a, 0xb2, 0x55, 0xa3, 0xd3, 0xcb, 0x59, 0x9b, 0x5e, 0xce, + 0xde, 0xd1, 0xd5, 0x8d, 0xa9, 0x5e, 0xdf, 0x98, 0xea, 0xef, 0x1b, 0x53, 0xfd, 0x7a, 0x6b, 0x2a, + 0xd7, 0xb7, 0xa6, 0xf2, 0xf3, 0xd6, 0x54, 0x3e, 0xbf, 0x0d, 0x09, 0x3f, 0xc9, 0x3c, 0xcb, 0x67, + 0x51, 0x77, 0xe2, 0x6f, 0x7a, 0xf6, 0x66, 0xcb, 0x3f, 0x71, 0x49, 0xdc, 0x2d, 0x90, 0xf3, 0xfc, + 0x0f, 0xcb, 0x87, 0x03, 0x9c, 0x7a, 0x0b, 0x12, 0x7e, 0xfd, 0x27, 0x00, 0x00, 0xff, 0xff, 0xa0, + 0xfc, 0x47, 0x56, 0xf8, 0x05, 0x00, 0x00, } func (m *ClobMatch) Marshal() (dAtA []byte, err error) { @@ -777,6 +791,16 @@ func (m *MatchPerpetualDeleveraging) MarshalToSizedBuffer(dAtA []byte) (int, err _ = i var l int _ = l + if m.IsFinalSettlement { + i-- + if m.IsFinalSettlement { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x20 + } if len(m.Fills) > 0 { for iNdEx := len(m.Fills) - 1; iNdEx >= 0; iNdEx-- { { @@ -983,6 +1007,9 @@ func (m *MatchPerpetualDeleveraging) Size() (n int) { n += 1 + l + sovMatches(uint64(l)) } } + if m.IsFinalSettlement { + n += 2 + } return n } @@ -1689,6 +1716,26 @@ func (m *MatchPerpetualDeleveraging) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsFinalSettlement", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMatches + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsFinalSettlement = bool(v != 0) default: iNdEx = preIndex skippy, err := skipMatches(dAtA[iNdEx:]) From 56d653aa28decdcbb94dae290936669e2b782775 Mon Sep 17 00:00:00 2001 From: lucas-dydx <76970939+lucas-dydx@users.noreply.github.com> Date: Tue, 5 Dec 2023 16:21:28 -0500 Subject: [PATCH 6/6] enable sending BpMevMatches and ProposalReceiveTime to MEV indexer (#840) --- .../src/codegen/dydxprotocol/clob/mev.ts | 26 ++- proto/dydxprotocol/clob/mev.proto | 2 + protocol/x/clob/keeper/mev.go | 2 + protocol/x/clob/types/mev.pb.go | 182 ++++++++++++++---- 4 files changed, 169 insertions(+), 43 deletions(-) diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/mev.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/mev.ts index c40aad41ee..979d68caed 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/mev.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/mev.ts @@ -94,6 +94,8 @@ export interface ValidatorMevMatchesSDKType { export interface MevNodeToNodeMetrics { validatorMevMatches?: ValidatorMevMatches; clobMidPrices: ClobMidPrice[]; + bpMevMatches?: ValidatorMevMatches; + proposalReceiveTime: Long; } /** * MevNodeToNodeMetrics is a data structure for encapsulating all MEV node <> @@ -103,6 +105,8 @@ export interface MevNodeToNodeMetrics { export interface MevNodeToNodeMetricsSDKType { validator_mev_matches?: ValidatorMevMatchesSDKType; clob_mid_prices: ClobMidPriceSDKType[]; + bp_mev_matches?: ValidatorMevMatchesSDKType; + proposal_receive_time: Long; } function createBaseMEVMatch(): MEVMatch { @@ -448,7 +452,9 @@ export const ValidatorMevMatches = { function createBaseMevNodeToNodeMetrics(): MevNodeToNodeMetrics { return { validatorMevMatches: undefined, - clobMidPrices: [] + clobMidPrices: [], + bpMevMatches: undefined, + proposalReceiveTime: Long.UZERO }; } @@ -462,6 +468,14 @@ export const MevNodeToNodeMetrics = { ClobMidPrice.encode(v!, writer.uint32(18).fork()).ldelim(); } + if (message.bpMevMatches !== undefined) { + ValidatorMevMatches.encode(message.bpMevMatches, writer.uint32(26).fork()).ldelim(); + } + + if (!message.proposalReceiveTime.isZero()) { + writer.uint32(32).uint64(message.proposalReceiveTime); + } + return writer; }, @@ -482,6 +496,14 @@ export const MevNodeToNodeMetrics = { message.clobMidPrices.push(ClobMidPrice.decode(reader, reader.uint32())); break; + case 3: + message.bpMevMatches = ValidatorMevMatches.decode(reader, reader.uint32()); + break; + + case 4: + message.proposalReceiveTime = (reader.uint64() as Long); + break; + default: reader.skipType(tag & 7); break; @@ -495,6 +517,8 @@ export const MevNodeToNodeMetrics = { const message = createBaseMevNodeToNodeMetrics(); message.validatorMevMatches = object.validatorMevMatches !== undefined && object.validatorMevMatches !== null ? ValidatorMevMatches.fromPartial(object.validatorMevMatches) : undefined; message.clobMidPrices = object.clobMidPrices?.map(e => ClobMidPrice.fromPartial(e)) || []; + message.bpMevMatches = object.bpMevMatches !== undefined && object.bpMevMatches !== null ? ValidatorMevMatches.fromPartial(object.bpMevMatches) : undefined; + message.proposalReceiveTime = object.proposalReceiveTime !== undefined && object.proposalReceiveTime !== null ? Long.fromValue(object.proposalReceiveTime) : Long.UZERO; return message; } diff --git a/proto/dydxprotocol/clob/mev.proto b/proto/dydxprotocol/clob/mev.proto index 7671fd2792..dfd4024d1e 100644 --- a/proto/dydxprotocol/clob/mev.proto +++ b/proto/dydxprotocol/clob/mev.proto @@ -57,4 +57,6 @@ message ValidatorMevMatches { message MevNodeToNodeMetrics { ValidatorMevMatches validator_mev_matches = 1; repeated ClobMidPrice clob_mid_prices = 2 [ (gogoproto.nullable) = false ]; + ValidatorMevMatches bp_mev_matches = 3; + uint64 proposal_receive_time = 4; } diff --git a/protocol/x/clob/keeper/mev.go b/protocol/x/clob/keeper/mev.go index 870dc0e0f1..4e401aed5d 100644 --- a/protocol/x/clob/keeper/mev.go +++ b/protocol/x/clob/keeper/mev.go @@ -345,6 +345,8 @@ func (k Keeper) RecordMevMetrics( MevNodeToNode: types.MevNodeToNodeMetrics{ ValidatorMevMatches: validatorMevMatches, ClobMidPrices: mevClobMidPrices, + BpMevMatches: blockProposerMevMatches, + ProposalReceiveTime: uint64(time.Now().Second()), }, }, ) diff --git a/protocol/x/clob/types/mev.pb.go b/protocol/x/clob/types/mev.pb.go index b5aed6c386..7b3fc3001b 100644 --- a/protocol/x/clob/types/mev.pb.go +++ b/protocol/x/clob/types/mev.pb.go @@ -339,6 +339,8 @@ func (m *ValidatorMevMatches) GetLiquidationMatches() []MEVLiquidationMatch { type MevNodeToNodeMetrics struct { ValidatorMevMatches *ValidatorMevMatches `protobuf:"bytes,1,opt,name=validator_mev_matches,json=validatorMevMatches,proto3" json:"validator_mev_matches,omitempty"` ClobMidPrices []ClobMidPrice `protobuf:"bytes,2,rep,name=clob_mid_prices,json=clobMidPrices,proto3" json:"clob_mid_prices"` + BpMevMatches *ValidatorMevMatches `protobuf:"bytes,3,opt,name=bp_mev_matches,json=bpMevMatches,proto3" json:"bp_mev_matches,omitempty"` + ProposalReceiveTime uint64 `protobuf:"varint,4,opt,name=proposal_receive_time,json=proposalReceiveTime,proto3" json:"proposal_receive_time,omitempty"` } func (m *MevNodeToNodeMetrics) Reset() { *m = MevNodeToNodeMetrics{} } @@ -388,6 +390,20 @@ func (m *MevNodeToNodeMetrics) GetClobMidPrices() []ClobMidPrice { return nil } +func (m *MevNodeToNodeMetrics) GetBpMevMatches() *ValidatorMevMatches { + if m != nil { + return m.BpMevMatches + } + return nil +} + +func (m *MevNodeToNodeMetrics) GetProposalReceiveTime() uint64 { + if m != nil { + return m.ProposalReceiveTime + } + return 0 +} + func init() { proto.RegisterType((*MEVMatch)(nil), "dydxprotocol.clob.MEVMatch") proto.RegisterType((*MEVLiquidationMatch)(nil), "dydxprotocol.clob.MEVLiquidationMatch") @@ -399,48 +415,51 @@ func init() { func init() { proto.RegisterFile("dydxprotocol/clob/mev.proto", fileDescriptor_01e0eddc304623e6) } var fileDescriptor_01e0eddc304623e6 = []byte{ - // 651 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x54, 0x4d, 0x6b, 0x13, 0x4f, - 0x1c, 0xce, 0x36, 0x7d, 0xc9, 0x7f, 0xda, 0x52, 0xfe, 0x93, 0x5a, 0xd6, 0x16, 0x92, 0x35, 0x42, - 0x89, 0x88, 0x1b, 0x51, 0xf1, 0x22, 0x08, 0xb6, 0xb6, 0x50, 0xe8, 0x6a, 0xba, 0x4a, 0x0f, 0x05, - 0x19, 0x26, 0x3b, 0x93, 0x74, 0xec, 0xce, 0xce, 0x76, 0xdf, 0x68, 0xbe, 0x85, 0x5f, 0xc5, 0xab, - 0x37, 0x6f, 0x3d, 0xf6, 0xe8, 0x49, 0xa4, 0xfd, 0x16, 0x9e, 0x64, 0x66, 0x5f, 0xb2, 0x49, 0x93, - 0x83, 0xe8, 0xc9, 0xcb, 0x32, 0xfb, 0xcc, 0x6f, 0x9e, 0xe7, 0xf7, 0xcc, 0x33, 0xfc, 0xc0, 0x16, - 0x19, 0x92, 0x0b, 0x3f, 0x10, 0x91, 0x70, 0x84, 0xdb, 0x71, 0x5c, 0xd1, 0xeb, 0x70, 0x9a, 0x98, - 0x0a, 0x81, 0xff, 0x97, 0x37, 0x4d, 0xb9, 0xb9, 0xb9, 0x3e, 0x10, 0x03, 0xa1, 0xa0, 0x8e, 0x5c, - 0xa5, 0x85, 0x9b, 0x0f, 0xc6, 0x58, 0xc2, 0xb8, 0x87, 0x1d, 0x47, 0xc4, 0x5e, 0x14, 0x96, 0xd6, - 0x59, 0xe9, 0xbd, 0xdb, 0x82, 0xf2, 0x83, 0x7c, 0xcc, 0x82, 0xb4, 0xa4, 0xf5, 0xa5, 0x0a, 0x6a, - 0xd6, 0xde, 0xb1, 0x85, 0x23, 0xe7, 0x14, 0x62, 0x70, 0x37, 0xc2, 0x67, 0x34, 0x40, 0x22, 0x20, - 0x34, 0x40, 0x23, 0x3e, 0xc4, 0x88, 0xae, 0x19, 0x5a, 0x7b, 0xf9, 0xc9, 0xb6, 0x39, 0xd6, 0x67, - 0x49, 0xde, 0x7c, 0x57, 0xac, 0x0f, 0x88, 0xbd, 0xa1, 0x88, 0xde, 0x4a, 0x9e, 0x32, 0x0e, 0x5b, - 0x60, 0x35, 0x95, 0xe8, 0x53, 0x8a, 0x7c, 0x9f, 0xeb, 0x73, 0x86, 0xd6, 0x5e, 0xb0, 0x97, 0x15, - 0xb8, 0x4f, 0x69, 0xd7, 0xe7, 0xb2, 0x0d, 0x3e, 0xb3, 0x8d, 0xea, 0xef, 0xb5, 0xc1, 0xa7, 0xb7, - 0xf1, 0x18, 0xac, 0x4f, 0x48, 0x44, 0xcc, 0x39, 0x0b, 0xf5, 0x79, 0x43, 0x6b, 0xcf, 0xdb, 0x70, - 0xec, 0x94, 0xda, 0x81, 0x0f, 0x01, 0x2c, 0x9f, 0x60, 0x21, 0xea, 0xc5, 0x43, 0x7d, 0xc1, 0xd0, - 0xda, 0x35, 0x7b, 0x6d, 0x54, 0x7f, 0x10, 0xee, 0xc4, 0x43, 0xe9, 0x92, 0x8f, 0xb9, 0x5c, 0x4c, - 0x5d, 0xf2, 0x92, 0x4b, 0x03, 0xac, 0x14, 0x61, 0x48, 0x63, 0x4b, 0x86, 0xd6, 0x5e, 0xb5, 0x81, - 0xc4, 0xba, 0x98, 0x05, 0x07, 0x04, 0x36, 0xc1, 0x72, 0x9f, 0xb9, 0x2e, 0xc2, 0x5c, 0x76, 0xad, - 0xd7, 0x54, 0x6f, 0x40, 0x42, 0xaf, 0x14, 0xd2, 0xfa, 0x59, 0x05, 0x75, 0x6b, 0xef, 0xf8, 0x90, - 0x9d, 0xc7, 0x8c, 0xe0, 0x88, 0x09, 0x2f, 0xcd, 0xb1, 0x0f, 0x74, 0x37, 0xc3, 0x28, 0xf9, 0x93, - 0x18, 0x77, 0xe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0, 0x4e, 0x92, 0x7b, 0x41, 0x9c, 0x26, - 0x68, 0x64, 0x41, 0x9b, 0xa1, 0x3c, 0xc5, 0xbb, 0x5d, 0x4f, 0xa6, 0x5c, 0x88, 0x05, 0xd6, 0x54, - 0x08, 0x9c, 0x11, 0xe4, 0xcb, 0x58, 0x72, 0x3f, 0xcd, 0x19, 0x51, 0xe4, 0xf1, 0x65, 0x46, 0x56, - 0x9d, 0x12, 0x16, 0xee, 0x74, 0x2f, 0xaf, 0x1b, 0xda, 0xd5, 0x75, 0x43, 0xfb, 0x71, 0xdd, 0xd0, - 0x3e, 0xdd, 0x34, 0x2a, 0x57, 0x37, 0x8d, 0xca, 0xb7, 0x9b, 0x46, 0xe5, 0xe4, 0xf9, 0x80, 0x45, - 0xa7, 0x71, 0xcf, 0x74, 0x04, 0xef, 0x8c, 0x4d, 0xf9, 0xe4, 0xd9, 0x23, 0xe7, 0x14, 0x33, 0xaf, - 0x53, 0x20, 0x17, 0xe9, 0xe4, 0x8f, 0x86, 0x3e, 0x0d, 0x7b, 0x8b, 0x0a, 0x7e, 0xfa, 0x2b, 0x00, - 0x00, 0xff, 0xff, 0x29, 0x71, 0x09, 0x34, 0x8c, 0x06, 0x00, 0x00, + // 696 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x55, 0xcd, 0x4e, 0xdb, 0x4a, + 0x18, 0x8d, 0x13, 0x7e, 0x72, 0x07, 0xb8, 0xe8, 0x4e, 0x00, 0xe5, 0x82, 0x94, 0xb8, 0xa9, 0x84, + 0x52, 0x55, 0x75, 0x2a, 0x5a, 0x75, 0x53, 0xa9, 0x52, 0xa1, 0x20, 0x21, 0xe1, 0x36, 0xb8, 0x88, + 0x05, 0x52, 0x35, 0x1a, 0x7b, 0x26, 0x61, 0x8a, 0xc7, 0x63, 0xfc, 0x27, 0xf2, 0x16, 0x7d, 0x95, + 0x6e, 0xbb, 0xed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, 0xe9, 0xe0, 0x37, 0xb2, 0x4d, 0x23, 0xd9, 0x3b, 0x62, 0x9c, 0x6e, + 0xf7, 0x2f, 0xaf, 0x5b, 0xca, 0xd5, 0x75, 0x4b, 0xf9, 0x71, 0xdd, 0x52, 0x3e, 0xdd, 0xb4, 0x2a, + 0x57, 0x37, 0xad, 0xca, 0xb7, 0x9b, 0x56, 0xe5, 0xe4, 0xc5, 0x90, 0x05, 0xa7, 0xa1, 0xa9, 0x59, + 0x82, 0xf7, 0x4a, 0xff, 0x99, 0xe8, 0xf9, 0x13, 0xeb, 0x14, 0x33, 0xa7, 0x97, 0x23, 0x17, 0xc9, + 0xbf, 0x27, 0x18, 0xb9, 0xd4, 0x37, 0xe7, 0x62, 0xf8, 0xd9, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x4b, 0x24, 0x41, 0x3b, 0x0e, 0x07, 0x00, 0x00, } func (m *MEVMatch) Marshal() (dAtA []byte, err error) { @@ -712,6 +731,23 @@ func (m *MevNodeToNodeMetrics) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.ProposalReceiveTime != 0 { + i = encodeVarintMev(dAtA, i, uint64(m.ProposalReceiveTime)) + i-- + dAtA[i] = 0x20 + } + if m.BpMevMatches != nil { + { + size, err := m.BpMevMatches.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintMev(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } if len(m.ClobMidPrices) > 0 { for iNdEx := len(m.ClobMidPrices) - 1; iNdEx >= 0; iNdEx-- { { @@ -869,6 +905,13 @@ func (m *MevNodeToNodeMetrics) Size() (n int) { n += 1 + l + sovMev(uint64(l)) } } + if m.BpMevMatches != nil { + l = m.BpMevMatches.Size() + n += 1 + l + sovMev(uint64(l)) + } + if m.ProposalReceiveTime != 0 { + n += 1 + sovMev(uint64(m.ProposalReceiveTime)) + } return n } @@ -1665,6 +1708,61 @@ func (m *MevNodeToNodeMetrics) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BpMevMatches", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMev + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthMev + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthMev + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.BpMevMatches == nil { + m.BpMevMatches = &ValidatorMevMatches{} + } + if err := m.BpMevMatches.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ProposalReceiveTime", wireType) + } + m.ProposalReceiveTime = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMev + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ProposalReceiveTime |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipMev(dAtA[iNdEx:])