mirror of
https://github.com/mempool/mempool.git
synced 2025-01-03 20:24:28 +01:00
Merge pull request #1373 from antonilol/difficulty
fix and improve block time predictions
This commit is contained in:
commit
b781b3b065
@ -32,23 +32,19 @@ class DifficultyAdjustmentApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeAvgDiff = difficultyChange * 0.1;
|
let timeAvgMins = blocksInEpoch ? diff / blocksInEpoch / 60 : 10;
|
||||||
|
|
||||||
let timeAvgMins = 10;
|
// Testnet difficulty is set to 1 after 20 minutes of no blocks,
|
||||||
|
|
||||||
if (timeAvgDiff > 0) {
|
|
||||||
timeAvgMins -= Math.abs(timeAvgDiff);
|
|
||||||
} else {
|
|
||||||
timeAvgMins += Math.abs(timeAvgDiff);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Testnet difficulty is set to 1 after 20 minutes of no blockSize,
|
|
||||||
// therefore the time between blocks will always be below 20 minutes (1200s).
|
// therefore the time between blocks will always be below 20 minutes (1200s).
|
||||||
let timeOffset = 0;
|
let timeOffset = 0;
|
||||||
if (config.MEMPOOL.NETWORK === 'testnet' && now - latestBlock.timestamp + timeAvgMins * 60 > 1200) {
|
if (config.MEMPOOL.NETWORK === 'testnet') {
|
||||||
timeOffset = -Math.min(now - latestBlock.timestamp, 1200) * 1000;
|
if (timeAvgMins > 20) {
|
||||||
timeAvgMins = 20;
|
timeAvgMins = 20;
|
||||||
}
|
}
|
||||||
|
if (now - latestBlock.timestamp + timeAvgMins * 60 > 1200) {
|
||||||
|
timeOffset = -Math.min(now - latestBlock.timestamp, 1200) * 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const timeAvg = timeAvgMins * 60 * 1000 ;
|
const timeAvg = timeAvgMins * 60 * 1000 ;
|
||||||
const remainingTime = (remainingBlocks * timeAvg) + (now * 1000);
|
const remainingTime = (remainingBlocks * timeAvg) + (now * 1000);
|
||||||
|
Loading…
Reference in New Issue
Block a user