@secondlayer/subgraphs 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/src/index.js +9 -9
- package/dist/src/index.js.map +7 -7
- package/dist/src/runtime/block-processor.js +4 -4
- package/dist/src/runtime/block-processor.js.map +5 -5
- package/dist/src/runtime/catchup.d.ts +16 -2
- package/dist/src/runtime/catchup.js +68 -20
- package/dist/src/runtime/catchup.js.map +6 -6
- package/dist/src/runtime/context.js +4 -4
- package/dist/src/runtime/context.js.map +3 -3
- package/dist/src/runtime/processor.js +73 -28
- package/dist/src/runtime/processor.js.map +11 -11
- package/dist/src/runtime/reindex.js +9 -9
- package/dist/src/runtime/reindex.js.map +6 -6
- package/dist/src/runtime/reorg.js +4 -4
- package/dist/src/runtime/reorg.js.map +5 -5
- package/dist/src/schema/index.js +6 -6
- package/dist/src/schema/index.js.map +4 -4
- package/dist/src/service.js +73 -28
- package/dist/src/service.js.map +11 -11
- package/dist/src/validate.js.map +2 -2
- package/package.json +3 -3
package/dist/src/service.js
CHANGED
|
@@ -187,9 +187,9 @@ class SubgraphContext {
|
|
|
187
187
|
const blockHeight = op.data._block_height ?? this.block.height;
|
|
188
188
|
const txId = op.data._tx_id ?? this._tx.txId;
|
|
189
189
|
const baseRow = op.kind === "update" ? { ...op.data, ...op.set ?? {} } : { ...op.data };
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
baseRow._upsert_keys = undefined;
|
|
191
|
+
baseRow._upsert_fallback_keys = undefined;
|
|
192
|
+
baseRow._upsert_fallback_set = undefined;
|
|
193
193
|
return {
|
|
194
194
|
op: op.kind,
|
|
195
195
|
table: op.table,
|
|
@@ -1336,16 +1336,16 @@ function generateSubgraphSQL(def, schemaNameOverride) {
|
|
|
1336
1336
|
const statements = [];
|
|
1337
1337
|
const needsTrgm = Object.values(def.schema).some((table) => Object.values(table.columns).some((col) => col.search));
|
|
1338
1338
|
if (needsTrgm) {
|
|
1339
|
-
statements.push(
|
|
1339
|
+
statements.push("CREATE EXTENSION IF NOT EXISTS pg_trgm");
|
|
1340
1340
|
}
|
|
1341
1341
|
statements.push(`CREATE SCHEMA IF NOT EXISTS ${schemaName}`);
|
|
1342
1342
|
for (const [tableName, tableDef] of Object.entries(def.schema)) {
|
|
1343
1343
|
const qualifiedName = `${schemaName}.${tableName}`;
|
|
1344
1344
|
const columnDefs = [
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1345
|
+
"_id BIGSERIAL PRIMARY KEY",
|
|
1346
|
+
"_block_height BIGINT NOT NULL",
|
|
1347
|
+
"_tx_id TEXT NOT NULL",
|
|
1348
|
+
"_created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()"
|
|
1349
1349
|
];
|
|
1350
1350
|
for (const [colName, col] of Object.entries(tableDef.columns)) {
|
|
1351
1351
|
const sqlType = TYPE_MAP[col.type];
|
|
@@ -1860,10 +1860,47 @@ import {
|
|
|
1860
1860
|
import { getSubgraph } from "@secondlayer/shared/db/queries/subgraphs";
|
|
1861
1861
|
import { logger as logger6 } from "@secondlayer/shared/logger";
|
|
1862
1862
|
var LOG_INTERVAL2 = 1000;
|
|
1863
|
-
var
|
|
1864
|
-
|
|
1865
|
-
|
|
1863
|
+
var HOBBY_CATCHUP_BATCH_CONFIG = {
|
|
1864
|
+
defaultBatchSize: 50,
|
|
1865
|
+
minBatchSize: 25,
|
|
1866
|
+
maxBatchSize: 100,
|
|
1867
|
+
prefetch: false
|
|
1868
|
+
};
|
|
1869
|
+
var STANDARD_CATCHUP_BATCH_CONFIG = {
|
|
1870
|
+
defaultBatchSize: 500,
|
|
1871
|
+
minBatchSize: 100,
|
|
1872
|
+
maxBatchSize: 1000,
|
|
1873
|
+
prefetch: true
|
|
1874
|
+
};
|
|
1866
1875
|
var catchingUp = new Set;
|
|
1876
|
+
function parsePositiveInt2(value) {
|
|
1877
|
+
if (value == null || value.trim() === "")
|
|
1878
|
+
return;
|
|
1879
|
+
const parsed = Number.parseInt(value, 10);
|
|
1880
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
|
|
1881
|
+
}
|
|
1882
|
+
function parseBoolean(value) {
|
|
1883
|
+
if (value == null || value.trim() === "")
|
|
1884
|
+
return;
|
|
1885
|
+
const normalized = value.trim().toLowerCase();
|
|
1886
|
+
if (normalized === "true")
|
|
1887
|
+
return true;
|
|
1888
|
+
if (normalized === "false")
|
|
1889
|
+
return false;
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
function resolveCatchupBatchConfig(env = process.env) {
|
|
1893
|
+
const base = env.TENANT_PLAN?.trim().toLowerCase() === "hobby" ? HOBBY_CATCHUP_BATCH_CONFIG : STANDARD_CATCHUP_BATCH_CONFIG;
|
|
1894
|
+
const minBatchSize = parsePositiveInt2(env.SUBGRAPH_CATCHUP_MIN_BATCH_SIZE) ?? base.minBatchSize;
|
|
1895
|
+
const maxBatchSize = parsePositiveInt2(env.SUBGRAPH_CATCHUP_MAX_BATCH_SIZE) ?? base.maxBatchSize;
|
|
1896
|
+
const defaultBatchSize = parsePositiveInt2(env.SUBGRAPH_CATCHUP_BATCH_SIZE) ?? base.defaultBatchSize;
|
|
1897
|
+
return {
|
|
1898
|
+
minBatchSize,
|
|
1899
|
+
maxBatchSize,
|
|
1900
|
+
defaultBatchSize: Math.min(Math.max(defaultBatchSize, minBatchSize), maxBatchSize),
|
|
1901
|
+
prefetch: parseBoolean(env.SUBGRAPH_CATCHUP_PREFETCH) ?? base.prefetch
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1867
1904
|
function coalesceGaps(blocks) {
|
|
1868
1905
|
if (blocks.length === 0)
|
|
1869
1906
|
return [];
|
|
@@ -1886,11 +1923,11 @@ function coalesceGaps(blocks) {
|
|
|
1886
1923
|
ranges.push({ start, end, reason });
|
|
1887
1924
|
return ranges;
|
|
1888
1925
|
}
|
|
1889
|
-
function adjustBatchSize(current, avgEvents) {
|
|
1926
|
+
function adjustBatchSize(current, avgEvents, config) {
|
|
1890
1927
|
if (avgEvents > 50)
|
|
1891
|
-
return Math.max(Math.round(current * 0.5),
|
|
1928
|
+
return Math.max(Math.round(current * 0.5), config.minBatchSize);
|
|
1892
1929
|
if (avgEvents < 10)
|
|
1893
|
-
return Math.min(Math.round(current * 1.5),
|
|
1930
|
+
return Math.min(Math.round(current * 1.5), config.maxBatchSize);
|
|
1894
1931
|
return current;
|
|
1895
1932
|
}
|
|
1896
1933
|
async function catchUpSubgraph(subgraph, subgraphName) {
|
|
@@ -1921,10 +1958,11 @@ async function catchUpSubgraph(subgraph, subgraphName) {
|
|
|
1921
1958
|
});
|
|
1922
1959
|
const stats = new StatsAccumulator(subgraphName, true);
|
|
1923
1960
|
let processed = 0;
|
|
1924
|
-
|
|
1961
|
+
const batchConfig = resolveCatchupBatchConfig();
|
|
1962
|
+
let batchSize = batchConfig.defaultBatchSize;
|
|
1925
1963
|
let currentHeight = startBlock;
|
|
1926
|
-
let
|
|
1927
|
-
let nextBatchPromise = loadBlockRange(sourceDb, currentHeight,
|
|
1964
|
+
let prefetchedBatchEnd = Math.min(currentHeight + batchSize - 1, chainTip);
|
|
1965
|
+
let nextBatchPromise = batchConfig.prefetch ? loadBlockRange(sourceDb, currentHeight, prefetchedBatchEnd) : undefined;
|
|
1928
1966
|
while (currentHeight <= chainTip) {
|
|
1929
1967
|
const currentRow = await getSubgraph(targetDb, subgraphName);
|
|
1930
1968
|
if (!currentRow || currentRow.status !== "active") {
|
|
@@ -1934,12 +1972,21 @@ async function catchUpSubgraph(subgraph, subgraphName) {
|
|
|
1934
1972
|
});
|
|
1935
1973
|
break;
|
|
1936
1974
|
}
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1975
|
+
let batchEnd;
|
|
1976
|
+
let batch;
|
|
1977
|
+
if (nextBatchPromise) {
|
|
1978
|
+
batch = await nextBatchPromise;
|
|
1979
|
+
batchEnd = prefetchedBatchEnd;
|
|
1980
|
+
const nextStart = batchEnd + 1;
|
|
1981
|
+
if (nextStart <= chainTip) {
|
|
1982
|
+
prefetchedBatchEnd = Math.min(nextStart + batchSize - 1, chainTip);
|
|
1983
|
+
nextBatchPromise = loadBlockRange(sourceDb, nextStart, prefetchedBatchEnd);
|
|
1984
|
+
} else {
|
|
1985
|
+
nextBatchPromise = undefined;
|
|
1986
|
+
}
|
|
1987
|
+
} else {
|
|
1988
|
+
batchEnd = Math.min(currentHeight + batchSize - 1, chainTip);
|
|
1989
|
+
batch = await loadBlockRange(sourceDb, currentHeight, batchEnd);
|
|
1943
1990
|
}
|
|
1944
1991
|
const batchFailedBlocks = [];
|
|
1945
1992
|
for (let height = currentHeight;height <= batchEnd; height++) {
|
|
@@ -1993,7 +2040,7 @@ async function catchUpSubgraph(subgraph, subgraphName) {
|
|
|
1993
2040
|
});
|
|
1994
2041
|
}
|
|
1995
2042
|
const avg = avgEventsPerBlock(batch);
|
|
1996
|
-
batchSize = adjustBatchSize(batchSize, avg);
|
|
2043
|
+
batchSize = adjustBatchSize(batchSize, avg, batchConfig);
|
|
1997
2044
|
currentHeight = batchEnd + 1;
|
|
1998
2045
|
}
|
|
1999
2046
|
await stats.flush(targetDb);
|
|
@@ -2081,9 +2128,7 @@ import { listen as listen2 } from "@secondlayer/shared/queue/listener";
|
|
|
2081
2128
|
import {
|
|
2082
2129
|
getTargetDb as getTargetDb5
|
|
2083
2130
|
} from "@secondlayer/shared/db";
|
|
2084
|
-
import {
|
|
2085
|
-
getSubscriptionSigningSecret
|
|
2086
|
-
} from "@secondlayer/shared/db/queries/subscriptions";
|
|
2131
|
+
import { getSubscriptionSigningSecret } from "@secondlayer/shared/db/queries/subscriptions";
|
|
2087
2132
|
import { logger as logger9 } from "@secondlayer/shared/logger";
|
|
2088
2133
|
import { listen } from "@secondlayer/shared/queue/listener";
|
|
2089
2134
|
import { sql as sql4 } from "kysely";
|
|
@@ -2957,5 +3002,5 @@ var shutdown = async () => {
|
|
|
2957
3002
|
process.on("SIGINT", shutdown);
|
|
2958
3003
|
process.on("SIGTERM", shutdown);
|
|
2959
3004
|
|
|
2960
|
-
//# debugId=
|
|
3005
|
+
//# debugId=A1AAE72D48D7A5B964756E2164756E21
|
|
2961
3006
|
//# sourceMappingURL=service.js.map
|