From 91981fe06b684f140021d3d82f2914221091f2a0 Mon Sep 17 00:00:00 2001 From: zengzengzenghuy Date: Wed, 25 Oct 2023 16:44:49 +0800 Subject: [PATCH] fix: remove lastProcessedBlock and move queryBlockLength logic to index.ts --- packages/reporter/src/BlockListener.ts | 6 ------ packages/reporter/src/index.ts | 10 ++++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/reporter/src/BlockListener.ts b/packages/reporter/src/BlockListener.ts index 53f67dcf..8d7f3091 100644 --- a/packages/reporter/src/BlockListener.ts +++ b/packages/reporter/src/BlockListener.ts @@ -8,7 +8,6 @@ class BlocksListener { controllers: any[] logger: winston.Logger timeFetchBlocksMs: number - lastProcessedBlock: bigint = 0n multiclient: Multiclient _interval: ReturnType | undefined // NodeJs.Timeout sourceChain: Chain @@ -43,10 +42,6 @@ class BlocksListener { let currentBlockNumber = await client.getBlockNumber() - if (this.queryBlockLength > 256 - this.blockBuffer) { - this.logger.error(`Please choose a block length less than ${256 - this.blockBuffer}!`) - } - const startBlock = currentBlockNumber - BigInt(this.queryBlockLength) const endBlock = currentBlockNumber - BigInt(this.blockBuffer) const blocks = await Promise.all( @@ -59,7 +54,6 @@ class BlocksListener { await Promise.all(this.controllers.map((_controller: any) => _controller.onBlocks(blocks))) - this.lastProcessedBlock = endBlock this.logger.info(`Waiting for ${this.timeFetchBlocksMs / 1000}s...`) } catch (_err) { this.logger.error(`error from block listener ${_err}`) diff --git a/packages/reporter/src/index.ts b/packages/reporter/src/index.ts index 854e7a1f..338ad5c1 100644 --- a/packages/reporter/src/index.ts +++ b/packages/reporter/src/index.ts @@ -13,6 +13,8 @@ function main() { const goerliRPC = process.env.GOERLI_RPC_URL as string const gnosisRPC = process.env.GNOSIS_RPC_URL as string const privKey = process.env.PRIVATE_KEY as `0x${string}` + const queryBlockLength = Number(settings.blockListener.queryBlockLength) + const blockBuffer = Number(settings.blockListener.blockBuffer) const logger = winston.createLogger({ level: "info", @@ -63,6 +65,10 @@ function main() { }, }) + if (queryBlockLength > 256 - blockBuffer) { + throw logger.error(`Please choose a block length less than ${256 - Number(settings.blockListener.blockBuffer)}!`) + } + const controllersEnabled = process.env.REPORTERS_ENABLED?.split(",") const blocksListener = new BlocksListener({ controllers: [ambReporterController, sygmaReporterController, telepathyReporterController].filter( @@ -72,8 +78,8 @@ function main() { logger, multiclient: multiClient, sourceChain: goerli, - queryBlockLength: Number(settings.blockListener.queryBlockLength), // modify the query block length here, <256 - blockBuffer: Number(settings.blockListener.blockBuffer), + queryBlockLength, // modify the query block length here, <256 - block buffer + blockBuffer, }) blocksListener.start() }