From 4b246daf0d31f4a5e96dd7d5f51c07db5771313d Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Thu, 11 Jan 2024 12:33:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9D=97=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/CheckIn.ts | 2 +- src/service/block.sync.service.ts | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/models/CheckIn.ts b/src/models/CheckIn.ts index 756a4cf..aa971dd 100644 --- a/src/models/CheckIn.ts +++ b/src/models/CheckIn.ts @@ -42,7 +42,7 @@ export class CheckInClass extends BaseModule { event.count = preDayEvent.count + 1 } try { - await CheckIn.insertOrUpdate({ hash: event.hash }, event) + await CheckIn.insertOrUpdate({ from: event.from, dataTag: event.dataTag }, event) } catch (err) { logger.info('save check record error: ', event.dataTag, event.from, err.message || err) } diff --git a/src/service/block.sync.service.ts b/src/service/block.sync.service.ts index 94e1adc..4a8871b 100644 --- a/src/service/block.sync.service.ts +++ b/src/service/block.sync.service.ts @@ -27,28 +27,22 @@ export class BlockSyncSvr { async execute() { try { - if (!this.batchCount) { - let currentBlock = await retryEthBlockNumber(this.rpc) - if (currentBlock.error) { - process.exit(1) - } - this.batchCount = parseInt(currentBlock.result, 16) - this.fromBlock - } - + let currentBlock = await retryEthBlockNumber(this.rpc) let blockStr = await new RedisClient().get(this.redisKey) if (blockStr) { this.fromBlock = Math.max(parseInt(blockStr), this.fromBlock) } + this.batchCount = parseInt(currentBlock.result, 16) - this.fromBlock + if (this.batchCount <= 0) { + return + } let blocks = getPastBlocksIter({ chainId: this.chainCfg.id, rpc: this.rpc, fromBlock: this.fromBlock, amount: this.batchCount }) - const amount = await this.processBlockDatas(blocks) - if (amount > 0) { - this.batchCount = amount + 1 - } + await this.processBlockDatas(blocks) } catch (err) { console.log(err) }