disable orders endpoint, add flag to disable gpa refresh

This commit is contained in:
wphan
2023-11-30 12:20:08 -08:00
parent 3497795a56
commit 9a371ce54e
2 changed files with 235 additions and 207 deletions

View File

@@ -46,6 +46,7 @@ import {
sleep, sleep,
validateDlobQuery, validateDlobQuery,
} from './utils/utils'; } from './utils/utils';
import FEATURE_FLAGS from './utils/featureFlags';
import { import {
DLOBProvider, DLOBProvider,
getDLOBProviderFromOrderSubscriber, getDLOBProviderFromOrderSubscriber,
@@ -174,7 +175,7 @@ const main = async () => {
const clearingHousePublicKey = new PublicKey(sdkConfig.DRIFT_PROGRAM_ID); const clearingHousePublicKey = new PublicKey(sdkConfig.DRIFT_PROGRAM_ID);
const connection = new Connection(endpoint, { const connection = new Connection(endpoint, {
wsEndpoint: wsEndpoint, wsEndpoint,
commitment: stateCommitment, commitment: stateCommitment,
}); });
@@ -274,7 +275,8 @@ const main = async () => {
`dlob provider initialized in ${Date.now() - initDLOBProviderStart} ms` `dlob provider initialized in ${Date.now() - initDLOBProviderStart} ms`
); );
logger.info(`dlob provider size ${dlobProvider.size()}`); logger.info(`dlob provider size ${dlobProvider.size()}`);
if (useWebsocket) {
if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) {
const recursiveFetch = (delay = WS_FALLBACK_FETCH_INTERVAL) => { const recursiveFetch = (delay = WS_FALLBACK_FETCH_INTERVAL) => {
setTimeout(() => { setTimeout(() => {
dlobProvider.fetch().then(() => { dlobProvider.fetch().then(() => {
@@ -322,6 +324,7 @@ const main = async () => {
app.get('/startup', handleStartup); app.get('/startup', handleStartup);
app.get('/', handleHealthCheck(slotSource)); app.get('/', handleHealthCheck(slotSource));
if (FEATURE_FLAGS.ENABLE_ORDERS_ENDPOINTS) {
app.get('/orders/json/raw', async (_req, res, next) => { app.get('/orders/json/raw', async (_req, res, next) => {
try { try {
// object with userAccount key and orders object serialized // object with userAccount key and orders object serialized
@@ -339,7 +342,10 @@ const main = async () => {
}); });
} }
for (const { userAccount, publicKey } of dlobProvider.getUserAccounts()) { for (const {
userAccount,
publicKey,
} of dlobProvider.getUserAccounts()) {
for (const order of userAccount.orders) { for (const order of userAccount.orders) {
if (isVariant(order.status, 'init')) { if (isVariant(order.status, 'init')) {
continue; continue;
@@ -392,7 +398,10 @@ const main = async () => {
} }
oracles.push(oracleHuman); oracles.push(oracleHuman);
} }
for (const { userAccount, publicKey } of dlobProvider.getUserAccounts()) { for (const {
userAccount,
publicKey,
} of dlobProvider.getUserAccounts()) {
for (const order of userAccount.orders) { for (const order of userAccount.orders) {
if (isVariant(order.status, 'init')) { if (isVariant(order.status, 'init')) {
continue; continue;
@@ -426,7 +435,8 @@ const main = async () => {
maxTs: order.maxTs.toString(), maxTs: order.maxTs.toString(),
}; };
if (order.quoteAssetAmount) { if (order.quoteAssetAmount) {
orderHuman['quoteAssetAmount'] = order.quoteAssetAmount.toString(); orderHuman['quoteAssetAmount'] =
order.quoteAssetAmount.toString();
} }
orders.push({ orders.push({
@@ -454,7 +464,10 @@ const main = async () => {
try { try {
const dlobOrders: DLOBOrders = []; const dlobOrders: DLOBOrders = [];
for (const { userAccount, publicKey } of dlobProvider.getUserAccounts()) { for (const {
userAccount,
publicKey,
} of dlobProvider.getUserAccounts()) {
for (const order of userAccount.orders) { for (const order of userAccount.orders) {
if (isVariant(order.status, 'init')) { if (isVariant(order.status, 'init')) {
continue; continue;
@@ -477,7 +490,8 @@ const main = async () => {
app.get('/orders/idlWithSlot', async (req, res, next) => { app.get('/orders/idlWithSlot', async (req, res, next) => {
try { try {
const { marketName, marketIndex, marketType } = req.query; const { marketName, marketIndex, marketType } = req.query;
const { normedMarketType, normedMarketIndex, error } = validateDlobQuery( const { normedMarketType, normedMarketIndex, error } =
validateDlobQuery(
driftClient, driftClient,
driftEnv, driftEnv,
marketType as string, marketType as string,
@@ -502,7 +516,10 @@ const main = async () => {
const dlobOrders: DLOBOrders = []; const dlobOrders: DLOBOrders = [];
for (const { userAccount, publicKey } of dlobProvider.getUserAccounts()) { for (const {
userAccount,
publicKey,
} of dlobProvider.getUserAccounts()) {
for (const order of userAccount.orders) { for (const order of userAccount.orders) {
if (isVariant(order.status, 'init')) { if (isVariant(order.status, 'init')) {
continue; continue;
@@ -534,6 +551,7 @@ const main = async () => {
next(err); next(err);
} }
}); });
}
app.get('/topMakers', async (req, res, next) => { app.get('/topMakers', async (req, res, next) => {
try { try {

View File

@@ -1,7 +1,17 @@
// TODO : Is it worth adding proper infrastructure for feature flags? .. Would allow more powerful things like toggling them at runtime rather than being hardcoded
export const FEATURE_FLAGS = { export const FEATURE_FLAGS = {
OLD_ORACLE_PRICE_IN_L2: true, // TODO : Remove this once we're confident that NEW_ORACLE_DATA_IN_L2 works .. delete corresponding code // TODO : Remove this once we're confident that NEW_ORACLE_DATA_IN_L2 works .. delete corresponding code
OLD_ORACLE_PRICE_IN_L2: true,
NEW_ORACLE_DATA_IN_L2: true, NEW_ORACLE_DATA_IN_L2: true,
// enables old orders endpoint, disabled by default since the response is too big now
ENABLE_ORDERS_ENDPOINTS: process.env.ENABLE_ORDERS_ENDPOINTS
? process.env.ENABLE_ORDERS_ENDPOINTS.toLowerCase()
: false,
// disables periodically refreshing userAccounts via gPA
DISABLE_GPA_REFRESH: process.env.DISABLE_GPA_REFRESH
? process.env.DISABLE_GPA_REFRESH.toLowerCase()
: false,
}; };
export default FEATURE_FLAGS; export default FEATURE_FLAGS;