-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
341 changed files
with
11,575 additions
and
10,128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Protocol Benchmark | ||
on: # yamllint disable-line rule:truthy | ||
pull_request: | ||
paths: | ||
- 'protocol/**' | ||
push: | ||
branches: | ||
- main | ||
- 'release/protocol/v[0-9]+.[0-9]+.x' # e.g. release/protocol/v0.1.x | ||
- 'release/protocol/v[0-9]+.x' # e.g. release/protocol/v1.x | ||
paths: | ||
- 'protocol/**' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
benchmark: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./protocol | ||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v3 | ||
- name: Setup Golang | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.22 | ||
- name: Run Benchmarks | ||
run: make benchmark | tee ./benchmark_output.txt | ||
- name: Download previous benchmark data | ||
uses: actions/cache@v4 | ||
with: | ||
path: ./cache | ||
key: ${{ runner.os }}-benchmark | ||
- name: Store benchmark result | ||
uses: benchmark-action/github-action-benchmark@v1 | ||
with: | ||
tool: 'go' | ||
output-file-path: ./protocol/benchmark_output.txt | ||
external-data-json-path: ./cache/benchmark-data.json | ||
fail-on-alert: true | ||
alert-threshold: '150%' | ||
save-data-file: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export const TO_ENDER_TOPIC: string = 'to-ender'; | ||
|
||
export const ORDERBOOKS_WEBSOCKET_MESSAGE_VERSION: string = '1.0.0'; | ||
export const SUBACCOUNTS_WEBSOCKET_MESSAGE_VERSION: string = '2.4.0'; | ||
export const SUBACCOUNTS_WEBSOCKET_MESSAGE_VERSION: string = '3.0.0'; | ||
export const TRADES_WEBSOCKET_MESSAGE_VERSION: string = '2.1.0'; | ||
export const MARKETS_WEBSOCKET_MESSAGE_VERSION: string = '1.0.0'; | ||
export const CANDLES_WEBSOCKET_MESSAGE_VERSION: string = '1.0.0'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
indexer/packages/postgres/__tests__/loops/block-height-refresher.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { clearData, migrate, teardown } from '../../src/helpers/db-helpers'; | ||
import { clear, getLatestBlockHeight, updateBlockHeight } from '../../src/loops/block-height-refresher'; | ||
import { defaultBlock2 } from '../helpers/constants'; | ||
import { seedData } from '../helpers/mock-generators'; | ||
import config from '../../src/config'; | ||
|
||
describe('blockHeightRefresher', () => { | ||
beforeAll(async () => { | ||
await migrate(); | ||
await seedData(); | ||
await updateBlockHeight(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await clearData(); | ||
await teardown(); | ||
}); | ||
|
||
describe('getLatestBlockHeight', () => { | ||
it('successfully gets the latest block height after update', async () => { | ||
await updateBlockHeight(); | ||
expect(getLatestBlockHeight()).toBe(defaultBlock2.blockHeight); | ||
}); | ||
}); | ||
|
||
describe('clear', () => { | ||
it('throws an error if block height does not exist', () => { | ||
clear(); | ||
expect(() => getLatestBlockHeight()).toThrowError('Unable to find latest block height'); | ||
}); | ||
|
||
it('throws an error when clear is called in non-test environment', () => { | ||
const originalEnv = config.NODE_ENV; | ||
config.NODE_ENV = 'production'; | ||
expect(() => clear()).toThrowError('clear cannot be used in non-test env'); | ||
config.NODE_ENV = originalEnv; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
indexer/packages/postgres/src/loops/block-height-refresher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
stats, | ||
logger, | ||
NodeEnv, | ||
} from '@dydxprotocol-indexer/base'; | ||
|
||
import config from '../config'; | ||
import * as BlockTable from '../stores/block-table'; | ||
import { BlockFromDatabase, Options } from '../types'; | ||
import { startUpdateLoop } from './loopHelper'; | ||
|
||
let latestBlockHeight: string = ''; | ||
|
||
/** | ||
* Refresh loop to cache the latest block height from the database in-memory. | ||
*/ | ||
export async function start(): Promise<void> { | ||
await startUpdateLoop( | ||
updateBlockHeight, | ||
config.BLOCK_HEIGHT_REFRESHER_INTERVAL_MS, | ||
'updateBlockHeight', | ||
); | ||
} | ||
|
||
/** | ||
* Updates in-memory latest block height. | ||
*/ | ||
export async function updateBlockHeight(options?: Options): Promise<void> { | ||
const startTime: number = Date.now(); | ||
try { | ||
const latestBlock: BlockFromDatabase = await BlockTable.getLatest( | ||
options || { readReplica: true }, | ||
); | ||
latestBlockHeight = latestBlock.blockHeight; | ||
stats.timing(`${config.SERVICE_NAME}.loops.update_block_height`, Date.now() - startTime); | ||
// eslint-disable-next-line no-empty | ||
} catch (error) { } | ||
} | ||
|
||
/** | ||
* Gets the latest block height. | ||
*/ | ||
export function getLatestBlockHeight(): string { | ||
if (!latestBlockHeight) { | ||
const message: string = 'Unable to find latest block height'; | ||
logger.error({ | ||
at: 'block-height-refresher#getLatestBlockHeight', | ||
message, | ||
}); | ||
throw new Error(message); | ||
} | ||
return latestBlockHeight; | ||
} | ||
|
||
export function clear(): void { | ||
if (config.NODE_ENV !== NodeEnv.TEST) { | ||
throw new Error('clear cannot be used in non-test env'); | ||
} | ||
|
||
latestBlockHeight = ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.