diff --git a/indexer/CHANGELOG.md b/indexer/CHANGELOG.md index ff9b1fc786..dd98f9ad06 100644 --- a/indexer/CHANGELOG.md +++ b/indexer/CHANGELOG.md @@ -10,6 +10,8 @@ * [#469](https://github.com/dydxprotocol/v4-chain/pull/469) Added a reason field to `/screen` endpoint to display a reason for blocking an address. ### Bug Fixes +* [#528](https://github.com/dydxprotocol/v4-chain/pull/528) Fixed bug with bulk SQL queries with nullable numeric / string / boolean values. + * [#496](https://github.com/dydxprotocol/v4-chain/pull/496) Don't geo-block requests made to `comlink` if it's from an internal ip. * [#460](https://github.com/dydxprotocol/v4-chain/pull/460/files) Fixed track lag timing to output positive numbers. diff --git a/indexer/packages/postgres/__tests__/stores/compliance-data-table.test.ts b/indexer/packages/postgres/__tests__/stores/compliance-data-table.test.ts index 6b4e4c9f72..2802726c83 100644 --- a/indexer/packages/postgres/__tests__/stores/compliance-data-table.test.ts +++ b/indexer/packages/postgres/__tests__/stores/compliance-data-table.test.ts @@ -243,9 +243,13 @@ describe('Compliance data store', () => { ); expect(complianceData.length).toEqual(1); - const updatedTime: string = DateTime.fromISO( + const updatedTime1: string = DateTime.fromISO( nonBlockedComplianceData.updatedAt!, ).plus(10).toUTC().toISO(); + const updatedTime2: string = DateTime.fromISO( + nonBlockedComplianceData.updatedAt!, + ).plus(20).toUTC().toISO(); + const otherAddress: string = 'dydx1scu097p2sstqzupe6t687kpc2w4sv665fedctf'; await ComplianceDataTable.bulkUpsert( [ @@ -254,7 +258,14 @@ describe('Compliance data store', () => { ...nonBlockedComplianceData, riskScore: '30.00', blocked: true, - updatedAt: updatedTime, + updatedAt: updatedTime1, + }, + { + ...nonBlockedComplianceData, + address: otherAddress, + riskScore: undefined, + blocked: false, + updatedAt: updatedTime2, }, ], ); @@ -264,13 +275,20 @@ describe('Compliance data store', () => { [], { readReplica: true }, ); - expect(complianceData.length).toEqual(2); + expect(complianceData.length).toEqual(3); expect(complianceData[0]).toEqual(blockedComplianceData); expect(complianceData[1]).toEqual({ ...nonBlockedComplianceData, riskScore: '30.00', blocked: true, - updatedAt: updatedTime, + updatedAt: updatedTime1, + }); + expect(complianceData[2]).toEqual({ + ...nonBlockedComplianceData, + address: otherAddress, + riskScore: null, + blocked: false, + updatedAt: updatedTime2, }); }); }); diff --git a/indexer/packages/postgres/src/helpers/stores-helpers.ts b/indexer/packages/postgres/src/helpers/stores-helpers.ts index ad501f2a00..7fd583d843 100644 --- a/indexer/packages/postgres/src/helpers/stores-helpers.ts +++ b/indexer/packages/postgres/src/helpers/stores-helpers.ts @@ -110,10 +110,10 @@ export function setBulkRowsForUpdate({ }): string[] { return objectArray.map((object) => columns.map((col) => { if (stringColumns && stringColumns.includes(col)) { - return `'${object[col]}'`; + return `'${castNull(object[col])}'`; } if (numericColumns && numericColumns.includes(col)) { - return `${_.get(object, col)}`; + return `${castNull(_.get(object, col))}`; } if (bigintColumns && bigintColumns.includes(col)) { return castValue(object[col] as number | undefined | null, 'bigint'); @@ -128,12 +128,24 @@ export function setBulkRowsForUpdate({ return castBinaryValue(object[col] as Buffer | null | undefined); } if (booleanColumns && booleanColumns.includes(col)) { - return `${object[col]}`; + return `${castNull(object[col])}`; } throw new Error(`Unsupported column for bulk update: ${col}`); }).join(', ')); } +/** + * If the value is null || undefined, return 'NULL' + */ +function castNull( + value: Buffer | string | number | boolean | null | undefined, +): string { + if (value === null || value === undefined) { + return 'NULL'; + } + return `${value}`; +} + /** * If the value is null || undefined, return 'NULL' casted with typesuffix, otherwise return * the stringified value in quotes casted with typesuffix. diff --git a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/indexer_manager/event.ts b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/indexer_manager/event.ts index 436c3a7543..b97320fb3f 100644 --- a/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/indexer_manager/event.ts +++ b/indexer/packages/v4-protos/src/codegen/dydxprotocol/indexer/indexer_manager/event.ts @@ -118,12 +118,6 @@ export interface IndexerEventsStoreValueSDKType { export interface IndexerTendermintEvent { /** Subtype of the event e.g. "order_fill", "subaccount_update", etc. */ subtype: string; - /** - * Base64 encoded proto from the Tendermint event. - * TODO(DEC-1720): Change to bytes post-migration. - */ - - data: string; transactionIndex?: number; blockEvent?: IndexerTendermintEvent_BlockEvent; /** @@ -149,12 +143,6 @@ export interface IndexerTendermintEvent { export interface IndexerTendermintEventSDKType { /** Subtype of the event e.g. "order_fill", "subaccount_update", etc. */ subtype: string; - /** - * Base64 encoded proto from the Tendermint event. - * TODO(DEC-1720): Change to bytes post-migration. - */ - - data: string; transaction_index?: number; block_event?: IndexerTendermintEvent_BlockEventSDKType; /** @@ -301,7 +289,6 @@ export const IndexerEventsStoreValue = { function createBaseIndexerTendermintEvent(): IndexerTendermintEvent { return { subtype: "", - data: "", transactionIndex: undefined, blockEvent: undefined, eventIndex: 0, @@ -316,10 +303,6 @@ export const IndexerTendermintEvent = { writer.uint32(10).string(message.subtype); } - if (message.data !== "") { - writer.uint32(18).string(message.data); - } - if (message.transactionIndex !== undefined) { writer.uint32(24).uint32(message.transactionIndex); } @@ -356,10 +339,6 @@ export const IndexerTendermintEvent = { message.subtype = reader.string(); break; - case 2: - message.data = reader.string(); - break; - case 3: message.transactionIndex = reader.uint32(); break; @@ -392,7 +371,6 @@ export const IndexerTendermintEvent = { fromPartial(object: DeepPartial): IndexerTendermintEvent { const message = createBaseIndexerTendermintEvent(); message.subtype = object.subtype ?? ""; - message.data = object.data ?? ""; message.transactionIndex = object.transactionIndex ?? undefined; message.blockEvent = object.blockEvent ?? undefined; message.eventIndex = object.eventIndex ?? 0; diff --git a/indexer/services/comlink/__tests__/controllers/api/v4/compliance-controller.test.ts b/indexer/services/comlink/__tests__/controllers/api/v4/compliance-controller.test.ts index ecb0948e51..34e12bddaa 100644 --- a/indexer/services/comlink/__tests__/controllers/api/v4/compliance-controller.test.ts +++ b/indexer/services/comlink/__tests__/controllers/api/v4/compliance-controller.test.ts @@ -70,6 +70,10 @@ describe('compliance-controller#V4', () => { expect(response.body.restricted).toEqual(false); expect(response.reason).toBeUndefined(); expect(stats.timing).toHaveBeenCalledTimes(1); + expect(stats.increment).toHaveBeenCalledWith( + 'comlink.compliance-controller.compliance_data_cache_miss', + { provider: complianceProvider.provider }, + ); expect(complianceProvider.client.getComplianceResponse).toHaveBeenCalledTimes(1); data = await ComplianceTable.findAll({}, [], {}); @@ -98,6 +102,10 @@ describe('compliance-controller#V4', () => { expect(response.body.restricted).toEqual(false); expect(response.reason).toBeUndefined(); expect(stats.timing).toHaveBeenCalledTimes(1); + expect(stats.increment).toHaveBeenCalledWith( + 'comlink.compliance-controller.compliance_data_cache_hit', + { provider: complianceProvider.provider }, + ); expect(complianceProvider.client.getComplianceResponse).toHaveBeenCalledTimes(0); data = await ComplianceTable.findAll({}, [], {}); @@ -121,6 +129,10 @@ describe('compliance-controller#V4', () => { expect(response.body.restricted).toEqual(true); expect(response.body.reason).toEqual(INDEXER_COMPLIANCE_BLOCKED_PAYLOAD); expect(stats.timing).toHaveBeenCalledTimes(1); + expect(stats.increment).toHaveBeenCalledWith( + 'comlink.compliance-controller.compliance_data_cache_hit', + { provider: complianceProvider.provider }, + ); expect(complianceProvider.client.getComplianceResponse).toHaveBeenCalledTimes(0); data = await ComplianceTable.findAll({}, [], {}); @@ -149,6 +161,14 @@ describe('compliance-controller#V4', () => { expect(response.body.restricted).toEqual(false); expect(response.body.reason).toBeUndefined(); expect(stats.timing).toHaveBeenCalledTimes(1); + expect(stats.increment).toHaveBeenCalledWith( + 'comlink.compliance-controller.compliance_data_cache_hit', + { provider: complianceProvider.provider }, + ); + expect(stats.increment).toHaveBeenCalledWith( + 'comlink.compliance-controller.refresh_compliance_data_cache', + { provider: complianceProvider.provider }, + ); expect(complianceProvider.client.getComplianceResponse).toHaveBeenCalledTimes(1); data = await ComplianceTable.findAll({}, [], {}); @@ -183,6 +203,10 @@ describe('compliance-controller#V4', () => { expect(response.body.restricted).toEqual(true); expect(response.body.reason).toEqual(INDEXER_COMPLIANCE_BLOCKED_PAYLOAD); expect(stats.timing).toHaveBeenCalledTimes(1); + expect(stats.increment).toHaveBeenCalledWith( + 'comlink.compliance-controller.compliance_data_cache_hit', + { provider: complianceProvider.provider }, + ); expect(complianceProvider.client.getComplianceResponse).toHaveBeenCalledTimes(0); data = await ComplianceTable.findAll({}, [], {}); @@ -207,6 +231,10 @@ describe('compliance-controller#V4', () => { errorMsg: 'Too many requests', expectedStatus: 429, }); + expect(stats.increment).toHaveBeenCalledWith( + 'comlink.compliance-controller.compliance_screen_rate_limited_attempts', + { provider: complianceProvider.provider }, + ); }); it('Get /screen with multiple new address globally gets rate-limited', async () => { @@ -224,6 +252,10 @@ describe('compliance-controller#V4', () => { errorMsg: 'Too many requests', expectedStatus: 429, }); + expect(stats.increment).toHaveBeenCalledWith( + 'comlink.compliance-controller.compliance_screen_rate_limited_attempts', + { provider: complianceProvider.provider }, + ); }); }); }); diff --git a/indexer/services/comlink/src/controllers/api/v4/compliance-controller.ts b/indexer/services/comlink/src/controllers/api/v4/compliance-controller.ts index c2f1c1f0e7..501a2535dd 100644 --- a/indexer/services/comlink/src/controllers/api/v4/compliance-controller.ts +++ b/indexer/services/comlink/src/controllers/api/v4/compliance-controller.ts @@ -51,6 +51,13 @@ class ComplianceController extends Controller { complianceProvider.provider, ); + if (complianceData !== undefined) { + stats.increment( + `${config.SERVICE_NAME}.${controllerName}.compliance_data_cache_hit`, + { provider: complianceProvider.provider }, + ); + } + // Immediately return for blocked addresses, do not refresh if (complianceData?.blocked) { return { @@ -61,7 +68,19 @@ class ComplianceController extends Controller { if (complianceData === undefined || DateTime.fromISO(complianceData.updatedAt) < ageThreshold) { await checkRateLimit(this.ipAddress); - // TODO(IND-369): Use Ellptic client + + if (complianceData === undefined) { + stats.increment( + `${config.SERVICE_NAME}.${controllerName}.compliance_data_cache_miss`, + { provider: complianceProvider.provider }, + ); + } else { + stats.increment( + `${config.SERVICE_NAME}.${controllerName}.refresh_compliance_data_cache`, + { provider: complianceProvider.provider }, + ); + } + const response: ComplianceClientResponse = await complianceProvider.client.getComplianceResponse( address, @@ -111,6 +130,10 @@ router.get( return res.send(response); } catch (error) { if (error instanceof TooManyRequestsError) { + stats.increment( + `${config.SERVICE_NAME}.${controllerName}.compliance_screen_rate_limited_attempts`, + { provider: complianceProvider.provider }, + ); return create4xxResponse( res, 'Too many requests', diff --git a/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts b/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts index 901bfc2c83..576ee0e89e 100644 --- a/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts +++ b/indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts @@ -89,7 +89,6 @@ export function createIndexerTendermintEvent( // blockEvent return { subtype, - data: '', dataBytes, blockEvent: IndexerTendermintEvent_BlockEvent.BLOCK_EVENT_END_BLOCK, eventIndex, @@ -99,7 +98,6 @@ export function createIndexerTendermintEvent( // transactionIndex return { subtype, - data: '', dataBytes, transactionIndex, eventIndex, diff --git a/indexer/services/ender/__tests__/lib/helper.test.ts b/indexer/services/ender/__tests__/lib/helper.test.ts index d29c9f8500..cb78fd148c 100644 --- a/indexer/services/ender/__tests__/lib/helper.test.ts +++ b/indexer/services/ender/__tests__/lib/helper.test.ts @@ -47,7 +47,6 @@ describe('helper', () => { ...eventFields, subtype: 'order_fill', dataBytes: Uint8Array.from(Buffer.from('data')), - data: 'data', eventIndex: 0, version: 1, }; diff --git a/indexer/services/roundtable/__tests__/tasks/update-compliance-data.test.ts b/indexer/services/roundtable/__tests__/tasks/update-compliance-data.test.ts index 782e531744..4bc9902408 100644 --- a/indexer/services/roundtable/__tests__/tasks/update-compliance-data.test.ts +++ b/indexer/services/roundtable/__tests__/tasks/update-compliance-data.test.ts @@ -19,6 +19,10 @@ import { ClientAndProvider } from '../../src/helpers/compliance-clients'; import { ComplianceClientResponse } from '@dydxprotocol-indexer/compliance'; import { DateTime } from 'luxon'; +interface ComplianceClientResponseWithNull extends Omit { + riskScore: string | undefined | null; +} + describe('update-compliance-data', () => { let mockProvider: ClientAndProvider; @@ -215,6 +219,41 @@ describe('update-compliance-data', () => { expectTimingStats(mockProvider.provider); }); + it('succeeds with an active address to update, undefined risk-score', async () => { + // Seed database with compliance data older than the age threshold for active addresses + await setupComplianceData(config.MAX_ACTIVE_COMPLIANCE_DATA_AGE_SECONDS * 2); + + setupMockProvider( + mockProvider, + { [testConstants.defaultAddress]: { blocked: true, riskScore: undefined } }, + ); + + await updateComplianceDataTask(mockProvider); + + const complianceData: ComplianceDataFromDatabase[] = await ComplianceTable.findAll({}, [], {}); + expect(complianceData).toHaveLength(1); + expectUpdatedCompliance( + complianceData[0], + { + address: testConstants.defaultAddress, + blocked: true, + riskScore: null, + }, + mockProvider.provider, + ); + + expectGaugeStats({ + activeAddresses: 1, + newAddresses: 0, + oldAddresses: 0, + addressesScreened: 1, + upserted: 1, + }, + mockProvider.provider, + ); + expectTimingStats(mockProvider.provider); + }); + it('succeeds with an old address to update', async () => { // Seed database with old compliance data, and set up subaccounts to not be active await Promise.all([ @@ -529,7 +568,7 @@ async function setupSubaccounts( function setupMockProvider( clientAndProvider: ClientAndProvider, - expectedResponses: {[address: string]: {blocked: boolean, riskScore: string}}, + expectedResponses: {[address: string]: {blocked: boolean, riskScore: string | undefined }}, ): void { // eslint-disable-next-line no-param-reassign clientAndProvider.client.getComplianceResponse = jest.fn().mockImplementation( @@ -549,7 +588,7 @@ function setupMockProvider( function expectUpdatedCompliance( complianceData: ComplianceDataFromDatabase, - complianceClientResponse: ComplianceClientResponse, + complianceClientResponse: ComplianceClientResponseWithNull, provider: string, ): void { expect(complianceData).toEqual(expect.objectContaining({ diff --git a/proto/dydxprotocol/indexer/indexer_manager/event.proto b/proto/dydxprotocol/indexer/indexer_manager/event.proto index 8929ee2704..dae9211387 100644 --- a/proto/dydxprotocol/indexer/indexer_manager/event.proto +++ b/proto/dydxprotocol/indexer/indexer_manager/event.proto @@ -23,11 +23,9 @@ message IndexerEventsStoreValue { // the V4 application as well as additional metadata to determine the ordering // of the event within the block and the subtype of the event. message IndexerTendermintEvent { + reserved 2; // Subtype of the event e.g. "order_fill", "subaccount_update", etc. string subtype = 1; - // Base64 encoded proto from the Tendermint event. - // TODO(DEC-1720): Change to bytes post-migration. - string data = 2; // enum to specify that the IndexerTendermintEvent is a block event. enum BlockEvent { // Default value. This value is invalid and unused. diff --git a/protocol/CHANGELOG.md b/protocol/CHANGELOG.md index 5b29c2b56c..8acdbdc711 100644 --- a/protocol/CHANGELOG.md +++ b/protocol/CHANGELOG.md @@ -9,7 +9,9 @@ ### Improvements * [#479](https://github.com/dydxprotocol/v4-chain/pull/479) Ensure that rate limiting of short term order placements/cancellations is guarded against replay attacks. - + +* [#532](https://github.com/dydxprotocol/v4-chain/pull/532) Use updated `data-api.binance.vision` endpoint for Binance price data. + ### Bug Fixes * [#449](https://github.com/dydxprotocol/v4-chain/pull/449) Removes possible undesirable panics in x/rewards `EndBlocker`. diff --git a/protocol/Makefile b/protocol/Makefile index 75e6d2b4ed..68d755a851 100644 --- a/protocol/Makefile +++ b/protocol/Makefile @@ -401,3 +401,16 @@ update-swagger-docs: statik fi .PHONY: update-swagger-docs + +############################################################################### +### Sample Prengenesis ### +############################################################################### + +# Run at `./protocol` directory. +update-sample-pregenesis: + make build + ./scripts/genesis/prod_pregenesis.sh build/dydxprotocold + cp /tmp/prod-chain/.dydxprotocol/config/genesis.json ./scripts/genesis/sample_pregenesis.json + @echo "Updated ./scripts/genesis/sample_pregenesis.json" + +.PHONY: update-sample-pregenesis diff --git a/protocol/app/app.go b/protocol/app/app.go index 1d42aaaa53..6777aa0e8e 100644 --- a/protocol/app/app.go +++ b/protocol/app/app.go @@ -3,8 +3,6 @@ package app import ( "context" "encoding/json" - daemontypes "github.com/dydxprotocol/v4-chain/protocol/daemons/types" - "github.com/dydxprotocol/v4-chain/protocol/lib" "io" "math/big" "net/http" @@ -12,17 +10,10 @@ import ( "path/filepath" "strings" - "github.com/dydxprotocol/v4-chain/protocol/app/stoppable" - daemonservertypes "github.com/dydxprotocol/v4-chain/protocol/daemons/server/types" - "github.com/dydxprotocol/v4-chain/protocol/x/clob/rate_limit" - - gometrics "github.com/armon/go-metrics" - "github.com/dydxprotocol/v4-chain/protocol/lib/metrics" - - pricefeed_types "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/types" - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" + sdklog "cosmossdk.io/log" + gometrics "github.com/armon/go-metrics" dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" @@ -108,7 +99,11 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/app/upgrades" // Lib + "github.com/dydxprotocol/v4-chain/protocol/app/stoppable" + "github.com/dydxprotocol/v4-chain/protocol/lib" + "github.com/dydxprotocol/v4-chain/protocol/lib/metrics" timelib "github.com/dydxprotocol/v4-chain/protocol/lib/time" + "github.com/dydxprotocol/v4-chain/protocol/x/clob/rate_limit" // Mempool "github.com/dydxprotocol/v4-chain/protocol/mempool" @@ -120,10 +115,13 @@ import ( liquidationclient "github.com/dydxprotocol/v4-chain/protocol/daemons/liquidation/client" pricefeedclient "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client" "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/constants" + pricefeed_types "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/types" daemonserver "github.com/dydxprotocol/v4-chain/protocol/daemons/server" + daemonservertypes "github.com/dydxprotocol/v4-chain/protocol/daemons/server/types" bridgedaemontypes "github.com/dydxprotocol/v4-chain/protocol/daemons/server/types/bridge" liquidationtypes "github.com/dydxprotocol/v4-chain/protocol/daemons/server/types/liquidations" pricefeedtypes "github.com/dydxprotocol/v4-chain/protocol/daemons/server/types/pricefeed" + daemontypes "github.com/dydxprotocol/v4-chain/protocol/daemons/types" // Modules assetsmodule "github.com/dydxprotocol/v4-chain/protocol/x/assets" @@ -638,7 +636,7 @@ func New( context.Background(), daemonFlags, appFlags, - logger, + logger.With(sdklog.ModuleKey, "bridge-daemon"), &daemontypes.GrpcClientImpl{}, ); err != nil { panic(err) diff --git a/protocol/daemons/bridge/client/client.go b/protocol/daemons/bridge/client/client.go index 7f2215682e..ef47e1fae9 100644 --- a/protocol/daemons/bridge/client/client.go +++ b/protocol/daemons/bridge/client/client.go @@ -3,7 +3,6 @@ package client import ( "context" "fmt" - daemontypes "github.com/dydxprotocol/v4-chain/protocol/daemons/types" "math/big" "time" @@ -14,6 +13,7 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/daemons/bridge/client/types" "github.com/dydxprotocol/v4-chain/protocol/daemons/constants" "github.com/dydxprotocol/v4-chain/protocol/daemons/flags" + daemontypes "github.com/dydxprotocol/v4-chain/protocol/daemons/types" libeth "github.com/dydxprotocol/v4-chain/protocol/lib/eth" "github.com/dydxprotocol/v4-chain/protocol/lib/metrics" bridgetypes "github.com/dydxprotocol/v4-chain/protocol/x/bridge/types" diff --git a/protocol/daemons/pricefeed/client/price_function/binance/exchange_query_details.go b/protocol/daemons/pricefeed/client/price_function/binance/exchange_query_details.go index 695656915b..fc53a4b839 100644 --- a/protocol/daemons/pricefeed/client/price_function/binance/exchange_query_details.go +++ b/protocol/daemons/pricefeed/client/price_function/binance/exchange_query_details.go @@ -8,7 +8,7 @@ import ( var ( BinanceDetails = types.ExchangeQueryDetails{ Exchange: exchange_common.EXCHANGE_ID_BINANCE, - Url: "https://data.binance.com/api/v3/ticker/24hr", + Url: "https://data-api.binance.vision/api/v3/ticker/24hr", PriceFunction: BinancePriceFunction, IsMultiMarket: true, } diff --git a/protocol/daemons/pricefeed/client/price_function/binance/exchange_query_details_test.go b/protocol/daemons/pricefeed/client/price_function/binance/exchange_query_details_test.go index e313973552..d7185ff0e9 100644 --- a/protocol/daemons/pricefeed/client/price_function/binance/exchange_query_details_test.go +++ b/protocol/daemons/pricefeed/client/price_function/binance/exchange_query_details_test.go @@ -8,7 +8,7 @@ import ( ) func TestBinanceUrl(t *testing.T) { - require.Equal(t, "https://data.binance.com/api/v3/ticker/24hr", binance.BinanceDetails.Url) + require.Equal(t, "https://data-api.binance.vision/api/v3/ticker/24hr", binance.BinanceDetails.Url) } func TestBinanceUsUrl(t *testing.T) { diff --git a/protocol/indexer/indexer_manager/constants_test.go b/protocol/indexer/indexer_manager/constants_test.go index 3408ac7b9a..359535c566 100644 --- a/protocol/indexer/indexer_manager/constants_test.go +++ b/protocol/indexer/indexer_manager/constants_test.go @@ -25,29 +25,29 @@ var BlockTime = time.Unix(1650000000, 0).UTC() var OrderFillTendermintEvent = indexer_manager.IndexerTendermintEvent{ Subtype: indexerevents.SubtypeOrderFill, - Data: Data3, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{ TransactionIndex: 0, }, EventIndex: 0, + DataBytes: []byte(Data3), } var TransferTendermintEvent = indexer_manager.IndexerTendermintEvent{ Subtype: indexerevents.SubtypeTransfer, - Data: Data, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{ TransactionIndex: 0, }, EventIndex: 1, + DataBytes: []byte(Data), } var SubaccountTendermintEvent = indexer_manager.IndexerTendermintEvent{ Subtype: indexerevents.SubtypeSubaccountUpdate, - Data: Data2, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{ TransactionIndex: 1, }, EventIndex: 0, + DataBytes: []byte(Data2), } var makerOrder = v1.OrderToIndexerOrder(constants.Order_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB15) diff --git a/protocol/indexer/indexer_manager/event.pb.go b/protocol/indexer/indexer_manager/event.pb.go index 1a0f0d0c82..9dfba5da9e 100644 --- a/protocol/indexer/indexer_manager/event.pb.go +++ b/protocol/indexer/indexer_manager/event.pb.go @@ -167,9 +167,6 @@ func (m *IndexerEventsStoreValue) GetEvents() []*IndexerTendermintEventWrapper { type IndexerTendermintEvent struct { // Subtype of the event e.g. "order_fill", "subaccount_update", etc. Subtype string `protobuf:"bytes,1,opt,name=subtype,proto3" json:"subtype,omitempty"` - // Base64 encoded proto from the Tendermint event. - // TODO(DEC-1720): Change to bytes post-migration. - Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` // ordering_within_block is either the transaction index or a boolean // indicating the event was generated during processing the block rather than // any specific transaction e.g. during FinalizeBlock. @@ -252,13 +249,6 @@ func (m *IndexerTendermintEvent) GetSubtype() string { return "" } -func (m *IndexerTendermintEvent) GetData() string { - if m != nil { - return m.Data - } - return "" -} - func (m *IndexerTendermintEvent) GetTransactionIndex() uint32 { if x, ok := m.GetOrderingWithinBlock().(*IndexerTendermintEvent_TransactionIndex); ok { return x.TransactionIndex @@ -387,45 +377,45 @@ func init() { } var fileDescriptor_18a6a94c31da6b1f = []byte{ - // 597 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcd, 0x6e, 0xd3, 0x4c, - 0x14, 0xf5, 0x34, 0x69, 0xd2, 0xdc, 0x7c, 0xfd, 0x54, 0x46, 0xb4, 0x75, 0x5b, 0x35, 0xb1, 0x22, - 0x16, 0xde, 0xd4, 0x46, 0x81, 0x05, 0x0b, 0x36, 0xb8, 0x35, 0x4d, 0x04, 0x0a, 0x68, 0x1a, 0x8a, - 0x44, 0x17, 0xd6, 0x38, 0x19, 0x6c, 0x43, 0x32, 0x13, 0xd9, 0x93, 0xe0, 0xbe, 0x04, 0xea, 0xdb, - 0xf0, 0x0a, 0x5d, 0x76, 0xc9, 0x86, 0x1f, 0xb5, 0x2f, 0x82, 0x3c, 0x76, 0x4a, 0xa9, 0x2a, 0x81, - 0x94, 0x95, 0xef, 0xef, 0xb9, 0xe7, 0x7a, 0xe6, 0x0c, 0x3c, 0x1c, 0x9e, 0x0e, 0xd3, 0x49, 0x2c, - 0xa4, 0x18, 0x88, 0x91, 0x1d, 0xf1, 0x21, 0x4b, 0x59, 0x3c, 0xff, 0x7a, 0x63, 0xca, 0x69, 0xc0, - 0x62, 0x9b, 0xcd, 0x18, 0x97, 0x96, 0x2a, 0xc3, 0x0f, 0x6e, 0x76, 0x58, 0x45, 0xa5, 0x75, 0xab, - 0x63, 0xbb, 0x19, 0x08, 0x11, 0x8c, 0x98, 0xad, 0x0a, 0xfd, 0xe9, 0x7b, 0x5b, 0x46, 0x63, 0x96, - 0x48, 0x3a, 0x9e, 0xe4, 0x30, 0xdb, 0xf7, 0x03, 0x11, 0x08, 0x65, 0xda, 0x99, 0x95, 0x47, 0x5b, - 0x9f, 0x11, 0xec, 0x76, 0x73, 0xa8, 0x3e, 0xe3, 0x43, 0x16, 0x8f, 0x23, 0x2e, 0xdd, 0x6c, 0xfa, - 0xdb, 0x98, 0x4e, 0x26, 0x2c, 0xc6, 0x04, 0x96, 0x15, 0x1b, 0x1d, 0x19, 0xc8, 0xac, 0xb7, 0x9f, - 0x5a, 0xff, 0x42, 0xc7, 0xba, 0x1b, 0x93, 0xe4, 0x50, 0x78, 0x0b, 0x56, 0x64, 0xca, 0xbd, 0x90, - 0x26, 0xa1, 0xbe, 0x64, 0x20, 0xb3, 0x46, 0xaa, 0x32, 0xe5, 0x1d, 0x9a, 0x84, 0xad, 0x19, 0x6c, - 0x16, 0xbd, 0xaa, 0x23, 0x39, 0x92, 0x22, 0x66, 0xc7, 0x74, 0x34, 0x65, 0xf8, 0x04, 0x2a, 0xaa, - 0x3d, 0xd1, 0x91, 0x51, 0x32, 0xeb, 0xed, 0xfd, 0x45, 0xa8, 0x14, 0xeb, 0x91, 0x02, 0xb2, 0xf5, - 0xa5, 0x04, 0x1b, 0x77, 0x57, 0x62, 0x1d, 0xaa, 0xc9, 0xd4, 0x97, 0xa7, 0x13, 0xa6, 0xfe, 0x41, - 0x8d, 0xcc, 0x5d, 0x8c, 0xa1, 0x3c, 0xa4, 0x92, 0x16, 0x3b, 0x28, 0x1b, 0xef, 0xc1, 0x3d, 0x19, - 0x53, 0x9e, 0xd0, 0x81, 0x8c, 0x04, 0xf7, 0x14, 0x1b, 0xbd, 0x64, 0x20, 0x73, 0xb5, 0xa3, 0x91, - 0xb5, 0x1b, 0x29, 0x35, 0x0d, 0x7f, 0x80, 0xba, 0x3f, 0x12, 0x83, 0x8f, 0x5e, 0xfe, 0x93, 0xcb, - 0x06, 0x32, 0xff, 0x6f, 0x1f, 0x2e, 0xb2, 0x99, 0xe5, 0x64, 0x78, 0xca, 0xec, 0x68, 0x04, 0xfc, - 0x6b, 0x0f, 0x37, 0xa1, 0xae, 0xa6, 0x14, 0xa4, 0x96, 0x33, 0x52, 0x04, 0x54, 0x28, 0x27, 0xa3, - 0x43, 0x75, 0xc6, 0xe2, 0x24, 0x12, 0x5c, 0xaf, 0xa8, 0xe4, 0xdc, 0xc5, 0xbb, 0x00, 0xd9, 0x76, - 0x9e, 0x7f, 0x2a, 0x59, 0xa2, 0x57, 0x0d, 0x64, 0xfe, 0x47, 0x6a, 0x59, 0xc4, 0xc9, 0x02, 0x2d, - 0x0a, 0xf0, 0x7b, 0x2a, 0xde, 0x81, 0x4d, 0xe7, 0xe5, 0xab, 0xfd, 0x17, 0x9e, 0x7b, 0xec, 0xf6, - 0xfa, 0xde, 0x9b, 0xde, 0xd1, 0x6b, 0x77, 0xbf, 0xfb, 0xbc, 0xeb, 0x1e, 0xac, 0x69, 0xb7, 0x93, - 0x8e, 0x7b, 0xd8, 0xed, 0x79, 0x2a, 0xb2, 0x86, 0xf0, 0x16, 0xac, 0xdf, 0x4c, 0xba, 0xbd, 0x83, - 0x22, 0xb5, 0xe4, 0x6c, 0xc2, 0xba, 0x88, 0x87, 0x2c, 0x8e, 0x78, 0xe0, 0x7d, 0x8a, 0x64, 0x18, - 0x71, 0x4f, 0xad, 0xd6, 0xfa, 0x86, 0xee, 0x38, 0x39, 0xc5, 0x06, 0x6f, 0x40, 0x25, 0x64, 0x51, - 0x10, 0xe6, 0x97, 0x77, 0x95, 0x14, 0x1e, 0x7e, 0x02, 0xe5, 0x4c, 0x1e, 0xea, 0xdc, 0xea, 0xed, - 0x6d, 0x2b, 0xd7, 0x8e, 0x35, 0xd7, 0x8e, 0xd5, 0x9f, 0x6b, 0xc7, 0x59, 0x39, 0xff, 0xde, 0xd4, - 0xce, 0x7e, 0x34, 0x11, 0x51, 0x1d, 0xb8, 0x7f, 0x7d, 0x07, 0x4b, 0xea, 0x0e, 0x2e, 0x26, 0x87, - 0x02, 0x0b, 0xef, 0x40, 0x4d, 0xa6, 0x4a, 0x0e, 0x2c, 0xd1, 0xcb, 0x46, 0xc9, 0xac, 0x91, 0x15, - 0x99, 0x76, 0x94, 0xef, 0x9c, 0x9c, 0x5f, 0x36, 0xd0, 0xc5, 0x65, 0x03, 0xfd, 0xbc, 0x6c, 0xa0, - 0xb3, 0xab, 0x86, 0x76, 0x71, 0xd5, 0xd0, 0xbe, 0x5e, 0x35, 0xb4, 0x77, 0xcf, 0x82, 0x48, 0x86, - 0x53, 0xdf, 0x1a, 0x88, 0xb1, 0xfd, 0xc7, 0xb3, 0x32, 0x7b, 0xbc, 0x37, 0x08, 0x69, 0xc4, 0xed, - 0xbf, 0x3d, 0x34, 0x7e, 0x45, 0x55, 0x3c, 0xfa, 0x15, 0x00, 0x00, 0xff, 0xff, 0x59, 0xcc, 0xe8, - 0x07, 0x97, 0x04, 0x00, 0x00, + // 594 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcb, 0x6e, 0xd3, 0x40, + 0x14, 0xf5, 0x34, 0x69, 0x1e, 0x37, 0x14, 0x85, 0x11, 0x6d, 0xdd, 0x56, 0x4d, 0xac, 0x88, 0x85, + 0x37, 0xb5, 0x51, 0x60, 0xc1, 0x82, 0x0d, 0x6e, 0x4d, 0x13, 0x40, 0x01, 0x4d, 0x43, 0x91, 0xe8, + 0xc2, 0x1a, 0x27, 0x83, 0x6d, 0x48, 0x66, 0x22, 0x7b, 0x12, 0xd2, 0x9f, 0x40, 0xfd, 0x0d, 0xfe, + 0xa4, 0xcb, 0x2e, 0xd9, 0xf0, 0x50, 0xfb, 0x23, 0xc8, 0x63, 0xa7, 0x94, 0xaa, 0x12, 0x48, 0x5d, + 0x79, 0xee, 0xeb, 0xdc, 0x73, 0xc7, 0xf7, 0x0c, 0x3c, 0x1c, 0x1e, 0x0f, 0xe7, 0x93, 0x58, 0x48, + 0x31, 0x10, 0x23, 0x3b, 0xe2, 0x43, 0x36, 0x67, 0xf1, 0xe2, 0xeb, 0x8d, 0x29, 0xa7, 0x01, 0x8b, + 0x6d, 0x36, 0x63, 0x5c, 0x5a, 0x2a, 0x0d, 0x3f, 0xb8, 0x5a, 0x61, 0xe5, 0x99, 0xd6, 0xb5, 0x8a, + 0xcd, 0x66, 0x20, 0x44, 0x30, 0x62, 0xb6, 0x4a, 0xf4, 0xa7, 0x1f, 0x6c, 0x19, 0x8d, 0x59, 0x22, + 0xe9, 0x78, 0x92, 0xc1, 0x6c, 0xde, 0x0f, 0x44, 0x20, 0xd4, 0xd1, 0x4e, 0x4f, 0x99, 0xb7, 0xf5, + 0x05, 0xc1, 0x76, 0x37, 0x83, 0xea, 0x33, 0x3e, 0x64, 0xf1, 0x38, 0xe2, 0xd2, 0x4d, 0xbb, 0xbf, + 0x8b, 0xe9, 0x64, 0xc2, 0x62, 0x4c, 0x60, 0x59, 0xb1, 0xd1, 0x91, 0x81, 0xcc, 0x5a, 0xfb, 0xa9, + 0xf5, 0x3f, 0x74, 0xac, 0x9b, 0x31, 0x49, 0x06, 0x85, 0x37, 0xa0, 0x22, 0xe7, 0xdc, 0x0b, 0x69, + 0x12, 0xea, 0x4b, 0x06, 0x32, 0xab, 0xa4, 0x2c, 0xe7, 0xbc, 0x43, 0x93, 0xb0, 0x35, 0x83, 0xf5, + 0xbc, 0x56, 0x55, 0x24, 0x07, 0x52, 0xc4, 0xec, 0x90, 0x8e, 0xa6, 0x0c, 0x1f, 0x41, 0x49, 0x95, + 0x27, 0x3a, 0x32, 0x0a, 0x66, 0xad, 0xbd, 0x7b, 0x1b, 0x2a, 0xf9, 0x78, 0x24, 0x87, 0x6c, 0x7d, + 0x2d, 0xc0, 0xda, 0xcd, 0x99, 0x58, 0x87, 0x72, 0x32, 0xf5, 0xe5, 0xf1, 0x84, 0xa9, 0x3b, 0xa8, + 0x92, 0x85, 0x89, 0x77, 0xe0, 0x9e, 0x8c, 0x29, 0x4f, 0xe8, 0x40, 0x46, 0x82, 0x7b, 0xaa, 0xb3, + 0x5e, 0x30, 0x90, 0xb9, 0xd2, 0xd1, 0x48, 0xfd, 0x4a, 0x48, 0x21, 0xe3, 0x8f, 0x50, 0xf3, 0x47, + 0x62, 0xf0, 0xc9, 0xcb, 0x2e, 0xb4, 0x68, 0x20, 0xf3, 0x6e, 0x7b, 0xff, 0x36, 0x53, 0x58, 0x4e, + 0x8a, 0xa7, 0x8e, 0x1d, 0x8d, 0x80, 0x7f, 0x69, 0xe1, 0x26, 0xd4, 0x54, 0x97, 0x9c, 0xd4, 0x72, + 0x4a, 0x8a, 0x80, 0x72, 0x65, 0x64, 0x74, 0x28, 0xcf, 0x58, 0x9c, 0x44, 0x82, 0xeb, 0x25, 0x15, + 0x5c, 0x98, 0x78, 0x1b, 0x60, 0x48, 0x25, 0xf5, 0xfc, 0x63, 0xc9, 0x12, 0xbd, 0x6c, 0x20, 0xf3, + 0x0e, 0xa9, 0xa6, 0x1e, 0x27, 0x75, 0xb4, 0x28, 0xc0, 0x9f, 0xae, 0x78, 0x0b, 0xd6, 0x9d, 0x57, + 0xaf, 0x77, 0x5f, 0x7a, 0xee, 0xa1, 0xdb, 0xeb, 0x7b, 0x6f, 0x7b, 0x07, 0x6f, 0xdc, 0xdd, 0xee, + 0xf3, 0xae, 0xbb, 0x57, 0xd7, 0xae, 0x07, 0x1d, 0x77, 0xbf, 0xdb, 0xf3, 0x94, 0xa7, 0x8e, 0xf0, + 0x06, 0xac, 0x5e, 0x0d, 0xba, 0xbd, 0xbd, 0x3c, 0xb4, 0xe4, 0xac, 0xc3, 0xaa, 0x88, 0x87, 0x2c, + 0x8e, 0x78, 0xe0, 0x7d, 0x8e, 0x64, 0x18, 0x71, 0x4f, 0x8d, 0xf6, 0xa2, 0x58, 0x59, 0xaa, 0x17, + 0x5a, 0xdf, 0xd1, 0x0d, 0xff, 0x4a, 0x71, 0xc2, 0x6b, 0x50, 0x0a, 0x59, 0x14, 0x84, 0xd9, 0xba, + 0xae, 0x90, 0xdc, 0xc2, 0x4f, 0xa0, 0x98, 0x0a, 0x42, 0x6d, 0x5b, 0xad, 0xbd, 0x69, 0x65, 0x6a, + 0xb1, 0x16, 0x6a, 0xb1, 0xfa, 0x0b, 0xb5, 0x38, 0x95, 0xd3, 0x1f, 0x4d, 0xed, 0xe4, 0x67, 0x13, + 0x11, 0x55, 0x81, 0xfb, 0x97, 0x5b, 0x57, 0x50, 0x5b, 0x77, 0x3b, 0x01, 0xe4, 0x58, 0x78, 0x0b, + 0xaa, 0x72, 0xae, 0x04, 0xc0, 0x12, 0xbd, 0x68, 0x14, 0xcc, 0x2a, 0xa9, 0xc8, 0x79, 0x47, 0xd9, + 0xce, 0xd1, 0xe9, 0x79, 0x03, 0x9d, 0x9d, 0x37, 0xd0, 0xaf, 0xf3, 0x06, 0x3a, 0xb9, 0x68, 0x68, + 0x67, 0x17, 0x0d, 0xed, 0xdb, 0x45, 0x43, 0x7b, 0xff, 0x2c, 0x88, 0x64, 0x38, 0xf5, 0xad, 0x81, + 0x18, 0xdb, 0x7f, 0x3d, 0x24, 0xb3, 0xc7, 0x3b, 0x83, 0x90, 0x46, 0xdc, 0xfe, 0xd7, 0xd3, 0xe2, + 0x97, 0x54, 0xc6, 0xa3, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x09, 0xb2, 0x5f, 0x0d, 0x89, 0x04, + 0x00, 0x00, } func (m *IndexerTendermintEventWrapper) Marshal() (dAtA []byte, err error) { @@ -553,13 +543,6 @@ func (m *IndexerTendermintEvent) MarshalToSizedBuffer(dAtA []byte) (int, error) } } } - if len(m.Data) > 0 { - i -= len(m.Data) - copy(dAtA[i:], m.Data) - i = encodeVarintEvent(dAtA, i, uint64(len(m.Data))) - i-- - dAtA[i] = 0x12 - } if len(m.Subtype) > 0 { i -= len(m.Subtype) copy(dAtA[i:], m.Subtype) @@ -706,10 +689,6 @@ func (m *IndexerTendermintEvent) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - l = len(m.Data) - if l > 0 { - n += 1 + l + sovEvent(uint64(l)) - } if m.OrderingWithinBlock != nil { n += m.OrderingWithinBlock.Size() } @@ -1039,38 +1018,6 @@ func (m *IndexerTendermintEvent) Unmarshal(dAtA []byte) error { } m.Subtype = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowEvent - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthEvent - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthEvent - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex case 3: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field TransactionIndex", wireType) diff --git a/protocol/indexer/indexer_manager/event_manager.go b/protocol/indexer/indexer_manager/event_manager.go index 5238e96b45..5f540037c4 100644 --- a/protocol/indexer/indexer_manager/event_manager.go +++ b/protocol/indexer/indexer_manager/event_manager.go @@ -8,14 +8,13 @@ import ( type IndexerEventManager interface { Enabled() bool - AddTxnEvent(ctx sdk.Context, subType string, data string, version uint32, dataByes []byte) + AddTxnEvent(ctx sdk.Context, subType string, version uint32, dataByes []byte) SendOffchainData(message msgsender.Message) SendOnchainData(block *IndexerTendermintBlock) ProduceBlock(ctx sdk.Context) *IndexerTendermintBlock AddBlockEvent( ctx sdk.Context, subType string, - data string, blockEvent IndexerTendermintEvent_BlockEvent, version uint32, dataBytes []byte, @@ -69,12 +68,11 @@ func (i *indexerEventManagerImpl) SendOnchainData(block *IndexerTendermintBlock) func (i *indexerEventManagerImpl) AddTxnEvent( ctx sdk.Context, subType string, - data string, version uint32, dataBytes []byte, ) { if i.indexerMessageSender.Enabled() { - addTxnEvent(ctx, subType, data, version, i.indexerEventsTransientStoreKey, dataBytes) + addTxnEvent(ctx, subType, version, i.indexerEventsTransientStoreKey, dataBytes) } } @@ -91,13 +89,12 @@ func (i *indexerEventManagerImpl) ClearEvents( func (i *indexerEventManagerImpl) AddBlockEvent( ctx sdk.Context, subType string, - data string, blockEvent IndexerTendermintEvent_BlockEvent, version uint32, dataBytes []byte, ) { if i.indexerMessageSender.Enabled() { - addBlockEvent(ctx, subType, data, i.indexerEventsTransientStoreKey, blockEvent, version, dataBytes) + addBlockEvent(ctx, subType, i.indexerEventsTransientStoreKey, blockEvent, version, dataBytes) } } diff --git a/protocol/indexer/indexer_manager/event_manager_test.go b/protocol/indexer/indexer_manager/event_manager_test.go index 8fff25a6ce..9c2dc1b2da 100644 --- a/protocol/indexer/indexer_manager/event_manager_test.go +++ b/protocol/indexer/indexer_manager/event_manager_test.go @@ -17,9 +17,6 @@ import ( var ExpectedEvent0 = indexer_manager.IndexerTendermintEvent{ Subtype: indexerevents.SubtypeOrderFill, - Data: indexer_manager.GetB64EncodedEventMessage( - &OrderFillEvent, - ), OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{ TransactionIndex: 0, }, @@ -32,9 +29,6 @@ var ExpectedEvent0 = indexer_manager.IndexerTendermintEvent{ var ExpectedEvent1 = indexer_manager.IndexerTendermintEvent{ Subtype: indexerevents.SubtypeSubaccountUpdate, - Data: indexer_manager.GetB64EncodedEventMessage( - &SubaccountEvent, - ), OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{ TransactionIndex: 0, }, @@ -47,9 +41,6 @@ var ExpectedEvent1 = indexer_manager.IndexerTendermintEvent{ var ExpectedEvent2 = indexer_manager.IndexerTendermintEvent{ Subtype: indexerevents.SubtypeTransfer, - Data: indexer_manager.GetB64EncodedEventMessage( - &TransferEvent, - ), OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{ TransactionIndex: 1, }, @@ -62,9 +53,6 @@ var ExpectedEvent2 = indexer_manager.IndexerTendermintEvent{ var ExpectedEvent3 = indexer_manager.IndexerTendermintEvent{ Subtype: indexerevents.SubtypeFundingValues, - Data: indexer_manager.GetB64EncodedEventMessage( - &FundingRateAndIndexEvent, - ), OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_BlockEvent_{ BlockEvent: indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK, }, @@ -77,9 +65,6 @@ var ExpectedEvent3 = indexer_manager.IndexerTendermintEvent{ var ExpectedEvent4 = indexer_manager.IndexerTendermintEvent{ Subtype: indexerevents.SubtypeFundingValues, - Data: indexer_manager.GetB64EncodedEventMessage( - &FundingPremiumSampleEvent, - ), OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_BlockEvent_{ BlockEvent: indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK, }, @@ -92,9 +77,6 @@ var ExpectedEvent4 = indexer_manager.IndexerTendermintEvent{ var ExpectedEvent5 = indexer_manager.IndexerTendermintEvent{ Subtype: indexerevents.SubtypeFundingValues, - Data: indexer_manager.GetB64EncodedEventMessage( - &FundingPremiumSampleEvent, - ), OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_BlockEvent_{ BlockEvent: indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_BEGIN_BLOCK, }, @@ -107,9 +89,6 @@ var ExpectedEvent5 = indexer_manager.IndexerTendermintEvent{ var ExpectedEvent6 = indexer_manager.IndexerTendermintEvent{ Subtype: indexerevents.SubtypeFundingValues, - Data: indexer_manager.GetB64EncodedEventMessage( - &FundingRateAndIndexEvent, - ), OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_BlockEvent_{ BlockEvent: indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_BEGIN_BLOCK, }, @@ -170,9 +149,6 @@ func TestProduceBlockBasicTxnEvent(t *testing.T) { indexerEventManager.AddTxnEvent( ctx, indexerevents.SubtypeOrderFill, - indexer_manager.GetB64EncodedEventMessage( - &OrderFillEvent, - ), EventVersion, indexer_manager.GetBytes( &OrderFillEvent, @@ -201,9 +177,6 @@ func TestProduceBlockBasicBlockEvent(t *testing.T) { indexerEventManager.AddBlockEvent( ctx, indexerevents.SubtypeFundingValues, - indexer_manager.GetB64EncodedEventMessage( - &FundingRateAndIndexEvent, - ), indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK, EventVersion, indexer_manager.GetBytes( @@ -233,9 +206,6 @@ func TestProduceBlockMultipleTxnEvents(t *testing.T) { indexerEventManager.AddTxnEvent( ctx, indexerevents.SubtypeOrderFill, - indexer_manager.GetB64EncodedEventMessage( - &OrderFillEvent, - ), EventVersion, indexer_manager.GetBytes( &OrderFillEvent, @@ -244,9 +214,6 @@ func TestProduceBlockMultipleTxnEvents(t *testing.T) { indexerEventManager.AddTxnEvent( ctx, indexerevents.SubtypeSubaccountUpdate, - indexer_manager.GetB64EncodedEventMessage( - &SubaccountEvent, - ), EventVersion, indexer_manager.GetBytes( &SubaccountEvent, @@ -256,9 +223,6 @@ func TestProduceBlockMultipleTxnEvents(t *testing.T) { indexerEventManager.AddTxnEvent( ctx, indexerevents.SubtypeTransfer, - indexer_manager.GetB64EncodedEventMessage( - &TransferEvent, - ), EventVersion, indexer_manager.GetBytes( &TransferEvent, @@ -292,9 +256,6 @@ func TestProduceBlockMultipleTxnAndBlockEvents(t *testing.T) { indexerEventManager.AddTxnEvent( ctx, indexerevents.SubtypeOrderFill, - indexer_manager.GetB64EncodedEventMessage( - &OrderFillEvent, - ), EventVersion, indexer_manager.GetBytes( &OrderFillEvent, @@ -303,9 +264,6 @@ func TestProduceBlockMultipleTxnAndBlockEvents(t *testing.T) { indexerEventManager.AddTxnEvent( ctx, indexerevents.SubtypeSubaccountUpdate, - indexer_manager.GetB64EncodedEventMessage( - &SubaccountEvent, - ), EventVersion, indexer_manager.GetBytes( &SubaccountEvent, @@ -315,9 +273,6 @@ func TestProduceBlockMultipleTxnAndBlockEvents(t *testing.T) { indexerEventManager.AddTxnEvent( ctx, indexerevents.SubtypeTransfer, - indexer_manager.GetB64EncodedEventMessage( - &TransferEvent, - ), EventVersion, indexer_manager.GetBytes( &TransferEvent, @@ -326,9 +281,6 @@ func TestProduceBlockMultipleTxnAndBlockEvents(t *testing.T) { indexerEventManager.AddBlockEvent( ctx, indexerevents.SubtypeFundingValues, - indexer_manager.GetB64EncodedEventMessage( - &FundingRateAndIndexEvent, - ), indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK, EventVersion, indexer_manager.GetBytes( @@ -338,9 +290,6 @@ func TestProduceBlockMultipleTxnAndBlockEvents(t *testing.T) { indexerEventManager.AddBlockEvent( ctx, indexerevents.SubtypeFundingValues, - indexer_manager.GetB64EncodedEventMessage( - &FundingPremiumSampleEvent, - ), indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK, EventVersion, indexer_manager.GetBytes( @@ -350,9 +299,6 @@ func TestProduceBlockMultipleTxnAndBlockEvents(t *testing.T) { indexerEventManager.AddBlockEvent( ctx, indexerevents.SubtypeFundingValues, - indexer_manager.GetB64EncodedEventMessage( - &FundingPremiumSampleEvent, - ), indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_BEGIN_BLOCK, EventVersion, indexer_manager.GetBytes( @@ -362,9 +308,6 @@ func TestProduceBlockMultipleTxnAndBlockEvents(t *testing.T) { indexerEventManager.AddBlockEvent( ctx, indexerevents.SubtypeFundingValues, - indexer_manager.GetB64EncodedEventMessage( - &FundingRateAndIndexEvent, - ), indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_BEGIN_BLOCK, EventVersion, indexer_manager.GetBytes( @@ -403,9 +346,6 @@ func TestClearEvents(t *testing.T) { indexerEventManager.AddTxnEvent( ctx, indexerevents.SubtypeOrderFill, - indexer_manager.GetB64EncodedEventMessage( - &OrderFillEvent, - ), EventVersion, indexer_manager.GetBytes( &OrderFillEvent, diff --git a/protocol/indexer/indexer_manager/events.go b/protocol/indexer/indexer_manager/events.go index a33fcaa1c8..5d42769d1e 100644 --- a/protocol/indexer/indexer_manager/events.go +++ b/protocol/indexer/indexer_manager/events.go @@ -1,8 +1,6 @@ package indexer_manager import ( - "encoding/base64" - storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -42,21 +40,6 @@ func getIndexerEvents(ctx sdk.Context, storeKey storetypes.StoreKey) []*IndexerT return events.Events } -// GetB64EncodedEventMessage returns the base64 encoded event message. -// TODO(DEC-1720): Deprecate this function once we change the underlying proto to use bytes. -func GetB64EncodedEventMessage( - eventMessage proto.Message, -) string { - marshaler := &common.MarshalerImpl{} - eventMessageBytes, err := marshaler.Marshal(eventMessage) - if err != nil { - panic(err) - } - - b64encodedEventMessage := base64.StdEncoding.EncodeToString(eventMessageBytes) - return b64encodedEventMessage -} - // GetBytes returns the marshaled bytes of the event message. func GetBytes( eventMessage proto.Message, @@ -69,22 +52,10 @@ func GetBytes( return eventMessageBytes } -// GetBytesFromEventData returns the decoded bytes of the base64 event data string. -func GetBytesFromEventData( - event string, -) []byte { - bytes, err := base64.StdEncoding.DecodeString(event) - if err != nil { - panic(err) - } - return bytes -} - // addTxnEvent adds a transaction event to the context's transient store of indexer events. func addTxnEvent( ctx sdk.Context, subType string, - data string, version uint32, storeKey storetypes.StoreKey, dataBytes []byte, @@ -92,7 +63,6 @@ func addTxnEvent( event := IndexerTendermintEventWrapper{ Event: &IndexerTendermintEvent{ Subtype: subType, - Data: data, Version: version, OrderingWithinBlock: &IndexerTendermintEvent_TransactionIndex{}, DataBytes: dataBytes, @@ -106,7 +76,6 @@ func addTxnEvent( func addBlockEvent( ctx sdk.Context, subType string, - data string, storeKey storetypes.StoreKey, blockEvent IndexerTendermintEvent_BlockEvent, version uint32, @@ -115,7 +84,6 @@ func addBlockEvent( event := IndexerTendermintEventWrapper{ Event: &IndexerTendermintEvent{ Subtype: subType, - Data: data, Version: version, OrderingWithinBlock: &IndexerTendermintEvent_BlockEvent_{ BlockEvent: blockEvent, diff --git a/protocol/lib/error/logging.go b/protocol/lib/error/logging.go index 4f054cecb2..1c2ab1a102 100644 --- a/protocol/lib/error/logging.go +++ b/protocol/lib/error/logging.go @@ -5,8 +5,9 @@ import ( "fmt" "github.com/cometbft/cometbft/libs/log" + "github.com/dydxprotocol/v4-chain/protocol/lib/metrics" - errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" ) const ( @@ -40,16 +41,16 @@ func WrapErrorWithSourceModuleContext(err error, module string) error { WithLogKeyValue(SourceModuleKey, fmt.Sprintf("x/%v", module)) } -// LogErrorWithBlockHeight logs an error, appending the block height and ABCI callback to the error message. -func LogErrorWithBlockHeight(logger log.Logger, err error, blockHeight int64, callback string) { +// LogDeliverTxError logs an error, appending the block height and ABCI callback to the error message. +func LogDeliverTxError(logger log.Logger, err error, blockHeight int64, handler string, msg sdk.Msg) { if err != nil { - err = errorsmod.Wrapf( - err, - "Block height: %d, Callback: %s", - blockHeight, - callback, + logger.Error( + err.Error(), + metrics.BlockHeight, blockHeight, + metrics.Handler, handler, + metrics.Callback, metrics.DeliverTx, + metrics.Msg, msg, ) - logger.Error(err.Error()) } else { logger.Error("LogErrorWithBlockHeight called with nil error") } diff --git a/protocol/lib/error/logging_test.go b/protocol/lib/error/logging_test.go index 2a579d1e5e..c832cfef66 100644 --- a/protocol/lib/error/logging_test.go +++ b/protocol/lib/error/logging_test.go @@ -6,6 +6,8 @@ import ( liberror "github.com/dydxprotocol/v4-chain/protocol/lib/error" "github.com/dydxprotocol/v4-chain/protocol/mocks" + "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" + "github.com/stretchr/testify/mock" ) func TestWrapErrorWithSourceModuleContext_ErrorWithLogContext(t *testing.T) { @@ -35,25 +37,32 @@ func TestLogErrorWithOptionalContext_PlainError(t *testing.T) { logger.AssertExpectations(t) } -func TestLogErrorWithBlockHeight(t *testing.T) { +func TestLogDeliverTxError(t *testing.T) { logger := &mocks.Logger{} err := fmt.Errorf("test error") // Expect that the block height will be appended to the error message. - logger.On("Error", "Block height: 123, Callback: foobar: test error").Return() + logger.On( + "Error", + []interface{}{ + "test error", + mock.Anything, mock.Anything, mock.Anything, mock.Anything, + mock.Anything, mock.Anything, mock.Anything, mock.Anything, + }..., + ).Return() - liberror.LogErrorWithBlockHeight(logger, err, 123, "foobar") + liberror.LogDeliverTxError(logger, err, 123, "foobar", &types.MsgCancelOrder{}) logger.AssertExpectations(t) } -func TestLogErrorWithBlockHeight_NilError(t *testing.T) { +func TestLogDeliverTxError_NilError(t *testing.T) { logger := &mocks.Logger{} // Expect that the block height will be appended to the error message. logger.On("Error", "LogErrorWithBlockHeight called with nil error").Return() - liberror.LogErrorWithBlockHeight(logger, nil, 123, "foobar") + liberror.LogDeliverTxError(logger, nil, 123, "foobar", &types.MsgCancelOrder{}) logger.AssertExpectations(t) } diff --git a/protocol/lib/metrics/constants.go b/protocol/lib/metrics/constants.go index de01e6d949..cd59441af5 100644 --- a/protocol/lib/metrics/constants.go +++ b/protocol/lib/metrics/constants.go @@ -20,6 +20,7 @@ const ( Latency = "latency" Matched = "matched" MessageType = "message_type" + Msg = "msg" Negative = "negative" No = "no" NonDeterministic = "non_deterministic" @@ -33,6 +34,7 @@ const ( ValidateBasic = "validate_basic" Yes = "yes" CheckTx = "check_tx" + ReCheckTx = "recheck_tx" DeliverTx = "deliver_tx" ProcessProposal = "process_proposal" @@ -101,6 +103,7 @@ const ( ConditionalOrderTriggered = "conditional_order_triggered" ConditionalOrderUntriggered = "conditional_order_untriggered" ConvertToUpdates = "convert_to_updates" + CreateClobPair = "create_clob_pair" Expired = "expired" GetFillQuoteQuantums = "get_fill_quote_quantums" Hydrate = "hydrate" @@ -131,8 +134,10 @@ const ( PlaceOrder = "place_order" PlaceOrderAccounts = "place_order_accounts" PlaceOrderSubaccounts = "place_order_subaccounts" + PlaceStatefulOrder = "place_stateful_order" ProcessMatches = "process_matches" ProcessOperations = "process_operations" + ProposedOperations = "proposed_operations" Proposer = "proposer" RateLimit = "rate_limit" ReduceOnly = "reduce_only" @@ -161,6 +166,10 @@ const ( UnfilledLiquidationOrders = "unfilled_liquidation_orders" UnknownPlaceOrders = "unknown_place_orders" UnverifiedStatefulOrderRemoval = "unverified_stateful_order_removal" + UpdateBlockRateLimitConfiguration = "update_block_rate_limit_configuration" + UpdateClobPair = "update_clob_pair" + UpdateEquityTierLimitConfiguration = "update_equity_tier_limit_configuration" + UpdateLiquidationsConfig = "update_liquidations_config" ValidateMatches = "validate_matches" ValidateOrder = "validate_order" diff --git a/protocol/lib/metrics/util.go b/protocol/lib/metrics/util.go index 0208b48447..27f0ebced4 100644 --- a/protocol/lib/metrics/util.go +++ b/protocol/lib/metrics/util.go @@ -5,6 +5,8 @@ import ( "strconv" "time" + sdk "github.com/cosmos/cosmos-sdk/types" + gometrics "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" ) @@ -18,6 +20,32 @@ func IncrCountMetricWithLabels(module string, metric string, labels ...gometrics ) } +// IncrSuccessOrErrorCounter increments either the success or error counter for a given handler +// based on whether the given error is nil or not. This function is intended to be called in a +// defer block at the top of any function which returns an error. +func IncrSuccessOrErrorCounter(err error, module string, handler string, callback string, labels ...gometrics.Label) { + successOrError := Success + if err != nil { + successOrError = Error + } + + telemetry.IncrCounterWithLabels( + []string{ + module, + handler, + successOrError, + Count, + }, + 1, + append( + []gometrics.Label{ + GetLabelForStringValue(Callback, callback), + }, + labels..., + ), + ) +} + // NewBinaryStringLabel returns a metrics label with a value of "yes" or "no" depending on the condition. func NewBinaryStringLabel(metricName string, condition bool) gometrics.Label { labelValue := No @@ -67,3 +95,17 @@ func ModuleMeasureSinceWithLabels( ), ) } + +// 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. +func GetCallbackMetricFromCtx(ctx sdk.Context) string { + if ctx.IsReCheckTx() { + return ReCheckTx + } + if ctx.IsCheckTx() { + return CheckTx + } + + return DeliverTx +} diff --git a/protocol/lib/metrics/util_test.go b/protocol/lib/metrics/util_test.go index 9f1e404aa9..956a7208cc 100644 --- a/protocol/lib/metrics/util_test.go +++ b/protocol/lib/metrics/util_test.go @@ -1,13 +1,15 @@ package metrics_test import ( - gometrics "github.com/armon/go-metrics" - "github.com/dydxprotocol/v4-chain/protocol/lib/metrics" "math" "math/big" "testing" "time" + gometrics "github.com/armon/go-metrics" + "github.com/dydxprotocol/v4-chain/protocol/lib/metrics" + big_testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/big" + "github.com/stretchr/testify/require" ) @@ -205,6 +207,10 @@ func TestGetMetricValueFromBigInt(t *testing.T) { input: new(big.Int).SetUint64(math.MaxUint64), expected: float32(1.8446744e+19), }, + "overflow: 1234567 * 1e24": { + input: big_testutil.Int64MulPow10(1234567, 24), // 1234567 * 1e24 + expected: float32(1.234567e+30), + }, } for name, tc := range tests { t.Run(name, func(t *testing.T) { diff --git a/protocol/lib/quantums_test.go b/protocol/lib/quantums_test.go index 57eec9108f..2ba83a87ba 100644 --- a/protocol/lib/quantums_test.go +++ b/protocol/lib/quantums_test.go @@ -1,10 +1,11 @@ -package lib +package lib_test import ( "math" "math/big" "testing" + "github.com/dydxprotocol/v4-chain/protocol/lib" big_testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/big" ) @@ -89,7 +90,7 @@ func TestBaseToQuoteQuantums(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - quoteQuantums := BaseToQuoteQuantums( + quoteQuantums := lib.BaseToQuoteQuantums( tc.bigBaseQuantums, tc.baseCurrencyAtomicResolution, tc.priceValue, @@ -188,7 +189,7 @@ func TestQuoteToBaseQuantums(t *testing.T) { } for name, tc := range tests { t.Run(name, func(t *testing.T) { - baseQuantums := QuoteToBaseQuantums( + baseQuantums := lib.QuoteToBaseQuantums( tc.bigQuoteQuantums, tc.baseCurrencyAtomicResolution, tc.priceValue, diff --git a/protocol/lib/time/time.go b/protocol/lib/time/time.go deleted file mode 100644 index df574810fc..0000000000 --- a/protocol/lib/time/time.go +++ /dev/null @@ -1,15 +0,0 @@ -package time - -import ( - "time" -) - -// MustParseDuration turns a string into a duration. -// Panics if the string cannot be parsed. -func MustParseDuration(s string) time.Duration { - v, err := time.ParseDuration(s) - if err != nil { - panic(err) - } - return v -} diff --git a/protocol/lib/time/time_test.go b/protocol/lib/time/time_test.go deleted file mode 100644 index b970174b7a..0000000000 --- a/protocol/lib/time/time_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package time_test - -import ( - "testing" - "time" - - libtime "github.com/dydxprotocol/v4-chain/protocol/lib/time" - "github.com/stretchr/testify/require" -) - -func TestMustParseDuration(t *testing.T) { - tests := map[string]struct { - input string - expectPanic bool - expectedOutput time.Duration - }{ - "valid: zero": { - input: "0", - expectedOutput: time.Duration(0), - }, - "valid: zero with unit": { - input: "0ms", - expectedOutput: time.Duration(0), - }, - "valid: positive decimal": { - input: "1.137120913s", - expectedOutput: time.Duration(1137120913) * time.Nanosecond, - }, - "valid: negative decimal": { - input: "-0.123457913s", - expectedOutput: time.Duration(-123457913) * time.Nanosecond, - }, - "invalid: empty string": { - input: "", // empty input - expectPanic: true, - }, - "invalid: invalid format": { - input: "1.137120913", // no unit - expectPanic: true, - }, - } - - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - if tc.expectPanic { - require.Panics( - t, - func() { - v := libtime.MustParseDuration(tc.input) - require.Nil(t, v) - }, - ) - return - } - - v := libtime.MustParseDuration(tc.input) - require.Equal(t, tc.expectedOutput, v) - }) - } -} diff --git a/protocol/mocks/IndexerEventManager.go b/protocol/mocks/IndexerEventManager.go index 5cbac17b51..9f8b2df01d 100644 --- a/protocol/mocks/IndexerEventManager.go +++ b/protocol/mocks/IndexerEventManager.go @@ -16,14 +16,14 @@ type IndexerEventManager struct { mock.Mock } -// AddBlockEvent provides a mock function with given fields: ctx, subType, data, blockEvent, version, dataBytes -func (_m *IndexerEventManager) AddBlockEvent(ctx types.Context, subType string, data string, blockEvent indexer_manager.IndexerTendermintEvent_BlockEvent, version uint32, dataBytes []byte) { - _m.Called(ctx, subType, data, blockEvent, version, dataBytes) +// AddBlockEvent provides a mock function with given fields: ctx, subType, blockEvent, version, dataBytes +func (_m *IndexerEventManager) AddBlockEvent(ctx types.Context, subType string, blockEvent indexer_manager.IndexerTendermintEvent_BlockEvent, version uint32, dataBytes []byte) { + _m.Called(ctx, subType, blockEvent, version, dataBytes) } -// AddTxnEvent provides a mock function with given fields: ctx, subType, data, version, dataByes -func (_m *IndexerEventManager) AddTxnEvent(ctx types.Context, subType string, data string, version uint32, dataByes []byte) { - _m.Called(ctx, subType, data, version, dataByes) +// AddTxnEvent provides a mock function with given fields: ctx, subType, version, dataByes +func (_m *IndexerEventManager) AddTxnEvent(ctx types.Context, subType string, version uint32, dataByes []byte) { + _m.Called(ctx, subType, version, dataByes) } // ClearEvents provides a mock function with given fields: ctx diff --git a/protocol/scripts/genesis/check_sample_pregenesis_uptodate.sh b/protocol/scripts/genesis/check_sample_pregenesis_uptodate.sh new file mode 100755 index 0000000000..f2a79f5edc --- /dev/null +++ b/protocol/scripts/genesis/check_sample_pregenesis_uptodate.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# This script checks `sample_pregenesis.json` is up to date with the result of running `prod_pregenesis.sh`. +# Usage: % ./scripts/genesis/check_sample_pregenesis_uptodate.sh +# Currently can only be run locally on macOS. +# TODO(CORE-632): Make this script work on CI. +echo "Building binary..." +make build +echo "Running prod_pregenesis.sh..." +./scripts/genesis/prod_pregenesis.sh build/dydxprotocold + +diff_output=$(diff "/tmp/prod-chain/.dydxprotocol/config/genesis.json" "./scripts/genesis/sample_pregenesis.json") + +if [ -z "$diff_output" ]; then + echo "./scripts/genesis/sample_pregenesis.json is up-to-date" +else + echo "./scripts/genesis/sample_pregenesis.json is not up-to-date" + echo "$diff_output" + exit 1 +fi \ No newline at end of file diff --git a/protocol/scripts/genesis/prod_pregenesis.sh b/protocol/scripts/genesis/prod_pregenesis.sh index 221cfd3468..771c3bf26b 100755 --- a/protocol/scripts/genesis/prod_pregenesis.sh +++ b/protocol/scripts/genesis/prod_pregenesis.sh @@ -19,34 +19,32 @@ fi # Capture the required argument DYDX_BINARY="$1" +source "./testing/genesis.sh" + TMP_CHAIN_DIR="/tmp/prod-chain" TMP_EXCHANGE_CONFIG_JSON_DIR="/tmp/prod-exchange_config" -NINE_ZEROS="000000000" -EIGHTEEN_ZEROS="$NINE_ZEROS$NINE_ZEROS" BRIDGE_MODACC_BALANCE="1$NINE_ZEROS$EIGHTEEN_ZEROS" # 1e27 BRIDGE_MODACC_ADDR="dydx1zlefkpe3g0vvm9a4h0jf9000lmqutlh9jwjnsv" -source "./testing/genesis.sh" - # TODO(GENESIS): Update below values before running this script. Sample values are shown. ################## Start of required values to be updated ################## -CHAIN_ID="dydx-1" +CHAIN_ID="dydx-sample-1" # Base denomination of the native token. Usually comes with a prefix "u-", "a-" to indicate unit. -NATIVE_TOKEN="adv4tnt" +NATIVE_TOKEN="asample" # Denomination of the native token in whole coins. -NATIVE_TOKEN_WHOLE_COIN="dv4tnt" +NATIVE_TOKEN_WHOLE_COIN="sample" # Human readable name of token. -COIN_NAME="dYdX Testnet Token" +COIN_NAME="Sample Coin Name" # Market ID in the oracle price list for the rewards token. -REWARDS_TOKEN_MARKET_ID=11 +REWARDS_TOKEN_MARKET_ID=1 # The numerical chain ID of the Ethereum chain for bridge daemon to query. -ETH_CHAIN_ID=1 +ETH_CHAIN_ID=9 # The address of the Ethereum contract for bridge daemon to monitor for logs. -ETH_BRIDGE_ADDRESS="0xcca9D5f0a3c58b6f02BD0985fC7F9420EA24C1f0" # default value points to a Sepolia contract +ETH_BRIDGE_ADDRESS="0xsampleaddress" # default value points to a Sepolia contract # The next event id (the last processed id plus one) of the logs from the Ethereum contract. -BRIDGE_GENESIS_ACKNOWLEDGED_NEXT_ID=0 +BRIDGE_GENESIS_ACKNOWLEDGED_NEXT_ID=99 # The Ethereum block height of the most recently processed bridge event. -BRIDGE_GENESIS_ACKNOWLEDGED_ETH_BLOCK_HEIGHT=0 +BRIDGE_GENESIS_ACKNOWLEDGED_ETH_BLOCK_HEIGHT=99999 # Genesis time of the chain. GENESIS_TIME="2023-12-31T00:00:00Z" # Start time of the community vesting schedule. @@ -116,6 +114,7 @@ function overwrite_genesis_production() { # Rewards params dasel put -t string -f "$GENESIS" '.app_state.rewards.params.denom' -v "$NATIVE_TOKEN" dasel put -t int -f "$GENESIS" '.app_state.rewards.params.fee_multiplier_ppm' -v '0' + dasel put -t int -f "$GENESIS" '.app_state.rewards.params.market_id' -v "$REWARDS_TOKEN_MARKET_ID" # Vest params # For community treasury diff --git a/protocol/scripts/genesis/sample_pregenesis.json b/protocol/scripts/genesis/sample_pregenesis.json index 432d3df7c0..c1f0cfa2bb 100644 --- a/protocol/scripts/genesis/sample_pregenesis.json +++ b/protocol/scripts/genesis/sample_pregenesis.json @@ -31,27 +31,27 @@ "coins": [ { "amount": "1000000000000000000000000000", - "denom": "adv4tnt" + "denom": "asample" } ] } ], "denom_metadata": [ { - "base": "adv4tnt", + "base": "asample", "denom_units": [ { - "denom": "adv4tnt" + "denom": "asample" }, { - "denom": "dv4tnt", + "denom": "sample", "exponent": 18 } ], "description": "The native token of the network", - "display": "dv4tnt", - "name": "dYdX Testnet Token", - "symbol": "dv4tnt" + "display": "sample", + "name": "Sample Coin Name", + "symbol": "sample" } ], "params": { @@ -72,13 +72,13 @@ }, "bridge": { "acknowledged_event_info": { - "eth_block_height": 0, - "next_id": 0 + "eth_block_height": 99999, + "next_id": 99 }, "event_params": { - "denom": "adv4tnt", - "eth_address": "0xcca9D5f0a3c58b6f02BD0985fC7F9420EA24C1f0", - "eth_chain_id": 1 + "denom": "asample", + "eth_address": "0xsampleaddress", + "eth_chain_id": 9 }, "propose_params": { "max_bridges_per_block": 10, @@ -526,7 +526,7 @@ "crisis": { "constant_fee": { "amount": "1000000000000000000", - "denom": "adv4tnt" + "denom": "asample" } }, "delaymsg": { @@ -765,7 +765,7 @@ "min_deposit": [ { "amount": "10000000000000000000000", - "denom": "adv4tnt" + "denom": "asample" } ], "min_initial_deposit_ratio": "0.000000000000000000", @@ -1646,10 +1646,10 @@ }, "rewards": { "params": { - "denom": "adv4tnt", + "denom": "asample", "denom_exponent": -18, "fee_multiplier_ppm": 0, - "market_id": 11, + "market_id": 1, "treasury_account": "rewards_treasury" } }, @@ -1671,7 +1671,7 @@ "last_total_power": "0", "last_validator_powers": [], "params": { - "bond_denom": "adv4tnt", + "bond_denom": "asample", "historical_entries": 10000, "max_entries": 7, "max_validators": 60, @@ -1703,14 +1703,14 @@ "vest": { "vest_entries": [ { - "denom": "adv4tnt", + "denom": "asample", "end_time": "2050-01-01T00:00:00Z", "start_time": "2001-01-01T00:00:00Z", "treasury_account": "community_treasury", "vester_account": "community_vester" }, { - "denom": "adv4tnt", + "denom": "asample", "end_time": "2050-01-01T00:00:00Z", "start_time": "2001-01-01T00:00:00Z", "treasury_account": "rewards_treasury", @@ -1719,7 +1719,7 @@ ] } }, - "chain_id": "dydx-1", + "chain_id": "dydx-sample-1", "consensus_params": { "block": { "max_bytes": "4194304", diff --git a/protocol/testing/genesis.sh b/protocol/testing/genesis.sh index 9913ff58c5..2c05331376 100755 --- a/protocol/testing/genesis.sh +++ b/protocol/testing/genesis.sh @@ -6,6 +6,9 @@ set -eo pipefail # If you are making a change to genesis which is _required_ for the chain to function, # then that change probably belongs in `DefaultGenesis` for the module, and not here. +NINE_ZEROS="000000000" +EIGHTEEN_ZEROS="$NINE_ZEROS$NINE_ZEROS" + # Address of the `subaccounts` module account. # Obtained from `authtypes.NewModuleAddress(subaccounttypes.ModuleName)`. SUBACCOUNTS_MODACC_ADDR="dydx1v88c3xv9xyv3eetdx0tvcmq7ung3dywp5upwc6" @@ -19,13 +22,13 @@ NATIVE_TOKEN="adv4tnt" # public testnet token DEFAULT_SUBACCOUNT_QUOTE_BALANCE=100000000000000000 DEFAULT_SUBACCOUNT_QUOTE_BALANCE_FAUCET=900000000000000000 # Each testnet validator has 1 million whole coins of native token. -TESTNET_VALIDATOR_NATIVE_TOKEN_BALANCE=1000000000000000000000000 # 1e24 +TESTNET_VALIDATOR_NATIVE_TOKEN_BALANCE=1000000$EIGHTEEN_ZEROS # 1e24 # Each testnet validator self-delegates 500k whole coins of native token. -TESTNET_VALIDATOR_SELF_DELEGATE_AMOUNT=500000000000000000000000 # 5e23 +TESTNET_VALIDATOR_SELF_DELEGATE_AMOUNT=500000$EIGHTEEN_ZEROS # 5e23 ETH_CHAIN_ID=11155111 # sepolia # https://sepolia.etherscan.io/address/0xcca9D5f0a3c58b6f02BD0985fC7F9420EA24C1f0 ETH_BRIDGE_ADDRESS="0xcca9D5f0a3c58b6f02BD0985fC7F9420EA24C1f0" -TOTAL_NATIVE_TOKEN_SUPPLY=1000000000000000000000000000 # 1e27 +TOTAL_NATIVE_TOKEN_SUPPLY=1000000000$EIGHTEEN_ZEROS # 1e27 BRIDGE_GENESIS_ACKNOWLEDGED_NEXT_ID=5 BRIDGE_GENESIS_ACKNOWLEDGED_ETH_BLOCK_HEIGHT=4322136 @@ -60,8 +63,8 @@ function edit_genesis() { REWARDS_VESTER_ACCOUNT_BALANCE="$7" if [ -z "$REWARDS_VESTER_ACCOUNT_BALANCE" ]; then - # Default to 1e12. - REWARDS_VESTER_ACCOUNT_BALANCE="1000000000000" + # Default to 10 million full coins. + REWARDS_VESTER_ACCOUNT_BALANCE="10000000$EIGHTEEN_ZEROS" fi # Consensus params diff --git a/protocol/testutil/big/big.go b/protocol/testutil/big/big.go index fea0e9da13..bf1e9a7a17 100644 --- a/protocol/testutil/big/big.go +++ b/protocol/testutil/big/big.go @@ -3,6 +3,8 @@ package big import ( "math/big" + + "github.com/dydxprotocol/v4-chain/protocol/lib" ) // MustFirst is used for returning the first value of the SetString @@ -13,3 +15,16 @@ func MustFirst[T *big.Int | *big.Rat](n T, success bool) T { } return n } + +// Int64MulPow10 returns the result of `val * 10^exponent`, in *big.Int. +func Int64MulPow10( + val int64, + exponent uint64, +) ( + result *big.Int, +) { + return new(big.Int).Mul( + big.NewInt(val), + lib.BigPow10(exponent), + ) +} diff --git a/protocol/testutil/big/big_test.go b/protocol/testutil/big/big_test.go new file mode 100644 index 0000000000..40f73f7fcd --- /dev/null +++ b/protocol/testutil/big/big_test.go @@ -0,0 +1,57 @@ +package big_test + +import ( + "math/big" + "testing" + + big_testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/big" + "github.com/stretchr/testify/require" +) + +func TestInt64MulPow10(t *testing.T) { + tests := map[string]struct { + val int64 + exponent uint64 + expectedResult string + }{ + "Regular value and exponent": { + val: 215, + exponent: 4, + expectedResult: "2150000", + }, + "Zero value": { + val: 0, + exponent: 3, + expectedResult: "0", + }, + "Zero exponent": { + val: 2, + exponent: 0, + expectedResult: "2", + }, + "(-2) * 1e3": { + val: -2, + exponent: 3, + expectedResult: "-2000", + }, + "123456789 * 1e10": { + val: 123456789, + exponent: 10, + expectedResult: "1234567890000000000", + }, + "87654321 * 1e18": { + val: 87654321, + exponent: 18, + expectedResult: "87654321000000000000000000", + }, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + result := big_testutil.Int64MulPow10(tc.val, tc.exponent) + bigExpected, valid := new(big.Int).SetString(tc.expectedResult, 10) + require.True(t, valid) + require.Equal(t, bigExpected, result) + }) + } +} diff --git a/protocol/testutil/keeper/assets.go b/protocol/testutil/keeper/assets.go index daae28ea07..d73f521986 100644 --- a/protocol/testutil/keeper/assets.go +++ b/protocol/testutil/keeper/assets.go @@ -109,10 +109,9 @@ func GetAssetCreateEventsFromIndexerBlock( if event.Subtype != indexerevents.SubtypeAsset { continue } - bytes := indexer_manager.GetBytesFromEventData(event.Data) unmarshaler := common.UnmarshalerImpl{} var assetEvent indexerevents.AssetCreateEventV1 - err := unmarshaler.Unmarshal(bytes, &assetEvent) + err := unmarshaler.Unmarshal(event.DataBytes, &assetEvent) if err != nil { panic(err) } diff --git a/protocol/testutil/keeper/clob.go b/protocol/testutil/keeper/clob.go index a036e82526..eca73d7d0a 100644 --- a/protocol/testutil/keeper/clob.go +++ b/protocol/testutil/keeper/clob.go @@ -270,20 +270,6 @@ func CreateNClobPair( mockIndexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - clobtest.MustPerpetualId(items[i]), - items[i].Id, - perps[i].Params.Ticker, - perps[i].Params.MarketId, - items[i].Status, - items[i].QuantumConversionExponent, - perps[i].Params.AtomicResolution, - items[i].SubticksPerTick, - items[i].StepBaseQuantums, - perps[i].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( diff --git a/protocol/testutil/keeper/perpetuals.go b/protocol/testutil/keeper/perpetuals.go index f90c09419c..b115a03ffa 100644 --- a/protocol/testutil/keeper/perpetuals.go +++ b/protocol/testutil/keeper/perpetuals.go @@ -199,10 +199,9 @@ func GetLiquidityTierUpsertEventsFromIndexerBlock( if event.Subtype != indexerevents.SubtypeLiquidityTier { continue } - bytes := indexer_manager.GetBytesFromEventData(event.Data) unmarshaler := common.UnmarshalerImpl{} var liquidityTierEvent indexerevents.LiquidityTierUpsertEventV1 - err := unmarshaler.Unmarshal(bytes, &liquidityTierEvent) + err := unmarshaler.Unmarshal(event.DataBytes, &liquidityTierEvent) if err != nil { panic(err) } diff --git a/protocol/testutil/keeper/prices.go b/protocol/testutil/keeper/prices.go index ce6bf69c5e..1d4037485a 100644 --- a/protocol/testutil/keeper/prices.go +++ b/protocol/testutil/keeper/prices.go @@ -185,10 +185,9 @@ func getMarketEventsFromIndexerBlock( if event.Subtype != indexerevents.SubtypeMarket { continue } - bytes := indexer_manager.GetBytesFromEventData(event.Data) unmarshaler := common.UnmarshalerImpl{} var marketEvent indexerevents.MarketEventV1 - err := unmarshaler.Unmarshal(bytes, &marketEvent) + err := unmarshaler.Unmarshal(event.DataBytes, &marketEvent) if err != nil { panic(err) } diff --git a/protocol/testutil/keeper/subaccounts.go b/protocol/testutil/keeper/subaccounts.go index fb004d3262..2c9408297c 100644 --- a/protocol/testutil/keeper/subaccounts.go +++ b/protocol/testutil/keeper/subaccounts.go @@ -144,10 +144,9 @@ func GetSubaccountUpdateEventsFromIndexerBlock( if event.Subtype != indexerevents.SubtypeSubaccountUpdate { continue } - bytes := indexer_manager.GetBytesFromEventData(event.Data) unmarshaler := common.UnmarshalerImpl{} var subaccountUpdate indexerevents.SubaccountUpdateEventV1 - err := unmarshaler.Unmarshal(bytes, &subaccountUpdate) + err := unmarshaler.Unmarshal(event.DataBytes, &subaccountUpdate) if err != nil { panic(err) } diff --git a/protocol/x/assets/keeper/asset.go b/protocol/x/assets/keeper/asset.go index 61aeac62a8..b4fde3a028 100644 --- a/protocol/x/assets/keeper/asset.go +++ b/protocol/x/assets/keeper/asset.go @@ -95,15 +95,6 @@ func (k Keeper) CreateAsset( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeAsset, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewAssetCreateEvent( - assetId, - asset.Symbol, - asset.HasMarket, - asset.MarketId, - asset.AtomicResolution, - ), - ), indexerevents.AssetEventVersion, indexer_manager.GetBytes( indexerevents.NewAssetCreateEvent( diff --git a/protocol/x/bridge/types/genesis.go b/protocol/x/bridge/types/genesis.go index c53a8dcefb..ee9948d855 100644 --- a/protocol/x/bridge/types/genesis.go +++ b/protocol/x/bridge/types/genesis.go @@ -1,7 +1,7 @@ package types import ( - "github.com/dydxprotocol/v4-chain/protocol/lib/time" + "time" ) // DefaultGenesis returns the default bridge genesis state. @@ -14,9 +14,9 @@ func DefaultGenesis() *GenesisState { }, ProposeParams: ProposeParams{ MaxBridgesPerBlock: 10, - ProposeDelayDuration: time.MustParseDuration("60s"), + ProposeDelayDuration: 60 * time.Second, SkipRatePpm: 800_000, // 80% - SkipIfBlockDelayedByDuration: time.MustParseDuration("5s"), + SkipIfBlockDelayedByDuration: 5 * time.Second, }, SafetyParams: SafetyParams{ IsDisabled: false, diff --git a/protocol/x/clob/abci.go b/protocol/x/clob/abci.go index 7e648d28de..afca2ad63b 100644 --- a/protocol/x/clob/abci.go +++ b/protocol/x/clob/abci.go @@ -53,12 +53,6 @@ func EndBlocker( keeper.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewStatefulOrderRemovalEvent( - orderId, - indexershared.OrderRemovalReason_ORDER_REMOVAL_REASON_EXPIRED, - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewStatefulOrderRemovalEvent( diff --git a/protocol/x/clob/abci_test.go b/protocol/x/clob/abci_test.go index e8efd1547a..2292181516 100644 --- a/protocol/x/clob/abci_test.go +++ b/protocol/x/clob/abci_test.go @@ -147,12 +147,6 @@ func TestEndBlocker_Failure(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewStatefulOrderRemovalEvent( - orderId, - indexershared.OrderRemovalReason_ORDER_REMOVAL_REASON_EXPIRED, - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewStatefulOrderRemovalEvent( @@ -693,20 +687,6 @@ func TestEndBlocker_Success(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.BtcUsd_20PercentInitial_10PercentMaintenance.Params.Ticker, - constants.BtcUsd_20PercentInitial_10PercentMaintenance.Params.MarketId, - constants.ClobPair_Btc.Status, - constants.ClobPair_Btc.QuantumConversionExponent, - constants.BtcUsd_20PercentInitial_10PercentMaintenance.Params.AtomicResolution, - constants.ClobPair_Btc.SubticksPerTick, - constants.ClobPair_Btc.StepBaseQuantums, - constants.BtcUsd_20PercentInitial_10PercentMaintenance.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -739,20 +719,6 @@ func TestEndBlocker_Success(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 1, - 1, - constants.EthUsd_20PercentInitial_10PercentMaintenance.Params.Ticker, - constants.EthUsd_20PercentInitial_10PercentMaintenance.Params.MarketId, - constants.ClobPair_Eth.Status, - constants.ClobPair_Eth.QuantumConversionExponent, - constants.EthUsd_20PercentInitial_10PercentMaintenance.Params.AtomicResolution, - constants.ClobPair_Eth.SubticksPerTick, - constants.ClobPair_Eth.StepBaseQuantums, - constants.EthUsd_20PercentInitial_10PercentMaintenance.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -789,12 +755,6 @@ func TestEndBlocker_Success(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewStatefulOrderRemovalEvent( - orderId, - indexershared.OrderRemovalReason_ORDER_REMOVAL_REASON_EXPIRED, - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewStatefulOrderRemovalEvent( @@ -810,11 +770,6 @@ func TestEndBlocker_Success(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewConditionalOrderTriggeredEvent( - orderId, - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewConditionalOrderTriggeredEvent( diff --git a/protocol/x/clob/e2e/short_term_orders_test.go b/protocol/x/clob/e2e/short_term_orders_test.go index 879ba67fc2..551945f630 100644 --- a/protocol/x/clob/e2e/short_term_orders_test.go +++ b/protocol/x/clob/e2e/short_term_orders_test.go @@ -149,28 +149,7 @@ func TestPlaceOrder(t *testing.T) { Time: ctx.BlockTime(), Events: []*indexer_manager.IndexerTendermintEvent{ { - Subtype: indexerevents.SubtypeSubaccountUpdate, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewSubaccountUpdateEvent( - &constants.Bob_Num0, - []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( - PlaceOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, - }, - // Maker fees calculate to 0 so asset position doesn't change. - []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(bobSubaccount.GetUsdcPosition()), - }, - }, - nil, // no funding payments - ), - ), + Subtype: indexerevents.SubtypeSubaccountUpdate, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 0, Version: indexerevents.SubaccountUpdateEventVersion, @@ -197,28 +176,7 @@ func TestPlaceOrder(t *testing.T) { ), }, { - Subtype: indexerevents.SubtypeSubaccountUpdate, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewSubaccountUpdateEvent( - &constants.Alice_Num0, - []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( - PlaceOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, - }, - // Taker fees calculate to 0 so asset position doesn't change. - []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(aliceSubaccount.GetUsdcPosition()), - }, - }, - nil, // no funding payments - ), - ), + Subtype: indexerevents.SubtypeSubaccountUpdate, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 1, Version: indexerevents.SubaccountUpdateEventVersion, @@ -245,18 +203,7 @@ func TestPlaceOrder(t *testing.T) { ), }, { - Subtype: indexerevents.SubtypeOrderFill, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewOrderFillEvent( - PlaceOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB20.Order, - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order, - PlaceOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB20.Order.GetBaseQuantums(), - 0, // Fees are 0 due to lost precision - 0, - PlaceOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB20.Order.GetBaseQuantums(), - PlaceOrder_Alice_Num0_Id0_Clob0_Buy5_Price10_GTB20.Order.GetBaseQuantums(), - ), - ), + Subtype: indexerevents.SubtypeOrderFill, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 2, Version: indexerevents.OrderFillEventVersion, @@ -361,28 +308,7 @@ func TestPlaceOrder(t *testing.T) { Time: ctx.BlockTime(), Events: []*indexer_manager.IndexerTendermintEvent{ { - Subtype: indexerevents.SubtypeSubaccountUpdate, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewSubaccountUpdateEvent( - &constants.Bob_Num0, - []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, - }, - // Maker fees calculate to 0 so asset position doesn't change. - []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(bobSubaccount.GetUsdcPosition()), - }, - }, - nil, // no funding payments - ), - ), + Subtype: indexerevents.SubtypeSubaccountUpdate, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 0, Version: indexerevents.SubaccountUpdateEventVersion, @@ -409,28 +335,7 @@ func TestPlaceOrder(t *testing.T) { ), }, { - Subtype: indexerevents.SubtypeSubaccountUpdate, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewSubaccountUpdateEvent( - &constants.Alice_Num0, - []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, - }, - // Taker fees calculate to 0 so asset position doesn't change. - []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(aliceSubaccount.GetUsdcPosition()), - }, - }, - nil, // no funding payments - ), - ), + Subtype: indexerevents.SubtypeSubaccountUpdate, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 1, Version: indexerevents.SubaccountUpdateEventVersion, @@ -457,18 +362,7 @@ func TestPlaceOrder(t *testing.T) { ), }, { - Subtype: indexerevents.SubtypeOrderFill, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewOrderFillEvent( - PlaceOrder_Alice_Num0_Id0_Clob0_Buy6_Price10_GTB20.Order, - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order, - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetBaseQuantums(), - 0, // Fees are 0 due to lost precision - 0, - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetBaseQuantums(), - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetBaseQuantums(), - ), - ), + Subtype: indexerevents.SubtypeOrderFill, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 2, Version: indexerevents.OrderFillEventVersion, @@ -573,28 +467,7 @@ func TestPlaceOrder(t *testing.T) { Time: ctx.BlockTime(), Events: []*indexer_manager.IndexerTendermintEvent{ { - Subtype: indexerevents.SubtypeSubaccountUpdate, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewSubaccountUpdateEvent( - &constants.Alice_Num0, - []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(int64( - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, - }, - // Taker fees calculate to 0 so asset position doesn't change. - []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(aliceSubaccount.GetUsdcPosition()), - }, - }, - nil, // no funding payments - ), - ), + Subtype: indexerevents.SubtypeSubaccountUpdate, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 0, Version: indexerevents.SubaccountUpdateEventVersion, @@ -621,28 +494,7 @@ func TestPlaceOrder(t *testing.T) { ), }, { - Subtype: indexerevents.SubtypeSubaccountUpdate, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewSubaccountUpdateEvent( - &constants.Bob_Num0, - []*satypes.PerpetualPosition{ - { - PerpetualId: Clob_0.MustGetPerpetualId(), - Quantums: dtypes.NewInt(-int64( - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetQuantums())), - FundingIndex: dtypes.NewInt(0), - }, - }, - // Maker fees calculate to 0 so asset position doesn't change. - []*satypes.AssetPosition{ - { - AssetId: assettypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(bobSubaccount.GetUsdcPosition()), - }, - }, - nil, // no funding payments - ), - ), + Subtype: indexerevents.SubtypeSubaccountUpdate, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 1, Version: indexerevents.SubaccountUpdateEventVersion, @@ -669,18 +521,7 @@ func TestPlaceOrder(t *testing.T) { ), }, { - Subtype: indexerevents.SubtypeOrderFill, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewOrderFillEvent( - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order, - PlaceOrder_Alice_Num0_Id0_Clob0_Buy6_Price10_GTB20.Order, - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetBaseQuantums(), - 0, // Fees are 0 due to lost precision - 0, - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetBaseQuantums(), - PlaceOrder_Bob_Num0_Id0_Clob0_Sell5_Price10_GTB20.Order.GetBaseQuantums(), - ), - ), + Subtype: indexerevents.SubtypeOrderFill, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 2, Version: indexerevents.OrderFillEventVersion, diff --git a/protocol/x/clob/genesis_test.go b/protocol/x/clob/genesis_test.go index c3ce7d6535..55f105735a 100644 --- a/protocol/x/clob/genesis_test.go +++ b/protocol/x/clob/genesis_test.go @@ -443,20 +443,6 @@ func TestGenesis(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - perpetualId, - uint32(i), - perpetual.Params.Ticker, - perpetual.Params.MarketId, - clobPair.Status, - clobPair.QuantumConversionExponent, - perpetual.Params.AtomicResolution, - clobPair.SubticksPerTick, - clobPair.StepBaseQuantums, - perpetual.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( diff --git a/protocol/x/clob/keeper/clob_pair.go b/protocol/x/clob/keeper/clob_pair.go index e7bb26116f..34a8cea716 100644 --- a/protocol/x/clob/keeper/clob_pair.go +++ b/protocol/x/clob/keeper/clob_pair.go @@ -90,20 +90,6 @@ func (k Keeper) CreatePerpetualClobPair( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - perpetualId, - clobPairId, - perpetual.Params.Ticker, - perpetual.Params.MarketId, - status, - quantumConversionExponent, - perpetual.Params.AtomicResolution, - subticksPerTick, - stepSizeBaseQuantums.ToUint64(), - perpetual.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -480,15 +466,6 @@ func (k Keeper) UpdateClobPair( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeUpdateClobPair, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewUpdateClobPairEvent( - clobPair.GetClobPairId(), - clobPair.Status, - clobPair.QuantumConversionExponent, - types.SubticksPerTick(clobPair.GetSubticksPerTick()), - satypes.BaseQuantums(clobPair.GetStepBaseQuantums()), - ), - ), indexerevents.UpdateClobPairEventVersion, indexer_manager.GetBytes( indexerevents.NewUpdateClobPairEvent( diff --git a/protocol/x/clob/keeper/clob_pair_test.go b/protocol/x/clob/keeper/clob_pair_test.go index 947cfefdd0..133de5651e 100644 --- a/protocol/x/clob/keeper/clob_pair_test.go +++ b/protocol/x/clob/keeper/clob_pair_test.go @@ -50,20 +50,6 @@ func TestCreatePerpetualClobPair_MultiplePerpetual(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - clobPair.MustGetPerpetualId(), - clobPair.Id, - constants.Perpetuals_DefaultGenesisState.Perpetuals[i].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[i].Params.MarketId, - clobPair.Status, - clobPair.QuantumConversionExponent, - constants.Perpetuals_DefaultGenesisState.Perpetuals[i].Params.AtomicResolution, - clobPair.SubticksPerTick, - clobPair.StepBaseQuantums, - constants.Perpetuals_DefaultGenesisState.Perpetuals[i].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -186,20 +172,6 @@ func TestCreatePerpetualClobPair_FailsWithDuplicateClobPairId(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - clobPair.MustGetPerpetualId(), - clobPair.Id, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.MarketId, - clobPair.Status, - clobPair.QuantumConversionExponent, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.AtomicResolution, - clobPair.SubticksPerTick, - clobPair.StepBaseQuantums, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -291,20 +263,6 @@ func TestCreatePerpetualClobPair(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - perpetualId, - perpetualId, - perpetual.Params.Ticker, - perpetual.Params.MarketId, - tc.clobPair.Status, - tc.clobPair.QuantumConversionExponent, - perpetual.Params.AtomicResolution, - tc.clobPair.SubticksPerTick, - tc.clobPair.StepBaseQuantums, - perpetual.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -457,20 +415,6 @@ func TestCreateMultipleClobPairs(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - perpetualId, - perpetualId, - perpetual.Params.Ticker, - perpetual.Params.MarketId, - make.clobPair.Status, - make.clobPair.QuantumConversionExponent, - perpetual.Params.AtomicResolution, - make.clobPair.SubticksPerTick, - make.clobPair.StepBaseQuantums, - perpetual.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -666,20 +610,6 @@ func TestUpdateClobPair(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.MarketId, - types.ClobPair_STATUS_INITIALIZING, - clobPair.QuantumConversionExponent, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.AtomicResolution, - clobPair.SubticksPerTick, - clobPair.StepBaseQuantums, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -711,15 +641,6 @@ func TestUpdateClobPair(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypeUpdateClobPair, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewUpdateClobPairEvent( - clobPair.GetClobPairId(), - types.ClobPair_STATUS_ACTIVE, - clobPair.QuantumConversionExponent, - types.SubticksPerTick(clobPair.GetSubticksPerTick()), - satypes.BaseQuantums(clobPair.GetStepBaseQuantums()), - ), - ), indexerevents.UpdateClobPairEventVersion, indexer_manager.GetBytes( indexerevents.NewUpdateClobPairEvent( @@ -746,20 +667,6 @@ func TestUpdateClobPair(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.MarketId, - clobPair.Status, - clobPair.QuantumConversionExponent, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.AtomicResolution, - clobPair.SubticksPerTick, - clobPair.StepBaseQuantums, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -797,20 +704,6 @@ func TestUpdateClobPair(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.MarketId, - clobPair.Status, - clobPair.QuantumConversionExponent, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.AtomicResolution, - clobPair.SubticksPerTick, - clobPair.StepBaseQuantums, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( diff --git a/protocol/x/clob/keeper/get_price_premium_test.go b/protocol/x/clob/keeper/get_price_premium_test.go index d23e1136ad..eb91c6c27c 100644 --- a/protocol/x/clob/keeper/get_price_premium_test.go +++ b/protocol/x/clob/keeper/get_price_premium_test.go @@ -170,20 +170,6 @@ func TestGetPricePremiumForPerpetual(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - perpetualId, - 0, - perpetual.Params.Ticker, - perpetual.Params.MarketId, - tc.args.clobPair.Status, - tc.args.clobPair.QuantumConversionExponent, - perpetual.Params.AtomicResolution, - tc.args.clobPair.SubticksPerTick, - tc.args.clobPair.StepBaseQuantums, - perpetual.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( diff --git a/protocol/x/clob/keeper/liquidations_test.go b/protocol/x/clob/keeper/liquidations_test.go index 300a88eb06..1d17df49a6 100644 --- a/protocol/x/clob/keeper/liquidations_test.go +++ b/protocol/x/clob/keeper/liquidations_test.go @@ -1054,20 +1054,6 @@ func TestPlacePerpetualLiquidation_PreexistingLiquidation(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.BtcUsd_100PercentMarginRequirement.Params.Ticker, - constants.BtcUsd_100PercentMarginRequirement.Params.MarketId, - constants.ClobPair_Btc.Status, - constants.ClobPair_Btc.QuantumConversionExponent, - constants.BtcUsd_100PercentMarginRequirement.Params.AtomicResolution, - constants.ClobPair_Btc.SubticksPerTick, - constants.ClobPair_Btc.StepBaseQuantums, - constants.BtcUsd_100PercentMarginRequirement.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -1097,20 +1083,6 @@ func TestPlacePerpetualLiquidation_PreexistingLiquidation(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 1, - 1, - constants.EthUsd_100PercentMarginRequirement.Params.Ticker, - constants.EthUsd_100PercentMarginRequirement.Params.MarketId, - constants.ClobPair_Eth.Status, - constants.ClobPair_Eth.QuantumConversionExponent, - constants.EthUsd_100PercentMarginRequirement.Params.AtomicResolution, - constants.ClobPair_Eth.SubticksPerTick, - constants.ClobPair_Eth.StepBaseQuantums, - constants.EthUsd_100PercentMarginRequirement.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -1982,20 +1954,6 @@ func TestPlacePerpetualLiquidation_Deleveraging(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - uint32(i), - uint32(i), - perpetuals[i].Params.Ticker, - perpetuals[i].Params.MarketId, - clobPair.Status, - clobPair.QuantumConversionExponent, - perpetuals[i].Params.AtomicResolution, - clobPair.SubticksPerTick, - clobPair.StepBaseQuantums, - perpetuals[i].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -2109,20 +2067,6 @@ func TestPlacePerpetualLiquidation_SendOffchainMessages(t *testing.T) { indexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.MarketId, - constants.ClobPair_Btc.Status, - constants.ClobPair_Btc.QuantumConversionExponent, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.AtomicResolution, - constants.ClobPair_Btc.SubticksPerTick, - constants.ClobPair_Btc.StepBaseQuantums, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -3643,20 +3587,6 @@ func TestGetLiquidationInsuranceFundDelta(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - tc.perpetuals[0].Params.Ticker, - tc.perpetuals[0].Params.MarketId, - constants.ClobPair_Btc.Status, - constants.ClobPair_Btc.QuantumConversionExponent, - tc.perpetuals[0].Params.AtomicResolution, - constants.ClobPair_Btc.SubticksPerTick, - constants.ClobPair_Btc.StepBaseQuantums, - tc.perpetuals[0].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -4408,20 +4338,6 @@ func TestGetPerpetualPositionToLiquidate(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - perpetualId, - uint32(i), - tc.perpetuals[perpetualId].Params.Ticker, - tc.perpetuals[perpetualId].Params.MarketId, - clobPair.Status, - clobPair.QuantumConversionExponent, - tc.perpetuals[perpetualId].Params.AtomicResolution, - clobPair.SubticksPerTick, - clobPair.StepBaseQuantums, - tc.perpetuals[perpetualId].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -5040,20 +4956,6 @@ func TestGetMaxAndMinPositionNotionalLiquidatable(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.BtcUsd_100PercentMarginRequirement.Params.Ticker, - constants.BtcUsd_100PercentMarginRequirement.Params.MarketId, - constants.ClobPair_Btc.Status, - constants.ClobPair_Btc.QuantumConversionExponent, - constants.BtcUsd_100PercentMarginRequirement.Params.AtomicResolution, - constants.ClobPair_Btc.SubticksPerTick, - constants.ClobPair_Btc.StepBaseQuantums, - constants.BtcUsd_100PercentMarginRequirement.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -5207,20 +5109,6 @@ func TestSortLiquidationOrders(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.BtcUsd_100PercentMarginRequirement.Params.Ticker, - constants.BtcUsd_100PercentMarginRequirement.Params.MarketId, - constants.ClobPair_Btc.Status, - constants.ClobPair_Btc.QuantumConversionExponent, - constants.BtcUsd_100PercentMarginRequirement.Params.AtomicResolution, - constants.ClobPair_Btc.SubticksPerTick, - constants.ClobPair_Btc.StepBaseQuantums, - constants.BtcUsd_100PercentMarginRequirement.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( diff --git a/protocol/x/clob/keeper/msg_server_cancel_orders.go b/protocol/x/clob/keeper/msg_server_cancel_orders.go index 535f3833ac..a7bb9115ba 100644 --- a/protocol/x/clob/keeper/msg_server_cancel_orders.go +++ b/protocol/x/clob/keeper/msg_server_cancel_orders.go @@ -25,6 +25,13 @@ func (k msgServer) CancelOrder( ctx := sdk.UnwrapSDKContext(goCtx) defer func() { + metrics.IncrSuccessOrErrorCounter( + err, + types.ModuleName, + metrics.CancelOrder, + metrics.DeliverTx, + msg.OrderId.GetOrderIdLabels()..., + ) if err != nil { // Gracefully handle the case where the order was already removed from state. This can happen if an Order // Removal Operation was included in the same block as the MsgCancelOrder. By the time we try to cancel @@ -44,17 +51,18 @@ func (k msgServer) CancelOrder( 1, msg.OrderId.GetOrderIdLabels(), ) + err = errorsmod.Wrapf( + types.ErrStatefulOrderCancellationFailedForAlreadyRemovedOrder, + "Error: %s", + err.Error(), + ) k.Keeper.Logger(ctx).Info( - errorsmod.Wrapf( - types.ErrStatefulOrderCancellationFailedForAlreadyRemovedOrder, - "Error: %s", - err.Error(), - ).Error(), + err.Error(), ) return } } - errorlib.LogErrorWithBlockHeight(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), metrics.DeliverTx) + errorlib.LogDeliverTxError(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), "CancelOrder", msg) } }() @@ -82,12 +90,6 @@ func (k msgServer) CancelOrder( k.Keeper.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewStatefulOrderRemovalEvent( - msg.OrderId, - indexershared.OrderRemovalReason_ORDER_REMOVAL_REASON_USER_CANCELED, - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewStatefulOrderRemovalEvent( @@ -97,11 +99,5 @@ func (k msgServer) CancelOrder( ), ) - telemetry.IncrCounterWithLabels( - []string{types.ModuleName, metrics.StatefulCancellationMsgHandlerSuccess, metrics.Count}, - 1, - msg.OrderId.GetOrderIdLabels(), - ) - return &types.MsgCancelOrderResponse{}, nil } diff --git a/protocol/x/clob/keeper/msg_server_cancel_orders_test.go b/protocol/x/clob/keeper/msg_server_cancel_orders_test.go index e9edd303ce..413183018a 100644 --- a/protocol/x/clob/keeper/msg_server_cancel_orders_test.go +++ b/protocol/x/clob/keeper/msg_server_cancel_orders_test.go @@ -2,7 +2,6 @@ package keeper_test import ( "context" - "fmt" "testing" "time" @@ -67,6 +66,7 @@ func TestCancelOrder_InfoLogIfOrderNotFound(t *testing.T) { orderToCancel := constants.CancelLongTermOrder_Alice_Num0_Id0_Clob0_GTBT15 ctx := ks.Ctx.WithBlockHeight(2) + ctx = ctx.WithIsCheckTx(false).WithIsReCheckTx(false) mockLogger := &mocks.Logger{} mockLogger.On("With", mock.Anything, mock.Anything).Return(mockLogger) mockLogger.On("Info", @@ -83,7 +83,7 @@ func TestCancelOrder_InfoLogIfOrderNotFound(t *testing.T) { ctx = ctx.WithLogger(mockLogger) ctx = ctx.WithBlockTime(time.Unix(int64(2), 0)) ks.BlockTimeKeeper.SetPreviousBlockInfo(ctx, &blocktimetypes.BlockInfo{ - Height: 2, + Height: 1, Timestamp: time.Unix(int64(2), 0), }) @@ -96,7 +96,7 @@ func TestCancelOrder_InfoLogIfOrderNotFound(t *testing.T) { ) _, err := msgServer.CancelOrder(ctx, &orderToCancel) - require.ErrorIs(t, err, types.ErrStatefulOrderDoesNotExist) + require.ErrorIs(t, err, types.ErrStatefulOrderCancellationFailedForAlreadyRemovedOrder) mockLogger.AssertExpectations(t) } @@ -109,16 +109,21 @@ func TestCancelOrder_ErrorLogIfGTBTTooLow(t *testing.T) { orderToCancel := constants.CancelLongTermOrder_Alice_Num0_Id0_Clob0_GTBT15 ctx := ks.Ctx.WithBlockHeight(2) + ctx = ctx.WithIsCheckTx(false).WithIsReCheckTx(false) mockLogger := &mocks.Logger{} mockLogger.On("With", mock.Anything, mock.Anything).Return(mockLogger) mockLogger.On( "Error", - fmt.Sprintf("Block height: 2, Callback: deliver_tx: %s", types.ErrTimeExceedsGoodTilBlockTime.Error()), + []interface{}{ + types.ErrTimeExceedsGoodTilBlockTime.Error(), + mock.Anything, mock.Anything, mock.Anything, mock.Anything, + mock.Anything, mock.Anything, mock.Anything, mock.Anything, + }..., ).Return() ctx = ctx.WithLogger(mockLogger) ctx = ctx.WithBlockTime(time.Unix(int64(2), 0)) ks.BlockTimeKeeper.SetPreviousBlockInfo(ctx, &blocktimetypes.BlockInfo{ - Height: 2, + Height: 1, Timestamp: time.Unix(int64(20), 0), }) @@ -163,7 +168,7 @@ func TestCancelOrder_Error(t *testing.T) { ctx := ks.Ctx.WithBlockHeight(2) ctx = ctx.WithBlockTime(time.Unix(int64(2), 0)) ks.BlockTimeKeeper.SetPreviousBlockInfo(ctx, &blocktimetypes.BlockInfo{ - Height: 2, + Height: 1, Timestamp: time.Unix(int64(2), 0), }) @@ -204,7 +209,7 @@ func TestCancelOrder_Success(t *testing.T) { ctx := ks.Ctx.WithBlockHeight(2) ctx = ctx.WithBlockTime(time.Unix(int64(2), 0)) ks.BlockTimeKeeper.SetPreviousBlockInfo(ctx, &blocktimetypes.BlockInfo{ - Height: 2, + Height: 1, Timestamp: time.Unix(int64(2), 0), }) @@ -213,12 +218,6 @@ func TestCancelOrder_Success(t *testing.T) { "AddTxnEvent", ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewStatefulOrderRemovalEvent( - tc.StatefulOrderPlacement.GetOrderId(), - indexershared.OrderRemovalReason_ORDER_REMOVAL_REASON_USER_CANCELED, - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewStatefulOrderRemovalEvent( diff --git a/protocol/x/clob/keeper/msg_server_create_clob_pair.go b/protocol/x/clob/keeper/msg_server_create_clob_pair.go index 8962dce50d..12e61338e8 100644 --- a/protocol/x/clob/keeper/msg_server_create_clob_pair.go +++ b/protocol/x/clob/keeper/msg_server_create_clob_pair.go @@ -21,8 +21,9 @@ func (k msgServer) CreateClobPair( ctx := sdk.UnwrapSDKContext(goCtx) defer func() { + metrics.IncrSuccessOrErrorCounter(err, types.ModuleName, metrics.CreateClobPair, metrics.DeliverTx) if err != nil { - errorlib.LogErrorWithBlockHeight(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), metrics.DeliverTx) + errorlib.LogDeliverTxError(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), "CreateClobPair", msg) } }() diff --git a/protocol/x/clob/keeper/msg_server_create_clob_pair_test.go b/protocol/x/clob/keeper/msg_server_create_clob_pair_test.go index 0102a7b311..c947629f1d 100644 --- a/protocol/x/clob/keeper/msg_server_create_clob_pair_test.go +++ b/protocol/x/clob/keeper/msg_server_create_clob_pair_test.go @@ -51,20 +51,6 @@ func TestCreateClobPair(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - testClobPair1.MustGetPerpetualId(), - testClobPair1.GetId(), - testPerp1.Params.Ticker, - testPerp1.Params.MarketId, - testClobPair1.Status, - testClobPair1.QuantumConversionExponent, - testPerp1.Params.AtomicResolution, - testClobPair1.SubticksPerTick, - testClobPair1.StepBaseQuantums, - testPerp1.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( diff --git a/protocol/x/clob/keeper/msg_server_place_order.go b/protocol/x/clob/keeper/msg_server_place_order.go index d05f5ca91f..479f01f5f3 100644 --- a/protocol/x/clob/keeper/msg_server_place_order.go +++ b/protocol/x/clob/keeper/msg_server_place_order.go @@ -5,7 +5,6 @@ import ( errorsmod "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" "github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager" @@ -25,8 +24,15 @@ func (k msgServer) PlaceOrder(goCtx context.Context, msg *types.MsgPlaceOrder) ( ctx := sdk.UnwrapSDKContext(goCtx) defer func() { + metrics.IncrSuccessOrErrorCounter( + err, + types.ModuleName, + metrics.PlaceOrder, + metrics.DeliverTx, + msg.Order.GetOrderLabels()..., + ) if err != nil { - errorlib.LogErrorWithBlockHeight(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), metrics.DeliverTx) + errorlib.LogDeliverTxError(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), "PlaceOrder", msg) } }() @@ -66,11 +72,6 @@ func (k msgServer) PlaceOrder(goCtx context.Context, msg *types.MsgPlaceOrder) ( k.Keeper.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewConditionalOrderPlacementEvent( - order, - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewConditionalOrderPlacementEvent( @@ -86,11 +87,6 @@ func (k msgServer) PlaceOrder(goCtx context.Context, msg *types.MsgPlaceOrder) ( k.Keeper.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewLongTermOrderPlacementEvent( - order, - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewLongTermOrderPlacementEvent( @@ -109,11 +105,5 @@ func (k msgServer) PlaceOrder(goCtx context.Context, msg *types.MsgPlaceOrder) ( processProposerMatchesEvents, ) - telemetry.IncrCounterWithLabels( - []string{types.ModuleName, metrics.StatefulOrderMsgHandlerSuccess, metrics.Count}, - 1, - order.GetOrderLabels(), - ) - return &types.MsgPlaceOrderResponse{}, nil } diff --git a/protocol/x/clob/keeper/msg_server_place_order_test.go b/protocol/x/clob/keeper/msg_server_place_order_test.go index f551160253..7951bfb6b1 100644 --- a/protocol/x/clob/keeper/msg_server_place_order_test.go +++ b/protocol/x/clob/keeper/msg_server_place_order_test.go @@ -114,20 +114,6 @@ func TestPlaceOrder_Error(t *testing.T) { indexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - clobtest.MustPerpetualId(clobPair), - clobPair.Id, - perpetual.Params.Ticker, - perpetual.Params.MarketId, - clobPair.Status, - clobPair.QuantumConversionExponent, - perpetual.Params.AtomicResolution, - clobPair.SubticksPerTick, - clobPair.StepBaseQuantums, - perpetual.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -269,20 +255,6 @@ func TestPlaceOrder_Success(t *testing.T) { indexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - perpetual.Params.Ticker, - perpetual.Params.MarketId, - clobPair.Status, - clobPair.QuantumConversionExponent, - perpetual.Params.AtomicResolution, - clobPair.SubticksPerTick, - clobPair.StepBaseQuantums, - perpetual.Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -316,11 +288,6 @@ func TestPlaceOrder_Success(t *testing.T) { "AddTxnEvent", ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewConditionalOrderPlacementEvent( - tc.StatefulOrderPlacement, - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewConditionalOrderPlacementEvent( @@ -333,11 +300,6 @@ func TestPlaceOrder_Success(t *testing.T) { "AddTxnEvent", ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewLongTermOrderPlacementEvent( - tc.StatefulOrderPlacement, - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewLongTermOrderPlacementEvent( diff --git a/protocol/x/clob/keeper/msg_server_proposed_operations.go b/protocol/x/clob/keeper/msg_server_proposed_operations.go index 0b0c16fc2b..fc077039fa 100644 --- a/protocol/x/clob/keeper/msg_server_proposed_operations.go +++ b/protocol/x/clob/keeper/msg_server_proposed_operations.go @@ -16,8 +16,9 @@ func (k msgServer) ProposedOperations( ctx := sdk.UnwrapSDKContext(goCtx) defer func() { + metrics.IncrSuccessOrErrorCounter(err, types.ModuleName, metrics.ProposedOperations, metrics.DeliverTx) if err != nil { - errorlib.LogErrorWithBlockHeight(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), metrics.DeliverTx) + errorlib.LogDeliverTxError(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), "ProposedOperations", msg) } }() diff --git a/protocol/x/clob/keeper/msg_server_proposed_operations_test.go b/protocol/x/clob/keeper/msg_server_proposed_operations_test.go index 459a33016a..7e0311da0f 100644 --- a/protocol/x/clob/keeper/msg_server_proposed_operations_test.go +++ b/protocol/x/clob/keeper/msg_server_proposed_operations_test.go @@ -30,7 +30,14 @@ func TestProposedOperations(t *testing.T) { setupMocks: func(ctx sdk.Context, mck *mocks.ClobKeeper) { mck.On("ProcessProposerOperations", ctx, operationsQueue).Return(testError) mockLogger := &mocks.Logger{} - mockLogger.On("Error", "Block height: 20, Callback: deliver_tx: error").Return() + mockLogger.On( + "Error", + []interface{}{ + testError.Error(), + mock.Anything, mock.Anything, mock.Anything, mock.Anything, + mock.Anything, mock.Anything, mock.Anything, mock.Anything, + }..., + ).Return() mck.On("Logger", ctx).Return(mockLogger) }, expectedErr: testError, diff --git a/protocol/x/clob/keeper/msg_server_update_block_rate_limit_config.go b/protocol/x/clob/keeper/msg_server_update_block_rate_limit_config.go index cd423ec21a..bdf10ee340 100644 --- a/protocol/x/clob/keeper/msg_server_update_block_rate_limit_config.go +++ b/protocol/x/clob/keeper/msg_server_update_block_rate_limit_config.go @@ -20,8 +20,9 @@ func (k msgServer) UpdateBlockRateLimitConfiguration( ctx := sdk.UnwrapSDKContext(goCtx) defer func() { + metrics.IncrSuccessOrErrorCounter(err, types.ModuleName, metrics.UpdateBlockRateLimitConfiguration, metrics.DeliverTx) if err != nil { - errorlib.LogErrorWithBlockHeight(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), metrics.DeliverTx) + errorlib.LogDeliverTxError(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), "UpdateBlockRateLimitConfiguration", msg) } }() diff --git a/protocol/x/clob/keeper/msg_server_update_clob_pair.go b/protocol/x/clob/keeper/msg_server_update_clob_pair.go index 39f8b8dc54..2d03f5f0d8 100644 --- a/protocol/x/clob/keeper/msg_server_update_clob_pair.go +++ b/protocol/x/clob/keeper/msg_server_update_clob_pair.go @@ -19,8 +19,9 @@ func (k msgServer) UpdateClobPair( ctx := sdk.UnwrapSDKContext(goCtx) defer func() { + metrics.IncrSuccessOrErrorCounter(err, types.ModuleName, metrics.UpdateClobPair, metrics.DeliverTx) if err != nil { - errorlib.LogErrorWithBlockHeight(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), metrics.DeliverTx) + errorlib.LogDeliverTxError(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), "UpdateClobPair", msg) } }() diff --git a/protocol/x/clob/keeper/msg_server_update_clob_pair_test.go b/protocol/x/clob/keeper/msg_server_update_clob_pair_test.go index 0c0432c775..a015825741 100644 --- a/protocol/x/clob/keeper/msg_server_update_clob_pair_test.go +++ b/protocol/x/clob/keeper/msg_server_update_clob_pair_test.go @@ -61,15 +61,6 @@ func TestMsgServerUpdateClobPair(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypeUpdateClobPair, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewUpdateClobPairEvent( - clobPair.GetClobPairId(), - types.ClobPair_STATUS_ACTIVE, - clobPair.QuantumConversionExponent, - types.SubticksPerTick(clobPair.GetSubticksPerTick()), - satypes.BaseQuantums(clobPair.GetStepBaseQuantums()), - ), - ), indexerevents.UpdateClobPairEventVersion, indexer_manager.GetBytes( indexerevents.NewUpdateClobPairEvent( diff --git a/protocol/x/clob/keeper/msg_server_update_equity_tier_limit_config.go b/protocol/x/clob/keeper/msg_server_update_equity_tier_limit_config.go index 54a182d42b..86cf1f1c6e 100644 --- a/protocol/x/clob/keeper/msg_server_update_equity_tier_limit_config.go +++ b/protocol/x/clob/keeper/msg_server_update_equity_tier_limit_config.go @@ -20,8 +20,14 @@ func (k msgServer) UpdateEquityTierLimitConfiguration( ctx := sdk.UnwrapSDKContext(goCtx) defer func() { + metrics.IncrSuccessOrErrorCounter( + err, + types.ModuleName, + metrics.UpdateEquityTierLimitConfiguration, + metrics.DeliverTx, + ) if err != nil { - errorlib.LogErrorWithBlockHeight(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), metrics.DeliverTx) + errorlib.LogDeliverTxError(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), "UpdateEquityTierLimitConfiguration", msg) } }() diff --git a/protocol/x/clob/keeper/msg_server_update_liquidations_config.go b/protocol/x/clob/keeper/msg_server_update_liquidations_config.go index 47c1868b96..2345d4f3fa 100644 --- a/protocol/x/clob/keeper/msg_server_update_liquidations_config.go +++ b/protocol/x/clob/keeper/msg_server_update_liquidations_config.go @@ -20,8 +20,9 @@ func (k msgServer) UpdateLiquidationsConfig( ctx := sdk.UnwrapSDKContext(goCtx) defer func() { + metrics.IncrSuccessOrErrorCounter(err, types.ModuleName, metrics.UpdateLiquidationsConfig, metrics.DeliverTx) if err != nil { - errorlib.LogErrorWithBlockHeight(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), metrics.DeliverTx) + errorlib.LogDeliverTxError(k.Keeper.Logger(ctx), err, ctx.BlockHeight(), "UpdateLiquidationsConfig", msg) } }() diff --git a/protocol/x/clob/keeper/order_cancellation_test.go b/protocol/x/clob/keeper/order_cancellation_test.go index 5b3ec1c7ad..1774804ac1 100644 --- a/protocol/x/clob/keeper/order_cancellation_test.go +++ b/protocol/x/clob/keeper/order_cancellation_test.go @@ -130,7 +130,7 @@ func TestCancelOrder_KeeperForwardsErrorsFromMemclob(t *testing.T) { ks := keepertest.NewClobKeepersTestContext(t, memClob, &mocks.BankKeeper{}, &mocks.IndexerEventManager{}) ctx := ks.Ctx.WithIsCheckTx(true) ks.BlockTimeKeeper.SetPreviousBlockInfo(ctx, &blocktimetypes.BlockInfo{ - Height: 1, + Height: 14, Timestamp: time.Unix(int64(50), 0), }) diff --git a/protocol/x/clob/keeper/orders.go b/protocol/x/clob/keeper/orders.go index f7007e3f05..451adf44ea 100644 --- a/protocol/x/clob/keeper/orders.go +++ b/protocol/x/clob/keeper/orders.go @@ -7,6 +7,7 @@ import ( "time" errorsmod "cosmossdk.io/errors" + gometrics "github.com/armon/go-metrics" "github.com/cometbft/cometbft/crypto/tmhash" "github.com/cosmos/cosmos-sdk/telemetry" @@ -130,18 +131,37 @@ func (k Keeper) PlaceShortTermOrder( func (k Keeper) CancelStatefulOrder( ctx sdk.Context, msg *types.MsgCancelOrder, -) error { +) (err error) { + defer func() { + if err != nil { + telemetry.IncrCounterWithLabels( + []string{types.ModuleName, metrics.CancelStatefulOrder, metrics.Error, metrics.Count}, + 1, + []gometrics.Label{ + metrics.GetLabelForStringValue(metrics.Callback, metrics.GetCallbackMetricFromCtx(ctx)), + }, + ) + } else { + telemetry.IncrCounterWithLabels( + []string{types.ModuleName, metrics.CancelStatefulOrder, metrics.Success, metrics.Count}, + 1, + []gometrics.Label{ + metrics.GetLabelForStringValue(metrics.Callback, metrics.GetCallbackMetricFromCtx(ctx)), + }, + ) + } + }() + // 1. If this is a Short-Term order, panic. msg.OrderId.MustBeStatefulOrder() // 2. Perform stateful validation on the order cancellation. - err := k.PerformOrderCancellationStatefulValidation( + if err := k.PerformOrderCancellationStatefulValidation( ctx, msg, // Note that the blockHeight is not used during stateful order cancellation validation. 0, - ) - if err != nil { + ); err != nil { return err } @@ -179,7 +199,27 @@ func (k Keeper) CancelStatefulOrder( func (k Keeper) PlaceStatefulOrder( ctx sdk.Context, msg *types.MsgPlaceOrder, -) error { +) (err error) { + defer func() { + if err != nil { + telemetry.IncrCounterWithLabels( + []string{types.ModuleName, metrics.PlaceStatefulOrder, metrics.Error, metrics.Count}, + 1, + []gometrics.Label{ + metrics.GetLabelForStringValue(metrics.Callback, metrics.GetCallbackMetricFromCtx(ctx)), + }, + ) + } else { + telemetry.IncrCounterWithLabels( + []string{types.ModuleName, metrics.PlaceStatefulOrder, metrics.Success, metrics.Count}, + 1, + []gometrics.Label{ + metrics.GetLabelForStringValue(metrics.Callback, metrics.GetCallbackMetricFromCtx(ctx)), + }, + ) + } + }() + // 1. Ensure the order is not a Short-Term order. order := msg.Order order.OrderId.MustBeStatefulOrder() @@ -516,17 +556,41 @@ func (k Keeper) PerformOrderCancellationStatefulValidation( ) error { orderIdToCancel := msgCancelOrder.GetOrderId() if orderIdToCancel.IsStatefulOrder() { + previousBlockInfo := k.blockTimeKeeper.GetPreviousBlockInfo(ctx) + + prevBlockHeight := previousBlockInfo.Height + currBlockHeight := uint32(ctx.BlockHeight()) + if lib.IsDeliverTxMode(ctx) && prevBlockHeight != currBlockHeight-1 { + k.Logger(ctx).Error( + "PerformOrderCancellationStatefulValidation: prev block height is not one below"+ + "current block height in DeliverTx", + "previousBlockHeight", prevBlockHeight, + "currentBlockHeight", currBlockHeight, + "msgCancelOrder", msgCancelOrder, + ) + } + + // CheckTx or ReCheckTx + if !lib.IsDeliverTxMode(ctx) && currBlockHeight > 1 && prevBlockHeight != currBlockHeight { + k.Logger(ctx).Error( + "PerformOrderCancellationStatefulValidation: prev block height is not equal to current block height"+ + metrics.Callback, metrics.GetCallbackMetricFromCtx(ctx), + "previousBlockHeight", prevBlockHeight, + "currentBlockHeight", currBlockHeight, + "msgCancelOrder", msgCancelOrder, + ) + } + cancelGoodTilBlockTime := msgCancelOrder.GetGoodTilBlockTime() - previousBlockTime := k.blockTimeKeeper.GetPreviousBlockInfo(ctx).Timestamp // Return an error if `goodTilBlockTime` is less than previous block's blockTime - if cancelGoodTilBlockTime <= lib.MustConvertIntegerToUint32(previousBlockTime.Unix()) { + if cancelGoodTilBlockTime <= lib.MustConvertIntegerToUint32(previousBlockInfo.Timestamp.Unix()) { return types.ErrTimeExceedsGoodTilBlockTime } // Return an error if `goodTilBlockTime` is further into the future // than the previous block time plus `StatefulOrderTimeWindow`. - endTime := previousBlockTime.Add(types.StatefulOrderTimeWindow) + endTime := previousBlockInfo.Timestamp.Add(types.StatefulOrderTimeWindow) if cancelGoodTilBlockTime > lib.MustConvertIntegerToUint32(endTime.Unix()) { return errorsmod.Wrapf( types.ErrGoodTilBlockTimeExceedsStatefulOrderTimeWindow, diff --git a/protocol/x/clob/keeper/orders_test.go b/protocol/x/clob/keeper/orders_test.go index 482f029b22..6419c7be7b 100644 --- a/protocol/x/clob/keeper/orders_test.go +++ b/protocol/x/clob/keeper/orders_test.go @@ -1014,20 +1014,6 @@ func TestPlaceOrder_SendOffchainMessages(t *testing.T) { indexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.MarketId, - constants.ClobPair_Btc.Status, - constants.ClobPair_Btc.QuantumConversionExponent, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.AtomicResolution, - constants.ClobPair_Btc.SubticksPerTick, - constants.ClobPair_Btc.StepBaseQuantums, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -1082,20 +1068,6 @@ func TestPerformStatefulOrderValidation_PreExistingStatefulOrder(t *testing.T) { indexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.MarketId, - constants.ClobPair_Btc.Status, - constants.ClobPair_Btc.QuantumConversionExponent, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.AtomicResolution, - constants.ClobPair_Btc.SubticksPerTick, - constants.ClobPair_Btc.StepBaseQuantums, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -1826,20 +1798,6 @@ func TestGetStatePosition_Success(t *testing.T) { indexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - perpetualId, - uint32(i), - constants.Perpetuals_DefaultGenesisState.Perpetuals[i].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[i].Params.MarketId, - cp.Status, - cp.QuantumConversionExponent, - constants.Perpetuals_DefaultGenesisState.Perpetuals[i].Params.AtomicResolution, - cp.SubticksPerTick, - cp.StepBaseQuantums, - constants.Perpetuals_DefaultGenesisState.Perpetuals[i].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -2053,20 +2011,6 @@ func TestInitStatefulOrders(t *testing.T) { indexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.MarketId, - constants.ClobPair_Btc.Status, - constants.ClobPair_Btc.QuantumConversionExponent, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.AtomicResolution, - constants.ClobPair_Btc.SubticksPerTick, - constants.ClobPair_Btc.StepBaseQuantums, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -2215,20 +2159,6 @@ func TestHydrateUntriggeredConditionalOrdersInMemClob(t *testing.T) { indexerEventManager.On("AddTxnEvent", ks.Ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - 0, - 0, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.MarketId, - constants.ClobPair_Btc.Status, - constants.ClobPair_Btc.QuantumConversionExponent, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.AtomicResolution, - constants.ClobPair_Btc.SubticksPerTick, - constants.ClobPair_Btc.StepBaseQuantums, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( diff --git a/protocol/x/clob/keeper/process_operations.go b/protocol/x/clob/keeper/process_operations.go index 5304625cf1..d0a9a80621 100644 --- a/protocol/x/clob/keeper/process_operations.go +++ b/protocol/x/clob/keeper/process_operations.go @@ -410,14 +410,6 @@ func (k Keeper) PersistOrderRemovalToState( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewStatefulOrderRemovalEvent( - orderIdToRemove, - indexershared.ConvertOrderRemovalReasonToIndexerOrderRemovalReason( - orderRemoval.RemovalReason, - ), - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewStatefulOrderRemovalEvent( @@ -515,17 +507,6 @@ func (k Keeper) PersistMatchOrdersToState( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeOrderFill, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewOrderFillEvent( - matchWithOrders.MakerOrder.MustGetOrder(), - matchWithOrders.TakerOrder.MustGetOrder(), - matchWithOrders.FillAmount, - matchWithOrders.MakerFee, - matchWithOrders.TakerFee, - totalFilledMaker, - totalFilledTaker, - ), - ), indexerevents.OrderFillEventVersion, indexer_manager.GetBytes( indexerevents.NewOrderFillEvent( @@ -632,16 +613,6 @@ func (k Keeper) PersistMatchLiquidationToState( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeOrderFill, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewLiquidationOrderFillEvent( - matchWithOrders.MakerOrder.MustGetOrder(), - matchWithOrders.TakerOrder, - matchWithOrders.FillAmount, - matchWithOrders.MakerFee, - matchWithOrders.TakerFee, - totalFilledMaker, - ), - ), indexerevents.OrderFillEventVersion, indexer_manager.GetBytes( indexerevents.NewLiquidationOrderFillEvent( diff --git a/protocol/x/clob/keeper/process_operations_test.go b/protocol/x/clob/keeper/process_operations_test.go index 720bd8a8da..0bdcf20d46 100644 --- a/protocol/x/clob/keeper/process_operations_test.go +++ b/protocol/x/clob/keeper/process_operations_test.go @@ -1733,20 +1733,6 @@ func setupProcessProposerOperationsTestCase( mockIndexerEventManager.On("AddTxnEvent", mock.Anything, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - perpetualId, - uint32(i), - tc.perpetuals[perpetualId].Params.Ticker, - tc.perpetuals[perpetualId].Params.MarketId, - clobPair.Status, - clobPair.QuantumConversionExponent, - tc.perpetuals[perpetualId].Params.AtomicResolution, - clobPair.SubticksPerTick, - clobPair.StepBaseQuantums, - tc.perpetuals[perpetualId].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( @@ -1918,16 +1904,6 @@ func setupNewMockEventManager( call := mockIndexerEventManager.On("AddTxnEvent", mock.Anything, indexerevents.SubtypeOrderFill, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewLiquidationOrderFillEvent( - match.MakerOrder.MustGetOrder(), - match.TakerOrder, - match.FillAmount, - match.MakerFee, - match.TakerFee, - match.TotalFilledTaker, - ), - ), indexerevents.OrderFillEventVersion, indexer_manager.GetBytes( indexerevents.NewLiquidationOrderFillEvent( @@ -1946,17 +1922,6 @@ func setupNewMockEventManager( call := mockIndexerEventManager.On("AddTxnEvent", mock.Anything, indexerevents.SubtypeOrderFill, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewOrderFillEvent( - match.MakerOrder.MustGetOrder(), - match.TakerOrder.MustGetOrder(), - match.FillAmount, - match.MakerFee, - match.TakerFee, - match.TotalFilledMaker, - match.TotalFilledTaker, - ), - ), indexerevents.OrderFillEventVersion, indexer_manager.GetBytes( indexerevents.NewOrderFillEvent( @@ -1980,14 +1945,6 @@ func setupNewMockEventManager( mockIndexerEventManager.On("AddTxnEvent", mock.Anything, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewStatefulOrderRemovalEvent( - removal.OrderRemoval.OrderId, - shared.ConvertOrderRemovalReasonToIndexerOrderRemovalReason( - removal.OrderRemoval.RemovalReason, - ), - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewStatefulOrderRemovalEvent( diff --git a/protocol/x/clob/keeper/untriggered_conditional_orders.go b/protocol/x/clob/keeper/untriggered_conditional_orders.go index 5b1f650de2..f4d6094699 100644 --- a/protocol/x/clob/keeper/untriggered_conditional_orders.go +++ b/protocol/x/clob/keeper/untriggered_conditional_orders.go @@ -307,11 +307,6 @@ func (k Keeper) MaybeTriggerConditionalOrders(ctx sdk.Context) (triggeredConditi k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeStatefulOrder, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewConditionalOrderTriggeredEvent( - triggeredConditionalOrderId, - ), - ), indexerevents.StatefulOrderEventVersion, indexer_manager.GetBytes( indexerevents.NewConditionalOrderTriggeredEvent( diff --git a/protocol/x/clob/module_test.go b/protocol/x/clob/module_test.go index 33cdb2b776..94887e0a9e 100644 --- a/protocol/x/clob/module_test.go +++ b/protocol/x/clob/module_test.go @@ -303,20 +303,6 @@ func TestAppModule_InitExportGenesis(t *testing.T) { mockIndexerEventManager.On("AddTxnEvent", ctx, indexerevents.SubtypePerpetualMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPerpetualMarketCreateEvent( - uint32(0), - uint32(0), - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.Ticker, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.MarketId, - clob_types.ClobPair_STATUS_ACTIVE, - 0, - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.AtomicResolution, - uint32(100), - uint64(5), - constants.Perpetuals_DefaultGenesisState.Perpetuals[0].Params.LiquidityTier, - ), - ), indexerevents.PerpetualMarketEventVersion, indexer_manager.GetBytes( indexerevents.NewPerpetualMarketCreateEvent( diff --git a/protocol/x/clob/types/order_id_test.go b/protocol/x/clob/types/order_id_test.go index 1e3161ae55..4b8786bf1d 100644 --- a/protocol/x/clob/types/order_id_test.go +++ b/protocol/x/clob/types/order_id_test.go @@ -16,7 +16,7 @@ import ( // `OrderFlags` is greater than one byte (proto varints are encoded with 7 bits per byte). const numOrderIdFlagsTestCases = 129 -func TestMustMarshal(t *testing.T) { +func TestToStateKey(t *testing.T) { // Success b, _ := constants.OrderId_Alice_Num0_ClientId0_Clob0.Marshal() require.Equal(t, b, constants.OrderId_Alice_Num0_ClientId0_Clob0.ToStateKey()) diff --git a/protocol/x/delaymsg/keeper/delayed_message.go b/protocol/x/delaymsg/keeper/delayed_message.go index bc445e09cc..561e84e90f 100644 --- a/protocol/x/delaymsg/keeper/delayed_message.go +++ b/protocol/x/delaymsg/keeper/delayed_message.go @@ -119,6 +119,29 @@ func (k Keeper) SetDelayedMessage( ) ( err error, ) { + // Unpack the message and validate it. + // For messages that are being set from genesis state, we need to unpack the Any type to hydrate the cached value. + if err = msg.UnpackInterfaces(k.cdc); err != nil { + return err + } + + sdkMsg, err := msg.GetMessage() + if err != nil { + return errorsmod.Wrapf( + types.ErrInvalidInput, + "failed to delay msg: failed to get message with error '%v'", + err, + ) + } + + if err := k.ValidateMsg(sdkMsg); err != nil { + return errorsmod.Wrapf( + types.ErrInvalidInput, + "failed to delay message: failed to validate with error '%v'", + err, + ) + } + if msg.BlockHeight < lib.MustConvertIntegerToUint32(ctx.BlockHeight()) { return errorsmod.Wrapf( types.ErrInvalidInput, @@ -166,26 +189,19 @@ func validateSigners(msg sdk.Msg) error { return nil } -// DelayMessageByBlocks registers an sdk.Msg to be executed after blockDelay blocks. -func (k Keeper) DelayMessageByBlocks( - ctx sdk.Context, - msg sdk.Msg, - blockDelay uint32, -) ( - id uint32, - err error, -) { +// ValidateMsg validates that a message is routable, passes ValidateBasic, and has the expected signer. +func (k Keeper) ValidateMsg(msg sdk.Msg) error { handler := k.router.Handler(msg) // If the message type is not routable, return an error. if handler == nil { - return 0, errorsmod.Wrapf( + return errorsmod.Wrapf( types.ErrMsgIsUnroutable, sdk.MsgTypeURL(msg), ) } if err := msg.ValidateBasic(); err != nil { - return 0, errorsmod.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidInput, "message failed basic validation: %v", err, @@ -193,10 +209,21 @@ func (k Keeper) DelayMessageByBlocks( } if err := validateSigners(msg); err != nil { - return 0, err + return err } - nextId := k.GetNumMessages(ctx) + return nil +} + +// DelayMessageByBlocks registers an sdk.Msg to be executed after blockDelay blocks. +func (k Keeper) DelayMessageByBlocks( + ctx sdk.Context, + msg sdk.Msg, + blockDelay uint32, +) ( + id uint32, + err error, +) { blockHeight, err := lib.AddUint32(ctx.BlockHeight(), blockDelay) if err != nil { return 0, errorsmod.Wrapf( @@ -215,6 +242,7 @@ func (k Keeper) DelayMessageByBlocks( ) } + nextId := k.GetNumMessages(ctx) delayedMessage := types.DelayedMessage{ Id: nextId, Msg: anyMsg, diff --git a/protocol/x/delaymsg/keeper/delayed_message_test.go b/protocol/x/delaymsg/keeper/delayed_message_test.go index 8efaa4dd0d..a5fc349e8b 100644 --- a/protocol/x/delaymsg/keeper/delayed_message_test.go +++ b/protocol/x/delaymsg/keeper/delayed_message_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "fmt" + "math" "testing" "github.com/dydxprotocol/v4-chain/protocol/mocks" @@ -168,16 +169,13 @@ func TestDelayMessageByBlocks_Failures(t *testing.T) { tests := map[string]struct { msg sdk.Msg expectedError string + overflow bool }{ "No handler found": { msg: constants.NoHandlerMsg, expectedError: "/testpb.TestMsg: Message not recognized by router", }, - "Message fails ValidateBasic": { - msg: routableInvalidSdkMsg(), - expectedError: "message failed basic validation: Invalid msg: Invalid input", - }, - "Message fails validateSigners": { + "Message fails validation": { msg: &bridgetypes.MsgCompleteBridge{ Authority: authtypes.NewModuleAddress(bridgetypes.ModuleName).String(), Event: constants.BridgeEvent_Id0_Height0, @@ -188,11 +186,23 @@ func TestDelayMessageByBlocks_Failures(t *testing.T) { msg: unencodableSdkMsg(), expectedError: "failed to convert message to Any: Invalid input", }, + "Block number overflows": { + msg: constants.TestMsg1, + overflow: true, + expectedError: "failed to add block delay", + }, } for name, tc := range tests { t.Run(name, func(t *testing.T) { ctx, delaymsg, _, _, _, _ := keepertest.DelayMsgKeepers(t) - _, err := delaymsg.DelayMessageByBlocks(ctx, tc.msg, blockDelay1) + + delay := uint32(blockDelay1) + if tc.overflow { + ctx = ctx.WithBlockHeight(math.MaxInt64 - blockDelay1 - 1) + delay = math.MaxUint32 + } + + _, err := delaymsg.DelayMessageByBlocks(ctx, tc.msg, delay) require.ErrorContains(t, err, tc.expectedError) }) } @@ -333,10 +343,47 @@ func TestGetMessage_NotFound(t *testing.T) { require.Zero(t, delayedMsg) } +func TestValidateMsg(t *testing.T) { + tests := map[string]struct { + msg sdk.Msg + expectedError string + }{ + "No handler found": { + msg: constants.NoHandlerMsg, + expectedError: "/testpb.TestMsg: Message not recognized by router", + }, + "Message fails ValidateBasic": { + msg: routableInvalidSdkMsg(), + expectedError: "message failed basic validation: Invalid msg: Invalid input", + }, + "Message fails validateSigners": { + msg: &bridgetypes.MsgCompleteBridge{ + Authority: authtypes.NewModuleAddress(bridgetypes.ModuleName).String(), + Event: constants.BridgeEvent_Id0_Height0, + }, + expectedError: "message signer must be delaymsg module address: Invalid signer", + }, + "Valid message": { + msg: constants.TestMsg1, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + _, delaymsg, _, _, _, _ := keepertest.DelayMsgKeepers(t) + err := delaymsg.ValidateMsg(tc.msg) + if tc.expectedError == "" { + require.NoError(t, err) + } else { + require.ErrorContains(t, err, tc.expectedError) + } + }) + } +} + func TestSetDelayedMessage(t *testing.T) { tests := map[string]struct { msg types.DelayedMessage - expErr error + expErr string }{ "Success": { msg: types.DelayedMessage{ @@ -345,13 +392,31 @@ func TestSetDelayedMessage(t *testing.T) { BlockHeight: 1, }, }, + "nil msg": { + msg: types.DelayedMessage{}, + expErr: "failed to delay msg: failed to get message with error 'Delayed msg is nil': Invalid input", + }, + "invalid msg": { + msg: types.DelayedMessage{ + Id: 0, + Msg: encoding.EncodeMessageToAny( + t, + &bridgetypes.MsgCompleteBridge{ + Authority: authtypes.NewModuleAddress(bridgetypes.ModuleName).String(), + Event: constants.BridgeEvent_Id0_Height0, + }, + ), + BlockHeight: 1, + }, + expErr: "failed to delay message: failed to validate with error 'message signer must be delaymsg", + }, "invalid block height": { msg: types.DelayedMessage{ Id: 0, Msg: encoding.EncodeMessageToAny(t, constants.TestMsg1), BlockHeight: 0, }, - expErr: fmt.Errorf("failed to delay message: block height 0 is in the past: Invalid input"), + expErr: "failed to delay message: block height 0 is in the past: Invalid input", }, "duplicate id": { msg: types.DelayedMessage{ @@ -359,7 +424,7 @@ func TestSetDelayedMessage(t *testing.T) { Msg: encoding.EncodeMessageToAny(t, constants.TestMsg1), BlockHeight: 1, }, - expErr: fmt.Errorf("failed to delay message: message with id 1 already exists: Invalid input"), + expErr: "failed to delay message: message with id 1 already exists: Invalid input", }, } for name, tc := range tests { @@ -378,10 +443,10 @@ func TestSetDelayedMessage(t *testing.T) { ctx = ctx.WithBlockHeight(1) err = delaymsg.SetDelayedMessage(ctx, &tc.msg) - if tc.expErr == nil { + if tc.expErr == "" { require.NoError(t, err) } else { - require.EqualError(t, tc.expErr, err.Error()) + require.ErrorContains(t, err, tc.expErr) } }) } diff --git a/protocol/x/perpetuals/keeper/perpetual.go b/protocol/x/perpetuals/keeper/perpetual.go index 028e998fac..4cdfdd6084 100644 --- a/protocol/x/perpetuals/keeper/perpetual.go +++ b/protocol/x/perpetuals/keeper/perpetual.go @@ -121,15 +121,6 @@ func (k Keeper) ModifyPerpetual( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeUpdatePerpetual, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewUpdatePerpetualEventV1( - perpetual.Params.Id, - perpetual.Params.Ticker, - perpetual.Params.MarketId, - perpetual.Params.AtomicResolution, - perpetual.Params.LiquidityTier, - ), - ), indexerevents.UpdatePerpetualEventVersion, indexer_manager.GetBytes( indexerevents.NewUpdatePerpetualEventV1( @@ -328,9 +319,6 @@ func (k Keeper) processPremiumVotesIntoSamples( k.indexerEventManager.AddBlockEvent( ctx, indexerevents.SubtypeFundingValues, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewPremiumSamplesEvent(newSamplesForEvent), - ), indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK, indexerevents.FundingValuesEventVersion, indexer_manager.GetBytes( @@ -726,9 +714,6 @@ func (k Keeper) MaybeProcessNewFundingTickEpoch(ctx sdk.Context) { k.indexerEventManager.AddBlockEvent( ctx, indexerevents.SubtypeFundingValues, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewFundingRatesAndIndicesEvent(newFundingRatesAndIndicesForEvent), - ), indexer_manager.IndexerTendermintEvent_BLOCK_EVENT_END_BLOCK, indexerevents.FundingValuesEventVersion, indexer_manager.GetBytes( @@ -1301,15 +1286,6 @@ func (k Keeper) SetLiquidityTier( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeLiquidityTier, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewLiquidityTierUpsertEvent( - id, - name, - initialMarginPpm, - maintenanceFractionPpm, - basePositionNotional, - ), - ), indexerevents.LiquidityTierEventVersion, indexer_manager.GetBytes( indexerevents.NewLiquidityTierUpsertEvent( diff --git a/protocol/x/perpetuals/keeper/perpetual_test.go b/protocol/x/perpetuals/keeper/perpetual_test.go index b5a626106f..86391b4733 100644 --- a/protocol/x/perpetuals/keeper/perpetual_test.go +++ b/protocol/x/perpetuals/keeper/perpetual_test.go @@ -123,10 +123,9 @@ func getUpdatePerpetualEventsFromIndexerBlock( continue } if _, ok := event.OrderingWithinBlock.(*indexer_manager.IndexerTendermintEvent_TransactionIndex); ok { - bytes := indexer_manager.GetBytesFromEventData(event.Data) unmarshaler := common.UnmarshalerImpl{} var updatePerpetualEvent indexerevents.UpdatePerpetualEventV1 - err := unmarshaler.Unmarshal(bytes, &updatePerpetualEvent) + err := unmarshaler.Unmarshal(event.DataBytes, &updatePerpetualEvent) if err != nil { panic(err) } @@ -2017,10 +2016,9 @@ func getFundingBlockEventsFromIndexerBlock( continue } if _, ok := event.OrderingWithinBlock.(*indexer_manager.IndexerTendermintEvent_BlockEvent_); ok { - bytes := indexer_manager.GetBytesFromEventData(event.Data) unmarshaler := common.UnmarshalerImpl{} var fundingEvent indexerevents.FundingEventV1 - err := unmarshaler.Unmarshal(bytes, &fundingEvent) + err := unmarshaler.Unmarshal(event.DataBytes, &fundingEvent) if err != nil { panic(err) } diff --git a/protocol/x/prices/genesis.go b/protocol/x/prices/genesis.go index fa77c23b46..c7cceaf8ad 100644 --- a/protocol/x/prices/genesis.go +++ b/protocol/x/prices/genesis.go @@ -29,9 +29,6 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeMarket, - indexer_manager.GetB64EncodedEventMessage( - update, - ), indexerevents.MarketEventVersion, indexer_manager.GetBytes( update, diff --git a/protocol/x/prices/keeper/market.go b/protocol/x/prices/keeper/market.go index b71f3d38fc..5d66e2779a 100644 --- a/protocol/x/prices/keeper/market.go +++ b/protocol/x/prices/keeper/market.go @@ -49,14 +49,6 @@ func (k Keeper) CreateMarket( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewMarketCreateEvent( - marketParam.Id, - marketParam.Pair, - marketParam.MinPriceChangePpm, - marketParam.Exponent, - ), - ), indexerevents.MarketEventVersion, indexer_manager.GetBytes( indexerevents.NewMarketCreateEvent( diff --git a/protocol/x/prices/keeper/market_param.go b/protocol/x/prices/keeper/market_param.go index 5292658549..db59c3f50a 100644 --- a/protocol/x/prices/keeper/market_param.go +++ b/protocol/x/prices/keeper/market_param.go @@ -52,13 +52,6 @@ func (k Keeper) ModifyMarketParam( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeMarket, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewMarketModifyEvent( - marketParam.Id, - marketParam.Pair, - marketParam.MinPriceChangePpm, - ), - ), indexerevents.MarketEventVersion, indexer_manager.GetBytes( indexerevents.NewMarketModifyEvent( diff --git a/protocol/x/prices/keeper/market_price.go b/protocol/x/prices/keeper/market_price.go index b5adcb30d9..19588c4481 100644 --- a/protocol/x/prices/keeper/market_price.go +++ b/protocol/x/prices/keeper/market_price.go @@ -99,9 +99,6 @@ func (k Keeper) UpdateMarketPrices( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeMarket, - indexer_manager.GetB64EncodedEventMessage( - update, - ), indexerevents.MarketEventVersion, indexer_manager.GetBytes( update, diff --git a/protocol/x/rewards/keeper/keeper.go b/protocol/x/rewards/keeper/keeper.go index 84aa7d30c7..96bfc51a96 100644 --- a/protocol/x/rewards/keeper/keeper.go +++ b/protocol/x/rewards/keeper/keeper.go @@ -247,7 +247,7 @@ func (k Keeper) ProcessRewardsForBlock( allRewardShares, totalRewardWeight := k.getAllRewardSharesAndTotalWeight(ctx) // Measure total reward weight. telemetry.SetGauge( - float32(totalRewardWeight.Int64()), + metrics.GetMetricValueFromBigInt(totalRewardWeight), types.ModuleName, metrics.TotalRewardShareWeight, ) @@ -274,7 +274,7 @@ func (k Keeper) ProcessRewardsForBlock( tokensToDistribute := lib.BigMin(rewardTokenBalance.Amount.BigInt(), bigIntRewardTokenAmount) // Measure distributed token amount. telemetry.SetGauge( - float32(tokensToDistribute.Int64()), + metrics.GetMetricValueFromBigInt(tokensToDistribute), types.ModuleName, metrics.DistributedRewardTokens, ) @@ -333,7 +333,7 @@ func (k Keeper) ProcessRewardsForBlock( params.Denom, ) telemetry.SetGauge( - float32(remainingTreasuryBalance.Amount.Int64()), + metrics.GetMetricValueFromBigInt(remainingTreasuryBalance.Amount.BigInt()), types.ModuleName, metrics.TreasuryBalanceAfterDistribution, ) diff --git a/protocol/x/rewards/keeper/keeper_test.go b/protocol/x/rewards/keeper/keeper_test.go index 0c06bae3e7..a523381205 100644 --- a/protocol/x/rewards/keeper/keeper_test.go +++ b/protocol/x/rewards/keeper/keeper_test.go @@ -11,6 +11,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/dydxprotocol/v4-chain/protocol/dtypes" testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" + big_testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/big" feetierstypes "github.com/dydxprotocol/v4-chain/protocol/x/feetiers/types" pricestypes "github.com/dydxprotocol/v4-chain/protocol/x/prices/types" "github.com/dydxprotocol/v4-chain/protocol/x/rewards/types" @@ -272,6 +273,7 @@ func TestAddRewardSharesForFill(t *testing.T) { func TestProcessRewardsForBlock(t *testing.T) { testRewardTokenMarketId := uint32(33) testRewardTokenMarket := "test-market" + // TODO(CORE-645): Update test to -18 denom for consistency with prod. TestRewardTokenDenomExp := int32(-6) tokenPrice2Usdc := pricestypes.MarketPrice{ @@ -408,51 +410,55 @@ func TestProcessRewardsForBlock(t *testing.T) { ZeroTreasuryAccountBalance, }, }, - "three reward shares, enough treasury balance, fee multipler = 0.99": { + "three reward shares, enough treasury balance, fee multipler = 0.99, realistic numbers": { rewardShares: []types.RewardShare{ { Address: TestAddress1, - Weight: dtypes.NewInt(1_000_000), // $1 weight of fee + Weight: dtypes.NewInt(1_025_590_000), // $1025.59 weight of fee }, { Address: TestAddress2, - Weight: dtypes.NewInt(2_000_000), // $2 weight of fee + Weight: dtypes.NewInt(2_021_300_000), // $2021.3 weight of fee }, { Address: TestAddress3, - Weight: dtypes.NewInt(3_000_000), // $3 weight of fee + Weight: dtypes.NewInt(835_660_000), // $835.66 weight of fee }, }, - tokenPrice: tokenPrice2Usdc, - treasuryAccountBalance: sdkmath.NewInt(1_000_000_000), // 1000 full coins - feeMultiplierPpm: 990_000, // 99% + tokenPrice: tokenPrice2Usdc, + treasuryAccountBalance: sdkmath.NewIntFromBigInt( + big_testutil.Int64MulPow10(2_000_123, 18), //~2_000_123 full coin. + ), // 1000 full coins + feeMultiplierPpm: 990_000, // 99% expectedBalances: []banktypes.Balance{ { Address: TestAddress1, Coins: []sdk.Coin{{ Denom: TestRewardTokenDenom, - Amount: sdkmath.NewInt(495_000), // $1 weight / $2 price * 99% = 0.495 full coin + Amount: sdkmath.NewInt(507_667_050), // $1 weight / $2 price * 99% = 0.495 full coin }}, }, { Address: TestAddress2, Coins: []sdk.Coin{{ Denom: TestRewardTokenDenom, - Amount: sdkmath.NewInt(990_000), // $2 weight / $2 price * 99% = 0.99 full coin + Amount: sdkmath.NewInt(1_000_543_500), // $2021.3 weight / $2 price * 99% ~= 1000 full coin }}, }, { Address: TestAddress3, Coins: []sdk.Coin{{ Denom: TestRewardTokenDenom, - Amount: sdkmath.NewInt(1_485_000), // $3 weight / $2 price * 99% = 1.485 full coin + Amount: sdkmath.NewInt(413_651_700), // $835.66 weight / $2 price * 99% ~= 413 full coin }}, }, { Address: authtypes.NewModuleAddress(types.TreasuryAccountName).String(), Coins: []sdk.Coin{{ - Denom: TestRewardTokenDenom, - Amount: sdkmath.NewInt(997_030_000), // 997.03 full coins + Denom: TestRewardTokenDenom, + Amount: sdkmath.NewIntFromBigInt( + big_testutil.MustFirst(new(big.Int).SetString("2000122999999998078137750", 10)), + ), // ~2_000_122.9 full coins }}, }, }, diff --git a/protocol/x/sending/app_test.go b/protocol/x/sending/app_test.go index 057251d636..7cc6c2ebd5 100644 --- a/protocol/x/sending/app_test.go +++ b/protocol/x/sending/app_test.go @@ -160,20 +160,7 @@ func TestMsgDepositToSubaccount(t *testing.T) { Time: ctx.BlockTime(), Events: []*indexer_manager.IndexerTendermintEvent{ { - Subtype: indexerevents.SubtypeSubaccountUpdate, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewSubaccountUpdateEvent( - &tc.subaccountId, - []*satypes.PerpetualPosition{}, - []*satypes.AssetPosition{ - { - AssetId: assetstypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(subaccountQuantumsAfterDeposit), - }, - }, - nil, // no funding payment should have occurred - ), - ), + Subtype: indexerevents.SubtypeSubaccountUpdate, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 0, Version: indexerevents.SubaccountUpdateEventVersion, @@ -192,15 +179,7 @@ func TestMsgDepositToSubaccount(t *testing.T) { ), }, { - Subtype: indexerevents.SubtypeTransfer, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewDepositEvent( - tc.accountAccAddress.String(), - tc.subaccountId, - tc.asset.Id, - satypes.BaseQuantums(tc.quantums.Uint64()), - ), - ), + Subtype: indexerevents.SubtypeTransfer, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 1, Version: indexerevents.TransferEventVersion, @@ -370,20 +349,7 @@ func TestMsgWithdrawFromSubaccount(t *testing.T) { Time: ctx.BlockTime(), Events: []*indexer_manager.IndexerTendermintEvent{ { - Subtype: indexerevents.SubtypeSubaccountUpdate, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewSubaccountUpdateEvent( - &tc.subaccountId, - []*satypes.PerpetualPosition{}, - []*satypes.AssetPosition{ - { - AssetId: assetstypes.AssetUsdc.Id, - Quantums: dtypes.NewIntFromBigInt(subaccountQuantumsAfterWithdraw), - }, - }, - nil, // no funding payment should have occurred - ), - ), + Subtype: indexerevents.SubtypeSubaccountUpdate, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 0, Version: indexerevents.SubaccountUpdateEventVersion, @@ -402,15 +368,7 @@ func TestMsgWithdrawFromSubaccount(t *testing.T) { ), }, { - Subtype: indexerevents.SubtypeTransfer, - Data: indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewWithdrawEvent( - tc.subaccountId, - tc.accountAccAddress.String(), - tc.asset.Id, - satypes.BaseQuantums(tc.quantums.Uint64()), - ), - ), + Subtype: indexerevents.SubtypeTransfer, OrderingWithinBlock: &indexer_manager.IndexerTendermintEvent_TransactionIndex{}, EventIndex: 1, Version: indexerevents.TransferEventVersion, diff --git a/protocol/x/sending/keeper/transfer.go b/protocol/x/sending/keeper/transfer.go index 505f191638..433c3df6ae 100644 --- a/protocol/x/sending/keeper/transfer.go +++ b/protocol/x/sending/keeper/transfer.go @@ -53,9 +53,6 @@ func (k Keeper) ProcessTransfer( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeTransfer, - indexer_manager.GetB64EncodedEventMessage( - k.GenerateTransferEvent(pendingTransfer), - ), indexerevents.TransferEventVersion, indexer_manager.GetBytes( k.GenerateTransferEvent(pendingTransfer), @@ -122,9 +119,6 @@ func (k Keeper) ProcessDepositToSubaccount( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeTransfer, - indexer_manager.GetB64EncodedEventMessage( - k.GenerateDepositEvent(msgDepositToSubaccount), - ), indexerevents.TransferEventVersion, indexer_manager.GetBytes( k.GenerateDepositEvent(msgDepositToSubaccount), @@ -189,9 +183,6 @@ func (k Keeper) ProcessWithdrawFromSubaccount( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeTransfer, - indexer_manager.GetB64EncodedEventMessage( - k.GenerateWithdrawEvent(msgWithdrawFromSubaccount), - ), indexerevents.TransferEventVersion, indexer_manager.GetBytes( k.GenerateWithdrawEvent(msgWithdrawFromSubaccount), diff --git a/protocol/x/sending/keeper/transfer_test.go b/protocol/x/sending/keeper/transfer_test.go index af4653b88b..7c7fc73028 100644 --- a/protocol/x/sending/keeper/transfer_test.go +++ b/protocol/x/sending/keeper/transfer_test.go @@ -8,7 +8,6 @@ import ( "github.com/dydxprotocol/v4-chain/protocol/indexer/common" indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" - "github.com/dydxprotocol/v4-chain/protocol/indexer/indexer_manager" "github.com/dydxprotocol/v4-chain/protocol/mocks" "github.com/dydxprotocol/v4-chain/protocol/x/sending/keeper" @@ -50,10 +49,9 @@ func assertTransferEventInIndexerBlock( if event.Subtype != indexerevents.SubtypeTransfer { continue } - bytes := indexer_manager.GetBytesFromEventData(event.Data) unmarshaler := common.UnmarshalerImpl{} var transfer indexerevents.TransferEventV1 - err := unmarshaler.Unmarshal(bytes, &transfer) + err := unmarshaler.Unmarshal(event.DataBytes, &transfer) if err != nil { panic(err) } @@ -77,10 +75,9 @@ func assertDepositEventInIndexerBlock( if event.Subtype != indexerevents.SubtypeTransfer { continue } - bytes := indexer_manager.GetBytesFromEventData(event.Data) unmarshaler := common.UnmarshalerImpl{} var deposit indexerevents.TransferEventV1 - err := unmarshaler.Unmarshal(bytes, &deposit) + err := unmarshaler.Unmarshal(event.DataBytes, &deposit) if err != nil { panic(err) } @@ -104,10 +101,9 @@ func assertWithdrawEventInIndexerBlock( if event.Subtype != indexerevents.SubtypeTransfer { continue } - bytes := indexer_manager.GetBytesFromEventData(event.Data) unmarshaler := common.UnmarshalerImpl{} var withdraw indexerevents.TransferEventV1 - err := unmarshaler.Unmarshal(bytes, &withdraw) + err := unmarshaler.Unmarshal(event.DataBytes, &withdraw) if err != nil { panic(err) } diff --git a/protocol/x/subaccounts/genesis.go b/protocol/x/subaccounts/genesis.go index 7b312cc1bd..a861f28caa 100644 --- a/protocol/x/subaccounts/genesis.go +++ b/protocol/x/subaccounts/genesis.go @@ -19,14 +19,6 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeSubaccountUpdate, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewSubaccountUpdateEvent( - elem.Id, - elem.PerpetualPositions, - elem.AssetPositions, - nil, - ), - ), indexerevents.SubaccountUpdateEventVersion, indexer_manager.GetBytes( indexerevents.NewSubaccountUpdateEvent( diff --git a/protocol/x/subaccounts/keeper/subaccount.go b/protocol/x/subaccounts/keeper/subaccount.go index e80c0100c1..35e3a04db8 100644 --- a/protocol/x/subaccounts/keeper/subaccount.go +++ b/protocol/x/subaccounts/keeper/subaccount.go @@ -299,17 +299,6 @@ func (k Keeper) UpdateSubaccounts( k.GetIndexerEventManager().AddTxnEvent( ctx, indexerevents.SubtypeSubaccountUpdate, - indexer_manager.GetB64EncodedEventMessage( - indexerevents.NewSubaccountUpdateEvent( - u.SettledSubaccount.Id, - getUpdatedPerpetualPositions( - u, - fundingPayments, - ), - getUpdatedAssetPositions(u), - fundingPayments, - ), - ), indexerevents.SubaccountUpdateEventVersion, indexer_manager.GetBytes( indexerevents.NewSubaccountUpdateEvent( diff --git a/protocol/x/vest/keeper/keeper.go b/protocol/x/vest/keeper/keeper.go index 875bb4e941..b1938f684c 100644 --- a/protocol/x/vest/keeper/keeper.go +++ b/protocol/x/vest/keeper/keeper.go @@ -2,10 +2,11 @@ package keeper import ( "fmt" - "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/constants" "math/big" "time" + "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/constants" + errorsmod "cosmossdk.io/errors" sdklog "cosmossdk.io/log" @@ -148,14 +149,14 @@ func (k Keeper) ProcessVesting(ctx sdk.Context) { // Report vest amount. telemetry.SetGaugeWithLabels( []string{types.ModuleName, metrics.VestAmount}, - float32(vestAmount.Int64()), + metrics.GetMetricValueFromBigInt(vestAmount.BigInt()), []gometrics.Label{metrics.GetLabelForStringValue(metrics.VesterAccount, entry.VesterAccount)}, ) // Report vester account balance after vest event. balanceAfterVest := k.bankKeeper.GetBalance(ctx, authtypes.NewModuleAddress(entry.VesterAccount), entry.Denom) telemetry.SetGaugeWithLabels( []string{types.ModuleName, metrics.BalanceAfterVestEvent}, - float32(balanceAfterVest.Amount.Int64()), + metrics.GetMetricValueFromBigInt(balanceAfterVest.Amount.BigInt()), []gometrics.Label{metrics.GetLabelForStringValue(metrics.VesterAccount, entry.VesterAccount)}, ) } diff --git a/protocol/x/vest/keeper/keeper_test.go b/protocol/x/vest/keeper/keeper_test.go index 23ffc0f45d..3c44f821fc 100644 --- a/protocol/x/vest/keeper/keeper_test.go +++ b/protocol/x/vest/keeper/keeper_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "math/big" "testing" "time" @@ -10,6 +11,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" testapp "github.com/dydxprotocol/v4-chain/protocol/testutil/app" + big_testutil "github.com/dydxprotocol/v4-chain/protocol/testutil/big" blocktimetypes "github.com/dydxprotocol/v4-chain/protocol/x/blocktime/types" rewardstypes "github.com/dydxprotocol/v4-chain/protocol/x/rewards/types" "github.com/dydxprotocol/v4-chain/protocol/x/vest/types" @@ -97,6 +99,8 @@ func TestProcessVesting(t *testing.T) { testVestTokenDenom := "testdenom" testVesterAccount := rewardstypes.VesterAccountName testTreasuryAccount := rewardstypes.TreasuryAccountName + testPrevBlockTime := time.Date(2023, 11, 5, 8, 55, 20, 0, time.UTC).In(time.UTC) + testCurrBlockTime := time.Date(2023, 11, 5, 8, 55, 22, 0, time.UTC).In(time.UTC) for name, tc := range map[string]struct { vesterBalance sdkmath.Int @@ -150,6 +154,30 @@ func TestProcessVesting(t *testing.T) { expectedTreasuryBalance: sdkmath.NewInt(2_000), expectedVesterBalance: sdkmath.NewInt(1_998_000), }, + "vesting in progress, realistic values, start_time < prev_block_time < block_time < end_time": { + vesterBalance: sdkmath.NewIntFromBigInt( + big_testutil.Int64MulPow10(20_000_000, 18), // 20 million full coin, 2e26 in base denom. + ), + vestEntry: types.VestEntry{ + VesterAccount: testVesterAccount, + TreasuryAccount: testTreasuryAccount, + Denom: testVestTokenDenom, + StartTime: types.DefaultVestingStartTime, + EndTime: types.DefaultVestingEndTime, + }, + prevBlockTime: testPrevBlockTime, + blockTime: testCurrBlockTime, + expectedTreasuryBalance: sdkmath.NewIntFromBigInt( + big_testutil.MustFirst( + new(big.Int).SetString("1095437830069111172", 10), // 1.09e18 + ), + ), + expectedVesterBalance: sdkmath.NewIntFromBigInt( + big_testutil.MustFirst( + new(big.Int).SetString("19999998904562169930888828", 10), // 1.99e25 + ), + ), + }, "vesting in progress, start_time < prev_block_time < block_time < end_time, rounds down": { vesterBalance: sdkmath.NewInt(2_005_000), vestEntry: types.VestEntry{ diff --git a/v4-proto-js/package.json b/v4-proto-js/package.json index e2745bb0bf..90cdad18ce 100644 --- a/v4-proto-js/package.json +++ b/v4-proto-js/package.json @@ -24,7 +24,7 @@ "transpile": "(cd .. && make proto-export-deps && rm -rf .proto-export-deps/cosmos/autocli) && rm -rf src/ && telescope transpile --protoDirs ../.proto-export-deps --outPath ./src/codegen --no-includeAminos --includeLCDClients --includeRPCClients" }, "publishConfig": { - "access": "restricted" + "access": "public" }, "repository": { "type": "git",