Skip to content

Commit 6c4aa23

Browse files
authored
fix: skip indexing from outdated schnaps api (#537)
1 parent 08fe370 commit 6c4aa23

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/helpers/turbo.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const SCHNAPS_API_URL = process.env.SCHNAPS_API_URL;
1212
const NETWORK_PREFIX = process.env.NETWORK === 'mainnet' ? 's:' : 's-tn:';
1313
const RUN_INTERVAL = 10 * 1e3; // 10 seconds
1414

15+
const provider = snapshot.utils.getProvider(process.env.DEFAULT_NETWORK, {
16+
broviderUrl: process.env.BROVIDER_URL || 'https://rpc.snapshot.org'
17+
});
18+
1519
// Periodically sync the turbo status of spaces with the schnaps-api
1620
export async function trackTurboStatuses() {
1721
if (!SCHNAPS_API_URL) return;
@@ -63,6 +67,10 @@ async function updateTurboStatuses(spaces: { id: string; turbo_expiration: numbe
6367
async function getSpacesExpirationDates(): Promise<Space[]> {
6468
const query = `
6569
query GetSpaces {
70+
_metadata(id: "last_indexed_block") {
71+
id
72+
value
73+
}
6674
spaces {
6775
id
6876
turbo_expiration
@@ -87,6 +95,12 @@ async function getSpacesExpirationDates(): Promise<Space[]> {
8795
return [];
8896
}
8997

98+
const block = await provider.getBlock('latest');
99+
if (block.number - Number(data.data._metadata.value) > 10) {
100+
console.log('Schnaps API is outdated. Skipping update.');
101+
return [];
102+
}
103+
90104
return data.data.spaces;
91105
} catch (e) {
92106
capture(e);

0 commit comments

Comments
 (0)