envio 3.15.0-subgraph → 3.16.0
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 +40 -34
- package/evm.schema.json +3 -3
- package/fuel.schema.json +2 -2
- package/index.d.ts +3 -3
- package/licenses/README.md +1 -1
- package/package.json +9 -10
- package/src/Batch.res.mjs +5 -5
- package/src/BatchProcessing.res +1 -0
- package/src/BatchProcessing.res.mjs +1 -0
- package/src/Bin.res +0 -7
- package/src/Bin.res.mjs +0 -8
- package/src/ChainFetching.res +17 -456
- package/src/ChainFetching.res.mjs +33 -404
- package/src/ChainState.res +48 -83
- package/src/ChainState.res.mjs +83 -115
- package/src/ChainState.resi +0 -26
- package/src/Clock.res +57 -0
- package/src/Clock.res.mjs +72 -0
- package/src/Config.res +7 -16
- package/src/Config.res.mjs +4 -11
- package/src/ContractRegisterContext.res +6 -3
- package/src/ContractRegisterContext.res.mjs +2 -4
- package/src/Core.res +5 -136
- package/src/Core.res.mjs +1 -90
- package/src/CrossChainState.res +2 -8
- package/src/CrossChainState.res.mjs +3 -3
- package/src/Ecosystem.res +4 -7
- package/src/Ecosystem.res.mjs +8 -8
- package/src/EffectState.res +10 -2
- package/src/EffectState.res.mjs +8 -4
- package/src/EffectState.resi +3 -1
- package/src/EntityId.res +2 -7
- package/src/EntityId.res.mjs +1 -8
- package/src/EntityTables.res +4 -1
- package/src/EntityTables.res.mjs +1 -1
- package/src/Env.res +0 -16
- package/src/Env.res.mjs +0 -11
- package/src/EventProcessing.res +1 -38
- package/src/EventProcessing.res.mjs +1 -28
- package/src/FetchState.res +160 -319
- package/src/FetchState.res.mjs +182 -292
- package/src/FinalizeBackfill.res +2 -4
- package/src/FinalizeBackfill.res.mjs +3 -4
- package/src/HandlerLoader.res +15 -39
- package/src/HandlerLoader.res.mjs +8 -27
- package/src/HandlerRegister.res +0 -4
- package/src/HandlerRegister.res.mjs +2 -5
- package/src/HandlerRegister.resi +0 -2
- package/src/InMemoryTable.res +17 -16
- package/src/InMemoryTable.res.mjs +14 -15
- package/src/IndexerState.res +28 -4
- package/src/IndexerState.res.mjs +19 -6
- package/src/IndexerState.resi +4 -0
- package/src/Internal.res +0 -110
- package/src/Internal.res.mjs +1 -115
- package/src/LoadLayer.res +21 -47
- package/src/LoadLayer.res.mjs +47 -72
- package/src/LoadLayer.resi +0 -26
- package/src/Main.res +1 -14
- package/src/Main.res.mjs +3 -4
- package/src/Persistence.res +3 -23
- package/src/Persistence.res.mjs +3 -3
- package/src/Rollback.res +0 -1
- package/src/Rollback.res.mjs +1 -1
- package/src/RunScope.res +0 -3
- package/src/SafeCheckpointTracking.res +4 -4
- package/src/SafeCheckpointTracking.res.mjs +1 -1
- package/src/SimulateItems.res +26 -42
- package/src/SimulateItems.res.mjs +16 -40
- package/src/StagedRows.res +106 -0
- package/src/StagedRows.res.mjs +102 -0
- package/src/Staging.res +32 -14
- package/src/Staging.res.mjs +17 -20
- package/src/Storage.res +277 -998
- package/src/Storage.res.mjs +216 -731
- package/src/Supervisor.res +75 -56
- package/src/Supervisor.res.mjs +55 -26
- package/src/TestIndexer.res +22 -27
- package/src/TestIndexer.res.mjs +20 -17
- package/src/Throttler.res +15 -8
- package/src/Throttler.res.mjs +9 -6
- package/src/Throttler.resi +1 -1
- package/src/UserContext.res +46 -410
- package/src/UserContext.res.mjs +30 -318
- package/src/Utils.res +0 -23
- package/src/Utils.res.mjs +1 -17
- package/src/Writing.res +0 -1
- package/src/Writing.res.mjs +1 -1
- package/src/bindings/ClickHouse.res +0 -322
- package/src/bindings/ClickHouse.res.mjs +0 -338
- package/src/bindings/StorageClient.res +107 -175
- package/src/bindings/StorageClient.res.mjs +19 -8
- package/src/bindings/Vitest.res +0 -26
- package/src/bindings/Vitest.res.mjs +0 -3
- package/src/db/Table.res +24 -150
- package/src/db/Table.res.mjs +38 -272
- package/src/sources/AddressSet.res +0 -2
- package/src/sources/AddressStore.res +0 -3
- package/src/sources/ChainSources.res +2 -0
- package/src/sources/ChainSources.res.mjs +2 -2
- package/src/sources/EvmChain.res +4 -7
- package/src/sources/EvmChain.res.mjs +5 -4
- package/src/sources/EvmHyperSyncSource.res +2 -2
- package/src/sources/EvmHyperSyncSource.res.mjs +1 -1
- package/src/sources/EvmRpcClient.res +13 -3
- package/src/sources/EvmRpcClient.res.mjs +4 -3
- package/src/sources/EvmRpcWs.res +4 -3
- package/src/sources/EvmRpcWs.res.mjs +2 -2
- package/src/sources/HeightFeed.res +31 -10
- package/src/sources/HeightFeed.res.mjs +10 -6
- package/src/sources/HeightStream.res +32 -17
- package/src/sources/HeightStream.res.mjs +10 -10
- package/src/sources/HyperSync.res +1 -2
- package/src/sources/HyperSync.res.mjs +1 -2
- package/src/sources/HyperSyncSSE.res +4 -6
- package/src/sources/HyperSyncSSE.res.mjs +2 -2
- package/src/sources/RpcSource.res +10 -1
- package/src/sources/RpcSource.res.mjs +4 -3
- package/src/sources/Source.res +3 -0
- package/src/sources/SourceManager.res +85 -104
- package/src/sources/SourceManager.res.mjs +18 -37
- package/src/sources/SourceManager.resi +3 -5
- package/src/sources/StartBlockResolver.res +1 -0
- package/src/sources/StartBlockResolver.res.mjs +4 -3
- package/src/sources/SvmHyperSyncSource.res +2 -2
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
- package/svm.schema.json +3 -3
- package/src/EffectCacheLookup.res +0 -98
- package/src/EffectCacheLookup.res.mjs +0 -116
- package/src/PgWriting.res +0 -36
- package/src/PgWriting.res.mjs +0 -34
- package/src/PreloadLookahead.res +0 -184
- package/src/PreloadLookahead.res.mjs +0 -197
- package/src/SubgraphLog.res +0 -19
- package/src/SubgraphLog.res.mjs +0 -26
- package/src/SyncWrites.res +0 -101
- package/src/SyncWrites.res.mjs +0 -98
- package/src/db/IndexDefinition.res +0 -47
- package/src/db/IndexDefinition.res.mjs +0 -60
- package/src/sources/CallSource.res +0 -274
- package/src/sources/CallSource.res.mjs +0 -196
- package/src/subgraph/abi-types.ts +0 -84
- package/src/subgraph/aggregations.ts +0 -745
- package/src/subgraph/as-package.ts +0 -143
- package/src/subgraph/assemblyscript-regex.ts +0 -67
- package/src/subgraph/assemblyscript.ts +0 -731
- package/src/subgraph/blocks.ts +0 -398
- package/src/subgraph/calls-source.ts +0 -702
- package/src/subgraph/calls.ts +0 -258
- package/src/subgraph/conformance.ts +0 -106
- package/src/subgraph/errors.ts +0 -85
- package/src/subgraph/graft.ts +0 -73
- package/src/subgraph/graph-cli-worker.mjs +0 -35
- package/src/subgraph/graph-cli.ts +0 -900
- package/src/subgraph/graph-node-decimal.ts +0 -199
- package/src/subgraph/graph-ts-enums.ts +0 -28
- package/src/subgraph/graph-ts-types/VERSION +0 -2
- package/src/subgraph/graph-ts-types/chain/arweave.d.ts +0 -70
- package/src/subgraph/graph-ts-types/chain/cosmos.d.ts +0 -327
- package/src/subgraph/graph-ts-types/chain/ethereum.d.ts +0 -233
- package/src/subgraph/graph-ts-types/chain/near.d.ts +0 -253
- package/src/subgraph/graph-ts-types/chain/starknet.d.ts +0 -32
- package/src/subgraph/graph-ts-types/common/collections.d.ts +0 -136
- package/src/subgraph/graph-ts-types/common/conversion.d.ts +0 -11
- package/src/subgraph/graph-ts-types/common/datasource.d.ts +0 -30
- package/src/subgraph/graph-ts-types/common/eager-offset.d.ts +0 -0
- package/src/subgraph/graph-ts-types/common/json.d.ts +0 -17
- package/src/subgraph/graph-ts-types/common/numbers.d.ts +0 -120
- package/src/subgraph/graph-ts-types/common/value.d.ts +0 -120
- package/src/subgraph/graph-ts-types/common/yaml.d.ts +0 -90
- package/src/subgraph/graph-ts-types/global/global.d.ts +0 -194
- package/src/subgraph/graph-ts-types/helper-functions.d.ts +0 -22
- package/src/subgraph/graph-ts-types/index.d.ts +0 -102
- package/src/subgraph/graph-ts.ts +0 -4280
- package/src/subgraph/hosts.ts +0 -554
- package/src/subgraph/log.ts +0 -28
- package/src/subgraph/receipts.ts +0 -184
- package/src/subgraph/register-slots.ts +0 -93
- package/src/subgraph/rollup.ts +0 -109
- package/src/subgraph/rpc.ts +0 -337
- package/src/subgraph/runtime.ts +0 -2060
- package/src/subgraph/scope.ts +0 -177
- package/src/subgraph/stats.ts +0 -42
- package/src/subgraph/template-instances.ts +0 -66
- package/src/subgraph/toolchain.ts +0 -327
- package/src/subgraph/transient.ts +0 -176
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Every host op that leaves the process — contract calls, balances, block
|
|
3
|
-
* timestamps, IPFS, Arweave, ENS — runs through `untilAnswered`.
|
|
4
|
-
*
|
|
5
|
-
* envio exits on a handler error; it has no batch retry. So a transient failure
|
|
6
|
-
* that escaped a host op would stop the whole indexer on one rate-limited call,
|
|
7
|
-
* where graph-node backs off and asks again. Only a deterministic answer — a
|
|
8
|
-
* value, a revert, a definite miss — may reach the mapping or end the run.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { warn } from "./log.ts";
|
|
12
|
-
|
|
13
|
-
const MAX_BACKOFF_MS = 30_000;
|
|
14
|
-
|
|
15
|
-
function positive(name: string, fallback: number): number {
|
|
16
|
-
const value = Number(process.env[name]);
|
|
17
|
-
return Number.isFinite(value) && value > 0 ? value : fallback;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Each attempt's deadline: a request that never answers is given up on. */
|
|
21
|
-
export function requestTimeoutMs(): number {
|
|
22
|
-
return positive("ENVIO_SUBGRAPH_REQUEST_TIMEOUT_MS", 30_000);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function firstBackoffMs(): number {
|
|
26
|
-
return positive("ENVIO_SUBGRAPH_RETRY_BACKOFF_MS", 500);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** A response status the endpoint answered with. */
|
|
30
|
-
export class HttpStatusError extends Error {
|
|
31
|
-
constructor(
|
|
32
|
-
readonly url: string,
|
|
33
|
-
readonly status: number,
|
|
34
|
-
statusText: string,
|
|
35
|
-
) {
|
|
36
|
-
super(`${url} answered ${status} ${statusText}`.trim());
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
class AttemptTimeout extends Error {
|
|
41
|
-
constructor(what: string, ms: number) {
|
|
42
|
-
super(`${what} didn't answer within ${ms}ms`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const TRANSIENT_TEXT =
|
|
47
|
-
/rate.?limit|too many requests|capacity|limit exceeded|exceeds? (the |its |defined )?limit|timed? ?out|timeout|header not found|ECONNRESET|ECONNREFUSED|EPIPE|ETIMEDOUT|EAI_AGAIN|ENOTFOUND|socket hang up|fetch failed|network|temporar|unavailable|overloaded|busy|try again/i;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* JSON-RPC codes public endpoints send for "slow down": -32005 "limit
|
|
51
|
-
* exceeded" (Infura, Tenderly), -32097 (blastapi), -32090 (Alchemy).
|
|
52
|
-
*/
|
|
53
|
-
const RATE_LIMIT_CODES = new Set([-32005, -32097, -32090]);
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* The rate limits, and the node's own failure, -32603 "Internal error", which
|
|
57
|
-
* the same request answers on the next try. graph-node asks again after every
|
|
58
|
-
* eth_call error that isn't a revert (`interpret_eth_call_error`).
|
|
59
|
-
*/
|
|
60
|
-
const TRANSIENT_CODES = new Set([...RATE_LIMIT_CODES, -32603]);
|
|
61
|
-
|
|
62
|
-
function transientStatus(status: number): boolean {
|
|
63
|
-
return status === 408 || status === 425 || status === 429 || status >= 500;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const RATE_LIMIT_TEXT = /rate.?limit|too many requests|request limit|limit exceeded/i;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* The endpoint saying "slow down" — HTTP 429, or a JSON-RPC rate-limit error —
|
|
70
|
-
* on an error or on a JSON-RPC error object, anywhere down its cause chain.
|
|
71
|
-
*/
|
|
72
|
-
export function isRateLimit(error: unknown): boolean {
|
|
73
|
-
let current: any = error;
|
|
74
|
-
for (let depth = 0; current && depth < 10; depth++) {
|
|
75
|
-
if (current.status === 429 || current.code === 429 || RATE_LIMIT_CODES.has(current.code)) return true;
|
|
76
|
-
if (typeof current.message === "string" && RATE_LIMIT_TEXT.test(current.message)) return true;
|
|
77
|
-
current = current.cause;
|
|
78
|
-
}
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Whether asking again could get a different answer. A status decides it when
|
|
84
|
-
* there is one; otherwise the error's own words do, down its cause chain.
|
|
85
|
-
*/
|
|
86
|
-
export function isTransient(error: unknown): boolean {
|
|
87
|
-
let current: any = error;
|
|
88
|
-
for (let depth = 0; current && depth < 10; depth++) {
|
|
89
|
-
if (current instanceof AttemptTimeout) return true;
|
|
90
|
-
if (current.name === "AbortError" || current.name === "TimeoutError") return true;
|
|
91
|
-
if (typeof current.status === "number") return transientStatus(current.status);
|
|
92
|
-
if (TRANSIENT_CODES.has(current.code)) return true;
|
|
93
|
-
if (typeof current.message === "string" && TRANSIENT_TEXT.test(current.message)) return true;
|
|
94
|
-
current = current.cause;
|
|
95
|
-
}
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* One try, given `requestTimeoutMs`. The deadline holds even if the attempt
|
|
103
|
-
* ignores its signal, so a hung request can't stall the handler waiting on it.
|
|
104
|
-
*/
|
|
105
|
-
export async function withDeadline<T>(
|
|
106
|
-
what: string,
|
|
107
|
-
attempt: (signal: AbortSignal) => Promise<T>,
|
|
108
|
-
): Promise<T> {
|
|
109
|
-
const timeout = requestTimeoutMs();
|
|
110
|
-
const controller = new AbortController();
|
|
111
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
112
|
-
const deadline = new Promise<never>((_, reject) => {
|
|
113
|
-
timer = setTimeout(() => {
|
|
114
|
-
const error = new AttemptTimeout(what, timeout);
|
|
115
|
-
controller.abort(error);
|
|
116
|
-
reject(error);
|
|
117
|
-
}, timeout);
|
|
118
|
-
});
|
|
119
|
-
try {
|
|
120
|
-
return await Promise.race([attempt(controller.signal), deadline]);
|
|
121
|
-
} finally {
|
|
122
|
-
clearTimeout(timer);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Tries `attempt` until it answers, backing off exponentially between transient
|
|
128
|
-
* failures. With `maxTries`, the last transient failure is thrown once that
|
|
129
|
-
* many attempts have failed; with `budgetMs`, once the next wait would end
|
|
130
|
-
* past that long after the first attempt.
|
|
131
|
-
*/
|
|
132
|
-
export async function untilAnswered<T>(
|
|
133
|
-
what: string,
|
|
134
|
-
attempt: (signal: AbortSignal) => Promise<T>,
|
|
135
|
-
{
|
|
136
|
-
maxTries = Infinity,
|
|
137
|
-
// An attempt that goes through a gate (`rpc.ts`) gets its deadline there,
|
|
138
|
-
// once it holds a slot: timed from here, a request still queued behind
|
|
139
|
-
// the gate would time out unsent, be asked again, and be sent twice.
|
|
140
|
-
deadline = true,
|
|
141
|
-
budgetMs = Infinity,
|
|
142
|
-
}: { maxTries?: number; deadline?: boolean; budgetMs?: number } = {},
|
|
143
|
-
): Promise<T> {
|
|
144
|
-
const started = Date.now();
|
|
145
|
-
for (let tries = 0; ; tries++) {
|
|
146
|
-
try {
|
|
147
|
-
return await (deadline ? withDeadline(what, attempt) : attempt(new AbortController().signal));
|
|
148
|
-
} catch (error) {
|
|
149
|
-
if (!isTransient(error) || tries + 1 >= maxTries) throw error;
|
|
150
|
-
const wait = Math.min(firstBackoffMs() * 2 ** tries, MAX_BACKOFF_MS);
|
|
151
|
-
if (Date.now() - started + wait > budgetMs) throw error;
|
|
152
|
-
const reason = error instanceof Error ? error.message.split("\n")[0] : String(error);
|
|
153
|
-
warn(`Envio Subgraph: ${what} failed (${reason}); asking again in ${wait}ms.`);
|
|
154
|
-
await sleep(wait);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* A revert is data: the mapping's `try_` sees `{reverted: true}`, and every
|
|
161
|
-
* node gives the same one. Geth says it in the message; Parity, OpenEthereum
|
|
162
|
-
* and older Nethermind answer -32015 "VM execution error." and say it in the
|
|
163
|
-
* error's data ("Reverted 0x…"), as graph-node reads them.
|
|
164
|
-
*/
|
|
165
|
-
export function isRevert(error: unknown): boolean {
|
|
166
|
-
let current: any = error;
|
|
167
|
-
for (let depth = 0; current && depth < 10; depth++) {
|
|
168
|
-
for (const text of [current.message, current.data]) {
|
|
169
|
-
if (typeof text === "string" && REVERT_TEXT.test(text)) return true;
|
|
170
|
-
}
|
|
171
|
-
current = current.cause;
|
|
172
|
-
}
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const REVERT_TEXT = /revert|invalid opcode|bad instruction|bad jump|out of gas/i;
|