dlob server self update
This commit is contained in:
@@ -13,6 +13,7 @@ export type DLOBProvider = {
|
|||||||
getUserAccount(publicKey: PublicKey): UserAccount | undefined;
|
getUserAccount(publicKey: PublicKey): UserAccount | undefined;
|
||||||
size(): number;
|
size(): number;
|
||||||
fetch(): Promise<void>;
|
fetch(): Promise<void>;
|
||||||
|
getSlot(): number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getDLOBProviderFromUserMap(userMap: UserMap): DLOBProvider {
|
export function getDLOBProviderFromUserMap(userMap: UserMap): DLOBProvider {
|
||||||
@@ -43,6 +44,9 @@ export function getDLOBProviderFromUserMap(userMap: UserMap): DLOBProvider {
|
|||||||
fetch: () => {
|
fetch: () => {
|
||||||
return userMap.sync();
|
return userMap.sync();
|
||||||
},
|
},
|
||||||
|
getSlot: () => {
|
||||||
|
return userMap.getSlot();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +86,9 @@ export function getDLOBProviderFromOrderSubscriber(
|
|||||||
fetch() {
|
fetch() {
|
||||||
return orderSubscriber.fetch();
|
return orderSubscriber.fetch();
|
||||||
},
|
},
|
||||||
|
getSlot: () => {
|
||||||
|
return orderSubscriber.getSlot();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,5 +128,8 @@ export function getDLOBProviderFromGrpcOrderSubscriber(
|
|||||||
fetch() {
|
fetch() {
|
||||||
return orderSubscriber.fetch();
|
return orderSubscriber.fetch();
|
||||||
},
|
},
|
||||||
|
getSlot: () => {
|
||||||
|
return orderSubscriber.getSlot();
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
52
src/index.ts
52
src/index.ts
@@ -20,7 +20,6 @@ import {
|
|||||||
DriftEnv,
|
DriftEnv,
|
||||||
SlotSource,
|
SlotSource,
|
||||||
SlotSubscriber,
|
SlotSubscriber,
|
||||||
UserMap,
|
|
||||||
Wallet,
|
Wallet,
|
||||||
getUserStatsAccountPublicKey,
|
getUserStatsAccountPublicKey,
|
||||||
getVariant,
|
getVariant,
|
||||||
@@ -34,7 +33,6 @@ import { logger, setLogLevel } from './utils/logger';
|
|||||||
|
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
import {
|
import {
|
||||||
gpaFetchDurationHistogram,
|
|
||||||
handleHealthCheck,
|
handleHealthCheck,
|
||||||
accountUpdatesCounter,
|
accountUpdatesCounter,
|
||||||
cacheHitCounter,
|
cacheHitCounter,
|
||||||
@@ -57,7 +55,6 @@ import FEATURE_FLAGS from './utils/featureFlags';
|
|||||||
import {
|
import {
|
||||||
DLOBProvider,
|
DLOBProvider,
|
||||||
getDLOBProviderFromOrderSubscriber,
|
getDLOBProviderFromOrderSubscriber,
|
||||||
getDLOBProviderFromUserMap,
|
|
||||||
} from './dlobProvider';
|
} from './dlobProvider';
|
||||||
import { RedisClient } from './utils/redisClient';
|
import { RedisClient } from './utils/redisClient';
|
||||||
|
|
||||||
@@ -249,10 +246,7 @@ const main = async () => {
|
|||||||
type: 'polling',
|
type: 'polling',
|
||||||
accountLoader: bulkAccountLoader,
|
accountLoader: bulkAccountLoader,
|
||||||
};
|
};
|
||||||
|
slotSource = bulkAccountLoader;
|
||||||
slotSource = {
|
|
||||||
getSlot: () => bulkAccountLoader!.getSlot(),
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
accountSubscription = {
|
accountSubscription = {
|
||||||
type: 'websocket',
|
type: 'websocket',
|
||||||
@@ -260,10 +254,6 @@ const main = async () => {
|
|||||||
};
|
};
|
||||||
slotSubscriber = new SlotSubscriber(connection);
|
slotSubscriber = new SlotSubscriber(connection);
|
||||||
await slotSubscriber.subscribe();
|
await slotSubscriber.subscribe();
|
||||||
|
|
||||||
slotSource = {
|
|
||||||
getSlot: () => slotSubscriber!.getSlot(),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
driftClient = new DriftClient({
|
driftClient = new DriftClient({
|
||||||
@@ -281,6 +271,7 @@ const main = async () => {
|
|||||||
subscriptionConfig = {
|
subscriptionConfig = {
|
||||||
type: 'websocket',
|
type: 'websocket',
|
||||||
commitment: stateCommitment,
|
commitment: stateCommitment,
|
||||||
|
resyncIntervalMs: WS_FALLBACK_FETCH_INTERVAL,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
subscriptionConfig = {
|
subscriptionConfig = {
|
||||||
@@ -306,23 +297,7 @@ const main = async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
dlobProvider = getDLOBProviderFromOrderSubscriber(orderSubscriber);
|
dlobProvider = getDLOBProviderFromOrderSubscriber(orderSubscriber);
|
||||||
|
slotSource = dlobProvider;
|
||||||
slotSource = {
|
|
||||||
getSlot: () => orderSubscriber.getSlot(),
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
const userMap = new UserMap({
|
|
||||||
driftClient,
|
|
||||||
subscriptionConfig: {
|
|
||||||
type: 'websocket',
|
|
||||||
resubTimeoutMs: 30_000,
|
|
||||||
commitment: stateCommitment,
|
|
||||||
},
|
|
||||||
skipInitialLoad: false,
|
|
||||||
includeIdle: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
dlobProvider = getDLOBProviderFromUserMap(userMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const dlobCoder = DLOBOrdersCoder.create();
|
const dlobCoder = DLOBOrdersCoder.create();
|
||||||
@@ -344,27 +319,6 @@ const main = async () => {
|
|||||||
logger.info(
|
logger.info(
|
||||||
`GPA refresh?: ${useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH}`
|
`GPA refresh?: ${useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH}`
|
||||||
);
|
);
|
||||||
if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) {
|
|
||||||
const recursiveFetch = (delay = WS_FALLBACK_FETCH_INTERVAL) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
const startFetch = Date.now();
|
|
||||||
dlobProvider
|
|
||||||
.fetch()
|
|
||||||
.then(() => {
|
|
||||||
gpaFetchDurationHistogram.record(Date.now() - startFetch);
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
logger.error('Failed to fetch GPA');
|
|
||||||
console.log(e);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
recursiveFetch();
|
|
||||||
});
|
|
||||||
}, delay);
|
|
||||||
};
|
|
||||||
recursiveFetch();
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info(`Initializing DLOBSubscriber...`);
|
logger.info(`Initializing DLOBSubscriber...`);
|
||||||
const initDlobSubscriberStart = Date.now();
|
const initDlobSubscriberStart = Date.now();
|
||||||
|
|||||||
Reference in New Issue
Block a user