@apibara/protocol 2.1.0-beta.5 → 2.1.0-beta.50
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/dist/codec.cjs +242 -0
- package/dist/codec.cjs.map +1 -0
- package/dist/codec.d.cts +81 -0
- package/dist/codec.d.mts +81 -0
- package/dist/codec.d.ts +81 -0
- package/dist/codec.mjs +224 -0
- package/dist/codec.mjs.map +1 -0
- package/dist/index.cjs +45 -30
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +41 -22
- package/dist/index.mjs.map +1 -0
- package/dist/rpc/index.cjs +12 -0
- package/dist/rpc/index.cjs.map +1 -0
- package/dist/rpc/index.d.cts +6 -0
- package/dist/rpc/index.d.mts +6 -0
- package/dist/rpc/index.d.ts +6 -0
- package/dist/rpc/index.mjs +3 -0
- package/dist/rpc/index.mjs.map +1 -0
- package/dist/shared/{protocol.4b1cfe2c.d.cts → protocol.0e734e33.d.cts} +400 -247
- package/dist/shared/{protocol.4b1cfe2c.d.mts → protocol.21e66b9e.d.mts} +400 -247
- package/dist/shared/{protocol.e39e40d6.cjs → protocol.53f81a1e.cjs} +177 -177
- package/dist/shared/protocol.53f81a1e.cjs.map +1 -0
- package/dist/shared/protocol.54f17699.cjs +536 -0
- package/dist/shared/protocol.54f17699.cjs.map +1 -0
- package/dist/shared/{protocol.991ff9ad.mjs → protocol.68fdd897.mjs} +176 -171
- package/dist/shared/protocol.68fdd897.mjs.map +1 -0
- package/dist/shared/protocol.6ab8d6dd.d.mts +104 -0
- package/dist/shared/protocol.7aa4aab6.d.cts +104 -0
- package/dist/shared/protocol.8407f25e.d.ts +104 -0
- package/dist/shared/{protocol.4b1cfe2c.d.ts → protocol.8fb09325.d.ts} +400 -247
- package/dist/shared/protocol.bde61588.mjs +530 -0
- package/dist/shared/protocol.bde61588.mjs.map +1 -0
- package/dist/testing/index.cjs +26 -38
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +107 -54
- package/dist/testing/index.d.mts +107 -54
- package/dist/testing/index.d.ts +107 -54
- package/dist/testing/index.mjs +26 -38
- package/dist/testing/index.mjs.map +1 -0
- package/package.json +14 -3
- package/src/client.ts +39 -14
- package/src/codec.ts +662 -0
- package/src/common.ts +70 -53
- package/src/config.ts +4 -4
- package/src/index.ts +2 -0
- package/src/proto/google/protobuf/duration.ts +8 -6
- package/src/proto/stream.ts +38 -24
- package/src/rpc/chain-tracker.ts +327 -0
- package/src/rpc/client.ts +51 -0
- package/src/rpc/config.ts +88 -0
- package/src/rpc/data-stream.ts +366 -0
- package/src/rpc/helpers.ts +9 -0
- package/src/rpc/index.ts +13 -0
- package/src/status.ts +9 -16
- package/src/stream.ts +145 -144
- package/src/testing/mock.ts +36 -38
- package/src/common.test.ts +0 -67
- package/src/status.test.ts +0 -51
- package/src/stream.test-d.ts +0 -33
- package/src/stream.test.ts +0 -254
- package/src/testing/client.test.ts +0 -97
- package/src/testing/mock.test.ts +0 -35
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const viem = require('viem');
|
|
4
|
+
|
|
5
|
+
class RpcStreamConfig {
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function blockInfoToCursor(blockInfo) {
|
|
9
|
+
return {
|
|
10
|
+
orderKey: blockInfo.blockNumber,
|
|
11
|
+
uniqueKey: blockInfo.blockHash
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var __accessCheck = (obj, member, msg) => {
|
|
16
|
+
if (!member.has(obj))
|
|
17
|
+
throw TypeError("Cannot " + msg);
|
|
18
|
+
};
|
|
19
|
+
var __privateGet = (obj, member, getter) => {
|
|
20
|
+
__accessCheck(obj, member, "read from private field");
|
|
21
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
22
|
+
};
|
|
23
|
+
var __privateAdd = (obj, member, value) => {
|
|
24
|
+
if (member.has(obj))
|
|
25
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
26
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
27
|
+
};
|
|
28
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
29
|
+
__accessCheck(obj, member, "write to private field");
|
|
30
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
var _finalized, _head, _canonical;
|
|
34
|
+
class ChainTracker {
|
|
35
|
+
constructor({ head, finalized }) {
|
|
36
|
+
__privateAdd(this, _finalized, void 0);
|
|
37
|
+
__privateAdd(this, _head, void 0);
|
|
38
|
+
__privateAdd(this, _canonical, void 0);
|
|
39
|
+
__privateSet(this, _finalized, finalized);
|
|
40
|
+
__privateSet(this, _head, head);
|
|
41
|
+
__privateSet(this, _canonical, /* @__PURE__ */ new Map([
|
|
42
|
+
[finalized.blockNumber, finalized],
|
|
43
|
+
[head.blockNumber, head]
|
|
44
|
+
]));
|
|
45
|
+
}
|
|
46
|
+
head() {
|
|
47
|
+
return blockInfoToCursor(__privateGet(this, _head));
|
|
48
|
+
}
|
|
49
|
+
finalized() {
|
|
50
|
+
return blockInfoToCursor(__privateGet(this, _finalized));
|
|
51
|
+
}
|
|
52
|
+
updateFinalized(newFinalized) {
|
|
53
|
+
if (newFinalized.blockNumber < __privateGet(this, _finalized).blockNumber) {
|
|
54
|
+
throw new Error("Finalized cursor moved backwards");
|
|
55
|
+
}
|
|
56
|
+
if (newFinalized.blockNumber === __privateGet(this, _finalized).blockNumber) {
|
|
57
|
+
if (newFinalized.blockHash !== __privateGet(this, _finalized).blockHash) {
|
|
58
|
+
throw new Error("Received a different finalized cursor");
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
for (let bn = __privateGet(this, _finalized).blockNumber; bn < newFinalized.blockNumber; bn++) {
|
|
63
|
+
__privateGet(this, _canonical).delete(bn);
|
|
64
|
+
}
|
|
65
|
+
__privateGet(this, _canonical).set(newFinalized.blockNumber, newFinalized);
|
|
66
|
+
__privateSet(this, _finalized, newFinalized);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
addToCanonicalChain({ blockInfo }) {
|
|
70
|
+
const existing = __privateGet(this, _canonical).get(blockInfo.blockNumber);
|
|
71
|
+
if (existing) {
|
|
72
|
+
if (existing.blockHash !== blockInfo.blockHash) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Block already exists in canonical chain: previous ${existing.blockHash}, new ${blockInfo.blockHash}`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const parent = __privateGet(this, _canonical).get(blockInfo.blockNumber - 1n);
|
|
79
|
+
if (!parent) {
|
|
80
|
+
throw new Error("Parent block not in canonical chain");
|
|
81
|
+
}
|
|
82
|
+
if (parent.blockHash !== blockInfo.parentBlockHash) {
|
|
83
|
+
throw new Error("Parent block hash mismatch.");
|
|
84
|
+
}
|
|
85
|
+
__privateGet(this, _canonical).set(blockInfo.blockNumber, blockInfo);
|
|
86
|
+
return { status: "success" };
|
|
87
|
+
}
|
|
88
|
+
async updateHead({
|
|
89
|
+
newHead,
|
|
90
|
+
fetchCursorByHash
|
|
91
|
+
}) {
|
|
92
|
+
if (newHead.blockNumber === __privateGet(this, _head).blockNumber && newHead.blockHash === __privateGet(this, _head).blockHash) {
|
|
93
|
+
return { status: "unchanged" };
|
|
94
|
+
}
|
|
95
|
+
if (newHead.blockNumber === __privateGet(this, _head).blockNumber + 1n && newHead.parentBlockHash === __privateGet(this, _head).blockHash) {
|
|
96
|
+
__privateGet(this, _canonical).set(newHead.blockNumber, newHead);
|
|
97
|
+
__privateSet(this, _head, newHead);
|
|
98
|
+
return { status: "success" };
|
|
99
|
+
}
|
|
100
|
+
if (newHead.blockNumber <= __privateGet(this, _head).blockNumber) {
|
|
101
|
+
let currentNewHead = newHead;
|
|
102
|
+
for (let bn = newHead.blockNumber + 1n; bn <= __privateGet(this, _head).blockNumber; bn++) {
|
|
103
|
+
__privateGet(this, _canonical).delete(bn);
|
|
104
|
+
}
|
|
105
|
+
const existing = __privateGet(this, _canonical).get(currentNewHead.blockNumber);
|
|
106
|
+
if (existing && existing.blockHash === currentNewHead.blockHash) {
|
|
107
|
+
__privateSet(this, _head, existing);
|
|
108
|
+
return {
|
|
109
|
+
status: "reorg",
|
|
110
|
+
cursor: blockInfoToCursor(existing)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
while (currentNewHead.blockNumber > __privateGet(this, _finalized).blockNumber) {
|
|
114
|
+
__privateGet(this, _canonical).delete(currentNewHead.blockNumber);
|
|
115
|
+
const canonicalParent = __privateGet(this, _canonical).get(
|
|
116
|
+
currentNewHead.blockNumber - 1n
|
|
117
|
+
);
|
|
118
|
+
if (!canonicalParent) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
"Cannot reconcile new head with canonical chain: missing parent in canonical chain"
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (canonicalParent.blockHash === currentNewHead.parentBlockHash) {
|
|
124
|
+
__privateSet(this, _head, canonicalParent);
|
|
125
|
+
return {
|
|
126
|
+
status: "reorg",
|
|
127
|
+
cursor: blockInfoToCursor(canonicalParent)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const parent = await fetchCursorByHash(currentNewHead.parentBlockHash);
|
|
131
|
+
if (!parent) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
"Cannot reconcile new head with canonical chain: failed to fetch parent"
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
currentNewHead = parent;
|
|
137
|
+
}
|
|
138
|
+
throw new Error("Cannot reconcile new head with canonical chain.");
|
|
139
|
+
}
|
|
140
|
+
let current = newHead;
|
|
141
|
+
let reorgDetected = false;
|
|
142
|
+
const blocksToApply = [newHead];
|
|
143
|
+
while (true) {
|
|
144
|
+
const parent = await fetchCursorByHash(current.parentBlockHash);
|
|
145
|
+
if (!parent) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
"Cannot reconcile new head with canonical chain: failed to fetch parent"
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
if (parent.blockNumber === __privateGet(this, _head).blockNumber) {
|
|
151
|
+
if (parent.blockHash === __privateGet(this, _head).blockHash) {
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
const headParent = __privateGet(this, _canonical).get(__privateGet(this, _head).blockNumber - 1n);
|
|
155
|
+
if (!headParent) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
"Cannot reconcile new head with canonical chain: missing parent in canonical chain"
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
__privateGet(this, _canonical).delete(__privateGet(this, _head).blockNumber);
|
|
161
|
+
__privateSet(this, _head, headParent);
|
|
162
|
+
reorgDetected = true;
|
|
163
|
+
}
|
|
164
|
+
blocksToApply.push(parent);
|
|
165
|
+
current = parent;
|
|
166
|
+
}
|
|
167
|
+
for (const block of blocksToApply.reverse()) {
|
|
168
|
+
__privateGet(this, _canonical).set(block.blockNumber, block);
|
|
169
|
+
}
|
|
170
|
+
const previousHead = __privateGet(this, _head);
|
|
171
|
+
__privateSet(this, _head, newHead);
|
|
172
|
+
if (reorgDetected) {
|
|
173
|
+
return {
|
|
174
|
+
status: "reorg",
|
|
175
|
+
cursor: blockInfoToCursor(previousHead)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
return { status: "success" };
|
|
179
|
+
}
|
|
180
|
+
async initializeStartingCursor({
|
|
181
|
+
cursor,
|
|
182
|
+
fetchCursor
|
|
183
|
+
}) {
|
|
184
|
+
const head = this.head();
|
|
185
|
+
const finalized = this.finalized();
|
|
186
|
+
if (cursor.orderKey > head.orderKey) {
|
|
187
|
+
return { canonical: false, reason: "cursor is ahead of head" };
|
|
188
|
+
}
|
|
189
|
+
const expectedInfo = await fetchCursor(cursor.orderKey);
|
|
190
|
+
if (!cursor.uniqueKey) {
|
|
191
|
+
if (expectedInfo === null) {
|
|
192
|
+
throw new Error("Failed to initialize canonical cursor");
|
|
193
|
+
}
|
|
194
|
+
if (expectedInfo.blockNumber > finalized.orderKey) {
|
|
195
|
+
__privateGet(this, _canonical).set(expectedInfo.blockNumber, expectedInfo);
|
|
196
|
+
}
|
|
197
|
+
return { canonical: true, fullCursor: blockInfoToCursor(expectedInfo) };
|
|
198
|
+
}
|
|
199
|
+
if (expectedInfo === null) {
|
|
200
|
+
return {
|
|
201
|
+
canonical: false,
|
|
202
|
+
reason: "expected block does not exist"
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const expectedCursor = blockInfoToCursor(expectedInfo);
|
|
206
|
+
if (!expectedCursor.uniqueKey) {
|
|
207
|
+
return {
|
|
208
|
+
canonical: false,
|
|
209
|
+
reason: "expected cursor has no unique key (hash)"
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
if (expectedCursor.orderKey !== cursor.orderKey) {
|
|
213
|
+
return {
|
|
214
|
+
canonical: false,
|
|
215
|
+
reason: "cursor order key does not match expected order key"
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
if (viem.fromHex(expectedCursor.uniqueKey, "bigint") !== viem.fromHex(cursor.uniqueKey, "bigint")) {
|
|
219
|
+
return {
|
|
220
|
+
canonical: false,
|
|
221
|
+
reason: `cursor hash does not match expected hash: ${cursor.uniqueKey} !== ${expectedCursor.uniqueKey}`
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
if (expectedInfo.blockNumber > finalized.orderKey) {
|
|
225
|
+
__privateGet(this, _canonical).set(expectedInfo.blockNumber, expectedInfo);
|
|
226
|
+
}
|
|
227
|
+
return { canonical: true, fullCursor: expectedCursor };
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
_finalized = new WeakMap();
|
|
231
|
+
_head = new WeakMap();
|
|
232
|
+
_canonical = new WeakMap();
|
|
233
|
+
function createChainTracker({
|
|
234
|
+
head,
|
|
235
|
+
finalized
|
|
236
|
+
}) {
|
|
237
|
+
return new ChainTracker({ finalized, head });
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
var __defProp = Object.defineProperty;
|
|
241
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
242
|
+
var __publicField = (obj, key, value) => {
|
|
243
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
244
|
+
return value;
|
|
245
|
+
};
|
|
246
|
+
const DEFAULT_HEARTBEAT_INTERVAL_MS = 3e4;
|
|
247
|
+
class RpcDataStream {
|
|
248
|
+
constructor(config, request, options) {
|
|
249
|
+
this.config = config;
|
|
250
|
+
this.request = request;
|
|
251
|
+
this.options = options;
|
|
252
|
+
__publicField(this, "heartbeatIntervalMs");
|
|
253
|
+
this.heartbeatIntervalMs = request.heartbeatInterval ? Number(request.heartbeatInterval.seconds) * 1e3 : DEFAULT_HEARTBEAT_INTERVAL_MS;
|
|
254
|
+
}
|
|
255
|
+
async *[Symbol.asyncIterator]() {
|
|
256
|
+
const startingState = await this.initialize();
|
|
257
|
+
yield* dataStreamLoop(startingState);
|
|
258
|
+
}
|
|
259
|
+
async initialize() {
|
|
260
|
+
if (this.request.filter.length === 0) {
|
|
261
|
+
throw new Error("Request.filter: empty.");
|
|
262
|
+
}
|
|
263
|
+
if (this.request.filter.length > 1) {
|
|
264
|
+
throw new Error("Request.filter: only one filter is supported.");
|
|
265
|
+
}
|
|
266
|
+
const [head, finalized] = await Promise.all([
|
|
267
|
+
this.config.fetchCursor({ blockTag: "latest" }),
|
|
268
|
+
this.config.fetchCursor({ blockTag: "finalized" })
|
|
269
|
+
]);
|
|
270
|
+
if (finalized === null) {
|
|
271
|
+
throw new Error("EvmRpcStream requires a finalized block");
|
|
272
|
+
}
|
|
273
|
+
if (head === null) {
|
|
274
|
+
throw new Error("EvmRpcStream requires a chain with blocks.");
|
|
275
|
+
}
|
|
276
|
+
const chainTracker = createChainTracker({
|
|
277
|
+
head,
|
|
278
|
+
finalized
|
|
279
|
+
});
|
|
280
|
+
let cursor;
|
|
281
|
+
if (this.request.startingCursor) {
|
|
282
|
+
cursor = this.request.startingCursor;
|
|
283
|
+
const { canonical, reason, fullCursor } = await chainTracker.initializeStartingCursor({
|
|
284
|
+
cursor,
|
|
285
|
+
fetchCursor: (blockNumber) => this.config.fetchCursor({ blockNumber })
|
|
286
|
+
});
|
|
287
|
+
if (!canonical) {
|
|
288
|
+
throw new Error(`Starting cursor is not canonical: ${reason}`);
|
|
289
|
+
}
|
|
290
|
+
cursor = fullCursor;
|
|
291
|
+
} else {
|
|
292
|
+
cursor = { orderKey: -1n };
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
cursor,
|
|
296
|
+
lastHeartbeat: Date.now(),
|
|
297
|
+
lastFinalizedRefresh: Date.now(),
|
|
298
|
+
lastBackfillMessage: Date.now(),
|
|
299
|
+
chainTracker,
|
|
300
|
+
config: this.config,
|
|
301
|
+
heartbeatIntervalMs: this.heartbeatIntervalMs,
|
|
302
|
+
filter: this.request.filter[0],
|
|
303
|
+
options: this.options
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
async function* dataStreamLoop(state) {
|
|
308
|
+
while (shouldContinue(state)) {
|
|
309
|
+
const { cursor, chainTracker } = state;
|
|
310
|
+
if (shouldSendHeartbeat(state)) {
|
|
311
|
+
state.lastHeartbeat = Date.now();
|
|
312
|
+
yield { _tag: "heartbeat" };
|
|
313
|
+
}
|
|
314
|
+
if (shouldRefreshFinalized(state)) {
|
|
315
|
+
const finalizedInfo = await state.config.fetchCursor({
|
|
316
|
+
blockTag: "finalized"
|
|
317
|
+
});
|
|
318
|
+
if (finalizedInfo === null) {
|
|
319
|
+
throw new Error("Failed to fetch finalized cursor");
|
|
320
|
+
}
|
|
321
|
+
const finalized2 = blockInfoToCursor(finalizedInfo);
|
|
322
|
+
const finalizedChanged = state.chainTracker.updateFinalized(finalizedInfo);
|
|
323
|
+
if (finalizedChanged && state.cursor.orderKey > finalized2.orderKey) {
|
|
324
|
+
yield { _tag: "finalize", finalize: { cursor: finalized2 } };
|
|
325
|
+
}
|
|
326
|
+
state.lastFinalizedRefresh = Date.now();
|
|
327
|
+
}
|
|
328
|
+
const finalized = chainTracker.finalized();
|
|
329
|
+
if (cursor.orderKey < finalized.orderKey) {
|
|
330
|
+
yield* backfillFinalizedBlocks(state);
|
|
331
|
+
} else {
|
|
332
|
+
if (isAtHead(state)) {
|
|
333
|
+
yield* waitForHeadChange(state);
|
|
334
|
+
} else {
|
|
335
|
+
yield* produceNextBlock(state);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async function* backfillFinalizedBlocks(state) {
|
|
341
|
+
const { cursor, chainTracker, config, filter } = state;
|
|
342
|
+
const finalized = chainTracker.finalized();
|
|
343
|
+
const force = shouldForceBackfill(state);
|
|
344
|
+
const filterData = await config.fetchBlockRange({
|
|
345
|
+
startBlock: cursor.orderKey + 1n,
|
|
346
|
+
finalizedBlock: finalized.orderKey,
|
|
347
|
+
force,
|
|
348
|
+
filter
|
|
349
|
+
});
|
|
350
|
+
if (filterData.endBlock > finalized.orderKey) {
|
|
351
|
+
throw new Error(
|
|
352
|
+
"Network-specific stream returned invalid data, crossing the finalized block."
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
for (const data of filterData.data) {
|
|
356
|
+
state.lastHeartbeat = Date.now();
|
|
357
|
+
state.lastBackfillMessage = Date.now();
|
|
358
|
+
yield {
|
|
359
|
+
_tag: "data",
|
|
360
|
+
data: {
|
|
361
|
+
cursor: data.cursor,
|
|
362
|
+
endCursor: data.endCursor,
|
|
363
|
+
data: [data.block],
|
|
364
|
+
finality: "finalized",
|
|
365
|
+
production: "backfill"
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
if (filterData.endBlock === finalized.orderKey) {
|
|
370
|
+
state.cursor = finalized;
|
|
371
|
+
} else {
|
|
372
|
+
state.cursor = { orderKey: filterData.endBlock };
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
async function* produceNextBlock(state) {
|
|
376
|
+
const currentBlockHash = state.cursor.uniqueKey;
|
|
377
|
+
if (currentBlockHash === void 0) {
|
|
378
|
+
throw new Error("Live production phase without cursor's hash.");
|
|
379
|
+
}
|
|
380
|
+
const result = await state.config.fetchBlockByNumber({
|
|
381
|
+
blockNumber: state.cursor.orderKey + 1n,
|
|
382
|
+
isAtHead: isAtHead(state),
|
|
383
|
+
expectedParentBlockHash: currentBlockHash,
|
|
384
|
+
filter: state.filter
|
|
385
|
+
});
|
|
386
|
+
if (result.status === "reorg") {
|
|
387
|
+
throw new Error("Reorg not implemented");
|
|
388
|
+
}
|
|
389
|
+
const { data, blockInfo } = result;
|
|
390
|
+
state.cursor = {
|
|
391
|
+
orderKey: blockInfo.blockNumber,
|
|
392
|
+
uniqueKey: blockInfo.blockHash
|
|
393
|
+
};
|
|
394
|
+
const { status: headUpdateStatus } = state.chainTracker.addToCanonicalChain({
|
|
395
|
+
blockInfo
|
|
396
|
+
});
|
|
397
|
+
if (headUpdateStatus !== "success") {
|
|
398
|
+
throw new Error("Failed to update head. Would cause reorg.");
|
|
399
|
+
}
|
|
400
|
+
if (data.block !== null) {
|
|
401
|
+
state.lastHeartbeat = Date.now();
|
|
402
|
+
const production = isAtHead(state) ? "live" : "backfill";
|
|
403
|
+
yield {
|
|
404
|
+
_tag: "data",
|
|
405
|
+
data: {
|
|
406
|
+
cursor: data.cursor,
|
|
407
|
+
endCursor: data.endCursor,
|
|
408
|
+
data: [data.block],
|
|
409
|
+
finality: "accepted",
|
|
410
|
+
production
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
async function* waitForHeadChange(state) {
|
|
416
|
+
const { chainTracker, config } = state;
|
|
417
|
+
const heartbeatDeadline = state.lastHeartbeat + state.heartbeatIntervalMs;
|
|
418
|
+
const finalizedRefreshDeadline = state.lastFinalizedRefresh + config.finalizedRefreshIntervalMs();
|
|
419
|
+
while (true) {
|
|
420
|
+
const now = Date.now();
|
|
421
|
+
if (now >= heartbeatDeadline || now >= finalizedRefreshDeadline) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const maybeNewHead = await config.fetchCursor({ blockTag: "latest" });
|
|
425
|
+
if (maybeNewHead === null) {
|
|
426
|
+
throw new Error("Failed to fetch the latest block");
|
|
427
|
+
}
|
|
428
|
+
const result = await chainTracker.updateHead({
|
|
429
|
+
newHead: maybeNewHead,
|
|
430
|
+
fetchCursorByHash: (blockHash) => config.fetchCursor({ blockHash })
|
|
431
|
+
});
|
|
432
|
+
switch (result.status) {
|
|
433
|
+
case "unchanged": {
|
|
434
|
+
const heartbeatTimeout = heartbeatDeadline - now;
|
|
435
|
+
const finalizedTimeout = finalizedRefreshDeadline - now;
|
|
436
|
+
await sleep(
|
|
437
|
+
Math.min(
|
|
438
|
+
heartbeatTimeout,
|
|
439
|
+
finalizedTimeout,
|
|
440
|
+
config.headRefreshIntervalMs()
|
|
441
|
+
)
|
|
442
|
+
);
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
case "reorg": {
|
|
446
|
+
const { cursor } = result;
|
|
447
|
+
if (cursor.orderKey < state.cursor.orderKey) {
|
|
448
|
+
state.cursor = cursor;
|
|
449
|
+
yield {
|
|
450
|
+
_tag: "invalidate",
|
|
451
|
+
invalidate: { cursor }
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
case "success": {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
function shouldSendHeartbeat(state) {
|
|
463
|
+
const { heartbeatIntervalMs, lastHeartbeat } = state;
|
|
464
|
+
const now = Date.now();
|
|
465
|
+
return now - lastHeartbeat >= heartbeatIntervalMs;
|
|
466
|
+
}
|
|
467
|
+
function shouldForceBackfill(state) {
|
|
468
|
+
const { lastBackfillMessage, heartbeatIntervalMs } = state;
|
|
469
|
+
const now = Date.now();
|
|
470
|
+
return now - lastBackfillMessage >= heartbeatIntervalMs;
|
|
471
|
+
}
|
|
472
|
+
function shouldContinue(state) {
|
|
473
|
+
const { endingCursor } = state.options || {};
|
|
474
|
+
if (endingCursor === void 0)
|
|
475
|
+
return true;
|
|
476
|
+
return state.cursor.orderKey < endingCursor.orderKey;
|
|
477
|
+
}
|
|
478
|
+
function shouldRefreshFinalized(state) {
|
|
479
|
+
const { lastFinalizedRefresh, config } = state;
|
|
480
|
+
const now = Date.now();
|
|
481
|
+
return now - lastFinalizedRefresh >= config.finalizedRefreshIntervalMs();
|
|
482
|
+
}
|
|
483
|
+
function isAtHead(state) {
|
|
484
|
+
const head = state.chainTracker.head();
|
|
485
|
+
return state.cursor.orderKey === head.orderKey;
|
|
486
|
+
}
|
|
487
|
+
function sleep(duration) {
|
|
488
|
+
return new Promise((resolve) => setTimeout(resolve, duration));
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
class RpcClient {
|
|
492
|
+
constructor(config) {
|
|
493
|
+
this.config = config;
|
|
494
|
+
}
|
|
495
|
+
async status(_request, _options) {
|
|
496
|
+
const [currentHead, finalized] = await Promise.all([
|
|
497
|
+
this.config.fetchCursor({ blockTag: "latest" }),
|
|
498
|
+
this.config.fetchCursor({ blockTag: "finalized" })
|
|
499
|
+
]);
|
|
500
|
+
const starting = { orderKey: 0n };
|
|
501
|
+
return {
|
|
502
|
+
currentHead: currentHead ? blockInfoToCursor(currentHead) : void 0,
|
|
503
|
+
lastIngested: currentHead ? blockInfoToCursor(currentHead) : void 0,
|
|
504
|
+
finalized: finalized ? blockInfoToCursor(finalized) : void 0,
|
|
505
|
+
starting
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
streamData(request, options) {
|
|
509
|
+
const index = 0;
|
|
510
|
+
for (const filter of request.filter) {
|
|
511
|
+
const { valid, error } = this.config.validateFilter(filter);
|
|
512
|
+
if (!valid) {
|
|
513
|
+
throw new Error(`Filter at position ${index} is invalid: ${error}`);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return new RpcDataStream(this.config, request, options);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
function createRpcClient(config) {
|
|
520
|
+
return new RpcClient(config);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
const index = {
|
|
524
|
+
__proto__: null,
|
|
525
|
+
RpcClient: RpcClient,
|
|
526
|
+
RpcDataStream: RpcDataStream,
|
|
527
|
+
RpcStreamConfig: RpcStreamConfig,
|
|
528
|
+
createRpcClient: createRpcClient
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
exports.RpcClient = RpcClient;
|
|
532
|
+
exports.RpcDataStream = RpcDataStream;
|
|
533
|
+
exports.RpcStreamConfig = RpcStreamConfig;
|
|
534
|
+
exports.createRpcClient = createRpcClient;
|
|
535
|
+
exports.index = index;
|
|
536
|
+
//# sourceMappingURL=protocol.54f17699.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.54f17699.cjs","sources":["../../src/rpc/config.ts","../../src/rpc/helpers.ts","../../src/rpc/chain-tracker.ts","../../src/rpc/data-stream.ts","../../src/rpc/client.ts"],"sourcesContent":["import type { Bytes, Cursor } from \"../common\";\n\nexport type FetchBlockRangeArgs<TFilter> = {\n startBlock: bigint;\n finalizedBlock: bigint;\n force: boolean;\n filter: TFilter;\n};\n\nexport type FetchBlockRangeResult<TBlock> = {\n startBlock: bigint;\n endBlock: bigint;\n data: FetchBlockResult<TBlock>[];\n};\n\nexport type FetchBlockResult<TBlock> = {\n block: TBlock | null;\n cursor: Cursor | undefined;\n endCursor: Cursor;\n};\n\nexport type BlockInfo = {\n blockNumber: bigint;\n blockHash: Bytes;\n parentBlockHash: Bytes;\n};\n\nexport type FetchBlockByNumberArgs<TFilter> = {\n blockNumber: bigint;\n expectedParentBlockHash: Bytes;\n isAtHead: boolean;\n filter: TFilter;\n};\n\nexport type FetchBlockByNumberResult<TBlock> =\n | {\n status: \"success\";\n data: FetchBlockResult<TBlock>;\n blockInfo: BlockInfo;\n }\n | {\n status: \"reorg\";\n blockInfo: BlockInfo;\n };\n\nexport type FetchCursorArgs =\n | {\n blockTag: \"latest\" | \"finalized\";\n blockNumber?: undefined;\n blockHash?: undefined;\n }\n | {\n blockTag?: undefined;\n blockNumber: bigint;\n blockHash?: undefined;\n }\n | {\n blockTag?: undefined;\n blockNumber?: undefined;\n blockHash: Bytes;\n };\n\nexport type ValidateFilterResult =\n | {\n valid: true;\n error?: undefined;\n }\n | {\n valid: false;\n error: string;\n };\n\nexport abstract class RpcStreamConfig<TFilter, TBlock> {\n abstract headRefreshIntervalMs(): number;\n abstract finalizedRefreshIntervalMs(): number;\n\n abstract fetchCursor(args: FetchCursorArgs): Promise<BlockInfo | null>;\n\n abstract validateFilter(filter: TFilter): ValidateFilterResult;\n\n abstract fetchBlockRange(\n args: FetchBlockRangeArgs<TFilter>,\n ): Promise<FetchBlockRangeResult<TBlock>>;\n\n abstract fetchBlockByNumber(\n args: FetchBlockByNumberArgs<TFilter>,\n ): Promise<FetchBlockByNumberResult<TBlock>>;\n}\n","import type { Cursor } from \"../common\";\nimport type { BlockInfo } from \"./config\";\n\nexport function blockInfoToCursor(blockInfo: BlockInfo): Cursor {\n return {\n orderKey: blockInfo.blockNumber,\n uniqueKey: blockInfo.blockHash,\n };\n}\n","import { fromHex } from \"viem\";\nimport type { Bytes, Cursor } from \"../common\";\nimport type { BlockInfo } from \"./config\";\nimport { blockInfoToCursor } from \"./helpers\";\n\ntype UpdateHeadArgs = {\n newHead: BlockInfo;\n fetchCursorByHash: (hash: Bytes) => Promise<BlockInfo | null>;\n};\n\ntype UpdateHeadResult =\n | {\n status: \"unchanged\";\n }\n | {\n status: \"success\";\n }\n | {\n status: \"reorg\";\n cursor: Cursor;\n };\n\nexport class ChainTracker {\n #finalized: BlockInfo;\n #head: BlockInfo;\n #canonical: Map<bigint, BlockInfo>;\n\n constructor({ head, finalized }: { finalized: BlockInfo; head: BlockInfo }) {\n this.#finalized = finalized;\n this.#head = head;\n this.#canonical = new Map([\n [finalized.blockNumber, finalized],\n [head.blockNumber, head],\n ]);\n }\n\n head(): Cursor {\n return blockInfoToCursor(this.#head);\n }\n\n finalized(): Cursor {\n return blockInfoToCursor(this.#finalized);\n }\n\n updateFinalized(newFinalized: BlockInfo) {\n // console.debug(\n // `updateFinalized: new=${newFinalized.blockNumber} old=${this.#finalized.blockNumber}`,\n // );\n\n if (newFinalized.blockNumber < this.#finalized.blockNumber) {\n throw new Error(\"Finalized cursor moved backwards\");\n }\n\n if (newFinalized.blockNumber === this.#finalized.blockNumber) {\n if (newFinalized.blockHash !== this.#finalized.blockHash) {\n throw new Error(\"Received a different finalized cursor\");\n }\n\n return false;\n }\n\n // Delete all blocks that are now finalized.\n for (\n let bn = this.#finalized.blockNumber;\n bn < newFinalized.blockNumber;\n bn++\n ) {\n this.#canonical.delete(bn);\n }\n\n this.#canonical.set(newFinalized.blockNumber, newFinalized);\n this.#finalized = newFinalized;\n\n return true;\n }\n\n addToCanonicalChain({ blockInfo }: { blockInfo: BlockInfo }) {\n // console.debug(`addToCanonicalChain: block=${blockInfo.blockNumber}`);\n\n const existing = this.#canonical.get(blockInfo.blockNumber);\n\n if (existing) {\n if (existing.blockHash !== blockInfo.blockHash) {\n throw new Error(\n `Block already exists in canonical chain: previous ${existing.blockHash}, new ${blockInfo.blockHash}`,\n );\n }\n }\n\n const parent = this.#canonical.get(blockInfo.blockNumber - 1n);\n if (!parent) {\n throw new Error(\"Parent block not in canonical chain\");\n }\n\n if (parent.blockHash !== blockInfo.parentBlockHash) {\n throw new Error(\"Parent block hash mismatch.\");\n }\n\n this.#canonical.set(blockInfo.blockNumber, blockInfo);\n\n // console.log(\"Canon updated: \", canonical);\n\n return { status: \"success\" };\n }\n\n async updateHead({\n newHead,\n fetchCursorByHash,\n }: UpdateHeadArgs): Promise<UpdateHeadResult> {\n // console.debug(\n // `updateHead: new=${newHead.blockNumber} old=${this.#head.blockNumber}`,\n // );\n\n // No changes to the chain.\n if (\n newHead.blockNumber === this.#head.blockNumber &&\n newHead.blockHash === this.#head.blockHash\n ) {\n return { status: \"unchanged\" };\n }\n\n // Most common case: the new head is the block after the current head.\n if (\n newHead.blockNumber === this.#head.blockNumber + 1n &&\n newHead.parentBlockHash === this.#head.blockHash\n ) {\n this.#canonical.set(newHead.blockNumber, newHead);\n this.#head = newHead;\n return { status: \"success\" };\n }\n\n // The new chain is not longer.\n if (newHead.blockNumber <= this.#head.blockNumber) {\n // console.log(\"head=\", this.#head, \"newhead=\", newHead);\n let currentNewHead = newHead;\n // Delete all blocks from canonical chain after the new head.\n for (\n let bn = newHead.blockNumber + 1n;\n bn <= this.#head.blockNumber;\n bn++\n ) {\n this.#canonical.delete(bn);\n }\n\n // Check if the chain was simply shrunk to this block.\n const existing = this.#canonical.get(currentNewHead.blockNumber);\n if (existing && existing.blockHash === currentNewHead.blockHash) {\n this.#head = existing;\n return {\n status: \"reorg\",\n cursor: blockInfoToCursor(existing),\n };\n }\n\n while (currentNewHead.blockNumber > this.#finalized.blockNumber) {\n this.#canonical.delete(currentNewHead.blockNumber);\n\n const canonicalParent = this.#canonical.get(\n currentNewHead.blockNumber - 1n,\n );\n\n if (!canonicalParent) {\n throw new Error(\n \"Cannot reconcile new head with canonical chain: missing parent in canonical chain\",\n );\n }\n\n // We found the common ancestor.\n if (canonicalParent.blockHash === currentNewHead.parentBlockHash) {\n this.#head = canonicalParent;\n return {\n status: \"reorg\",\n cursor: blockInfoToCursor(canonicalParent),\n };\n }\n\n const parent = await fetchCursorByHash(currentNewHead.parentBlockHash);\n\n if (!parent) {\n throw new Error(\n \"Cannot reconcile new head with canonical chain: failed to fetch parent\",\n );\n }\n\n currentNewHead = parent;\n }\n\n throw new Error(\"Cannot reconcile new head with canonical chain.\");\n }\n\n // In all other cases we need to \"join\" the new head with the existing chain.\n // The new chain is longer and we need the missing blocks.\n // This may result in reorgs.\n\n let current = newHead;\n let reorgDetected = false;\n const blocksToApply = [newHead];\n\n while (true) {\n const parent = await fetchCursorByHash(current.parentBlockHash);\n\n if (!parent) {\n throw new Error(\n \"Cannot reconcile new head with canonical chain: failed to fetch parent\",\n );\n }\n\n if (parent.blockNumber === this.#head.blockNumber) {\n if (parent.blockHash === this.#head.blockHash) {\n break;\n }\n\n const headParent = this.#canonical.get(this.#head.blockNumber - 1n);\n if (!headParent) {\n throw new Error(\n \"Cannot reconcile new head with canonical chain: missing parent in canonical chain\",\n );\n }\n\n // Update current head.\n this.#canonical.delete(this.#head.blockNumber);\n this.#head = headParent;\n reorgDetected = true;\n }\n\n blocksToApply.push(parent);\n current = parent;\n }\n\n for (const block of blocksToApply.reverse()) {\n this.#canonical.set(block.blockNumber, block);\n }\n\n const previousHead = this.#head;\n this.#head = newHead;\n\n if (reorgDetected) {\n return {\n status: \"reorg\",\n cursor: blockInfoToCursor(previousHead),\n };\n }\n\n return { status: \"success\" };\n }\n\n async initializeStartingCursor({\n cursor,\n fetchCursor,\n }: {\n cursor: Cursor;\n fetchCursor: (blockNumber: bigint) => Promise<BlockInfo | null>;\n }): Promise<\n | { canonical: true; reason?: undefined; fullCursor: Cursor }\n | { canonical: false; reason: string; fullCursor?: undefined }\n > {\n const head = this.head();\n const finalized = this.finalized();\n\n if (cursor.orderKey > head.orderKey) {\n return { canonical: false, reason: \"cursor is ahead of head\" };\n }\n\n const expectedInfo = await fetchCursor(cursor.orderKey);\n if (!cursor.uniqueKey) {\n if (expectedInfo === null) {\n throw new Error(\"Failed to initialize canonical cursor\");\n }\n\n if (expectedInfo.blockNumber > finalized.orderKey) {\n this.#canonical.set(expectedInfo.blockNumber, expectedInfo);\n }\n\n return { canonical: true, fullCursor: blockInfoToCursor(expectedInfo) };\n }\n\n if (expectedInfo === null) {\n return {\n canonical: false,\n reason: \"expected block does not exist\",\n };\n }\n\n const expectedCursor = blockInfoToCursor(expectedInfo);\n\n // These two checks are redundant, but they are kept to avoid issues with bad config implementations.\n if (!expectedCursor.uniqueKey) {\n return {\n canonical: false,\n reason: \"expected cursor has no unique key (hash)\",\n };\n }\n\n if (expectedCursor.orderKey !== cursor.orderKey) {\n return {\n canonical: false,\n reason: \"cursor order key does not match expected order key\",\n };\n }\n\n if (\n fromHex(expectedCursor.uniqueKey, \"bigint\") !==\n fromHex(cursor.uniqueKey, \"bigint\")\n ) {\n return {\n canonical: false,\n reason: `cursor hash does not match expected hash: ${cursor.uniqueKey} !== ${expectedCursor.uniqueKey}`,\n };\n }\n\n if (expectedInfo.blockNumber > finalized.orderKey) {\n this.#canonical.set(expectedInfo.blockNumber, expectedInfo);\n }\n\n return { canonical: true, fullCursor: expectedCursor };\n }\n}\n\nexport function createChainTracker({\n head,\n finalized,\n}: {\n head: BlockInfo;\n finalized: BlockInfo;\n}): ChainTracker {\n return new ChainTracker({ finalized, head });\n}\n","import type { StreamDataOptions } from \"../client\";\nimport type { Cursor } from \"../common\";\nimport type { StreamDataRequest, StreamDataResponse } from \"../stream\";\nimport { type ChainTracker, createChainTracker } from \"./chain-tracker\";\nimport type { RpcStreamConfig } from \"./config\";\nimport { blockInfoToCursor } from \"./helpers\";\n\nconst DEFAULT_HEARTBEAT_INTERVAL_MS = 30_000;\n\ntype State<TFilter, TBlock> = {\n // The network-specific config.\n config: RpcStreamConfig<TFilter, TBlock>;\n // The current cursor, that is the last block that was filtered.\n cursor: Cursor;\n // When the finalized block was last refreshed.\n lastFinalizedRefresh: number;\n // When the last heartbeat was sent.\n lastHeartbeat: number;\n // When the last backfill message was sent.\n lastBackfillMessage: number;\n // Track the chain's state.\n chainTracker: ChainTracker;\n // Heartbeat interval in milliseconds.\n heartbeatIntervalMs: number;\n // The request filter.\n filter: TFilter;\n // The request options.\n options?: StreamDataOptions;\n};\n\nexport class RpcDataStream<TFilter, TBlock> {\n private heartbeatIntervalMs: number;\n\n constructor(\n private config: RpcStreamConfig<TFilter, TBlock>,\n private request: StreamDataRequest<TFilter>,\n private options?: StreamDataOptions,\n ) {\n this.heartbeatIntervalMs = request.heartbeatInterval\n ? Number(request.heartbeatInterval.seconds) * 1000\n : DEFAULT_HEARTBEAT_INTERVAL_MS;\n }\n\n async *[Symbol.asyncIterator](): AsyncIterator<StreamDataResponse<TBlock>> {\n const startingState = await this.initialize();\n yield* dataStreamLoop(startingState);\n }\n\n private async initialize(): Promise<State<TFilter, TBlock>> {\n if (this.request.filter.length === 0) {\n throw new Error(\"Request.filter: empty.\");\n }\n\n if (this.request.filter.length > 1) {\n throw new Error(\"Request.filter: only one filter is supported.\");\n }\n\n const [head, finalized] = await Promise.all([\n this.config.fetchCursor({ blockTag: \"latest\" }),\n this.config.fetchCursor({ blockTag: \"finalized\" }),\n ]);\n\n if (finalized === null) {\n throw new Error(\"EvmRpcStream requires a finalized block\");\n }\n\n if (head === null) {\n throw new Error(\"EvmRpcStream requires a chain with blocks.\");\n }\n\n const chainTracker = createChainTracker({\n head,\n finalized,\n });\n\n let cursor: Cursor;\n if (this.request.startingCursor) {\n cursor = this.request.startingCursor;\n\n const { canonical, reason, fullCursor } =\n await chainTracker.initializeStartingCursor({\n cursor,\n fetchCursor: (blockNumber) =>\n this.config.fetchCursor({ blockNumber }),\n });\n\n if (!canonical) {\n throw new Error(`Starting cursor is not canonical: ${reason}`);\n }\n\n cursor = fullCursor;\n } else {\n cursor = { orderKey: -1n };\n }\n\n return {\n cursor,\n lastHeartbeat: Date.now(),\n lastFinalizedRefresh: Date.now(),\n lastBackfillMessage: Date.now(),\n chainTracker,\n config: this.config,\n heartbeatIntervalMs: this.heartbeatIntervalMs,\n filter: this.request.filter[0],\n options: this.options,\n };\n }\n}\n\nasync function* dataStreamLoop<TFilter, TBlock>(\n state: State<TFilter, TBlock>,\n): AsyncGenerator<StreamDataResponse<TBlock>> {\n while (shouldContinue(state)) {\n const { cursor, chainTracker } = state;\n\n // Always check for heartbeats first to ensure we don't miss any.\n if (shouldSendHeartbeat(state)) {\n state.lastHeartbeat = Date.now();\n yield { _tag: \"heartbeat\" };\n }\n\n if (shouldRefreshFinalized(state)) {\n const finalizedInfo = await state.config.fetchCursor({\n blockTag: \"finalized\",\n });\n\n if (finalizedInfo === null) {\n throw new Error(\"Failed to fetch finalized cursor\");\n }\n\n const finalized = blockInfoToCursor(finalizedInfo);\n const finalizedChanged =\n state.chainTracker.updateFinalized(finalizedInfo);\n\n // Only send finalized if it's needed.\n if (finalizedChanged && state.cursor.orderKey > finalized.orderKey) {\n yield { _tag: \"finalize\", finalize: { cursor: finalized } };\n }\n\n state.lastFinalizedRefresh = Date.now();\n }\n\n const finalized = chainTracker.finalized();\n\n // console.debug(\n // `RpcLoop: c=${cursor.orderKey} f=${finalized.orderKey} h=${chainTracker.head().orderKey}`,\n // );\n\n if (cursor.orderKey < finalized.orderKey) {\n yield* backfillFinalizedBlocks(state);\n } else {\n // If we're at the head, wait for a change.\n //\n // We don't want to produce a block immediately, but re-run the loop so\n // that it's like any other iteration.\n if (isAtHead(state)) {\n yield* waitForHeadChange(state);\n } else {\n yield* produceNextBlock(state);\n }\n }\n }\n}\n\nasync function* backfillFinalizedBlocks<TFilter, TBlock>(\n state: State<TFilter, TBlock>,\n): AsyncGenerator<StreamDataResponse<TBlock>> {\n const { cursor, chainTracker, config, filter } = state;\n const finalized = chainTracker.finalized();\n\n // While backfilling we want to regularly send some blocks (even if empty) so\n // that the client can store the cursor.\n const force = shouldForceBackfill(state);\n\n const filterData = await config.fetchBlockRange({\n startBlock: cursor.orderKey + 1n,\n finalizedBlock: finalized.orderKey,\n force,\n filter,\n });\n\n if (filterData.endBlock > finalized.orderKey) {\n throw new Error(\n \"Network-specific stream returned invalid data, crossing the finalized block.\",\n );\n }\n\n for (const data of filterData.data) {\n state.lastHeartbeat = Date.now();\n state.lastBackfillMessage = Date.now();\n yield {\n _tag: \"data\",\n data: {\n cursor: data.cursor,\n endCursor: data.endCursor,\n data: [data.block],\n finality: \"finalized\",\n production: \"backfill\",\n },\n };\n }\n\n // Notice that we check that filteredData.endBlock <= finalized.orderKey above.\n if (filterData.endBlock === finalized.orderKey) {\n // Prepare for transition to non-finalized data.\n state.cursor = finalized;\n } else {\n state.cursor = { orderKey: filterData.endBlock };\n }\n}\n\n// This is a generator to possibly produce data for the next block.\n//\n// It's a generator because it's not guaranteed to produce data for the next block.\nasync function* produceNextBlock<TFilter, TBlock>(\n state: State<TFilter, TBlock>,\n): AsyncGenerator<StreamDataResponse<TBlock>> {\n const currentBlockHash = state.cursor.uniqueKey;\n\n if (currentBlockHash === undefined) {\n throw new Error(\"Live production phase without cursor's hash.\");\n }\n\n const result = await state.config.fetchBlockByNumber({\n blockNumber: state.cursor.orderKey + 1n,\n isAtHead: isAtHead(state),\n expectedParentBlockHash: currentBlockHash,\n filter: state.filter,\n });\n\n // TODO: use the output of result to update the chain tracker.\n\n if (result.status === \"reorg\") {\n throw new Error(\"Reorg not implemented\");\n }\n\n const { data, blockInfo } = result;\n\n state.cursor = {\n orderKey: blockInfo.blockNumber,\n uniqueKey: blockInfo.blockHash,\n };\n\n const { status: headUpdateStatus } = state.chainTracker.addToCanonicalChain({\n blockInfo,\n });\n\n if (headUpdateStatus !== \"success\") {\n throw new Error(\"Failed to update head. Would cause reorg.\");\n }\n\n if (data.block !== null) {\n state.lastHeartbeat = Date.now();\n const production = isAtHead(state) ? \"live\" : \"backfill\";\n\n yield {\n _tag: \"data\",\n data: {\n cursor: data.cursor,\n endCursor: data.endCursor,\n data: [data.block],\n finality: \"accepted\",\n production,\n },\n };\n }\n}\n\nasync function* waitForHeadChange<TBlock>(\n state: State<unknown, TBlock>,\n): AsyncGenerator<StreamDataResponse<TBlock>> {\n const { chainTracker, config } = state;\n\n const heartbeatDeadline = state.lastHeartbeat + state.heartbeatIntervalMs;\n const finalizedRefreshDeadline =\n state.lastFinalizedRefresh + config.finalizedRefreshIntervalMs();\n\n while (true) {\n const now = Date.now();\n // Allow the outer loop to send the heartbeat message or refresh finalized blocks.\n if (now >= heartbeatDeadline || now >= finalizedRefreshDeadline) {\n return;\n }\n\n const maybeNewHead = await config.fetchCursor({ blockTag: \"latest\" });\n\n if (maybeNewHead === null) {\n throw new Error(\"Failed to fetch the latest block\");\n }\n\n const result = await chainTracker.updateHead({\n newHead: maybeNewHead,\n fetchCursorByHash: (blockHash) => config.fetchCursor({ blockHash }),\n });\n\n switch (result.status) {\n case \"unchanged\": {\n const heartbeatTimeout = heartbeatDeadline - now;\n const finalizedTimeout = finalizedRefreshDeadline - now;\n\n // Wait until whatever happens next.\n await sleep(\n Math.min(\n heartbeatTimeout,\n finalizedTimeout,\n config.headRefreshIntervalMs(),\n ),\n );\n\n break;\n }\n case \"reorg\": {\n const { cursor } = result;\n // Only handle reorgs if they involve blocks already processed.\n if (cursor.orderKey < state.cursor.orderKey) {\n state.cursor = cursor;\n\n yield {\n _tag: \"invalidate\",\n invalidate: { cursor },\n };\n }\n\n break;\n }\n case \"success\": {\n // Chain grew without any issues. Go back to the top-level loop to produce data.\n return;\n }\n }\n }\n}\n\nfunction shouldSendHeartbeat(state: State<unknown, unknown>): boolean {\n const { heartbeatIntervalMs, lastHeartbeat } = state;\n const now = Date.now();\n return now - lastHeartbeat >= heartbeatIntervalMs;\n}\n\nfunction shouldForceBackfill(state: State<unknown, unknown>): boolean {\n const { lastBackfillMessage, heartbeatIntervalMs } = state;\n const now = Date.now();\n return now - lastBackfillMessage >= heartbeatIntervalMs;\n}\n\nfunction shouldContinue(state: State<unknown, unknown>): boolean {\n const { endingCursor } = state.options || {};\n if (endingCursor === undefined) return true;\n\n return state.cursor.orderKey < endingCursor.orderKey;\n}\n\nfunction shouldRefreshFinalized(state: State<unknown, unknown>): boolean {\n const { lastFinalizedRefresh, config } = state;\n const now = Date.now();\n return now - lastFinalizedRefresh >= config.finalizedRefreshIntervalMs();\n}\n\nfunction isAtHead(state: State<unknown, unknown>): boolean {\n const head = state.chainTracker.head();\n return state.cursor.orderKey === head.orderKey;\n}\n\nfunction sleep(duration: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, duration));\n}\n","import type { Client, ClientCallOptions, StreamDataOptions } from \"../client\";\nimport type { Cursor } from \"../common\";\nimport type { StatusRequest, StatusResponse } from \"../status\";\nimport type { StreamDataRequest, StreamDataResponse } from \"../stream\";\nimport type { RpcStreamConfig } from \"./config\";\nimport { RpcDataStream } from \"./data-stream\";\nimport { blockInfoToCursor } from \"./helpers\";\n\nexport class RpcClient<TFilter, TBlock> implements Client<TFilter, TBlock> {\n constructor(private config: RpcStreamConfig<TFilter, TBlock>) {}\n\n async status(\n _request?: StatusRequest,\n _options?: ClientCallOptions,\n ): Promise<StatusResponse> {\n const [currentHead, finalized] = await Promise.all([\n this.config.fetchCursor({ blockTag: \"latest\" }),\n this.config.fetchCursor({ blockTag: \"finalized\" }),\n ]);\n\n const starting: Cursor = { orderKey: 0n };\n\n return {\n currentHead: currentHead ? blockInfoToCursor(currentHead) : undefined,\n lastIngested: currentHead ? blockInfoToCursor(currentHead) : undefined,\n finalized: finalized ? blockInfoToCursor(finalized) : undefined,\n starting,\n };\n }\n\n streamData(\n request: StreamDataRequest<TFilter>,\n options?: StreamDataOptions,\n ): AsyncIterable<StreamDataResponse<TBlock>> {\n const index = 0;\n for (const filter of request.filter) {\n const { valid, error } = this.config.validateFilter(filter);\n if (!valid) {\n throw new Error(`Filter at position ${index} is invalid: ${error}`);\n }\n }\n\n return new RpcDataStream(this.config, request, options);\n }\n}\n\nexport function createRpcClient<TFilter, TBlock>(\n config: RpcStreamConfig<TFilter, TBlock>,\n): RpcClient<TFilter, TBlock> {\n return new RpcClient(config);\n}\n"],"names":["fromHex","finalized"],"mappings":";;;;AAwEO,MAAe,eAAiC,CAAA;AAevD;;ACpFO,SAAS,kBAAkB,SAA8B,EAAA;AAC9D,EAAO,OAAA;AAAA,IACL,UAAU,SAAU,CAAA,WAAA;AAAA,IACpB,WAAW,SAAU,CAAA,SAAA;AAAA,GACvB,CAAA;AACF;;;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