Skip to content

Commit 311400f

Browse files
thelostone-mc0xKurthussedev
authored
improvments for GG (#662)
* have fallback IPFS * feat: store ipfs data in db * chore: move prices to it's own schema * Refactor lock acquisition and release logic (#661) * update lock logic * forceRelease of schema * index single chain (#657) * update schema name * updates * fix * Revert "Refactor lock acquisition and release logic (#661)" This reverts commit 9a2ffe1. * chore: avoid duplicate write + cleanup (#664) * chore: avoid duplicate write * cleanup * improve locking (#665) add forciblyAcquireLockForSchema * test * remove unused code * add unique constraint * chore: revert acquireWriteLock function * f * fix: args parser --------- Co-authored-by: Kurt <[email protected]> Co-authored-by: Hussein Martinez <[email protected]>
1 parent 8305b2b commit 311400f

12 files changed

+636
-86
lines changed

.env.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ DATABASE_URL=postgres://postgres:postgres@localhost:5432/grants_stack_indexer
4242
# METIS_ANDROMEDA_RPC_URL
4343

4444
#COINGECKO_API_KEY=
45-
#IPFS_GATEWAY=
45+
#IPFS_GATEWAYs=[]
46+
#WHITELISTED_ADDRESSES=["0x123..","0x456.."]
4647

4748
# optional, enable the Postgraphile Pro plugin: https://www.npmjs.com/package/@graphile/pro
4849
#GRAPHILE_LICENSE

docs/reindexing.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ When deploying changes to the indexer, it's important to clarify the results you
1212
- The indexer will create a new schema in Postgres named `chain_data_${version}`. If this schema does not exist, it will be created, all necessary tables will be set up, and indexing will start from scratch.
1313
- If the schema already exists, the indexer will resume indexing from the last indexed block unless the `--drop-db` flag is specified via the CLI. This will drop the existing database and start fresh.
1414

15-
### Using `--drop-db` in Development
15+
### Dropping Schemas in Development
1616

17-
- During development, you can use the `--drop-db` flag to ensure the indexer always deletes the existing schema and migrates from scratch. This can be useful for testing schema changes and event handler modifications without retaining old data.
17+
- During development, you can use the `--drop-db` flag to ensure the indexer always deletes all existing schema and migrates from scratch. This can be useful for testing schema changes and event handler modifications without retaining old data.
18+
19+
- During development, you can use the `--drop-chain-db` flag to ensure the indexer always deletes chain schema and migrates from scratch.
20+
21+
- During development, you can use the `--drop-ipfs-db` flag to ensure the indexer always deletes ipfs schema and migrates from scratch.
22+
23+
- During development, you can use the `--drop-price-db` flag to ensure the indexer always deletes price schema and migrates from scratch.
1824

1925
### Important Notes
2026

indexer-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ services:
2020
ENABLE_RESOURCE_MONITOR: ${ENABLE_RESOURCE_MONITOR}
2121
ESTIMATES_LINEARQF_WORKER_POOL_SIZE: ${ESTIMATES_LINEARQF_WORKER_POOL_SIZE}
2222
PINO_PRETTY: ${PINO_PRETTY}
23-
IPFS_GATEWAY: ${IPFS_GATEWAY}
23+
IPFS_GATEWAYS: ${IPFS_GATEWAYS}
2424
COINGECKO_API_KEY: ${COINGECKO_API_KEY}
2525
GRAPHILE_LICENSE: ${GRAPHILE_LICENSE}
2626
SEPOLIA_RPC_URL: ${SEPOLIA_RPC_URL}
@@ -62,7 +62,7 @@ services:
6262
ENABLE_RESOURCE_MONITOR: ${ENABLE_RESOURCE_MONITOR}
6363
ESTIMATES_LINEARQF_WORKER_POOL_SIZE: ${ESTIMATES_LINEARQF_WORKER_POOL_SIZE}
6464
PINO_PRETTY: ${PINO_PRETTY}
65-
IPFS_GATEWAY: ${IPFS_GATEWAY}
65+
IPFS_GATEWAYS: ${IPFS_GATEWAYS}
6666
COINGECKO_API_KEY: ${COINGECKO_API_KEY}
6767
GRAPHILE_LICENSE: ${GRAPHILE_LICENSE}
6868
SEPOLIA_RPC_URL: ${SEPOLIA_RPC_URL}

src/config.ts

+41-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ type CoingeckoSupportedChainId =
2020
| 42220
2121
| 1088;
2222

23-
const CHAIN_DATA_VERSION = "81";
23+
const CHAIN_DATA_VERSION = "83";
24+
const IPFS_DATA_VERSION = "1";
25+
const PRICE_DATA_VERSION = "1";
2426

2527
export type Token = {
2628
code: string;
@@ -1818,7 +1820,7 @@ export type Config = {
18181820
httpServerWaitForSync: boolean;
18191821
httpServerEnabled: boolean;
18201822
indexerEnabled: boolean;
1821-
ipfsGateway: string;
1823+
ipfsGateways: string[];
18221824
coingeckoApiKey: string | null;
18231825
coingeckoApiUrl: string;
18241826
chains: Chain[];
@@ -1829,11 +1831,18 @@ export type Config = {
18291831
readOnlyDatabaseUrl: string;
18301832
dataVersion: string;
18311833
databaseSchemaName: string;
1834+
ipfsDataVersion: string;
1835+
ipfsDatabaseSchemaName: string;
1836+
priceDataVersion: string;
1837+
priceDatabaseSchemaName: string;
18321838
hostname: string;
18331839
pinoPretty: boolean;
18341840
deploymentEnvironment: "local" | "development" | "staging" | "production";
18351841
enableResourceMonitor: boolean;
18361842
dropDb: boolean;
1843+
dropChainDb: boolean;
1844+
dropIpfsDb: boolean;
1845+
dropPriceDb: boolean;
18371846
removeCache: boolean;
18381847
estimatesLinearQfWorkerPoolSize: number | null;
18391848
};
@@ -1847,9 +1856,18 @@ export function getConfig(): Config {
18471856
"from-block": {
18481857
type: "string",
18491858
},
1859+
"drop-chain-db": {
1860+
type: "boolean",
1861+
},
1862+
"drop-ipfs-db": {
1863+
type: "boolean",
1864+
},
18501865
"drop-db": {
18511866
type: "boolean",
18521867
},
1868+
"drop-price-db": {
1869+
type: "boolean",
1870+
},
18531871
"rm-cache": {
18541872
type: "boolean",
18551873
},
@@ -1981,10 +1999,11 @@ export function getConfig(): Config {
19811999

19822000
const runOnce = z.boolean().default(false).parse(args["run-once"]);
19832001

1984-
const ipfsGateway = z
2002+
const ipfsGateways = z
19852003
.string()
1986-
.default("https://ipfs.io")
1987-
.parse(process.env.IPFS_GATEWAY);
2004+
.array()
2005+
.default(["https://ipfs.io"])
2006+
.parse(JSON.parse(process.env.IPFS_GATEWAYS!));
19882007

19892008
const sentryDsn = z
19902009
.union([z.string(), z.null()])
@@ -2001,7 +2020,16 @@ export function getConfig(): Config {
20012020
const dataVersion = CHAIN_DATA_VERSION;
20022021
const databaseSchemaName = `chain_data_${dataVersion}`;
20032022

2023+
const ipfsDataVersion = IPFS_DATA_VERSION;
2024+
const ipfsDatabaseSchemaName = `ipfs_data_${ipfsDataVersion}`;
2025+
2026+
const priceDataVersion = PRICE_DATA_VERSION;
2027+
const priceDatabaseSchemaName = `price_data_${priceDataVersion}`;
2028+
20042029
const dropDb = z.boolean().default(false).parse(args["drop-db"]);
2030+
const dropChainDb = z.boolean().default(false).parse(args["drop-chain-db"]);
2031+
const dropIpfsDb = z.boolean().default(false).parse(args["drop-ipfs-db"]);
2032+
const dropPriceDb = z.boolean().default(false).parse(args["drop-price-db"]);
20052033

20062034
const removeCache = z.boolean().default(false).parse(args["rm-cache"]);
20072035

@@ -2041,7 +2069,7 @@ export function getConfig(): Config {
20412069
cacheDir,
20422070
logLevel,
20432071
runOnce,
2044-
ipfsGateway,
2072+
ipfsGateways,
20452073
passportScorerId,
20462074
apiHttpPort,
20472075
pinoPretty,
@@ -2050,9 +2078,16 @@ export function getConfig(): Config {
20502078
databaseUrl,
20512079
readOnlyDatabaseUrl,
20522080
dropDb,
2081+
dropChainDb,
2082+
dropIpfsDb,
2083+
dropPriceDb,
20532084
removeCache,
20542085
dataVersion,
20552086
databaseSchemaName,
2087+
ipfsDataVersion,
2088+
ipfsDatabaseSchemaName,
2089+
priceDataVersion,
2090+
priceDatabaseSchemaName,
20562091
httpServerWaitForSync,
20572092
httpServerEnabled,
20582093
indexerEnabled,

src/database/changeset.ts

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
NewPrice,
1717
NewLegacyProject,
1818
NewApplicationPayout,
19+
NewIpfsData,
1920
} from "./schema.js";
2021

2122
export type DataChange =
@@ -140,4 +141,8 @@ export type DataChange =
140141
| {
141142
type: "InsertApplicationPayout";
142143
payout: NewApplicationPayout;
144+
}
145+
| {
146+
type: "InsertIpfsData";
147+
ipfs: NewIpfsData;
143148
};

0 commit comments

Comments
 (0)