mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-11 18:24:05 +00:00
Add isFEVM flag in config to avoid filtering event logs by topics (#454)
* Pass upstream config to indexer instance * Add isFEVM flag and refactor watcher config fields * Codegen changes for indexer * Add missing getter in dummy indexer for graph-node tests
This commit is contained in:
@@ -427,7 +427,7 @@ const _processEventsInSubgraphOrder = async (indexer: IndexerInterface, block: B
|
||||
isNewContractWatched = true;
|
||||
|
||||
// Check if filterLogsByAddresses is set to true
|
||||
if (indexer.serverConfig.filterLogsByAddresses) {
|
||||
if (indexer.upstreamConfig.ethServer.filterLogsByAddresses) {
|
||||
// Fetch and parse events for newly watched contracts
|
||||
const newContracts = watchedContracts.filter(contract => !initiallyWatchedContracts.includes(contract));
|
||||
const events = await indexer.fetchEventsForContracts(block.blockHash, block.blockNumber, newContracts);
|
||||
|
||||
+15
-11
@@ -29,6 +29,10 @@ export interface JobQueueConfig {
|
||||
// Max block range of historical processing after which it waits for completion of events processing
|
||||
// If set to -1 historical processing does not wait for events processing and completes till latest canonical block
|
||||
historicalMaxFetchAhead?: number;
|
||||
// Boolean to switch between modes of processing events when starting the server
|
||||
// Setting to true will fetch filtered events and required blocks in a range of blocks and then process them
|
||||
// Setting to false will fetch blocks consecutively with its events and then process them (Behaviour is followed in realtime processing near head)
|
||||
useBlockRanges: boolean;
|
||||
}
|
||||
|
||||
export interface GQLCacheConfig {
|
||||
@@ -205,26 +209,19 @@ export interface ServerConfig {
|
||||
subgraphPath: string;
|
||||
enableState: boolean;
|
||||
wasmRestartBlocksInterval: number;
|
||||
filterLogsByAddresses: boolean;
|
||||
filterLogsByTopics: boolean;
|
||||
maxEventsBlockRange: number;
|
||||
clearEntitiesCacheInterval: number;
|
||||
|
||||
// Boolean to switch between modes of processing events when starting the server.
|
||||
// Setting to true will fetch filtered events and required blocks in a range of blocks and then process them.
|
||||
// Setting to false will fetch blocks consecutively with its events and then process them (Behaviour is followed in realtime processing near head).
|
||||
useBlockRanges: boolean;
|
||||
|
||||
// Boolean to skip updating entity fields required in state creation and not required in the frontend.
|
||||
// Boolean to skip updating entity fields required in state creation and not required in the frontend
|
||||
skipStateFieldsUpdate: boolean;
|
||||
|
||||
// Max GQL API requests to process simultaneously (defaults to 1).
|
||||
// Max GQL API requests to process simultaneously (defaults to 1)
|
||||
maxSimultaneousRequests?: number;
|
||||
|
||||
// Max GQL API requests in queue until reject (defaults to -1, means do not reject).
|
||||
// Max GQL API requests in queue until reject (defaults to -1, means do not reject)
|
||||
maxRequestQueueLimit?: number;
|
||||
|
||||
// Boolean to load GQL query nested entity relations sequentially.
|
||||
// Boolean to load GQL query nested entity relations sequentially
|
||||
loadRelationsSequential: boolean;
|
||||
|
||||
// GQL cache-control max-age settings (in seconds)
|
||||
@@ -260,7 +257,14 @@ export interface UpstreamConfig {
|
||||
gqlApiEndpoint: string;
|
||||
rpcProviderEndpoint: string;
|
||||
rpcProviderMutationEndpoint: string;
|
||||
// Boolean flag to specify if rpc-eth-client should be used for RPC endpoint instead of ipld-eth-client (ipld-eth-server GQL client)
|
||||
rpcClient: boolean;
|
||||
// Boolean flag to specify if rpcProviderEndpoint is an FEVM RPC endpoint
|
||||
isFEVM: boolean;
|
||||
// Boolean flag to filter event logs by contracts
|
||||
filterLogsByAddresses: boolean;
|
||||
// Boolean flag to filter event logs by topics
|
||||
filterLogsByTopics: boolean;
|
||||
payments: EthServerPaymentsConfig;
|
||||
}
|
||||
traceProviderEndpoint: string;
|
||||
|
||||
@@ -103,7 +103,7 @@ export class EventWatcher {
|
||||
|
||||
// Check if filter for logs is enabled
|
||||
// Check if starting block for watcher is before latest canonical block
|
||||
if (this._config.server.useBlockRanges && startBlockNumber < latestCanonicalBlockNumber) {
|
||||
if (this._config.jobQueue.useBlockRanges && startBlockNumber < latestCanonicalBlockNumber) {
|
||||
let endBlockNumber = latestCanonicalBlockNumber;
|
||||
const historicalMaxFetchAhead = this._config.jobQueue.historicalMaxFetchAhead ?? DEFAULT_HISTORICAL_MAX_FETCH_AHEAD;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
import { UNKNOWN_EVENT_NAME, JOB_KIND_CONTRACT, QUEUE_EVENT_PROCESSING, DIFF_MERGE_BATCH_SIZE } from './constants';
|
||||
import { JobQueue } from './job-queue';
|
||||
import { Where, QueryOptions } from './database';
|
||||
import { ServerConfig } from './config';
|
||||
import { ServerConfig, UpstreamConfig } from './config';
|
||||
import { createOrUpdateStateData, StateDataMeta } from './state-helper';
|
||||
|
||||
const DEFAULT_MAX_EVENTS_BLOCK_RANGE = 1000;
|
||||
@@ -90,6 +90,7 @@ export type ResultEvent = {
|
||||
|
||||
export class Indexer {
|
||||
_serverConfig: ServerConfig;
|
||||
_upstreamConfig: UpstreamConfig;
|
||||
_db: DatabaseInterface;
|
||||
_ethClient: EthClient;
|
||||
_getStorageAt: GetStorageAt;
|
||||
@@ -100,13 +101,17 @@ export class Indexer {
|
||||
_stateStatusMap: { [key: string]: StateStatus } = {};
|
||||
|
||||
constructor (
|
||||
serverConfig: ServerConfig,
|
||||
config: {
|
||||
server: ServerConfig;
|
||||
upstream: UpstreamConfig;
|
||||
},
|
||||
db: DatabaseInterface,
|
||||
ethClient: EthClient,
|
||||
ethProvider: ethers.providers.BaseProvider,
|
||||
jobQueue: JobQueue
|
||||
) {
|
||||
this._serverConfig = serverConfig;
|
||||
this._serverConfig = config.server;
|
||||
this._upstreamConfig = config.upstream;
|
||||
this._db = db;
|
||||
this._ethClient = ethClient;
|
||||
this._ethProvider = ethProvider;
|
||||
@@ -1289,14 +1294,14 @@ export class Indexer {
|
||||
let addresses: string[] | undefined;
|
||||
let eventSignatures: string[] | undefined;
|
||||
|
||||
if (this._serverConfig.filterLogsByAddresses) {
|
||||
if (this._upstreamConfig.ethServer.filterLogsByAddresses) {
|
||||
const watchedContracts = this.getWatchedContracts();
|
||||
addresses = watchedContracts.map((watchedContract): string => {
|
||||
return watchedContract.address;
|
||||
});
|
||||
}
|
||||
|
||||
if (this._serverConfig.filterLogsByTopics) {
|
||||
if (this._upstreamConfig.ethServer.filterLogsByTopics && !this._upstreamConfig.ethServer.isFEVM) {
|
||||
const eventSignaturesSet = new Set<string>();
|
||||
eventSignaturesMap.forEach(sigs => sigs.forEach(sig => {
|
||||
eventSignaturesSet.add(sig);
|
||||
|
||||
@@ -572,7 +572,7 @@ export class JobRunner {
|
||||
this._blockAndEventsMap.delete(block.blockHash);
|
||||
|
||||
// Check if new contract was added and filterLogsByAddresses is set to true
|
||||
if (isNewContractWatched && this._indexer.serverConfig.filterLogsByAddresses) {
|
||||
if (isNewContractWatched && this._indexer.upstreamConfig.ethServer.filterLogsByAddresses) {
|
||||
// Delete jobs for any pending events processing
|
||||
await this.jobQueue.deleteJobs(QUEUE_EVENT_PROCESSING);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Connection, DeepPartial, EntityTarget, FindConditions, FindManyOptions,
|
||||
|
||||
import { MappingKey, StorageLayout } from '@cerc-io/solidity-mapper';
|
||||
|
||||
import { ServerConfig } from './config';
|
||||
import { ServerConfig, UpstreamConfig } from './config';
|
||||
import { Where, QueryOptions, Database } from './database';
|
||||
import { ValueResult, StateStatus } from './indexer';
|
||||
|
||||
@@ -81,6 +81,7 @@ export interface StateInterface {
|
||||
|
||||
export interface IndexerInterface {
|
||||
readonly serverConfig: ServerConfig
|
||||
readonly upstreamConfig: UpstreamConfig
|
||||
readonly storageLayoutMap: Map<string, StorageLayout>
|
||||
init (): Promise<void>
|
||||
getBlockProgress (blockHash: string): Promise<BlockProgressInterface | undefined>
|
||||
|
||||
Reference in New Issue
Block a user