@sentio/runtime 2.40.0-rc.2 → 2.40.0-rc.20

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.
@@ -48583,9 +48583,75 @@ var ProcessResult = {
48583
48583
  }
48584
48584
  };
48585
48585
  function createBaseEthCallParam() {
48586
- return { chainId: "", address: "", function: "", signature: "", args: [] };
48586
+ return { context: void 0, calldata: "" };
48587
48587
  }
48588
48588
  var EthCallParam = {
48589
+ encode(message, writer = import_minimal5.default.Writer.create()) {
48590
+ if (message.context !== void 0) {
48591
+ EthCallContext.encode(message.context, writer.uint32(10).fork()).ldelim();
48592
+ }
48593
+ if (message.calldata !== "") {
48594
+ writer.uint32(18).string(message.calldata);
48595
+ }
48596
+ return writer;
48597
+ },
48598
+ decode(input, length) {
48599
+ const reader = input instanceof import_minimal5.default.Reader ? input : import_minimal5.default.Reader.create(input);
48600
+ let end = length === void 0 ? reader.len : reader.pos + length;
48601
+ const message = createBaseEthCallParam();
48602
+ while (reader.pos < end) {
48603
+ const tag = reader.uint32();
48604
+ switch (tag >>> 3) {
48605
+ case 1:
48606
+ if (tag !== 10) {
48607
+ break;
48608
+ }
48609
+ message.context = EthCallContext.decode(reader, reader.uint32());
48610
+ continue;
48611
+ case 2:
48612
+ if (tag !== 18) {
48613
+ break;
48614
+ }
48615
+ message.calldata = reader.string();
48616
+ continue;
48617
+ }
48618
+ if ((tag & 7) === 4 || tag === 0) {
48619
+ break;
48620
+ }
48621
+ reader.skipType(tag & 7);
48622
+ }
48623
+ return message;
48624
+ },
48625
+ fromJSON(object2) {
48626
+ return {
48627
+ context: isSet3(object2.context) ? EthCallContext.fromJSON(object2.context) : void 0,
48628
+ calldata: isSet3(object2.calldata) ? globalThis.String(object2.calldata) : ""
48629
+ };
48630
+ },
48631
+ toJSON(message) {
48632
+ const obj = {};
48633
+ if (message.context !== void 0) {
48634
+ obj.context = EthCallContext.toJSON(message.context);
48635
+ }
48636
+ if (message.calldata !== "") {
48637
+ obj.calldata = message.calldata;
48638
+ }
48639
+ return obj;
48640
+ },
48641
+ create(base) {
48642
+ return EthCallParam.fromPartial(base ?? {});
48643
+ },
48644
+ fromPartial(object2) {
48645
+ const message = createBaseEthCallParam();
48646
+ message.context = object2.context !== void 0 && object2.context !== null ? EthCallContext.fromPartial(object2.context) : void 0;
48647
+ message.calldata = object2.calldata ?? "";
48648
+ return message;
48649
+ }
48650
+ };
48651
+ function createBaseEthCallContext() {
48652
+ return { chainId: "", address: "", blockTag: "" };
48653
+ }
48654
+ var EthCallContext = {
48589
48655
  encode(message, writer = import_minimal5.default.Writer.create()) {
48590
48656
  if (message.chainId !== "") {
48591
48657
  writer.uint32(10).string(message.chainId);
@@ -48593,21 +48659,15 @@ var EthCallParam = {
48593
48659
  if (message.address !== "") {
48594
48660
  writer.uint32(18).string(message.address);
48595
48661
  }
48596
- if (message.function !== "") {
48597
- writer.uint32(26).string(message.function);
48598
- }
48599
- if (message.signature !== "") {
48600
- writer.uint32(34).string(message.signature);
48601
- }
48602
- for (const v of message.args) {
48603
- Value.encode(Value.wrap(v), writer.uint32(42).fork()).ldelim();
48662
+ if (message.blockTag !== "") {
48663
+ writer.uint32(26).string(message.blockTag);
48604
48664
  }
48605
48665
  return writer;
48606
48666
  },
48607
48667
  decode(input, length) {
48608
48668
  const reader = input instanceof import_minimal5.default.Reader ? input : import_minimal5.default.Reader.create(input);
48609
48669
  let end = length === void 0 ? reader.len : reader.pos + length;
48610
- const message = createBaseEthCallParam();
48670
+ const message = createBaseEthCallContext();
48611
48671
  while (reader.pos < end) {
48612
48672
  const tag = reader.uint32();
48613
48673
  switch (tag >>> 3) {
@@ -48627,19 +48687,7 @@ var EthCallParam = {
48627
48687
  if (tag !== 26) {
48628
48688
  break;
48629
48689
  }
48630
- message.function = reader.string();
48631
- continue;
48632
- case 4:
48633
- if (tag !== 34) {
48634
- break;
48635
- }
48636
- message.signature = reader.string();
48637
- continue;
48638
- case 5:
48639
- if (tag !== 42) {
48640
- break;
48641
- }
48642
- message.args.push(Value.unwrap(Value.decode(reader, reader.uint32())));
48690
+ message.blockTag = reader.string();
48643
48691
  continue;
48644
48692
  }
48645
48693
  if ((tag & 7) === 4 || tag === 0) {
@@ -48653,9 +48701,7 @@ var EthCallParam = {
48653
48701
  return {
48654
48702
  chainId: isSet3(object2.chainId) ? globalThis.String(object2.chainId) : "",
48655
48703
  address: isSet3(object2.address) ? globalThis.String(object2.address) : "",
48656
- function: isSet3(object2.function) ? globalThis.String(object2.function) : "",
48657
- signature: isSet3(object2.signature) ? globalThis.String(object2.signature) : "",
48658
- args: globalThis.Array.isArray(object2?.args) ? [...object2.args] : []
48704
+ blockTag: isSet3(object2.blockTag) ? globalThis.String(object2.blockTag) : ""
48659
48705
  };
48660
48706
  },
48661
48707
  toJSON(message) {
@@ -48666,27 +48712,19 @@ var EthCallParam = {
48666
48712
  if (message.address !== "") {
48667
48713
  obj.address = message.address;
48668
48714
  }
48669
- if (message.function !== "") {
48670
- obj.function = message.function;
48671
- }
48672
- if (message.signature !== "") {
48673
- obj.signature = message.signature;
48674
- }
48675
- if (message.args?.length) {
48676
- obj.args = message.args;
48715
+ if (message.blockTag !== "") {
48716
+ obj.blockTag = message.blockTag;
48677
48717
  }
48678
48718
  return obj;
48679
48719
  },
48680
48720
  create(base) {
48681
- return EthCallParam.fromPartial(base ?? {});
48721
+ return EthCallContext.fromPartial(base ?? {});
48682
48722
  },
48683
48723
  fromPartial(object2) {
48684
- const message = createBaseEthCallParam();
48724
+ const message = createBaseEthCallContext();
48685
48725
  message.chainId = object2.chainId ?? "";
48686
48726
  message.address = object2.address ?? "";
48687
- message.function = object2.function ?? "";
48688
- message.signature = object2.signature ?? "";
48689
- message.args = object2.args?.map((e) => e) || [];
48727
+ message.blockTag = object2.blockTag ?? "";
48690
48728
  return message;
48691
48729
  }
48692
48730
  };
@@ -49562,7 +49600,7 @@ var Plugin = class {
49562
49600
  async processBinding(request, preparedData) {
49563
49601
  return ProcessResult.create();
49564
49602
  }
49565
- async preprocessBinding(request) {
49603
+ async preprocessBinding(request, preprocessStore) {
49566
49604
  return PreprocessResult.create();
49567
49605
  }
49568
49606
  };
@@ -49604,13 +49642,13 @@ var _PluginManager = class {
49604
49642
  return plugin.processBinding(request, preparedData);
49605
49643
  });
49606
49644
  }
49607
- preprocessBinding(request, dbContext) {
49645
+ preprocessBinding(request, preprocessStore, dbContext) {
49608
49646
  const plugin = this.typesToPlugin.get(request.handlerType);
49609
49647
  if (!plugin) {
49610
49648
  throw new Error(`No plugin for ${request.handlerType}`);
49611
49649
  }
49612
49650
  return this.dbContextLocalStorage.run(dbContext, () => {
49613
- return plugin.preprocessBinding(request);
49651
+ return plugin.preprocessBinding(request, preprocessStore);
49614
49652
  });
49615
49653
  }
49616
49654
  };
@@ -59488,6 +59526,13 @@ function errorString(e) {
59488
59526
  return e.message + "\n" + e.stack;
59489
59527
  }
59490
59528
  var USER_PROCESSOR = "user_processor";
59529
+ function makeEthCallKey(param) {
59530
+ if (!param.context) {
59531
+ throw new Error("null context for eth call");
59532
+ }
59533
+ const { chainId, address, blockTag } = param.context;
59534
+ return `${chainId}|${address}|${blockTag}|${param.calldata}`.toLowerCase();
59535
+ }
59491
59536
 
59492
59537
  // src/endpoints.ts
59493
59538
  var _Endpoints = class {
@@ -78261,6 +78306,7 @@ function getProvider2(chainId) {
78261
78306
  const network = Network.from(parseInt(chainId));
78262
78307
  const address = Endpoints.INSTANCE.chainServer.get(chainId);
78263
78308
  const key = network.chainId.toString() + "-" + address;
78309
+ console.debug(`init provider for ${chainId}, address: ${address}`);
78264
78310
  let provider = providers.get(key);
78265
78311
  if (provider) {
78266
78312
  return provider;
@@ -78382,6 +78428,7 @@ var ProcessorServiceImpl = class {
78382
78428
  // private processorConfig: ProcessConfigResponse
78383
78429
  loader;
78384
78430
  shutdownHandler;
78431
+ preparedData;
78385
78432
  constructor(loader, shutdownHandler) {
78386
78433
  this.loader = loader;
78387
78434
  this.shutdownHandler = shutdownHandler;
@@ -78421,10 +78468,10 @@ var ProcessorServiceImpl = class {
78421
78468
  return {};
78422
78469
  }
78423
78470
  async processBindings(request, options) {
78424
- const ethCallResults = await this.preprocessBindings(request.bindings, void 0, options);
78471
+ const preparedData = await this.preprocessBindings(request.bindings, {}, void 0, options);
78425
78472
  const promises = [];
78426
78473
  for (const binding of request.bindings) {
78427
- const promise2 = this.processBinding(binding, { ethCallResults });
78474
+ const promise2 = this.processBinding(binding, preparedData);
78428
78475
  if (GLOBAL_CONFIG.execution.sequential) {
78429
78476
  await promise2;
78430
78477
  }
@@ -78441,11 +78488,11 @@ var ProcessorServiceImpl = class {
78441
78488
  result
78442
78489
  };
78443
78490
  }
78444
- async preprocessBindings(bindings, dbContext, options) {
78445
- console.log("preprocessBindings start");
78491
+ async preprocessBindings(bindings, preprocessStore, dbContext, options) {
78492
+ console.debug(`preprocessBindings start, bindings: ${bindings.length}`);
78446
78493
  const promises = [];
78447
78494
  for (const binding of bindings) {
78448
- promises.push(this.preprocessBinding(binding, dbContext, options));
78495
+ promises.push(this.preprocessBinding(binding, preprocessStore, dbContext, options));
78449
78496
  }
78450
78497
  let preprocessResults;
78451
78498
  try {
@@ -78453,18 +78500,15 @@ var ProcessorServiceImpl = class {
78453
78500
  } catch (e) {
78454
78501
  throw e;
78455
78502
  }
78456
- console.log(
78457
- "ethCallParams: ",
78458
- preprocessResults.map((r) => r.ethCallParams)
78459
- );
78460
78503
  const groupedRequests = /* @__PURE__ */ new Map();
78461
78504
  const providers2 = /* @__PURE__ */ new Map();
78462
78505
  for (const result of preprocessResults) {
78463
78506
  for (const param of result.ethCallParams) {
78464
- if (!providers2.has(param.chainId)) {
78465
- providers2.set(param.chainId, getProvider2(param.chainId));
78507
+ const { chainId, address, blockTag } = param.context;
78508
+ if (!providers2.has(chainId)) {
78509
+ providers2.set(chainId, getProvider2(chainId));
78466
78510
  }
78467
- const key = param.chainId + "|" + param.address;
78511
+ const key = [chainId, address, blockTag].join("|");
78468
78512
  if (!groupedRequests.has(key)) {
78469
78513
  groupedRequests.set(key, []);
78470
78514
  }
@@ -78474,23 +78518,29 @@ var ProcessorServiceImpl = class {
78474
78518
  const start = Date.now();
78475
78519
  const callPromises = [];
78476
78520
  for (const params of groupedRequests.values()) {
78477
- console.log(`chain: ${params[0].chainId}, address: ${params[0].address}, totalCalls: ${params.length}`);
78521
+ const { chainId, address, blockTag } = params[0].context;
78478
78522
  for (const param of params) {
78479
- const frag = new Interface(param.signature);
78480
- const calldata = frag.encodeFunctionData(param.function, param.args);
78481
78523
  callPromises.push(
78482
- providers2.get(param.chainId).call({
78483
- to: param.address,
78484
- data: calldata
78485
- }).then((ret) => [calldata, frag.decodeFunctionResult(param.function, ret).toArray()])
78524
+ providers2.get(chainId).call({
78525
+ to: address,
78526
+ data: param.calldata,
78527
+ blockTag
78528
+ }).then((result) => [makeEthCallKey(param), result])
78486
78529
  );
78487
78530
  }
78488
78531
  }
78489
- const results = Object.fromEntries(await Promise.all(callPromises));
78532
+ let results = {};
78533
+ try {
78534
+ results = Object.fromEntries(await Promise.all(callPromises));
78535
+ } catch (e) {
78536
+ console.error(`eth call error: ${e}`);
78537
+ }
78490
78538
  console.log(`${callPromises.length} calls finished, elapsed: ${Date.now() - start}ms`);
78491
- return results;
78539
+ return {
78540
+ ethCallResults: results
78541
+ };
78492
78542
  }
78493
- async preprocessBinding(request, dbContext, options) {
78543
+ async preprocessBinding(request, preprocessStore, dbContext, options) {
78494
78544
  if (!this.started) {
78495
78545
  throw new import_nice_grpc.ServerError(import_nice_grpc.Status.UNAVAILABLE, "Service Not started.");
78496
78546
  }
@@ -78506,7 +78556,7 @@ var ProcessorServiceImpl = class {
78506
78556
  ]
78507
78557
  );
78508
78558
  }
78509
- return await PluginManager.INSTANCE.preprocessBinding(request, dbContext);
78559
+ return await PluginManager.INSTANCE.preprocessBinding(request, preprocessStore, dbContext);
78510
78560
  }
78511
78561
  async processBinding(request, preparedData, options) {
78512
78562
  if (!this.started) {
@@ -78534,6 +78584,7 @@ var ProcessorServiceImpl = class {
78534
78584
  }
78535
78585
  const subject = new import_rxjs.Subject();
78536
78586
  this.handleRequests(requests, subject).then(() => {
78587
+ this.preparedData = { ethCallResults: {} };
78537
78588
  subject.complete();
78538
78589
  }).catch((e) => {
78539
78590
  console.error(e);
@@ -78543,25 +78594,29 @@ var ProcessorServiceImpl = class {
78543
78594
  }
78544
78595
  async handlePreprocessRequests(requests, subject) {
78545
78596
  const contexts = new Contexts();
78597
+ const preprocessStore = {};
78546
78598
  for await (const request of requests) {
78547
78599
  try {
78548
- console.debug("received request:", request);
78549
78600
  if (request.bindings) {
78550
78601
  const bindings = request.bindings.bindings;
78551
78602
  const dbContext = contexts.new(request.processId, subject);
78552
78603
  const start = Date.now();
78553
- this.preprocessBindings(bindings, dbContext).then(() => {
78604
+ this.preprocessBindings(bindings, preprocessStore, dbContext, void 0).then((preparedData) => {
78605
+ this.preparedData = {
78606
+ ethCallResults: {
78607
+ ...this.preparedData?.ethCallResults,
78608
+ ...preparedData.ethCallResults
78609
+ }
78610
+ };
78554
78611
  subject.next({
78555
78612
  processId: request.processId
78556
78613
  });
78557
78614
  }).catch((e) => {
78558
78615
  console.debug(e);
78559
78616
  dbContext.error(request.processId, e);
78560
- process_binding_error.add(1);
78561
78617
  }).finally(() => {
78562
78618
  const cost = Date.now() - start;
78563
78619
  console.debug("preprocessBinding", request.processId, " took", cost, "ms");
78564
- process_binding_time.add(cost);
78565
78620
  contexts.delete(request.processId);
78566
78621
  });
78567
78622
  }
@@ -78597,7 +78652,7 @@ var ProcessorServiceImpl = class {
78597
78652
  const binding = request.binding;
78598
78653
  const dbContext = contexts.new(request.processId, subject);
78599
78654
  const start = Date.now();
78600
- PluginManager.INSTANCE.processBinding(binding, void 0, dbContext).then((result) => {
78655
+ PluginManager.INSTANCE.processBinding(binding, this.preparedData, dbContext).then((result) => {
78601
78656
  subject.next({
78602
78657
  result,
78603
78658
  processId: request.processId
@@ -78666,6 +78721,7 @@ export {
78666
78721
  mergeProcessResults,
78667
78722
  errorString,
78668
78723
  USER_PROCESSOR,
78724
+ makeEthCallKey,
78669
78725
  Endpoints,
78670
78726
  require_lib,
78671
78727
  require_lodash,
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _sentio_protos from '@sentio/protos';
2
- import { DeepPartial as DeepPartial$1, ProcessStreamResponse, DBResponse, DBRequest_DBUpsert, DBRequest, HandlerType, ProcessConfigResponse, StartRequest, DataBinding, PreparedData, ProcessResult, PreprocessResult, ProcessorServiceImplementation, ProcessConfigRequest, Empty, ProcessBindingsRequest, ProcessBindingResponse, ProcessStreamRequest, PreprocessStreamRequest, PreprocessStreamResponse } from '@sentio/protos';
2
+ import { DeepPartial as DeepPartial$1, ProcessStreamResponse, DBResponse, DBRequest_DBUpsert, DBRequest, HandlerType, ProcessConfigResponse, StartRequest, DataBinding, PreparedData, ProcessResult, PreprocessResult, EthCallParam, ProcessorServiceImplementation, ProcessConfigRequest, Empty, ProcessBindingsRequest, ProcessBindingResponse, ProcessStreamRequest, PreprocessStreamRequest, PreprocessStreamResponse } from '@sentio/protos';
3
3
  import { Subject } from 'rxjs';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
5
5
  import { Required } from 'utility-types';
@@ -41,7 +41,9 @@ declare abstract class Plugin {
41
41
  */
42
42
  stateDiff(config: ProcessConfigResponse): boolean;
43
43
  processBinding(request: DataBinding, preparedData: PreparedData | undefined): Promise<ProcessResult>;
44
- preprocessBinding(request: DataBinding): Promise<PreprocessResult>;
44
+ preprocessBinding(request: DataBinding, preprocessStore: {
45
+ [k: string]: any;
46
+ }): Promise<PreprocessResult>;
45
47
  }
46
48
  declare class PluginManager {
47
49
  static INSTANCE: PluginManager;
@@ -56,7 +58,9 @@ declare class PluginManager {
56
58
  */
57
59
  stateDiff(config: ProcessConfigResponse): boolean;
58
60
  processBinding(request: DataBinding, preparedData: PreparedData | undefined, dbContext?: StoreContext): Promise<ProcessResult>;
59
- preprocessBinding(request: DataBinding, dbContext?: StoreContext): Promise<PreprocessResult>;
61
+ preprocessBinding(request: DataBinding, preprocessStore: {
62
+ [k: string]: any;
63
+ }, dbContext?: StoreContext): Promise<PreprocessResult>;
60
64
  }
61
65
 
62
66
  declare class State {
@@ -85,6 +89,7 @@ declare abstract class ListStateStorage<T> extends StateStorage<T[]> {
85
89
  declare function mergeProcessResults(results: ProcessResult[]): Required<ProcessResult, 'states'>;
86
90
  declare function errorString(e: Error): string;
87
91
  declare const USER_PROCESSOR = "user_processor";
92
+ declare function makeEthCallKey(param: EthCallParam): string;
88
93
 
89
94
  declare class Endpoints {
90
95
  static INSTANCE: Endpoints;
@@ -106,15 +111,18 @@ declare class ProcessorServiceImpl implements ProcessorServiceImplementation {
106
111
  unhandled: Error;
107
112
  private readonly loader;
108
113
  private readonly shutdownHandler?;
114
+ private preparedData;
109
115
  constructor(loader: () => Promise<any>, shutdownHandler?: () => void);
110
116
  getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse>;
111
117
  start(request: StartRequest, context: CallContext): Promise<Empty>;
112
118
  stop(request: Empty, context: CallContext): Promise<Empty>;
113
119
  processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse>;
114
- preprocessBindings(bindings: DataBinding[], dbContext?: StoreContext, options?: CallContext): Promise<{
115
- [calldata: string]: any[];
116
- }>;
117
- preprocessBinding(request: DataBinding, dbContext?: StoreContext, options?: CallContext): Promise<PreprocessResult>;
120
+ preprocessBindings(bindings: DataBinding[], preprocessStore: {
121
+ [k: string]: any;
122
+ }, dbContext?: StoreContext, options?: CallContext): Promise<PreparedData>;
123
+ preprocessBinding(request: DataBinding, preprocessStore: {
124
+ [k: string]: any;
125
+ }, dbContext?: StoreContext, options?: CallContext): Promise<PreprocessResult>;
118
126
  processBinding(request: DataBinding, preparedData: PreparedData | undefined, options?: CallContext): Promise<ProcessResult>;
119
127
  processBindingsStream(requests: AsyncIterable<ProcessStreamRequest>, context: CallContext): AsyncGenerator<{
120
128
  processId?: number | undefined;
@@ -366,4 +374,4 @@ interface GlobalConfig {
366
374
  }
367
375
  declare const GLOBAL_CONFIG: GlobalConfig;
368
376
 
369
- export { ChainConfig, Endpoints, GLOBAL_CONFIG, GlobalConfig, ListStateStorage, MapStateStorage, Plugin, PluginManager, ProcessorServiceImpl, State, StateStorage, StoreContext, USER_PROCESSOR, errorString, mergeProcessResults, timeoutError };
377
+ export { ChainConfig, Endpoints, GLOBAL_CONFIG, GlobalConfig, ListStateStorage, MapStateStorage, Plugin, PluginManager, ProcessorServiceImpl, State, StateStorage, StoreContext, USER_PROCESSOR, errorString, makeEthCallKey, mergeProcessResults, timeoutError };
package/lib/index.js CHANGED
@@ -9,9 +9,10 @@ import {
9
9
  USER_PROCESSOR,
10
10
  __publicField,
11
11
  errorString,
12
+ makeEthCallKey,
12
13
  mergeProcessResults,
13
14
  timeoutError
14
- } from "./chunk-WDKQZPD5.js";
15
+ } from "./chunk-WN27EZMT.js";
15
16
 
16
17
  // src/state.ts
17
18
  var _State = class {
@@ -87,6 +88,7 @@ export {
87
88
  StoreContext,
88
89
  USER_PROCESSOR,
89
90
  errorString,
91
+ makeEthCallKey,
90
92
  mergeProcessResults,
91
93
  timeoutError
92
94
  };
@@ -40,7 +40,7 @@ import {
40
40
  require_minimal,
41
41
  require_src,
42
42
  trace
43
- } from "./chunk-WDKQZPD5.js";
43
+ } from "./chunk-WN27EZMT.js";
44
44
 
45
45
  // ../../node_modules/.pnpm/universalify@2.0.1/node_modules/universalify/index.js
46
46
  var require_universalify = __commonJS({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/runtime",
3
- "version": "2.40.0-rc.2",
3
+ "version": "2.40.0-rc.20",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -3,7 +3,7 @@ import Long from "long";
3
3
  import type { CallContext, CallOptions } from "nice-grpc-common";
4
4
  import _m0 from "protobufjs/minimal.js";
5
5
  import { Empty } from "../../google/protobuf/empty.js";
6
- import { ListValue, Struct, Value } from "../../google/protobuf/struct.js";
6
+ import { ListValue, Struct } from "../../google/protobuf/struct.js";
7
7
  import { Timestamp } from "../../google/protobuf/timestamp.js";
8
8
  import { BigInteger, CoinID, RichStruct, RichStructList, RichValueList } from "../../service/common/protos/common.js";
9
9
 
@@ -1069,11 +1069,14 @@ export interface ProcessResult {
1069
1069
  }
1070
1070
 
1071
1071
  export interface EthCallParam {
1072
+ context: EthCallContext | undefined;
1073
+ calldata: string;
1074
+ }
1075
+
1076
+ export interface EthCallContext {
1072
1077
  chainId: string;
1073
1078
  address: string;
1074
- function: string;
1075
- signature: string;
1076
- args: any[];
1079
+ blockTag: string;
1077
1080
  }
1078
1081
 
1079
1082
  export interface PreprocessResult {
@@ -1081,12 +1084,12 @@ export interface PreprocessResult {
1081
1084
  }
1082
1085
 
1083
1086
  export interface PreparedData {
1084
- ethCallResults: { [key: string]: Array<any> | undefined };
1087
+ ethCallResults: { [key: string]: string };
1085
1088
  }
1086
1089
 
1087
1090
  export interface PreparedData_EthCallResultsEntry {
1088
1091
  key: string;
1089
- value: Array<any> | undefined;
1092
+ value: string;
1090
1093
  }
1091
1094
 
1092
1095
  export interface RecordMetaData {
@@ -9337,25 +9340,16 @@ export const ProcessResult = {
9337
9340
  };
9338
9341
 
9339
9342
  function createBaseEthCallParam(): EthCallParam {
9340
- return { chainId: "", address: "", function: "", signature: "", args: [] };
9343
+ return { context: undefined, calldata: "" };
9341
9344
  }
9342
9345
 
9343
9346
  export const EthCallParam = {
9344
9347
  encode(message: EthCallParam, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
9345
- if (message.chainId !== "") {
9346
- writer.uint32(10).string(message.chainId);
9348
+ if (message.context !== undefined) {
9349
+ EthCallContext.encode(message.context, writer.uint32(10).fork()).ldelim();
9347
9350
  }
9348
- if (message.address !== "") {
9349
- writer.uint32(18).string(message.address);
9350
- }
9351
- if (message.function !== "") {
9352
- writer.uint32(26).string(message.function);
9353
- }
9354
- if (message.signature !== "") {
9355
- writer.uint32(34).string(message.signature);
9356
- }
9357
- for (const v of message.args) {
9358
- Value.encode(Value.wrap(v!), writer.uint32(42).fork()).ldelim();
9351
+ if (message.calldata !== "") {
9352
+ writer.uint32(18).string(message.calldata);
9359
9353
  }
9360
9354
  return writer;
9361
9355
  },
@@ -9372,35 +9366,100 @@ export const EthCallParam = {
9372
9366
  break;
9373
9367
  }
9374
9368
 
9375
- message.chainId = reader.string();
9369
+ message.context = EthCallContext.decode(reader, reader.uint32());
9376
9370
  continue;
9377
9371
  case 2:
9378
9372
  if (tag !== 18) {
9379
9373
  break;
9380
9374
  }
9381
9375
 
9382
- message.address = reader.string();
9376
+ message.calldata = reader.string();
9383
9377
  continue;
9384
- case 3:
9385
- if (tag !== 26) {
9378
+ }
9379
+ if ((tag & 7) === 4 || tag === 0) {
9380
+ break;
9381
+ }
9382
+ reader.skipType(tag & 7);
9383
+ }
9384
+ return message;
9385
+ },
9386
+
9387
+ fromJSON(object: any): EthCallParam {
9388
+ return {
9389
+ context: isSet(object.context) ? EthCallContext.fromJSON(object.context) : undefined,
9390
+ calldata: isSet(object.calldata) ? globalThis.String(object.calldata) : "",
9391
+ };
9392
+ },
9393
+
9394
+ toJSON(message: EthCallParam): unknown {
9395
+ const obj: any = {};
9396
+ if (message.context !== undefined) {
9397
+ obj.context = EthCallContext.toJSON(message.context);
9398
+ }
9399
+ if (message.calldata !== "") {
9400
+ obj.calldata = message.calldata;
9401
+ }
9402
+ return obj;
9403
+ },
9404
+
9405
+ create(base?: DeepPartial<EthCallParam>): EthCallParam {
9406
+ return EthCallParam.fromPartial(base ?? {});
9407
+ },
9408
+ fromPartial(object: DeepPartial<EthCallParam>): EthCallParam {
9409
+ const message = createBaseEthCallParam();
9410
+ message.context = (object.context !== undefined && object.context !== null)
9411
+ ? EthCallContext.fromPartial(object.context)
9412
+ : undefined;
9413
+ message.calldata = object.calldata ?? "";
9414
+ return message;
9415
+ },
9416
+ };
9417
+
9418
+ function createBaseEthCallContext(): EthCallContext {
9419
+ return { chainId: "", address: "", blockTag: "" };
9420
+ }
9421
+
9422
+ export const EthCallContext = {
9423
+ encode(message: EthCallContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
9424
+ if (message.chainId !== "") {
9425
+ writer.uint32(10).string(message.chainId);
9426
+ }
9427
+ if (message.address !== "") {
9428
+ writer.uint32(18).string(message.address);
9429
+ }
9430
+ if (message.blockTag !== "") {
9431
+ writer.uint32(26).string(message.blockTag);
9432
+ }
9433
+ return writer;
9434
+ },
9435
+
9436
+ decode(input: _m0.Reader | Uint8Array, length?: number): EthCallContext {
9437
+ const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
9438
+ let end = length === undefined ? reader.len : reader.pos + length;
9439
+ const message = createBaseEthCallContext();
9440
+ while (reader.pos < end) {
9441
+ const tag = reader.uint32();
9442
+ switch (tag >>> 3) {
9443
+ case 1:
9444
+ if (tag !== 10) {
9386
9445
  break;
9387
9446
  }
9388
9447
 
9389
- message.function = reader.string();
9448
+ message.chainId = reader.string();
9390
9449
  continue;
9391
- case 4:
9392
- if (tag !== 34) {
9450
+ case 2:
9451
+ if (tag !== 18) {
9393
9452
  break;
9394
9453
  }
9395
9454
 
9396
- message.signature = reader.string();
9455
+ message.address = reader.string();
9397
9456
  continue;
9398
- case 5:
9399
- if (tag !== 42) {
9457
+ case 3:
9458
+ if (tag !== 26) {
9400
9459
  break;
9401
9460
  }
9402
9461
 
9403
- message.args.push(Value.unwrap(Value.decode(reader, reader.uint32())));
9462
+ message.blockTag = reader.string();
9404
9463
  continue;
9405
9464
  }
9406
9465
  if ((tag & 7) === 4 || tag === 0) {
@@ -9411,17 +9470,15 @@ export const EthCallParam = {
9411
9470
  return message;
9412
9471
  },
9413
9472
 
9414
- fromJSON(object: any): EthCallParam {
9473
+ fromJSON(object: any): EthCallContext {
9415
9474
  return {
9416
9475
  chainId: isSet(object.chainId) ? globalThis.String(object.chainId) : "",
9417
9476
  address: isSet(object.address) ? globalThis.String(object.address) : "",
9418
- function: isSet(object.function) ? globalThis.String(object.function) : "",
9419
- signature: isSet(object.signature) ? globalThis.String(object.signature) : "",
9420
- args: globalThis.Array.isArray(object?.args) ? [...object.args] : [],
9477
+ blockTag: isSet(object.blockTag) ? globalThis.String(object.blockTag) : "",
9421
9478
  };
9422
9479
  },
9423
9480
 
9424
- toJSON(message: EthCallParam): unknown {
9481
+ toJSON(message: EthCallContext): unknown {
9425
9482
  const obj: any = {};
9426
9483
  if (message.chainId !== "") {
9427
9484
  obj.chainId = message.chainId;
@@ -9429,28 +9486,20 @@ export const EthCallParam = {
9429
9486
  if (message.address !== "") {
9430
9487
  obj.address = message.address;
9431
9488
  }
9432
- if (message.function !== "") {
9433
- obj.function = message.function;
9434
- }
9435
- if (message.signature !== "") {
9436
- obj.signature = message.signature;
9437
- }
9438
- if (message.args?.length) {
9439
- obj.args = message.args;
9489
+ if (message.blockTag !== "") {
9490
+ obj.blockTag = message.blockTag;
9440
9491
  }
9441
9492
  return obj;
9442
9493
  },
9443
9494
 
9444
- create(base?: DeepPartial<EthCallParam>): EthCallParam {
9445
- return EthCallParam.fromPartial(base ?? {});
9495
+ create(base?: DeepPartial<EthCallContext>): EthCallContext {
9496
+ return EthCallContext.fromPartial(base ?? {});
9446
9497
  },
9447
- fromPartial(object: DeepPartial<EthCallParam>): EthCallParam {
9448
- const message = createBaseEthCallParam();
9498
+ fromPartial(object: DeepPartial<EthCallContext>): EthCallContext {
9499
+ const message = createBaseEthCallContext();
9449
9500
  message.chainId = object.chainId ?? "";
9450
9501
  message.address = object.address ?? "";
9451
- message.function = object.function ?? "";
9452
- message.signature = object.signature ?? "";
9453
- message.args = object.args?.map((e) => e) || [];
9502
+ message.blockTag = object.blockTag ?? "";
9454
9503
  return message;
9455
9504
  },
9456
9505
  };
@@ -9523,9 +9572,7 @@ function createBasePreparedData(): PreparedData {
9523
9572
  export const PreparedData = {
9524
9573
  encode(message: PreparedData, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
9525
9574
  Object.entries(message.ethCallResults).forEach(([key, value]) => {
9526
- if (value !== undefined) {
9527
- PreparedData_EthCallResultsEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).ldelim();
9528
- }
9575
+ PreparedData_EthCallResultsEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).ldelim();
9529
9576
  });
9530
9577
  return writer;
9531
9578
  },
@@ -9559,13 +9606,10 @@ export const PreparedData = {
9559
9606
  fromJSON(object: any): PreparedData {
9560
9607
  return {
9561
9608
  ethCallResults: isObject(object.ethCallResults)
9562
- ? Object.entries(object.ethCallResults).reduce<{ [key: string]: Array<any> | undefined }>(
9563
- (acc, [key, value]) => {
9564
- acc[key] = value as Array<any> | undefined;
9565
- return acc;
9566
- },
9567
- {},
9568
- )
9609
+ ? Object.entries(object.ethCallResults).reduce<{ [key: string]: string }>((acc, [key, value]) => {
9610
+ acc[key] = String(value);
9611
+ return acc;
9612
+ }, {})
9569
9613
  : {},
9570
9614
  };
9571
9615
  },
@@ -9589,20 +9633,21 @@ export const PreparedData = {
9589
9633
  },
9590
9634
  fromPartial(object: DeepPartial<PreparedData>): PreparedData {
9591
9635
  const message = createBasePreparedData();
9592
- message.ethCallResults = Object.entries(object.ethCallResults ?? {}).reduce<
9593
- { [key: string]: Array<any> | undefined }
9594
- >((acc, [key, value]) => {
9595
- if (value !== undefined) {
9596
- acc[key] = value;
9597
- }
9598
- return acc;
9599
- }, {});
9636
+ message.ethCallResults = Object.entries(object.ethCallResults ?? {}).reduce<{ [key: string]: string }>(
9637
+ (acc, [key, value]) => {
9638
+ if (value !== undefined) {
9639
+ acc[key] = globalThis.String(value);
9640
+ }
9641
+ return acc;
9642
+ },
9643
+ {},
9644
+ );
9600
9645
  return message;
9601
9646
  },
9602
9647
  };
9603
9648
 
9604
9649
  function createBasePreparedData_EthCallResultsEntry(): PreparedData_EthCallResultsEntry {
9605
- return { key: "", value: undefined };
9650
+ return { key: "", value: "" };
9606
9651
  }
9607
9652
 
9608
9653
  export const PreparedData_EthCallResultsEntry = {
@@ -9610,8 +9655,8 @@ export const PreparedData_EthCallResultsEntry = {
9610
9655
  if (message.key !== "") {
9611
9656
  writer.uint32(10).string(message.key);
9612
9657
  }
9613
- if (message.value !== undefined) {
9614
- ListValue.encode(ListValue.wrap(message.value), writer.uint32(18).fork()).ldelim();
9658
+ if (message.value !== "") {
9659
+ writer.uint32(18).string(message.value);
9615
9660
  }
9616
9661
  return writer;
9617
9662
  },
@@ -9635,7 +9680,7 @@ export const PreparedData_EthCallResultsEntry = {
9635
9680
  break;
9636
9681
  }
9637
9682
 
9638
- message.value = ListValue.unwrap(ListValue.decode(reader, reader.uint32()));
9683
+ message.value = reader.string();
9639
9684
  continue;
9640
9685
  }
9641
9686
  if ((tag & 7) === 4 || tag === 0) {
@@ -9649,7 +9694,7 @@ export const PreparedData_EthCallResultsEntry = {
9649
9694
  fromJSON(object: any): PreparedData_EthCallResultsEntry {
9650
9695
  return {
9651
9696
  key: isSet(object.key) ? globalThis.String(object.key) : "",
9652
- value: globalThis.Array.isArray(object.value) ? [...object.value] : undefined,
9697
+ value: isSet(object.value) ? globalThis.String(object.value) : "",
9653
9698
  };
9654
9699
  },
9655
9700
 
@@ -9658,7 +9703,7 @@ export const PreparedData_EthCallResultsEntry = {
9658
9703
  if (message.key !== "") {
9659
9704
  obj.key = message.key;
9660
9705
  }
9661
- if (message.value !== undefined) {
9706
+ if (message.value !== "") {
9662
9707
  obj.value = message.value;
9663
9708
  }
9664
9709
  return obj;
@@ -9670,7 +9715,7 @@ export const PreparedData_EthCallResultsEntry = {
9670
9715
  fromPartial(object: DeepPartial<PreparedData_EthCallResultsEntry>): PreparedData_EthCallResultsEntry {
9671
9716
  const message = createBasePreparedData_EthCallResultsEntry();
9672
9717
  message.key = object.key ?? "";
9673
- message.value = object.value ?? undefined;
9718
+ message.value = object.value ?? "";
9674
9719
  return message;
9675
9720
  },
9676
9721
  };
package/src/plugin.ts CHANGED
@@ -28,7 +28,7 @@ export abstract class Plugin {
28
28
  return ProcessResult.create()
29
29
  }
30
30
 
31
- async preprocessBinding(request: DataBinding): Promise<PreprocessResult> {
31
+ async preprocessBinding(request: DataBinding, preprocessStore: { [k: string]: any }): Promise<PreprocessResult> {
32
32
  return PreprocessResult.create()
33
33
  }
34
34
  }
@@ -84,13 +84,17 @@ export class PluginManager {
84
84
  })
85
85
  }
86
86
 
87
- preprocessBinding(request: DataBinding, dbContext?: StoreContext): Promise<PreprocessResult> {
87
+ preprocessBinding(
88
+ request: DataBinding,
89
+ preprocessStore: { [k: string]: any },
90
+ dbContext?: StoreContext
91
+ ): Promise<PreprocessResult> {
88
92
  const plugin = this.typesToPlugin.get(request.handlerType)
89
93
  if (!plugin) {
90
94
  throw new Error(`No plugin for ${request.handlerType}`)
91
95
  }
92
96
  return this.dbContextLocalStorage.run(dbContext, () => {
93
- return plugin.preprocessBinding(request)
97
+ return plugin.preprocessBinding(request, preprocessStore)
94
98
  })
95
99
  }
96
100
  }
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.debug(`init provider for ${chainId}, address: ${address}`)
40
42
  let provider = providers.get(key)
41
43
 
42
44
  if (provider) {
package/src/service.ts CHANGED
@@ -25,7 +25,7 @@ import {
25
25
  } from '@sentio/protos'
26
26
 
27
27
  import { PluginManager } from './plugin.js'
28
- import { errorString, mergeProcessResults } from './utils.js'
28
+ import { errorString, makeEthCallKey, mergeProcessResults } from './utils.js'
29
29
  import { freezeGlobalConfig, GLOBAL_CONFIG } from './global-config.js'
30
30
 
31
31
  import { StoreContext } from './db-context.js'
@@ -33,7 +33,7 @@ import { Subject } from 'rxjs'
33
33
  import { metrics } from '@opentelemetry/api'
34
34
  import { getProvider } from './provider.js'
35
35
  import { EthChainId } from '@sentio/chain'
36
- import { Provider, Interface } from 'ethers'
36
+ import { Provider } from 'ethers'
37
37
 
38
38
  const meter = metrics.getMeter('processor_service')
39
39
  const process_binding_count = meter.createCounter('process_binding_count')
@@ -54,6 +54,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
54
54
 
55
55
  private readonly shutdownHandler?: () => void
56
56
 
57
+ private preparedData: PreparedData | undefined
58
+
57
59
  constructor(loader: () => Promise<any>, shutdownHandler?: () => void) {
58
60
  this.loader = loader
59
61
  this.shutdownHandler = shutdownHandler
@@ -126,11 +128,11 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
126
128
  }
127
129
 
128
130
  async processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse> {
129
- const ethCallResults = await this.preprocessBindings(request.bindings, undefined, options)
131
+ const preparedData = await this.preprocessBindings(request.bindings, {}, undefined, options)
130
132
 
131
133
  const promises = []
132
134
  for (const binding of request.bindings) {
133
- const promise = this.processBinding(binding, { ethCallResults })
135
+ const promise = this.processBinding(binding, preparedData)
134
136
  if (GLOBAL_CONFIG.execution.sequential) {
135
137
  await promise
136
138
  }
@@ -157,13 +159,14 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
157
159
 
158
160
  async preprocessBindings(
159
161
  bindings: DataBinding[],
162
+ preprocessStore: { [k: string]: any },
160
163
  dbContext?: StoreContext,
161
164
  options?: CallContext
162
- ): Promise<{ [calldata: string]: any[] }> {
163
- console.log('preprocessBindings start')
165
+ ): Promise<PreparedData> {
166
+ console.debug(`preprocessBindings start, bindings: ${bindings.length}`)
164
167
  const promises = []
165
168
  for (const binding of bindings) {
166
- promises.push(this.preprocessBinding(binding, dbContext, options))
169
+ promises.push(this.preprocessBinding(binding, preprocessStore, dbContext, options))
167
170
  }
168
171
  let preprocessResults: PreprocessResult[]
169
172
  try {
@@ -171,18 +174,15 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
171
174
  } catch (e) {
172
175
  throw e
173
176
  }
174
- console.log(
175
- 'ethCallParams: ',
176
- preprocessResults.map((r) => r.ethCallParams)
177
- )
178
177
  const groupedRequests = new Map<string, EthCallParam[]>()
179
178
  const providers = new Map<string, Provider>()
180
179
  for (const result of preprocessResults) {
181
180
  for (const param of result.ethCallParams) {
182
- if (!providers.has(param.chainId)) {
183
- providers.set(param.chainId, getProvider(param.chainId as EthChainId))
181
+ const { chainId, address, blockTag } = param.context!
182
+ if (!providers.has(chainId)) {
183
+ providers.set(chainId, getProvider(chainId as EthChainId))
184
184
  }
185
- const key = param.chainId + '|' + param.address
185
+ const key = [chainId, address, blockTag].join('|')
186
186
  if (!groupedRequests.has(key)) {
187
187
  groupedRequests.set(key, [])
188
188
  }
@@ -193,28 +193,36 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
193
193
  const start = Date.now()
194
194
  const callPromises = []
195
195
  for (const params of groupedRequests.values()) {
196
- console.log(`chain: ${params[0].chainId}, address: ${params[0].address}, totalCalls: ${params.length}`)
196
+ const { chainId, address, blockTag } = params[0].context!
197
+ // TODO multicall
197
198
  for (const param of params) {
198
- const frag = new Interface(param.signature)
199
- const calldata = frag.encodeFunctionData(param.function, param.args)
200
199
  callPromises.push(
201
200
  providers
202
- .get(param.chainId)!
201
+ .get(chainId)!
203
202
  .call({
204
- to: param.address,
205
- data: calldata
203
+ to: address,
204
+ data: param.calldata,
205
+ blockTag
206
206
  })
207
- .then((ret) => [calldata, frag.decodeFunctionResult(param.function, ret).toArray()] as [string, any[]])
207
+ .then((result) => [makeEthCallKey(param), result])
208
208
  )
209
209
  }
210
210
  }
211
- const results = Object.fromEntries(await Promise.all(callPromises))
211
+ let results: { [p: string]: string } = {}
212
+ try {
213
+ results = Object.fromEntries(await Promise.all(callPromises))
214
+ } catch (e) {
215
+ console.error(`eth call error: ${e}`)
216
+ }
212
217
  console.log(`${callPromises.length} calls finished, elapsed: ${Date.now() - start}ms`)
213
- return results
218
+ return {
219
+ ethCallResults: results
220
+ }
214
221
  }
215
222
 
216
223
  async preprocessBinding(
217
224
  request: DataBinding,
225
+ preprocessStore: { [k: string]: any },
218
226
  dbContext?: StoreContext,
219
227
  options?: CallContext
220
228
  ): Promise<PreprocessResult> {
@@ -233,7 +241,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
233
241
  ]
234
242
  )
235
243
  }
236
- return await PluginManager.INSTANCE.preprocessBinding(request, dbContext)
244
+ return await PluginManager.INSTANCE.preprocessBinding(request, preprocessStore, dbContext)
237
245
  }
238
246
 
239
247
  async processBinding(
@@ -269,6 +277,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
269
277
  const subject = new Subject<DeepPartial<ProcessStreamResponse>>()
270
278
  this.handleRequests(requests, subject)
271
279
  .then(() => {
280
+ this.preparedData = { ethCallResults: {} }
272
281
  subject.complete()
273
282
  })
274
283
  .catch((e) => {
@@ -283,16 +292,23 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
283
292
  subject: Subject<DeepPartial<PreprocessStreamResponse>>
284
293
  ) {
285
294
  const contexts = new Contexts()
295
+ const preprocessStore: { [k: string]: any } = {}
286
296
 
287
297
  for await (const request of requests) {
288
298
  try {
289
- console.debug('received request:', request)
290
299
  if (request.bindings) {
291
300
  const bindings = request.bindings.bindings
292
301
  const dbContext = contexts.new(request.processId, subject)
293
302
  const start = Date.now()
294
- this.preprocessBindings(bindings, dbContext)
295
- .then(() => {
303
+ this.preprocessBindings(bindings, preprocessStore, dbContext, undefined)
304
+ .then((preparedData) => {
305
+ // TODO maybe not proper to pass data in this way
306
+ this.preparedData = {
307
+ ethCallResults: {
308
+ ...this.preparedData?.ethCallResults,
309
+ ...preparedData.ethCallResults
310
+ }
311
+ }
296
312
  subject.next({
297
313
  processId: request.processId
298
314
  })
@@ -300,12 +316,10 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
300
316
  .catch((e) => {
301
317
  console.debug(e)
302
318
  dbContext.error(request.processId, e)
303
- process_binding_error.add(1)
304
319
  })
305
320
  .finally(() => {
306
321
  const cost = Date.now() - start
307
322
  console.debug('preprocessBinding', request.processId, ' took', cost, 'ms')
308
- process_binding_time.add(cost)
309
323
  contexts.delete(request.processId)
310
324
  })
311
325
  }
@@ -351,7 +365,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
351
365
  const binding = request.binding
352
366
  const dbContext = contexts.new(request.processId, subject)
353
367
  const start = Date.now()
354
- PluginManager.INSTANCE.processBinding(binding, undefined, dbContext)
368
+ PluginManager.INSTANCE.processBinding(binding, this.preparedData, dbContext)
355
369
  .then((result) => {
356
370
  subject.next({
357
371
  result,
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ProcessResult } from '@sentio/protos'
1
+ import { EthCallParam, ProcessResult } from '@sentio/protos'
2
2
 
3
3
  // TODO better handling this, because old proto doesn't have this
4
4
  import { StateResult, ProcessResult as ProcessResultFull } from './gen/processor/protos/processor.js'
@@ -8,7 +8,7 @@ import { Required } from 'utility-types'
8
8
  export function mergeProcessResults(results: ProcessResult[]): Required<ProcessResult, 'states'> {
9
9
  const res = {
10
10
  ...ProcessResultFull.create(),
11
- states: StateResult.create(),
11
+ states: StateResult.create()
12
12
  }
13
13
 
14
14
  for (const r of results) {
@@ -17,7 +17,7 @@ export function mergeProcessResults(results: ProcessResult[]): Required<ProcessR
17
17
  res.events = res.events.concat(r.events)
18
18
  res.exports = res.exports.concat(r.exports)
19
19
  res.states = {
20
- configUpdated: res.states?.configUpdated || r.states?.configUpdated || false,
20
+ configUpdated: res.states?.configUpdated || r.states?.configUpdated || false
21
21
  }
22
22
  }
23
23
  return res
@@ -28,3 +28,11 @@ export function errorString(e: Error): string {
28
28
  }
29
29
 
30
30
  export const USER_PROCESSOR = 'user_processor'
31
+
32
+ export function makeEthCallKey(param: EthCallParam) {
33
+ if (!param.context) {
34
+ throw new Error('null context for eth call')
35
+ }
36
+ const { chainId, address, blockTag } = param.context
37
+ return `${chainId}|${address}|${blockTag}|${param.calldata}`.toLowerCase()
38
+ }