Lisk Release Height Calculator
const moment = require('moment-timezone');
const request = require('request')
const rp = require('request-promise');
const approxMissedBlocksPerRound = 22;
const currentHeight = JSON.parse(await rp('https://testnet-service.lisk.com/api/v2/network/status')).data.height;
const currentTime = moment.tz("Europe/Berlin");
const calculateBlockByTime = (time) => {
const expectedTimeOfRelease = moment.tz(time, "Europe/Berlin");
const secondsRemaining = expectedTimeOfRelease.diff(currentTime, 'seconds');
const expectedBlocksRemaining = Math.floor(secondsRemaining / 10);
const expectedMissedBlocks = Math.floor(expectedBlocksRemaining / 103 * approxMissedBlocksPerRound);
const expectedBlockHeight = currentHeight + (expectedBlocksRemaining - expectedMissedBlocks);
const actualBlocksRemaining = expectedBlockHeight - currentHeight;
const expectedRound = Math.ceil(expectedBlockHeight / 103);
const expectedLastBlock = expectedRound * 103;
const reverseTimeCalculation = currentTime.add((expectedLastBlock - currentHeight + expectedMissedBlocks) * 10, 'seconds');
console.log({
currentHeight,
expectedBlockHeight,
expectedBlocksRemaining,
expectedMissedBlocks,
actualBlocksRemaining,
expectedTimeOfRelease: expectedTimeOfRelease.format(),
reverseTimeCalculation: reverseTimeCalculation.format(),
expectedRound,
expectedLastBlock
})
};
const calculateTimeByBlock = (blockHeight) => {
const blocksRemaining = blockHeight - currentHeight;
const expectedMissedBlocks = blocksRemaining / 103 * approxMissedBlocksPerRound;
const timeRemaining = (blocksRemaining + expectedMissedBlocks) * 10;
const expectedTime = currentTime.add(timeRemaining, 'seconds');
console.log(`Appx Time: ${expectedTime.format()}`);
}
calculateBlockByTime("2022-01-20 10:00:00")
// calculateTimeByBlock(15480866)
no comments