Skip to content

Commit

Permalink
Merge pull request #256 from thanhson1085/master
Browse files Browse the repository at this point in the history
call reward job only at checkpoint
  • Loading branch information
thanhson1085 authored Oct 29, 2018
2 parents 3d8b7da + 602714e commit 893daf7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 6 additions & 2 deletions crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 4 additions & 6 deletions queues/reward.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 893daf7

Please sign in to comment.