优化块同步代码

This commit is contained in:
CounterFire2023 2024-01-11 12:33:20 +08:00
parent 7596a8ac25
commit 4b246daf0d
2 changed files with 7 additions and 13 deletions

View File

@ -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)
}

View File

@ -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)
}