@sentio/runtime 2.40.0-rc.1 → 2.40.0-rc.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/lib/{chunk-LMUCLUM5.js → chunk-Y3KJTCAS.js} +658 -9
- package/lib/index.d.ts +64 -3
- package/lib/index.js +1 -1
- package/lib/processor-runner.js +4 -1
- package/package.json +1 -1
- package/src/full-service.ts +5 -0
- package/src/gen/processor/protos/processor.ts +545 -0
- package/src/provider.ts +2 -0
- package/src/service.ts +83 -7
package/src/provider.ts
CHANGED
@@ -37,6 +37,8 @@ export function getProvider(chainId?: EthChainId): Provider {
|
|
37
37
|
|
38
38
|
const address = Endpoints.INSTANCE.chainServer.get(chainId)
|
39
39
|
const key = network.chainId.toString() + '-' + address
|
40
|
+
|
41
|
+
console.log(`init provider for ${chainId}, address: ${address}`)
|
40
42
|
let provider = providers.get(key)
|
41
43
|
|
42
44
|
if (provider) {
|
package/src/service.ts
CHANGED
@@ -11,6 +11,8 @@ import {
|
|
11
11
|
HandlerType,
|
12
12
|
PreparedData,
|
13
13
|
PreprocessResult,
|
14
|
+
PreprocessStreamRequest,
|
15
|
+
PreprocessStreamResponse,
|
14
16
|
ProcessBindingResponse,
|
15
17
|
ProcessBindingsRequest,
|
16
18
|
ProcessConfigRequest,
|
@@ -124,7 +126,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
124
126
|
}
|
125
127
|
|
126
128
|
async processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse> {
|
127
|
-
const ethCallResults = await this.preprocessBindings(request, options)
|
129
|
+
const ethCallResults = await this.preprocessBindings(request.bindings, undefined, options)
|
128
130
|
|
129
131
|
const promises = []
|
130
132
|
for (const binding of request.bindings) {
|
@@ -154,12 +156,14 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
154
156
|
}
|
155
157
|
|
156
158
|
async preprocessBindings(
|
157
|
-
|
159
|
+
bindings: DataBinding[],
|
160
|
+
dbContext?: StoreContext,
|
158
161
|
options?: CallContext
|
159
162
|
): Promise<{ [calldata: string]: any[] }> {
|
163
|
+
console.log(`preprocessBindings start, bindings: ${bindings.length}`)
|
160
164
|
const promises = []
|
161
|
-
for (const binding of
|
162
|
-
promises.push(this.preprocessBinding(binding, options))
|
165
|
+
for (const binding of bindings) {
|
166
|
+
promises.push(this.preprocessBinding(binding, dbContext, options))
|
163
167
|
}
|
164
168
|
let preprocessResults: PreprocessResult[]
|
165
169
|
try {
|
@@ -167,6 +171,10 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
167
171
|
} catch (e) {
|
168
172
|
throw e
|
169
173
|
}
|
174
|
+
console.log(
|
175
|
+
'ethCallParams: ',
|
176
|
+
preprocessResults.map((r) => r.ethCallParams)
|
177
|
+
)
|
170
178
|
const groupedRequests = new Map<string, EthCallParam[]>()
|
171
179
|
const providers = new Map<string, Provider>()
|
172
180
|
for (const result of preprocessResults) {
|
@@ -200,12 +208,21 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
200
208
|
)
|
201
209
|
}
|
202
210
|
}
|
203
|
-
|
211
|
+
let results = {}
|
212
|
+
try {
|
213
|
+
results = Object.fromEntries(await Promise.all(callPromises))
|
214
|
+
} catch (e) {
|
215
|
+
console.error(`eth call error: ${e}`)
|
216
|
+
}
|
204
217
|
console.log(`${callPromises.length} calls finished, elapsed: ${Date.now() - start}ms`)
|
205
218
|
return results
|
206
219
|
}
|
207
220
|
|
208
|
-
async preprocessBinding(
|
221
|
+
async preprocessBinding(
|
222
|
+
request: DataBinding,
|
223
|
+
dbContext?: StoreContext,
|
224
|
+
options?: CallContext
|
225
|
+
): Promise<PreprocessResult> {
|
209
226
|
if (!this.started) {
|
210
227
|
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
211
228
|
}
|
@@ -221,7 +238,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
221
238
|
]
|
222
239
|
)
|
223
240
|
}
|
224
|
-
return await PluginManager.INSTANCE.preprocessBinding(request)
|
241
|
+
return await PluginManager.INSTANCE.preprocessBinding(request, dbContext)
|
225
242
|
}
|
226
243
|
|
227
244
|
async processBinding(
|
@@ -266,6 +283,65 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
266
283
|
yield* from(subject).pipe(withAbort(context.signal))
|
267
284
|
}
|
268
285
|
|
286
|
+
async handlePreprocessRequests(
|
287
|
+
requests: AsyncIterable<PreprocessStreamRequest>,
|
288
|
+
subject: Subject<DeepPartial<PreprocessStreamResponse>>
|
289
|
+
) {
|
290
|
+
const contexts = new Contexts()
|
291
|
+
|
292
|
+
for await (const request of requests) {
|
293
|
+
try {
|
294
|
+
console.debug('received request:', request)
|
295
|
+
if (request.bindings) {
|
296
|
+
const bindings = request.bindings.bindings
|
297
|
+
const dbContext = contexts.new(request.processId, subject)
|
298
|
+
const start = Date.now()
|
299
|
+
this.preprocessBindings(bindings, dbContext)
|
300
|
+
.then(() => {
|
301
|
+
subject.next({
|
302
|
+
processId: request.processId
|
303
|
+
})
|
304
|
+
})
|
305
|
+
.catch((e) => {
|
306
|
+
console.debug(e)
|
307
|
+
dbContext.error(request.processId, e)
|
308
|
+
process_binding_error.add(1)
|
309
|
+
})
|
310
|
+
.finally(() => {
|
311
|
+
const cost = Date.now() - start
|
312
|
+
console.debug('preprocessBinding', request.processId, ' took', cost, 'ms')
|
313
|
+
process_binding_time.add(cost)
|
314
|
+
contexts.delete(request.processId)
|
315
|
+
})
|
316
|
+
}
|
317
|
+
if (request.dbResult) {
|
318
|
+
const dbContext = contexts.get(request.processId)
|
319
|
+
dbContext?.result(request.dbResult)
|
320
|
+
}
|
321
|
+
} catch (e) {
|
322
|
+
// should not happen
|
323
|
+
console.error('unexpect error during handle loop', e)
|
324
|
+
}
|
325
|
+
}
|
326
|
+
}
|
327
|
+
|
328
|
+
async *preprocessBindingsStream(requests: AsyncIterable<PreprocessStreamRequest>, context: CallContext) {
|
329
|
+
if (!this.started) {
|
330
|
+
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
331
|
+
}
|
332
|
+
|
333
|
+
const subject = new Subject<DeepPartial<PreprocessStreamResponse>>()
|
334
|
+
this.handlePreprocessRequests(requests, subject)
|
335
|
+
.then(() => {
|
336
|
+
subject.complete()
|
337
|
+
})
|
338
|
+
.catch((e) => {
|
339
|
+
console.error(e)
|
340
|
+
subject.error(e)
|
341
|
+
})
|
342
|
+
yield* from(subject).pipe(withAbort(context.signal))
|
343
|
+
}
|
344
|
+
|
269
345
|
private async handleRequests(
|
270
346
|
requests: AsyncIterable<ProcessStreamRequest>,
|
271
347
|
subject: Subject<DeepPartial<ProcessStreamResponse>>
|