diff --git a/demo/validator1/.env.staging b/demo/validator1/.env.staging index 9b0cfc2..89e3609 100644 --- a/demo/validator1/.env.staging +++ b/demo/validator1/.env.staging @@ -24,4 +24,4 @@ VOTES_PROXY_PORT=5001 SIGN_RESTART_PORT=6001 -LOG_LEVEL=trace +LOG_LEVEL=info diff --git a/src/oracle/bncWatcher/bncWatcher.js b/src/oracle/bncWatcher/bncWatcher.js index 1320e43..159156c 100644 --- a/src/oracle/bncWatcher/bncWatcher.js +++ b/src/oracle/bncWatcher/bncWatcher.js @@ -79,6 +79,7 @@ async function fetchTimeIntervalsQueue() { break } const data = JSON.parse(msg.content) + let accept = false logger.trace('Consumed time interval event %o', data) if (epoch !== null && epoch !== data.epoch) { logger.warn('Two consequently events have different epochs, should not be like this') @@ -92,25 +93,15 @@ async function fetchTimeIntervalsQueue() { break } if (epoch === null) { + accept = true epoch = data.epoch startTime = await redis.get(`foreignTime${epoch}`) logger.trace(`Retrieved epoch ${epoch} and start time ${startTime} from redis`) if (startTime === null) { logger.warn(`Empty foreign time for epoch ${epoch}`) } - } /* - if (data.endTime) { - if (data.endTime - startTime < FOREIGN_FETCH_MAX_TIME_INTERVAL - && data.endTime < lastBncBlockTime) { - endTime = data.endTime - channel.ack(msg) - } else { - logger.trace('Requeuing current queue message') - channel.nack(msg, false, true) - } - break - } */ - if (data.prolongedTime - startTime < FOREIGN_FETCH_MAX_TIME_INTERVAL + } + if ((data.prolongedTime - startTime < FOREIGN_FETCH_MAX_TIME_INTERVAL || accept) && data.prolongedTime < lastBncBlockTime) { endTime = data.prolongedTime channel.ack(msg) diff --git a/src/oracle/ethWatcher/ethWatcher.js b/src/oracle/ethWatcher/ethWatcher.js index a8d616e..a37d412 100644 --- a/src/oracle/ethWatcher/ethWatcher.js +++ b/src/oracle/ethWatcher/ethWatcher.js @@ -225,8 +225,7 @@ async function initialize() { rangeSize = (await bridge.getRangeSize()).toNumber() logger.debug(`Range size ${rangeSize}`) logger.debug('Checking if current validator') - isCurrentValidator = (await bridge.getValidators()) - .includes(validatorAddress) + isCurrentValidator = (await bridge.getValidators()).includes(validatorAddress) if (isCurrentValidator) { logger.info(`${validatorAddress} is a current validator`) } else { @@ -266,7 +265,6 @@ async function loop() { for (let curBlockNumber = blockNumber, i = 0; curBlockNumber <= endBlock; curBlockNumber += 1) { let epochTimeUpdated = false - const curBlockTimestamp = await retry(() => getBlockTimestamp(curBlockNumber)) while (i < bridgeEvents.length && bridgeEvents[i].blockNumber === curBlockNumber) { const event = bridge.interface.parseLog(bridgeEvents[i]) logger.trace('Consumed event %o %o', event, bridgeEvents[i]) @@ -293,7 +291,7 @@ async function loop() { activeEpoch = true epochTimeIntervalsQueue.send({ blockNumber: curBlockNumber, - startTime: curBlockTimestamp * 1000, + startTime: await retry(() => getBlockTimestamp(curBlockNumber)) * 1000, epoch }) epochTimeUpdated = true @@ -304,7 +302,7 @@ async function loop() { activeEpoch = false epochTimeIntervalsQueue.send({ blockNumber: curBlockNumber, - prolongedTime: curBlockTimestamp * 1000, + prolongedTime: await retry(() => getBlockTimestamp(curBlockNumber)) * 1000, epoch }) break @@ -314,10 +312,10 @@ async function loop() { i += 1 } - if (!epochTimeUpdated && epoch > 0 && activeEpoch) { + if (curBlockNumber === endBlock && !epochTimeUpdated && epoch > 0 && activeEpoch) { epochTimeIntervalsQueue.send({ blockNumber: curBlockNumber, - prolongedTime: curBlockTimestamp * 1000, + prolongedTime: await retry(() => getBlockTimestamp(curBlockNumber)) * 1000, epoch }) } @@ -334,7 +332,7 @@ async function loop() { blockNumber = endBlock + 1 // Exec redis tx - await redisTx.set('homeBlock', blockNumber).exec() + await redisTx.set('homeBlock', endBlock).exec() await redis.save() }