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