@sentio/runtime 2.40.0-rc.3 → 2.40.0-rc.9

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
  };
@@ -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}`;
59535
+ }
59491
59536
 
59492
59537
  // src/endpoints.ts
59493
59538
  var _Endpoints = class {
@@ -78261,7 +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;
78264
- console.log(`init provider for ${chainId}, address: ${address}`);
78309
+ console.debug(`init provider for ${chainId}, address: ${address}`);
78265
78310
  let provider = providers.get(key);
78266
78311
  if (provider) {
78267
78312
  return provider;
@@ -78383,6 +78428,7 @@ var ProcessorServiceImpl = class {
78383
78428
  // private processorConfig: ProcessConfigResponse
78384
78429
  loader;
78385
78430
  shutdownHandler;
78431
+ preprocessedEthCalls;
78386
78432
  constructor(loader, shutdownHandler) {
78387
78433
  this.loader = loader;
78388
78434
  this.shutdownHandler = shutdownHandler;
@@ -78443,7 +78489,7 @@ var ProcessorServiceImpl = class {
78443
78489
  };
78444
78490
  }
78445
78491
  async preprocessBindings(bindings, dbContext, options) {
78446
- console.log(`preprocessBindings start, bindings: ${bindings.length}`);
78492
+ console.debug(`preprocessBindings start, bindings: ${bindings.length}`);
78447
78493
  const promises = [];
78448
78494
  for (const binding of bindings) {
78449
78495
  promises.push(this.preprocessBinding(binding, dbContext, options));
@@ -78454,7 +78500,7 @@ var ProcessorServiceImpl = class {
78454
78500
  } catch (e) {
78455
78501
  throw e;
78456
78502
  }
78457
- console.log(
78503
+ console.debug(
78458
78504
  "ethCallParams: ",
78459
78505
  preprocessResults.map((r) => r.ethCallParams)
78460
78506
  );
@@ -78462,10 +78508,11 @@ var ProcessorServiceImpl = class {
78462
78508
  const providers2 = /* @__PURE__ */ new Map();
78463
78509
  for (const result of preprocessResults) {
78464
78510
  for (const param of result.ethCallParams) {
78465
- if (!providers2.has(param.chainId)) {
78466
- providers2.set(param.chainId, getProvider2(param.chainId));
78511
+ const { chainId, address, blockTag } = param.context;
78512
+ if (!providers2.has(chainId)) {
78513
+ providers2.set(chainId, getProvider2(chainId));
78467
78514
  }
78468
- const key = param.chainId + "|" + param.address;
78515
+ const key = [chainId, address, blockTag].join("|");
78469
78516
  if (!groupedRequests.has(key)) {
78470
78517
  groupedRequests.set(key, []);
78471
78518
  }
@@ -78475,15 +78522,15 @@ var ProcessorServiceImpl = class {
78475
78522
  const start = Date.now();
78476
78523
  const callPromises = [];
78477
78524
  for (const params of groupedRequests.values()) {
78478
- console.log(`chain: ${params[0].chainId}, address: ${params[0].address}, totalCalls: ${params.length}`);
78525
+ const { chainId, address, blockTag } = params[0].context;
78526
+ console.log(`chain: ${chainId}, address: ${address}, blockTag: ${blockTag}, totalCalls: ${params.length}`);
78479
78527
  for (const param of params) {
78480
- const frag = new Interface(param.signature);
78481
- const calldata = frag.encodeFunctionData(param.function, param.args);
78482
78528
  callPromises.push(
78483
- providers2.get(param.chainId).call({
78484
- to: param.address,
78485
- data: calldata
78486
- }).then((ret) => [calldata, frag.decodeFunctionResult(param.function, ret).toArray()])
78529
+ providers2.get(chainId).call({
78530
+ to: address,
78531
+ data: param.calldata,
78532
+ blockTag
78533
+ }).then((result) => [makeEthCallKey(param), result])
78487
78534
  );
78488
78535
  }
78489
78536
  }
@@ -78563,11 +78610,9 @@ var ProcessorServiceImpl = class {
78563
78610
  }).catch((e) => {
78564
78611
  console.debug(e);
78565
78612
  dbContext.error(request.processId, e);
78566
- process_binding_error.add(1);
78567
78613
  }).finally(() => {
78568
78614
  const cost = Date.now() - start;
78569
78615
  console.debug("preprocessBinding", request.processId, " took", cost, "ms");
78570
- process_binding_time.add(cost);
78571
78616
  contexts.delete(request.processId);
78572
78617
  });
78573
78618
  }
@@ -78672,6 +78717,7 @@ export {
78672
78717
  mergeProcessResults,
78673
78718
  errorString,
78674
78719
  USER_PROCESSOR,
78720
+ makeEthCallKey,
78675
78721
  Endpoints,
78676
78722
  require_lib,
78677
78723
  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';
@@ -85,6 +85,7 @@ declare abstract class ListStateStorage<T> extends StateStorage<T[]> {
85
85
  declare function mergeProcessResults(results: ProcessResult[]): Required<ProcessResult, 'states'>;
86
86
  declare function errorString(e: Error): string;
87
87
  declare const USER_PROCESSOR = "user_processor";
88
+ declare function makeEthCallKey(param: EthCallParam): string;
88
89
 
89
90
  declare class Endpoints {
90
91
  static INSTANCE: Endpoints;
@@ -106,13 +107,14 @@ declare class ProcessorServiceImpl implements ProcessorServiceImplementation {
106
107
  unhandled: Error;
107
108
  private readonly loader;
108
109
  private readonly shutdownHandler?;
110
+ private readonly preprocessedEthCalls;
109
111
  constructor(loader: () => Promise<any>, shutdownHandler?: () => void);
110
112
  getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse>;
111
113
  start(request: StartRequest, context: CallContext): Promise<Empty>;
112
114
  stop(request: Empty, context: CallContext): Promise<Empty>;
113
115
  processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse>;
114
116
  preprocessBindings(bindings: DataBinding[], dbContext?: StoreContext, options?: CallContext): Promise<{
115
- [calldata: string]: any[];
117
+ [ethCallKey: string]: string;
116
118
  }>;
117
119
  preprocessBinding(request: DataBinding, dbContext?: StoreContext, options?: CallContext): Promise<PreprocessResult>;
118
120
  processBinding(request: DataBinding, preparedData: PreparedData | undefined, options?: CallContext): Promise<ProcessResult>;
@@ -366,4 +368,4 @@ interface GlobalConfig {
366
368
  }
367
369
  declare const GLOBAL_CONFIG: GlobalConfig;
368
370
 
369
- export { ChainConfig, Endpoints, GLOBAL_CONFIG, GlobalConfig, ListStateStorage, MapStateStorage, Plugin, PluginManager, ProcessorServiceImpl, State, StateStorage, StoreContext, USER_PROCESSOR, errorString, mergeProcessResults, timeoutError };
371
+ 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-Y3KJTCAS.js";
15
+ } from "./chunk-FFU5RYDX.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-Y3KJTCAS.js";
43
+ } from "./chunk-FFU5RYDX.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.3",
3
+ "version": "2.40.0-rc.9",
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/provider.ts CHANGED
@@ -38,7 +38,7 @@ export function getProvider(chainId?: EthChainId): Provider {
38
38
  const address = Endpoints.INSTANCE.chainServer.get(chainId)
39
39
  const key = network.chainId.toString() + '-' + address
40
40
 
41
- console.log(`init provider for ${chainId}, address: ${address}`)
41
+ console.debug(`init provider for ${chainId}, address: ${address}`)
42
42
  let provider = providers.get(key)
43
43
 
44
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 readonly preprocessedEthCalls: { [calldata: string]: any[] }
58
+
57
59
  constructor(loader: () => Promise<any>, shutdownHandler?: () => void) {
58
60
  this.loader = loader
59
61
  this.shutdownHandler = shutdownHandler
@@ -159,8 +161,8 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
159
161
  bindings: DataBinding[],
160
162
  dbContext?: StoreContext,
161
163
  options?: CallContext
162
- ): Promise<{ [calldata: string]: any[] }> {
163
- console.log(`preprocessBindings start, bindings: ${bindings.length}`)
164
+ ): Promise<{ [ethCallKey: string]: string }> {
165
+ console.debug(`preprocessBindings start, bindings: ${bindings.length}`)
164
166
  const promises = []
165
167
  for (const binding of bindings) {
166
168
  promises.push(this.preprocessBinding(binding, dbContext, options))
@@ -171,7 +173,7 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
171
173
  } catch (e) {
172
174
  throw e
173
175
  }
174
- console.log(
176
+ console.debug(
175
177
  'ethCallParams: ',
176
178
  preprocessResults.map((r) => r.ethCallParams)
177
179
  )
@@ -179,10 +181,11 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
179
181
  const providers = new Map<string, Provider>()
180
182
  for (const result of preprocessResults) {
181
183
  for (const param of result.ethCallParams) {
182
- if (!providers.has(param.chainId)) {
183
- providers.set(param.chainId, getProvider(param.chainId as EthChainId))
184
+ const { chainId, address, blockTag } = param.context!
185
+ if (!providers.has(chainId)) {
186
+ providers.set(chainId, getProvider(chainId as EthChainId))
184
187
  }
185
- const key = param.chainId + '|' + param.address
188
+ const key = [chainId, address, blockTag].join('|')
186
189
  if (!groupedRequests.has(key)) {
187
190
  groupedRequests.set(key, [])
188
191
  }
@@ -193,18 +196,19 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
193
196
  const start = Date.now()
194
197
  const callPromises = []
195
198
  for (const params of groupedRequests.values()) {
196
- console.log(`chain: ${params[0].chainId}, address: ${params[0].address}, totalCalls: ${params.length}`)
199
+ const { chainId, address, blockTag } = params[0].context!
200
+ console.log(`chain: ${chainId}, address: ${address}, blockTag: ${blockTag}, totalCalls: ${params.length}`)
201
+ // TODO multicall
197
202
  for (const param of params) {
198
- const frag = new Interface(param.signature)
199
- const calldata = frag.encodeFunctionData(param.function, param.args)
200
203
  callPromises.push(
201
204
  providers
202
- .get(param.chainId)!
205
+ .get(chainId)!
203
206
  .call({
204
- to: param.address,
205
- data: calldata
207
+ to: address,
208
+ data: param.calldata,
209
+ blockTag
206
210
  })
207
- .then((ret) => [calldata, frag.decodeFunctionResult(param.function, ret).toArray()] as [string, any[]])
211
+ .then((result) => [makeEthCallKey(param), result])
208
212
  )
209
213
  }
210
214
  }
@@ -305,12 +309,10 @@ export class ProcessorServiceImpl implements ProcessorServiceImplementation {
305
309
  .catch((e) => {
306
310
  console.debug(e)
307
311
  dbContext.error(request.processId, e)
308
- process_binding_error.add(1)
309
312
  })
310
313
  .finally(() => {
311
314
  const cost = Date.now() - start
312
315
  console.debug('preprocessBinding', request.processId, ' took', cost, 'ms')
313
- process_binding_time.add(cost)
314
316
  contexts.delete(request.processId)
315
317
  })
316
318
  }
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}`
38
+ }