Compare commits

...
Author SHA1 Message Date
nabarun 4ba07ef955 Upgrade watcher packages to version 0.2.103 (#19)
Part of [Investigate subgraph watchers lagging behind head](https://www.notion.so/Investigate-subgraph-watchers-lagging-behind-head-01b72294ca8e4f658e4c0e86b36d19e2)

- Export metric for total ETH RPC count
- Fix switching endpoint on max new block retries when `blockProcessingOffset` is set to some value

Reviewed-on: #19
Co-authored-by: Nabarun <nabarun@deepstacksoft.com>
Co-committed-by: Nabarun <nabarun@deepstacksoft.com>
2024-07-15 12:49:21 +00:00
nabarun ca153dcfc1 Upgrade watcher version to 0.2.102 (#18)
Part of [Investigate subgraph watchers lagging behind head](https://www.notion.so/Investigate-subgraph-watchers-lagging-behind-head-01b72294ca8e4f658e4c0e86b36d19e2)

- Set getLogsClientSwitchThresholdInSecs to 30 seconds

Reviewed-on: #18
Co-authored-by: Nabarun <nabarun@deepstacksoft.com>
Co-committed-by: Nabarun <nabarun@deepstacksoft.com>
2024-07-04 09:06:55 +00:00
nabarun a2f58cd345 Upgrade watcher version to 0.2.101 (#17)
Part of [Investigate subgraph watchers lagging behind head](https://www.notion.so/Investigate-subgraph-watchers-lagging-behind-head-01b72294ca8e4f658e4c0e86b36d19e2)

- Set `getLogsClientSwitchThresholdInSecs` to 30 seconds

Reviewed-on: #17
Co-authored-by: Nabarun <nabarun@deepstacksoft.com>
Co-committed-by: Nabarun <nabarun@deepstacksoft.com>
2024-07-04 08:50:50 +00:00
6 changed files with 113 additions and 80 deletions
+6
View File
@@ -12,6 +12,12 @@
yarn
```
* Run build:
```bash
yarn build
```
* Create a postgres12 database for the watcher:
```bash
+4 -1
View File
@@ -10,7 +10,6 @@
checkpointInterval = 2000
# Enable state creation
# CAUTION: Disable only if state creation is not desired or can be filled subsequently
enableState = false
subgraphPath = "./subgraph-build"
@@ -79,6 +78,10 @@
# Boolean flag to filter event logs by topics
filterLogsByTopics = true
# Switch clients if eth_getLogs call takes more than threshold (in secs)
# Set to 0 for disabling switching
getLogsClientSwitchThresholdInSecs = 30
[upstream.cache]
name = "requests"
enabled = false
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/ajna-watcher-ts",
"version": "0.1.13",
"version": "0.1.16",
"description": "ajna-watcher-ts",
"private": true,
"main": "dist/index.js",
@@ -39,11 +39,11 @@
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@apollo/client": "^3.3.19",
"@cerc-io/cli": "^0.2.98",
"@cerc-io/ipld-eth-client": "^0.2.98",
"@cerc-io/solidity-mapper": "^0.2.98",
"@cerc-io/util": "^0.2.98",
"@cerc-io/graph-node": "^0.2.98",
"@cerc-io/cli": "^0.2.103",
"@cerc-io/ipld-eth-client": "^0.2.103",
"@cerc-io/solidity-mapper": "^0.2.103",
"@cerc-io/util": "^0.2.103",
"@cerc-io/graph-node": "^0.2.103",
"@ethersproject/providers": "^5.4.4",
"debug": "^4.3.1",
"decimal.js": "^10.3.1",
+1 -1
View File
@@ -5,7 +5,7 @@
import { Entity, PrimaryGeneratedColumn, Column, Index } from 'typeorm';
@Entity()
@Index(['address'], { unique: true })
@Index(['address', 'kind'], { unique: true })
export class Contract {
@PrimaryGeneratedColumn()
id!: number;
+45 -21
View File
@@ -5,11 +5,10 @@
import assert from 'assert';
import { DeepPartial, FindConditions, FindManyOptions, ObjectLiteral } from 'typeorm';
import debug from 'debug';
import { ethers, constants } from 'ethers';
import { ethers, constants, providers } from 'ethers';
import { GraphQLResolveInfo } from 'graphql';
import { JsonFragment } from '@ethersproject/abi';
import { BaseProvider } from '@ethersproject/providers';
import { MappingKey, StorageLayout } from '@cerc-io/solidity-mapper';
import {
Indexer as BaseIndexer,
@@ -36,6 +35,7 @@ import {
EthFullTransaction,
ExtraEventData
} from '@cerc-io/util';
import { initClients } from '@cerc-io/cli';
import { GraphWatcher } from '@cerc-io/graph-node';
import PositionManagerArtifacts from './artifacts/PositionManager.json';
@@ -148,7 +148,7 @@ const KIND_ERC721POOL = 'ERC721Pool';
export class Indexer implements IndexerInterface {
_db: Database;
_ethClient: EthClient;
_ethProvider: BaseProvider;
_ethProvider: providers.JsonRpcProvider;
_baseIndexer: BaseIndexer;
_serverConfig: ServerConfig;
_upstreamConfig: UpstreamConfig;
@@ -171,7 +171,7 @@ export class Indexer implements IndexerInterface {
},
db: DatabaseInterface,
clients: Clients,
ethProvider: BaseProvider,
ethProvider: providers.JsonRpcProvider,
jobQueue: JobQueue,
graphWatcher?: GraphWatcherInterface
) {
@@ -326,13 +326,17 @@ export class Indexer implements IndexerInterface {
await this._baseIndexer.fetchStateStatus();
}
switchClients ({ ethClient, ethProvider }: { ethClient: EthClient, ethProvider: BaseProvider }): void {
async switchClients (): Promise<void> {
const { ethClient, ethProvider } = await this._baseIndexer.switchClients(initClients);
this._ethClient = ethClient;
this._ethProvider = ethProvider;
this._baseIndexer.switchClients({ ethClient, ethProvider });
this._graphWatcher.switchClients({ ethClient, ethProvider });
}
async isGetLogsRequestsSlow (): Promise<boolean> {
return this._baseIndexer.isGetLogsRequestsSlow();
}
async getMetaData (block: BlockHeight): Promise<ResultMeta | null> {
return this._baseIndexer.getMetaData(block);
}
@@ -520,23 +524,27 @@ export class Indexer implements IndexerInterface {
console.timeEnd('time:indexer#processBlockAfterEvents-dump_subgraph_state');
}
parseEventNameAndArgs (kind: string, logObj: any): { eventParsed: boolean, eventDetails: any } {
parseEventNameAndArgs (watchedContracts: Contract[], logObj: any): { eventParsed: boolean, eventDetails: any } {
const { topics, data } = logObj;
let logDescription: ethers.utils.LogDescription | undefined;
const contract = this._contractMap.get(kind);
assert(contract);
for (const watchedContract of watchedContracts) {
const contract = this._contractMap.get(watchedContract.kind);
assert(contract);
let logDescription: ethers.utils.LogDescription;
try {
logDescription = contract.parseLog({ data, topics });
} catch (err) {
// Return if no matching event found
if ((err as Error).message.includes('no matching event')) {
log(`WARNING: Skipping event for contract ${kind} as no matching event found in the ABI`);
return { eventParsed: false, eventDetails: {} };
try {
logDescription = contract.parseLog({ data, topics });
break;
} catch (err) {
// Continue loop only if no matching event found
if (!((err as Error).message.includes('no matching event'))) {
throw err;
}
}
}
throw err;
if (!logDescription) {
return { eventParsed: false, eventDetails: {} };
}
const { eventName, eventInfo, eventSignature } = this._baseIndexer.parseEvent(logDescription);
@@ -640,8 +648,8 @@ export class Indexer implements IndexerInterface {
return this._baseIndexer.getEventsByFilter(blockHash, contract, name);
}
isWatchedContract (address : string): Contract | undefined {
return this._baseIndexer.isWatchedContract(address);
isContractAddressWatched (address : string): Contract[] | undefined {
return this._baseIndexer.isContractAddressWatched(address);
}
getWatchedContracts (): Contract[] {
@@ -668,6 +676,10 @@ export class Indexer implements IndexerInterface {
return this._baseIndexer.getBlocks(blockFilter);
}
async getBlockByHash (blockHash?: string): Promise<{ block: any }> {
return this._baseIndexer.getBlockByHash(blockHash);
}
async updateSyncStatusIndexedBlock (blockHash: string, blockNumber: number, force = false): Promise<SyncStatus> {
return this._baseIndexer.updateSyncStatusIndexedBlock(blockHash, blockNumber, force);
}
@@ -1548,6 +1560,7 @@ export class Indexer implements IndexerInterface {
});
}
// eslint-disable-next-line @typescript-eslint/no-empty-function
_populateRelationsMap (): void {
this._relationsMap.set(Token, {
pools: {
@@ -2278,7 +2291,18 @@ export class Indexer implements IndexerInterface {
assert(blockHash);
assert(blockNumber);
const { events: dbEvents, transactions } = await this._baseIndexer.fetchEvents(blockHash, blockNumber, this.eventSignaturesMap, this.parseEventNameAndArgs.bind(this));
let dbEvents: DeepPartial<Event>[] = [];
let transactions: EthFullTransaction[] = [];
// Fetch events and txs only if subgraph config has any event handlers
if (this._graphWatcher.eventHandlerExists) {
({ events: dbEvents, transactions } = await this._baseIndexer.fetchEvents(
blockHash,
blockNumber,
this.eventSignaturesMap,
this.parseEventNameAndArgs.bind(this)
));
}
const dbTx = await this._db.createTransactionRunner();
try {
+51 -51
View File
@@ -199,10 +199,10 @@
binaryen "101.0.0-nightly.20210723"
long "^4.0.0"
"@cerc-io/cache@^0.2.98":
version "0.2.98"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fcache/-/0.2.98/cache-0.2.98.tgz#acbd54b0e3b0379652020f3dac832ed04cf392dc"
integrity sha512-scrDlufZIs0DDehEUL+eaab4Rz2r4G2fgvy2USeY3AnItreXMgUwTUAR7pXqh3FOCuj9crNfysH09Et+49/F/w==
"@cerc-io/cache@^0.2.103":
version "0.2.103"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fcache/-/0.2.103/cache-0.2.103.tgz#fce1151f27dcdda9d2a54b922aee0e61d50a42ce"
integrity sha512-zgxxfsY86M6jpBaXvyJzmBhxCB06HiQVFtgnJ8gt5JE7ZNtAZeXyYX0R4/jfQkxFPPDLt7FlgFTFLbkqa44DMA==
dependencies:
canonical-json "^0.0.4"
debug "^4.3.1"
@@ -210,19 +210,19 @@
fs-extra "^10.0.0"
level "^7.0.0"
"@cerc-io/cli@^0.2.98":
version "0.2.98"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fcli/-/0.2.98/cli-0.2.98.tgz#b29046fe48260e3e465c240d0aa64da84ad2338d"
integrity sha512-d79Gm3YOLn+CEidPBHaQhm1zu873O75LnFyH7fbIOubC4cBDWQk+RdH5U+8jU4b54EPZeVRotSoo7rQ5V8HsDg==
"@cerc-io/cli@^0.2.103":
version "0.2.103"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fcli/-/0.2.103/cli-0.2.103.tgz#daf6af4652928ca34624f49de0900b68dd57f42b"
integrity sha512-9uxJkgDl1nBLvwMUHngdG4fW0l13ZFw9I2Fl6F6s4vaP3LyutCYetipIUL6MNqRwxwSpSD0ARSF9l6h5aWICXA==
dependencies:
"@apollo/client" "^3.7.1"
"@cerc-io/cache" "^0.2.98"
"@cerc-io/ipld-eth-client" "^0.2.98"
"@cerc-io/cache" "^0.2.103"
"@cerc-io/ipld-eth-client" "^0.2.103"
"@cerc-io/libp2p" "^0.42.2-laconic-0.1.4"
"@cerc-io/nitro-node" "^0.1.15"
"@cerc-io/peer" "^0.2.98"
"@cerc-io/rpc-eth-client" "^0.2.98"
"@cerc-io/util" "^0.2.98"
"@cerc-io/peer" "^0.2.103"
"@cerc-io/rpc-eth-client" "^0.2.103"
"@cerc-io/util" "^0.2.103"
"@ethersproject/providers" "^5.4.4"
"@graphql-tools/utils" "^9.1.1"
"@ipld/dag-cbor" "^8.0.0"
@@ -243,16 +243,16 @@
typeorm "0.2.37"
yargs "^17.0.1"
"@cerc-io/graph-node@^0.2.98":
version "0.2.98"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fgraph-node/-/0.2.98/graph-node-0.2.98.tgz#06b7eb0feb1e1c4ae4e203b6007b8f0c0ac3c218"
integrity sha512-6PGVnPyRihW1f+yyU2TL61ALnsVN1f5MffmHxiJ+Co02F5t/RP7sfYjJPdT63S+W6mlwpnnmGyX0LuklOXpezQ==
"@cerc-io/graph-node@^0.2.103":
version "0.2.103"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fgraph-node/-/0.2.103/graph-node-0.2.103.tgz#f6fa475faf9c43c33fde0bc4c7a2cde915b2d7f7"
integrity sha512-12QbYvFp2rU7lc6wefbk+7wtstcs1KHnaTRW7E7VLY+Rdo1X5LXBwxYYujHoiUHHF7q3wfjzuUEfgHF3TNTRtw==
dependencies:
"@apollo/client" "^3.3.19"
"@cerc-io/assemblyscript" "0.19.10-watcher-ts-0.1.2"
"@cerc-io/cache" "^0.2.98"
"@cerc-io/ipld-eth-client" "^0.2.98"
"@cerc-io/util" "^0.2.98"
"@cerc-io/cache" "^0.2.103"
"@cerc-io/ipld-eth-client" "^0.2.103"
"@cerc-io/util" "^0.2.103"
"@types/json-diff" "^0.5.2"
"@types/yargs" "^17.0.0"
bn.js "^4.11.9"
@@ -269,14 +269,14 @@
typeorm-naming-strategies "^2.0.0"
yargs "^17.0.1"
"@cerc-io/ipld-eth-client@^0.2.98":
version "0.2.98"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fipld-eth-client/-/0.2.98/ipld-eth-client-0.2.98.tgz#c1a7128be1e81fb4d1ec9a9888b7e5e94ae710ac"
integrity sha512-qCnz7foqf+9+X/zEGAu5HGXlvzNwahcsKu6Rtreh8bxhR5VTuuF3KrEeFcQeL1Bhv5+w7KXs5I+ivEgo4ZvHSA==
"@cerc-io/ipld-eth-client@^0.2.103":
version "0.2.103"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fipld-eth-client/-/0.2.103/ipld-eth-client-0.2.103.tgz#e31e0610940e11b3d594329a7e1cf8b4a45c8968"
integrity sha512-FOJiRDKBI6PpDK9NZsnJcRR70qSC7QT8APoMEe3DXIs+PJbs3nFZlucgYDCYUD58hBz5HEbSHVfVUTpcZyWCgg==
dependencies:
"@apollo/client" "^3.7.1"
"@cerc-io/cache" "^0.2.98"
"@cerc-io/util" "^0.2.98"
"@cerc-io/cache" "^0.2.103"
"@cerc-io/util" "^0.2.103"
cross-fetch "^3.1.4"
debug "^4.3.1"
ethers "^5.4.4"
@@ -399,10 +399,10 @@
lodash "^4.17.21"
uint8arrays "^4.0.3"
"@cerc-io/peer@^0.2.65":
version "0.2.82"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fpeer/-/0.2.82/peer-0.2.82.tgz#e27a1cafd06c25f9c4e02d49d4615f45a76ce22b"
integrity sha512-wKkBXO7hxuN13Av60otDj+2O7nyoogYp+n8uTKNU9cv6J87OLRUZZAuGb5FggUONgDqxS3cyaXD6vqLpkhbbIA==
"@cerc-io/peer@^0.2.103":
version "0.2.103"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fpeer/-/0.2.103/peer-0.2.103.tgz#ade3e10a9c290ca53f617f3712be3b17a8e788e0"
integrity sha512-CKULKLx0GysWX9qXGNDj7gTmhW+kxLHy/VuZbxv6y/v6W7D6QZq+8O5NZ2gcVPa16qiOHToa/W9He8/itm4nPw==
dependencies:
"@cerc-io/libp2p" "^0.42.2-laconic-0.1.4"
"@cerc-io/prometheus-metrics" "1.1.4"
@@ -429,10 +429,10 @@
unique-names-generator "^4.7.1"
yargs "^17.0.1"
"@cerc-io/peer@^0.2.98":
version "0.2.98"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fpeer/-/0.2.98/peer-0.2.98.tgz#650c771be2a3767456f38c93cb86e6667f2867ec"
integrity sha512-b8sCTzFxfTgrlscNutBzML0y4rzkZvzjCpHDEp3P4fMRHIK9SM5o8yYaPS9g1NwoedjbLKCnCDrmaIGpLEbmqA==
"@cerc-io/peer@^0.2.65":
version "0.2.82"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fpeer/-/0.2.82/peer-0.2.82.tgz#e27a1cafd06c25f9c4e02d49d4615f45a76ce22b"
integrity sha512-wKkBXO7hxuN13Av60otDj+2O7nyoogYp+n8uTKNU9cv6J87OLRUZZAuGb5FggUONgDqxS3cyaXD6vqLpkhbbIA==
dependencies:
"@cerc-io/libp2p" "^0.42.2-laconic-0.1.4"
"@cerc-io/prometheus-metrics" "1.1.4"
@@ -471,23 +471,23 @@
it-stream-types "^1.0.4"
promjs "^0.4.2"
"@cerc-io/rpc-eth-client@^0.2.98":
version "0.2.98"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Frpc-eth-client/-/0.2.98/rpc-eth-client-0.2.98.tgz#005546cf25a245e60fa00b0c972239748ac1c29e"
integrity sha512-SjR621w5WxrhLsXyy17mTXo1UwvcPz9QPL4/mwQcwsvzDXoFff1bgxR7UGKInQG5QzGgwTJjAaozVqxQA1X3+g==
"@cerc-io/rpc-eth-client@^0.2.103":
version "0.2.103"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Frpc-eth-client/-/0.2.103/rpc-eth-client-0.2.103.tgz#2a6fdb64a63780e04cfaf782c4af9e9854ee30b9"
integrity sha512-efEdgYuwXoTfcZWa5/EwUCAC/dUqk5yh4VYcVAt78CLUSoDc7Iw//flzhNrTetvekuo1vGN5JcO+m4QEfrsy+A==
dependencies:
"@cerc-io/cache" "^0.2.98"
"@cerc-io/ipld-eth-client" "^0.2.98"
"@cerc-io/util" "^0.2.98"
"@cerc-io/cache" "^0.2.103"
"@cerc-io/ipld-eth-client" "^0.2.103"
"@cerc-io/util" "^0.2.103"
chai "^4.3.4"
ethers "^5.4.4"
left-pad "^1.3.0"
mocha "^8.4.0"
"@cerc-io/solidity-mapper@^0.2.98":
version "0.2.98"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fsolidity-mapper/-/0.2.98/solidity-mapper-0.2.98.tgz#6fc8dfcaf872e31964a6cca1ea9fbd7900119f8a"
integrity sha512-RmGmcgN0fZEZU0r4q14qPm2hVHUK/OQVPIEgyLEbcStHXupYLaTn79li1WpURI7yeVuJ7mFVaauviWA2DeG7dw==
"@cerc-io/solidity-mapper@^0.2.103":
version "0.2.103"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fsolidity-mapper/-/0.2.103/solidity-mapper-0.2.103.tgz#37110d683c571ad9422dfcb524a8079621580a7f"
integrity sha512-9prQvpNEIXiGFoAVQkEUxrtFnLIYjGA+kxGGLcWob0NEUWnopzRTjsE1SS1i7/OKDRI/cfjOT1AEa0DtQwufzg==
dependencies:
dotenv "^10.0.0"
@@ -496,15 +496,15 @@
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fts-channel/-/1.0.3-ts-nitro-0.1.1/ts-channel-1.0.3-ts-nitro-0.1.1.tgz#0768781313a167295c0bf21307f47e02dc17e936"
integrity sha512-2jFICUSyffuZ+8+qRhXuLSJq4GJ6Y02wxiXoubH0Kzv2lIKkJtWICY1ZQQhtXAvP0ncAQB85WJHqtqwH8l7J3Q==
"@cerc-io/util@^0.2.98":
version "0.2.98"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Futil/-/0.2.98/util-0.2.98.tgz#0bed961a20d43c8973d5b86b400086caa76d2d0a"
integrity sha512-s1St/bD9OjD3NIfx3gj1tDELgpiyxGl6le3mCs77jHM4KbEHW7pFjhe/5YsLXRvc5cIHwNsrCdOuSAIyVUtC2Q==
"@cerc-io/util@^0.2.103":
version "0.2.103"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Futil/-/0.2.103/util-0.2.103.tgz#d28858a5e17cb4bd76194275030e6a0b72f92cc8"
integrity sha512-tzCKcvK5l/yogQalFxh0z4HxAEjM1KGdSfnIsV0Bxo3lwmTjXtOJu5yT3UJtv8swJNF9+YLNUp9DiWGNTk63XA==
dependencies:
"@apollo/utils.keyvaluecache" "^1.0.1"
"@cerc-io/nitro-node" "^0.1.15"
"@cerc-io/peer" "^0.2.98"
"@cerc-io/solidity-mapper" "^0.2.98"
"@cerc-io/peer" "^0.2.103"
"@cerc-io/solidity-mapper" "^0.2.103"
"@cerc-io/ts-channel" "1.0.3-ts-nitro-0.1.1"
"@ethersproject/properties" "^5.7.0"
"@ethersproject/providers" "^5.4.4"