Skip to content

Commit

Permalink
fix: remove lastProcessedBlock and move queryBlockLength logic to ind…
Browse files Browse the repository at this point in the history
…ex.ts
  • Loading branch information
zengzengzenghuy committed Oct 25, 2023
1 parent 4422cda commit 91981fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 0 additions & 6 deletions packages/reporter/src/BlockListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class BlocksListener {
controllers: any[]
logger: winston.Logger
timeFetchBlocksMs: number
lastProcessedBlock: bigint = 0n
multiclient: Multiclient
_interval: ReturnType<typeof setInterval> | undefined // NodeJs.Timeout
sourceChain: Chain
Expand Down Expand Up @@ -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(
Expand 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}`)
Expand Down
10 changes: 8 additions & 2 deletions packages/reporter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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()
}
Expand Down

0 comments on commit 91981fe

Please sign in to comment.