优化块同步代码
This commit is contained in:
parent
7596a8ac25
commit
4b246daf0d
@ -42,7 +42,7 @@ export class CheckInClass extends BaseModule {
|
|||||||
event.count = preDayEvent.count + 1
|
event.count = preDayEvent.count + 1
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await CheckIn.insertOrUpdate({ hash: event.hash }, event)
|
await CheckIn.insertOrUpdate({ from: event.from, dataTag: event.dataTag }, event)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.info('save check record error: ', event.dataTag, event.from, err.message || err)
|
logger.info('save check record error: ', event.dataTag, event.from, err.message || err)
|
||||||
}
|
}
|
||||||
|
@ -27,28 +27,22 @@ export class BlockSyncSvr {
|
|||||||
|
|
||||||
async execute() {
|
async execute() {
|
||||||
try {
|
try {
|
||||||
if (!this.batchCount) {
|
let currentBlock = await retryEthBlockNumber(this.rpc)
|
||||||
let currentBlock = await retryEthBlockNumber(this.rpc)
|
|
||||||
if (currentBlock.error) {
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
this.batchCount = parseInt(currentBlock.result, 16) - this.fromBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
let blockStr = await new RedisClient().get(this.redisKey)
|
let blockStr = await new RedisClient().get(this.redisKey)
|
||||||
if (blockStr) {
|
if (blockStr) {
|
||||||
this.fromBlock = Math.max(parseInt(blockStr), this.fromBlock)
|
this.fromBlock = Math.max(parseInt(blockStr), this.fromBlock)
|
||||||
}
|
}
|
||||||
|
this.batchCount = parseInt(currentBlock.result, 16) - this.fromBlock
|
||||||
|
if (this.batchCount <= 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
let blocks = getPastBlocksIter({
|
let blocks = getPastBlocksIter({
|
||||||
chainId: this.chainCfg.id,
|
chainId: this.chainCfg.id,
|
||||||
rpc: this.rpc,
|
rpc: this.rpc,
|
||||||
fromBlock: this.fromBlock,
|
fromBlock: this.fromBlock,
|
||||||
amount: this.batchCount
|
amount: this.batchCount
|
||||||
})
|
})
|
||||||
const amount = await this.processBlockDatas(blocks)
|
await this.processBlockDatas(blocks)
|
||||||
if (amount > 0) {
|
|
||||||
this.batchCount = amount + 1
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user