Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrderbookMidPrice Cache & Candles Fix #2502

Closed
wants to merge 120 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
aaec10f
Revert "Add Orderbook Mid Price Cache (#2289)" (backport #2333) (#2334)
mergify[bot] Sep 24, 2024
ce8f484
Add Orderbook Mid Price Cache (backport #2338) (#2340)
mergify[bot] Sep 25, 2024
8a0a748
[OTE-784] Limit addresses for compliance check to dydx wallets with d…
mergify[bot] Sep 25, 2024
0f214f1
enable username generation roundtable (backport #2361) (#2362)
mergify[bot] Sep 26, 2024
a47c327
Add current equity as a pnl tick. (backport #2335) (#2365)
mergify[bot] Sep 26, 2024
9875783
Use vault table rather than placeholder config flags to fetch vaults.…
mergify[bot] Sep 26, 2024
d034716
Add sql script latency metrics (backport #2356) (#2371)
mergify[bot] Sep 26, 2024
8b933c6
Add oracle prices index on ("marketId", "effectiveAtHeight") (backpor…
mergify[bot] Sep 26, 2024
0502f73
Include getting main subaccount equity / pnl for megavault PnL query.…
mergify[bot] Sep 26, 2024
1389214
Add function to fetch availability zone id (#2326) (backport #2390) (…
mergify[bot] Sep 30, 2024
6dc0501
Create consumer using rack id (#2352) (backport #2393) (#2411)
mergify[bot] Sep 30, 2024
3e94eb4
Filter out to single tick per interval. (backport #2403) (#2418)
mergify[bot] Oct 1, 2024
6005a0d
[CT-629] Fix entryPrice calc (backport #2415) (#2417)
mergify[bot] Oct 1, 2024
e8af710
Revert "[CT-629] Fix entryPrice calc" (backport #2425) (#2426)
mergify[bot] Oct 1, 2024
dbe13a3
Fix flaky vault test. (backport #2422) (#2424)
mergify[bot] Oct 1, 2024
0b9e8a2
Split affiliate info fees by taker and maker (backport #2439) (#2448)
mergify[bot] Oct 3, 2024
c182cd9
Fix bug with PnL aggregation. (backport #2446) (#2451)
mergify[bot] Oct 3, 2024
939cb56
Get latest hourly tick to compute final tick for megavault PnL. (back…
mergify[bot] Oct 3, 2024
6800a36
add afflaiteReferredMakerRebates field to response (backport #2473) (…
mergify[bot] Oct 4, 2024
4b19a59
[OTE-846] Bazooka sequential clear (backport #2423) (#2477)
mergify[bot] Oct 7, 2024
ca6c044
[OTE-863] update username generation query (backport #2482) (#2483)
mergify[bot] Oct 14, 2024
071aa31
Improve vault endpoint performance. (backport #2475) (#2484)
mergify[bot] Oct 15, 2024
7a2200e
Return undefined from getOrderbookMidPriceMap (backport #2441) (#2486)
mergify[bot] Oct 15, 2024
54b3bce
[CT-629] Fix entryPrice calc (backport #2455) (#2496)
mergify[bot] Oct 16, 2024
666898f
Don't increment messageId for custom ping messages (backport #2493) (…
mergify[bot] Oct 16, 2024
5042763
[OTE-880] Emit log in case of collisions (backport #2500) (#2504)
mergify[bot] Oct 16, 2024
3339df5
[OTE-876] update roundtable loop timings for instrumentation and uncr…
mergify[bot] Oct 16, 2024
e2298c4
Remove orderbook cache roundtable job (backport #2510) (#2511)
mergify[bot] Oct 17, 2024
ec8b919
Add config var to exclude specific stateful order ids from being proc…
mergify[bot] Oct 18, 2024
bba2a12
add wallet when transfer to subaccount (backport #2519) (#2520)
mergify[bot] Oct 18, 2024
daddb13
update migration to stop excessive consumption of computation (backpo…
mergify[bot] Oct 18, 2024
bb809c2
Get funding index maps for vault positions in chunks. (backport #2525…
mergify[bot] Oct 22, 2024
32cbd9d
Vulcan topic to 210 partitions (backport #2528) (#2530)
mergify[bot] Oct 22, 2024
38a2d36
Fix typo and add test for invalid vaults. (backport #2535) (#2536)
mergify[bot] Oct 22, 2024
c49f48e
Add missing fields to perpetual markets kafka update (backport #2539)…
mergify[bot] Oct 28, 2024
c4348fb
De-duplicate and filter out invalid pnl ticks for megavault. (backpor…
mergify[bot] Oct 28, 2024
86f1b48
[CT-1307] Make pnl ticks computation consistent within a transaction.…
mergify[bot] Oct 30, 2024
07cdd6c
Dont set default value for fills rows (backport #2552) (#2553)
mergify[bot] Nov 4, 2024
4659c30
Update MsgSetActiveState proto (#2337)
jayy04 Sep 25, 2024
12a1743
Mergify for v7 branches (#2343)
adamfraser Sep 25, 2024
3580b16
Fix: deterministically fetch perp info from state (#2341)
ttl33 Sep 25, 2024
bb77d19
[TRA-617] Integrate PML and Megavault (#2331)
shrenujb Sep 25, 2024
881e36a
[OTE-829] upgrade handler for affiliates (#2332)
affanv14 Sep 25, 2024
10a018f
[CT-1198] Add smart account and circuit break ante handler (#2325)
jayy04 Sep 25, 2024
6473951
[OTE-823] Fix FNS onchain events staging + retrieval logic (#2318)
teddyding Sep 26, 2024
adb799d
Add OE Abort rate test flag (#2366)
teddyding Sep 26, 2024
ce662f2
[TRA-617] Fix calculation for atomic resolution (#2360)
shrenujb Sep 26, 2024
a97c503
Add a cli method for vault withdrawal (#2369)
shrenujb Sep 26, 2024
85ec697
[OTE-839] add query for unconditional revshare (#2380)
affanv14 Sep 26, 2024
d06d6cb
[OTE-840] add missing HasEndBlocker interface (#2384)
affanv14 Sep 27, 2024
d702760
migrate vault shares to megavault shares in v7 upgrade handler (backp…
mergify[bot] Sep 27, 2024
68c70d1
register deprecated MsgSetVaultQuotingParams (#2392)
tqin7 Sep 27, 2024
6189e19
initialize megavault module account in 7.0.0 upgrade handler (#2394)
tqin7 Sep 27, 2024
2f5a94c
[CT-1203] add clob pair id and subaccount num filters (#2388)
jayy04 Sep 30, 2024
5282ba0
[CT-1237] enable messages and add ante decorator to the chain (#2375)
jayy04 Sep 30, 2024
ebad2c6
Internalize logic to stage FinalizeBlock events (#2399)
teddyding Sep 30, 2024
b7dc456
[CT-1258] add order removal reason for expired permissioned keys (#2407)
jayy04 Sep 30, 2024
00af8a0
[CT-1259] account plus module code cleanup (#2408)
jayy04 Sep 30, 2024
ca5e96d
Add tests for when market pair name changes (#2280)
chenyaoy Oct 1, 2024
253f98d
chore: Bump Cometbft to log proposer when proposal is rejected (#2421)
teddyding Oct 1, 2024
753bac8
[TRA-611] Get MarketPrice exponent from marketmap (#2324)
chenyaoy Oct 1, 2024
0fb6232
Fix issue with flaky candle test (#2430)
adamfraser Oct 2, 2024
ca4a23c
[CT-1202] logic to handle unauthorized maker orders when authenticato…
jayy04 Oct 2, 2024
3fa58d7
Update large cap params in genesis (#2431)
chenyaoy Oct 2, 2024
6943580
feat: upgrade to connect/v2 (#2419)
Oct 2, 2024
f21b60d
Move FinalizeBlock event staging logic into a generic EventStager (#2…
teddyding Oct 2, 2024
8e90738
Update GetAllRevshare to handle liquidations (#2413)
affanv14 Oct 2, 2024
46b55e2
remove deprecated params from x/vault params query (#2387)
tqin7 Oct 2, 2024
d74cc70
Return undefined from getOrderbookMidPriceMap (#2441)
adamfraser Oct 2, 2024
c105563
[TRA-654] add listing module state init into v7 upgrade handler (#2432)
shrenujb Oct 3, 2024
d0da9ca
[CT-1259] move account plus test functions to testutil (#2444)
jayy04 Oct 3, 2024
e2a4c46
Update indexer testnet url (#2312)
Christopher-Li Oct 3, 2024
b018d6f
[OTE-849] Add metrics to track revenue shares (#2449)
affanv14 Oct 3, 2024
6aeb05e
[CT-1268] fix genesis for account plus (#2452)
jayy04 Oct 3, 2024
b8e03ea
[TRA-671] Prevent connect messages in x/authz (#2434)
chenyaoy Oct 3, 2024
595160d
fix tsnonce preventing multisignature bug (#2453)
jerryfan01234 Oct 3, 2024
000f601
feat: make PML compatible with OE by staging in-memory CLOB side effe…
teddyding Oct 3, 2024
ffa2efc
in testing, megavault main subaccount has 0 usdc by default (#2462)
tqin7 Oct 3, 2024
c171a0d
Update sidecar to connect v2 (#2458)
chenyaoy Oct 3, 2024
82fcd79
don't initialize megavault subaccount if balance is 0 in genesis (#2464)
tqin7 Oct 3, 2024
15621ce
remove megavault subaccount from sample pregenesis (#2467)
tqin7 Oct 3, 2024
2b50df0
[CT-1262] add e2e tests for new auth flow failure cases (#2461)
jayy04 Oct 8, 2024
75a93eb
[OTE-852] Register rpc routes in module (#2480)
affanv14 Oct 14, 2024
4eee7a2
Fix test flakiness due to using inconsistent time. (#2485)
vincentwschau Oct 15, 2024
3533030
Add GRPC gateway route for listing module and add hard cap setting (#…
shrenujb Oct 15, 2024
e085891
[OTE-877] deprecate OI indexer update event (#2499)
affanv14 Oct 16, 2024
7c40368
set each megavault share to be worth 0.001 usdc on 7.x upgrade (#2492)
tqin7 Oct 16, 2024
3db9b39
add metadata to megavault operator params (#2509)
tqin7 Oct 16, 2024
cc021ff
Rename MATIC to POL in genesis and tests (#2503)
chenyaoy Oct 17, 2024
51bd87f
[TRA-721] Enforce sidecar versions (#2491)
chenyaoy Oct 17, 2024
dea1f23
Drop patch number from upgrade name, v7.0.0 to v7.0 (#2512)
adamfraser Oct 18, 2024
518bab3
FNS polish - metrics, max msg size, default flag values (#2517)
jonfung-dydx Oct 18, 2024
4e1779c
Add script to get insurance fund balances (#2516)
ttl33 Oct 18, 2024
2c72413
reusing subscription ids (#2518)
jonfung-dydx Oct 18, 2024
fbd671a
FNS - bounds check raw subscription payload int vals (#2523)
jonfung-dydx Oct 21, 2024
6fb5a95
Protocol support for Rust (#2172)
therustmonk Oct 22, 2024
04b05b5
Bump SDK - Always Reset OE (#2531)
teddyding Oct 22, 2024
a4b96d8
[CT-1262] add e2e tests for permissioned keys success cases (#2479)
jayy04 Oct 22, 2024
99c040e
Change Rust protobufs crate name, license reference (#2541)
v0-e Oct 27, 2024
9ecd384
Use Rust proto crate name as `dydx-proto` (#2543)
v0-e Oct 28, 2024
412eece
De-duplicate and filter out invalid pnl ticks for megavault. (#2540)
vincentwschau Oct 28, 2024
6b4d9e3
[TRA-513] Deprecate exchange config json and min exchanges (#2524)
chenyaoy Oct 28, 2024
1010960
Full node streaming -- perp position to signed int (#2544)
jonfung-dydx Oct 28, 2024
cdceacf
[OTE-882] Add prefix to accountplus keeper (#2526)
jerryfan01234 Oct 28, 2024
8237d2a
pass shares to withdraw in megavault withdrawal query rest endpoint (…
tqin7 Oct 31, 2024
50d7a45
Add gRPC gateway routing for affiliate queries (#2554)
teddyding Nov 5, 2024
d1c8ed8
Bump Comet version (#2556)
teddyding Nov 6, 2024
f1bbac6
Update Rust protos, dependencies enhancements (#2538)
v0-e Nov 13, 2024
a65976e
fix(affiliates): [OTE-898] Refactor subaccount username generation (#…
teddyding Nov 14, 2024
de54494
Allow configuring day vault PnL starts. (#2570)
vincentwschau Nov 14, 2024
00557f6
Use alphanumeric suffix for username (#2573)
teddyding Nov 15, 2024
f408f71
fix(affiliates): Generate username with address, not subaccount id (#…
teddyding Nov 15, 2024
c51e491
Use repeatable read for pnl tick generation. (#2578)
vincentwschau Nov 18, 2024
25606e0
fix(affiliate): Use DB transaction for username generation; add more …
teddyding Nov 18, 2024
e92fb1a
Fix username generator unit test (#2582)
teddyding Nov 18, 2024
dc46447
Modify OrderbookMidPrice cache to cache multiple markets at once
adamfraser Oct 4, 2024
7d57b0d
Add OrderbookMidPriceMemoryCache to ender and populate candles mid pr…
adamfraser Oct 16, 2024
8791629
Temp Deploy
adamfraser Oct 16, 2024
9ef87bc
Add perpetual market refresher to roundtable
adamfraser Oct 28, 2024
cd80439
Run cache orderbook mid prices roundtable task
adamfraser Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,20 @@ pull_request_rules:
backport:
branches:
- release/protocol/v6.x
- name: backport to release/indexer/v7.x branch
conditions:
- base=main
- label=backport/indexer/v7.x
actions:
backport:
branches:
- release/indexer/v7.x
- name: backport to release/protocol/v7.x branch
conditions:
- base=main
- label=backport/protocol/v7.x
actions:
backport:
branches:
- release/protocol/v7.x

43 changes: 2 additions & 41 deletions .github/workflows/indexer-build-and-push-dev-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,14 @@ on: # yamllint disable-line rule:truthy
- main
- 'release/indexer/v[0-9]+.[0-9]+.x' # e.g. release/indexer/v0.1.x
- 'release/indexer/v[0-9]+.x' # e.g. release/indexer/v1.x
- 'adam/candles-memory-cache'
# TODO(DEC-837): Customize github build and push to ECR by service with paths

jobs:
# Build and push to dev
call-build-and-push-ecs-services-dev:
name: (Dev) Build and Push ECS Services
uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml
with:
ENVIRONMENT: dev
secrets: inherit

# Build and push to dev2
call-build-and-push-ecs-services-dev2:
name: (Dev2) Build and Push ECS Services
uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml
with:
ENVIRONMENT: dev2
secrets: inherit

# Build and push to dev3
call-build-and-push-ecs-services-dev3:
name: (Dev3) Build and Push ECS Services
uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml
with:
ENVIRONMENT: dev3
secrets: inherit

# Build and push to dev4
call-build-and-push-ecs-services-dev4:
name: (Dev4) Build and Push ECS Services
uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml
with:
ENVIRONMENT: dev4
secrets: inherit

# Build and push to dev5
call-build-and-push-ecs-services-dev5:
name: (Dev5) Build and Push ECS Services
uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml
with:
ENVIRONMENT: dev5
secrets: inherit

# Build and push to staging
call-build-and-push-ecs-services-staging:
name: (Staging) Build and Push ECS Services
uses: ./.github/workflows/indexer-build-and-push-all-ecr-images.yml
with:
ENVIRONMENT: staging
secrets: inherit
secrets: inherit
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ v4-proto-py/v4_proto
v4-proto-js/build
v4-proto-js/node_modules
v4-proto-js/src
v4-proto-rs/target
v4-proto-rs/Cargo.lock

.idea
.vscode
Expand Down
1 change: 1 addition & 0 deletions indexer/packages/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"homepage": "https://github.com/dydxprotocol/indexer#readme",
"dependencies": {
"@aws-sdk/client-ec2": "^3.354.0",
"axios": "^1.2.1",
"big.js": "^6.2.1",
"bignumber.js": "^9.0.2",
Expand Down
51 changes: 51 additions & 0 deletions indexer/packages/base/src/az-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { DescribeAvailabilityZonesCommand, EC2Client } from '@aws-sdk/client-ec2';

import { axiosRequest } from './axios';
import config from './config';
import logger from './logger';

export async function getAvailabilityZoneId(): Promise<string> {
if (config.ECS_CONTAINER_METADATA_URI_V4 !== '' && config.AWS_REGION !== '') {
const taskUrl = `${config.ECS_CONTAINER_METADATA_URI_V4}/task`;
try {
const response = await axiosRequest({
method: 'GET',
url: taskUrl,
}) as { AvailabilityZone: string };
const client = new EC2Client({ region: config.AWS_REGION });
const command = new DescribeAvailabilityZonesCommand({
ZoneNames: [response.AvailabilityZone],
});
try {
const ec2Response = await client.send(command);
const zoneId = ec2Response.AvailabilityZones![0].ZoneId!;
logger.info({
at: 'az-id#getAvailabilityZoneId',
message: `Got availability zone id ${zoneId}.`,
});
return ec2Response.AvailabilityZones![0].ZoneId!;
} catch (error) {
logger.error({
at: 'az-id#getAvailabilityZoneId',
message: 'Failed to fetch availabilty zone id from EC2. ',
error,
});
return '';
}
} catch (error) {
logger.error({
at: 'az-id#getAvailabilityZoneId',
message: 'Failed to retrieve availability zone from metadata endpoint. No availabilty zone id found.',
error,
taskUrl,
});
return '';
}
} else {
logger.error({
at: 'az-id#getAvailabilityZoneId',
message: 'No metadata URI or region. No availabilty zone id found.',
});
return '';
}
}
1 change: 1 addition & 0 deletions indexer/packages/base/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const baseConfigSchema = {
STATSD_PORT: parseInteger({ default: 8125 }),
LOG_LEVEL: parseString({ default: 'debug' }),
ECS_CONTAINER_METADATA_URI_V4: parseString({ default: '' }),
AWS_REGION: parseString({ default: '' }),
};

export default parseSchema(baseConfigSchema);
1 change: 1 addition & 0 deletions indexer/packages/base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './bugsnag';
export * from './stats-util';
export * from './date-helpers';
export * from './instance-id';
export * from './az-id';

// Do this outside logger.ts to avoid a dependency cycle with logger transports that may trigger
// additional logging.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const API_PATH: string = '/v2/wallet/synchronous';
export const API_URI: string = `https://aml-api.elliptic.co${API_PATH}`;
export const RISK_SCORE_KEY: string = 'risk_score';
export const NO_RULES_TRIGGERED_RISK_SCORE: number = -1;
// We use different negative values of risk score to represent different elliptic response states
export const NOT_IN_BLOCKCHAIN_RISK_SCORE: number = -2;

export class EllipticProviderClient extends ComplianceClient {
private apiKey: string;
Expand Down Expand Up @@ -98,7 +100,7 @@ export class EllipticProviderClient extends ComplianceClient {
`${config.SERVICE_NAME}.get_elliptic_risk_score.status_code`,
{ status: '404' },
);
return NO_RULES_TRIGGERED_RISK_SCORE;
return NOT_IN_BLOCKCHAIN_RISK_SCORE;
}

if (error?.response?.status === 429) {
Expand Down
1 change: 1 addition & 0 deletions indexer/packages/compliance/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './geoblocking/util';
export * from './types';
export * from './config';
export * from './constants';
export * from './clients/elliptic-provider';
4 changes: 2 additions & 2 deletions indexer/packages/kafka/__tests__/consumer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { TO_ENDER_TOPIC } from '../src';
describe.skip('consumer', () => {
beforeAll(async () => {
await Promise.all([
consumer.connect(),
consumer!.connect(),
producer.connect(),
]);
await consumer.subscribe({ topic: TO_ENDER_TOPIC });
await consumer!.subscribe({ topic: TO_ENDER_TOPIC });
await startConsumer();
});

Expand Down
75 changes: 42 additions & 33 deletions indexer/packages/kafka/src/consumer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
getAvailabilityZoneId,
logger,
} from '@dydxprotocol-indexer/base';
import {
Expand All @@ -13,15 +14,10 @@ const groupIdPrefix: string = config.SERVICE_NAME;
const groupIdSuffix: string = config.KAFKA_ENABLE_UNIQUE_CONSUMER_GROUP_IDS ? `_${uuidv4()}` : '';
const groupId: string = `${groupIdPrefix}${groupIdSuffix}`;

export const consumer: Consumer = kafka.consumer({
groupId,
sessionTimeout: config.KAFKA_SESSION_TIMEOUT_MS,
rebalanceTimeout: config.KAFKA_REBALANCE_TIMEOUT_MS,
heartbeatInterval: config.KAFKA_HEARTBEAT_INTERVAL_MS,
maxWaitTimeInMs: config.KAFKA_WAIT_MAX_TIME_MS,
readUncommitted: false,
maxBytes: 4194304, // 4MB
});
// As a hack, we made this mutable since CommonJS doesn't support top level await.
// Top level await would needed to fetch the az id (used as rack id).
// eslint-disable-next-line import/no-mutable-exports
export let consumer: Consumer | undefined;

// List of functions to run per message consumed.
let onMessageFunction: (topic: string, message: KafkaMessage) => Promise<void>;
Expand Down Expand Up @@ -51,38 +47,51 @@ export function updateOnBatchFunction(
// Whether the consumer is stopped.
let stopped: boolean = false;

consumer.on('consumer.disconnect', async () => {
export async function stopConsumer(): Promise<void> {
logger.info({
at: 'consumers#disconnect',
message: 'Kafka consumer disconnected',
at: 'kafka-consumer#stop',
message: 'Stopping kafka consumer',
groupId,
});

if (!stopped) {
await consumer.connect();
logger.info({
at: 'kafka-consumer#disconnect',
message: 'Kafka consumer reconnected',
groupId,
});
} else {
stopped = true;
await consumer!.disconnect();
}

export async function initConsumer(): Promise<void> {
consumer = kafka.consumer({
groupId,
sessionTimeout: config.KAFKA_SESSION_TIMEOUT_MS,
rebalanceTimeout: config.KAFKA_REBALANCE_TIMEOUT_MS,
heartbeatInterval: config.KAFKA_HEARTBEAT_INTERVAL_MS,
maxWaitTimeInMs: config.KAFKA_WAIT_MAX_TIME_MS,
readUncommitted: false,
maxBytes: 4194304, // 4MB
rackId: await getAvailabilityZoneId(),
});

consumer!.on('consumer.disconnect', async () => {
logger.info({
at: 'kafka-consumer#disconnect',
message: 'Not reconnecting since task is shutting down',
at: 'consumers#disconnect',
message: 'Kafka consumer disconnected',
groupId,
});
}
});

export async function stopConsumer(): Promise<void> {
logger.info({
at: 'kafka-consumer#stop',
message: 'Stopping kafka consumer',
groupId,
if (!stopped) {
await consumer!.connect();
logger.info({
at: 'kafka-consumer#disconnect',
message: 'Kafka consumer reconnected',
groupId,
});
} else {
logger.info({
at: 'kafka-consumer#disconnect',
message: 'Not reconnecting since task is shutting down',
groupId,
});
}
});

stopped = true;
await consumer.disconnect();
}

export async function startConsumer(batchProcessing: boolean = false): Promise<void> {
Expand All @@ -104,7 +113,7 @@ export async function startConsumer(batchProcessing: boolean = false): Promise<v
};
}

await consumer.run(consumerRunConfig);
await consumer!.run(consumerRunConfig);

logger.info({
at: 'consumers#connect',
Expand Down
30 changes: 24 additions & 6 deletions indexer/packages/postgres/__tests__/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const invalidTicker: string = 'INVALID-INVALID';
export const dydxChain: string = 'dydx';
export const defaultAddress: string = 'dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc565lnf';
export const defaultAddress2: string = 'dydx1n88uc38xhjgxzw9nwre4ep2c8ga4fjxc575lnf';
export const defaultAddress3: string = 'dydx199tqg4wdlnu4qjlxchpd7seg454937hjrknju4';
export const blockedAddress: string = 'dydx1f9k5qldwmqrnwy8hcgp4fw6heuvszt35egvtx2';
// Vault address for vault id 0 was generated using
// script protocol/scripts/vault/get_vault.go
Expand Down Expand Up @@ -100,6 +101,20 @@ export const defaultSubaccount3: SubaccountCreateObject = {
updatedAtHeight: createdHeight,
};

export const defaultSubaccount2Num0: SubaccountCreateObject = {
address: defaultAddress2,
subaccountNumber: 0,
updatedAt: createdDateTime.toISO(),
updatedAtHeight: createdHeight,
};

export const defaultSubaccount3Num0: SubaccountCreateObject = {
address: defaultAddress3,
subaccountNumber: 0,
updatedAt: createdDateTime.toISO(),
updatedAtHeight: createdHeight,
};

// defaultWalletAddress belongs to defaultWallet2 and is different from defaultAddress
export const defaultSubaccountDefaultWalletAddress: SubaccountCreateObject = {
address: defaultWalletAddress,
Expand Down Expand Up @@ -990,9 +1005,10 @@ export const defaultAffiliateInfo: AffiliateInfoCreateObject = {
affiliateEarnings: '10',
referredMakerTrades: 10,
referredTakerTrades: 20,
totalReferredFees: '10',
totalReferredMakerFees: '10',
totalReferredTakerFees: '10',
totalReferredMakerRebates: '-10',
totalReferredUsers: 5,
referredNetProtocolEarnings: '20',
firstReferralBlockHeight: '1',
referredTotalVolume: '1000',
};
Expand All @@ -1002,9 +1018,10 @@ export const defaultAffiliateInfo2: AffiliateInfoCreateObject = {
affiliateEarnings: '11',
referredMakerTrades: 11,
referredTakerTrades: 21,
totalReferredFees: '11',
totalReferredMakerFees: '11',
totalReferredTakerFees: '11',
totalReferredMakerRebates: '-11',
totalReferredUsers: 5,
referredNetProtocolEarnings: '21',
firstReferralBlockHeight: '11',
referredTotalVolume: '1000',
};
Expand All @@ -1014,9 +1031,10 @@ export const defaultAffiliateInfo3: AffiliateInfoCreateObject = {
affiliateEarnings: '12',
referredMakerTrades: 12,
referredTakerTrades: 22,
totalReferredFees: '12',
totalReferredMakerFees: '12',
totalReferredTakerFees: '12',
totalReferredMakerRebates: '-12',
totalReferredUsers: 10,
referredNetProtocolEarnings: '22',
firstReferralBlockHeight: '12',
referredTotalVolume: '1111111',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ import {
isolatedPerpetualMarket2,
isolatedSubaccount,
isolatedSubaccount2,
defaultSubaccount2Num0,
defaultSubaccount3Num0,
} from './constants';

export async function seedAdditionalSubaccounts() {
await Promise.all([
SubaccountTable.create(defaultSubaccount2Num0),
SubaccountTable.create(defaultSubaccount3Num0),
]);
}

export async function seedData() {
await Promise.all([
SubaccountTable.create(defaultSubaccount),
Expand Down
Loading
Loading