优化块同步代码
This commit is contained in:
parent
7596a8ac25
commit
4b246daf0d
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user