Minimized number of eth block timestamp requests
This commit is contained in:
parent
7f6030ee94
commit
1de3b2d75a
|
@ -24,4 +24,4 @@ VOTES_PROXY_PORT=5001
|
||||||
|
|
||||||
SIGN_RESTART_PORT=6001
|
SIGN_RESTART_PORT=6001
|
||||||
|
|
||||||
LOG_LEVEL=trace
|
LOG_LEVEL=info
|
||||||
|
|
|
@ -79,6 +79,7 @@ async function fetchTimeIntervalsQueue() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
const data = JSON.parse(msg.content)
|
const data = JSON.parse(msg.content)
|
||||||
|
let accept = false
|
||||||
logger.trace('Consumed time interval event %o', data)
|
logger.trace('Consumed time interval event %o', data)
|
||||||
if (epoch !== null && epoch !== data.epoch) {
|
if (epoch !== null && epoch !== data.epoch) {
|
||||||
logger.warn('Two consequently events have different epochs, should not be like this')
|
logger.warn('Two consequently events have different epochs, should not be like this')
|
||||||
|
@ -92,25 +93,15 @@ async function fetchTimeIntervalsQueue() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if (epoch === null) {
|
if (epoch === null) {
|
||||||
|
accept = true
|
||||||
epoch = data.epoch
|
epoch = data.epoch
|
||||||
startTime = await redis.get(`foreignTime${epoch}`)
|
startTime = await redis.get(`foreignTime${epoch}`)
|
||||||
logger.trace(`Retrieved epoch ${epoch} and start time ${startTime} from redis`)
|
logger.trace(`Retrieved epoch ${epoch} and start time ${startTime} from redis`)
|
||||||
if (startTime === null) {
|
if (startTime === null) {
|
||||||
logger.warn(`Empty foreign time for epoch ${epoch}`)
|
logger.warn(`Empty foreign time for epoch ${epoch}`)
|
||||||
}
|
}
|
||||||
} /*
|
}
|
||||||
if (data.endTime) {
|
if ((data.prolongedTime - startTime < FOREIGN_FETCH_MAX_TIME_INTERVAL || accept)
|
||||||
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
|
|
||||||
&& data.prolongedTime < lastBncBlockTime) {
|
&& data.prolongedTime < lastBncBlockTime) {
|
||||||
endTime = data.prolongedTime
|
endTime = data.prolongedTime
|
||||||
channel.ack(msg)
|
channel.ack(msg)
|
||||||
|
|
|
@ -225,8 +225,7 @@ async function initialize() {
|
||||||
rangeSize = (await bridge.getRangeSize()).toNumber()
|
rangeSize = (await bridge.getRangeSize()).toNumber()
|
||||||
logger.debug(`Range size ${rangeSize}`)
|
logger.debug(`Range size ${rangeSize}`)
|
||||||
logger.debug('Checking if current validator')
|
logger.debug('Checking if current validator')
|
||||||
isCurrentValidator = (await bridge.getValidators())
|
isCurrentValidator = (await bridge.getValidators()).includes(validatorAddress)
|
||||||
.includes(validatorAddress)
|
|
||||||
if (isCurrentValidator) {
|
if (isCurrentValidator) {
|
||||||
logger.info(`${validatorAddress} is a current validator`)
|
logger.info(`${validatorAddress} is a current validator`)
|
||||||
} else {
|
} else {
|
||||||
|
@ -266,7 +265,6 @@ async function loop() {
|
||||||
|
|
||||||
for (let curBlockNumber = blockNumber, i = 0; curBlockNumber <= endBlock; curBlockNumber += 1) {
|
for (let curBlockNumber = blockNumber, i = 0; curBlockNumber <= endBlock; curBlockNumber += 1) {
|
||||||
let epochTimeUpdated = false
|
let epochTimeUpdated = false
|
||||||
const curBlockTimestamp = await retry(() => getBlockTimestamp(curBlockNumber))
|
|
||||||
while (i < bridgeEvents.length && bridgeEvents[i].blockNumber === curBlockNumber) {
|
while (i < bridgeEvents.length && bridgeEvents[i].blockNumber === curBlockNumber) {
|
||||||
const event = bridge.interface.parseLog(bridgeEvents[i])
|
const event = bridge.interface.parseLog(bridgeEvents[i])
|
||||||
logger.trace('Consumed event %o %o', event, bridgeEvents[i])
|
logger.trace('Consumed event %o %o', event, bridgeEvents[i])
|
||||||
|
@ -293,7 +291,7 @@ async function loop() {
|
||||||
activeEpoch = true
|
activeEpoch = true
|
||||||
epochTimeIntervalsQueue.send({
|
epochTimeIntervalsQueue.send({
|
||||||
blockNumber: curBlockNumber,
|
blockNumber: curBlockNumber,
|
||||||
startTime: curBlockTimestamp * 1000,
|
startTime: await retry(() => getBlockTimestamp(curBlockNumber)) * 1000,
|
||||||
epoch
|
epoch
|
||||||
})
|
})
|
||||||
epochTimeUpdated = true
|
epochTimeUpdated = true
|
||||||
|
@ -304,7 +302,7 @@ async function loop() {
|
||||||
activeEpoch = false
|
activeEpoch = false
|
||||||
epochTimeIntervalsQueue.send({
|
epochTimeIntervalsQueue.send({
|
||||||
blockNumber: curBlockNumber,
|
blockNumber: curBlockNumber,
|
||||||
prolongedTime: curBlockTimestamp * 1000,
|
prolongedTime: await retry(() => getBlockTimestamp(curBlockNumber)) * 1000,
|
||||||
epoch
|
epoch
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
|
@ -314,10 +312,10 @@ async function loop() {
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!epochTimeUpdated && epoch > 0 && activeEpoch) {
|
if (curBlockNumber === endBlock && !epochTimeUpdated && epoch > 0 && activeEpoch) {
|
||||||
epochTimeIntervalsQueue.send({
|
epochTimeIntervalsQueue.send({
|
||||||
blockNumber: curBlockNumber,
|
blockNumber: curBlockNumber,
|
||||||
prolongedTime: curBlockTimestamp * 1000,
|
prolongedTime: await retry(() => getBlockTimestamp(curBlockNumber)) * 1000,
|
||||||
epoch
|
epoch
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -334,7 +332,7 @@ async function loop() {
|
||||||
|
|
||||||
blockNumber = endBlock + 1
|
blockNumber = endBlock + 1
|
||||||
// Exec redis tx
|
// Exec redis tx
|
||||||
await redisTx.set('homeBlock', blockNumber).exec()
|
await redisTx.set('homeBlock', endBlock).exec()
|
||||||
await redis.save()
|
await redis.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue