fix and improve block time predictions
This commit is contained in:
@@ -66,14 +66,7 @@ export class DifficultyComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
const timeAvgDiff = change * 0.1;
|
||||
|
||||
let timeAvgMins = 10;
|
||||
if (timeAvgDiff > 0) {
|
||||
timeAvgMins -= Math.abs(timeAvgDiff);
|
||||
} else {
|
||||
timeAvgMins += Math.abs(timeAvgDiff);
|
||||
}
|
||||
const timeAvgMins = blocksInEpoch ? diff / blocksInEpoch / 60 : 10;
|
||||
|
||||
const timeAvg = timeAvgMins.toFixed(0);
|
||||
const remainingTime = (remainingBlocks * timeAvgMins * 60 * 1000) + (now * 1000);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<app-time-until [time]="(1 * i) + now + 61000" [fastRender]="false" [fixedRender]="true"></app-time-until>
|
||||
</ng-template>
|
||||
<ng-template #timeDiffMainnet>
|
||||
<app-time-until [time]="(timeAvg * i) + now + timeAvg" [fastRender]="false" [fixedRender]="true" [forceFloorOnTimeIntervals]="['hour']"></app-time-until>
|
||||
<app-time-until [time]="(timeAvg * i) + lastBlockTime + timeAvg" [fastRender]="false" [fixedRender]="true" [forceFloorOnTimeIntervals]="['hour']"></app-time-until>
|
||||
</ng-template>
|
||||
</div>
|
||||
<ng-template #mergedBlock>
|
||||
|
||||
@@ -33,6 +33,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy {
|
||||
networkSubscription: Subscription;
|
||||
network = '';
|
||||
now = new Date().getTime();
|
||||
lastBlockTime: number;
|
||||
showMiningInfo = false;
|
||||
|
||||
blockWidth = 125;
|
||||
@@ -129,24 +130,22 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy {
|
||||
this.stateService.lastDifficultyAdjustment$
|
||||
])),
|
||||
map(([block, DATime]) => {
|
||||
this.lastBlockTime = block.timestamp * 1000;
|
||||
|
||||
this.now = new Date().getTime();
|
||||
const now = new Date().getTime() / 1000;
|
||||
const diff = now - DATime;
|
||||
const blocksInEpoch = block.height % 2016;
|
||||
let difficultyChange = 0;
|
||||
if (blocksInEpoch > 0) {
|
||||
difficultyChange = (600 / (diff / blocksInEpoch ) - 1) * 100;
|
||||
}
|
||||
const timeAvgDiff = difficultyChange * 0.1;
|
||||
|
||||
let timeAvgMins = 10;
|
||||
if (timeAvgDiff > 0 ){
|
||||
timeAvgMins -= Math.abs(timeAvgDiff);
|
||||
} else {
|
||||
timeAvgMins += Math.abs(timeAvgDiff);
|
||||
let timeAvg = blocksInEpoch ? diff / blocksInEpoch : 600;
|
||||
|
||||
// testnet difficulty is set to 1 after 20 minutes of no blockSize
|
||||
// therefore the time between blocks will always be below 20 minutes (1200s)
|
||||
if (this.stateService.network === 'testnet' && now - block.timestamp + timeAvg > 1200) {
|
||||
timeAvg = 1200;
|
||||
}
|
||||
|
||||
return timeAvgMins * 60 * 1000;
|
||||
return timeAvg * 1000;
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user