From 602714e3bdd2788112cfe82c13949fd19b4feca3 Mon Sep 17 00:00:00 2001 From: Nguyen Sy Thanh Son Date: Mon, 29 Oct 2018 05:03:40 +0000 Subject: [PATCH] call reward job only at checkpoint --- crawl.js | 8 ++++++-- queues/reward.js | 10 ++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crawl.js b/crawl.js index 390d20b1..84eda47a 100644 --- a/crawl.js +++ b/crawl.js @@ -164,8 +164,12 @@ function watchNewBlock () { try { let blk = await chain.eth.getBlock('latest') await updateSigners(blk) - q.create('reward', { block: blk }) - .priority('high').removeOnComplete(true).save() + let epoch = parseInt(config.get('blockchain.epoch')) + let blockNumber = blk.number + if (blockNumber % epoch === 0) { + q.create('reward', { block: blk }) + .priority('high').removeOnComplete(true).save() + } } catch (e) { console.error(e) } diff --git a/queues/reward.js b/queues/reward.js index afeb2598..e63b0e66 100644 --- a/queues/reward.js +++ b/queues/reward.js @@ -15,11 +15,9 @@ consumer.task = async function (job, done) { let epoch = parseInt(config.get('blockchain.epoch')) let blockNumber = parseInt(block.number) - if (blockNumber % epoch !== 0) { - return done() - } - try { + console.log('Cal reward', blockNumber, epoch) + let validator = await Validator.deployed() let bs = await BlockSigner.deployed() @@ -49,7 +47,7 @@ consumer.task = async function (job, done) { let signers = (sn || {}).signers || [] - console.log('Reward masternodes', signers) + console.log('Reward masternodes', blockNumber, blockNumber / epoch, signers) let totalReward = config.get('blockchain.reward') // TOMO let mnRewardRate = config.get('blockchain.masternodeRewardRate') @@ -146,7 +144,7 @@ consumer.task = async function (job, done) { await Promise.all(map) } catch (e) { console.log('ERROR Reward', e) - done(e) + done() } done()