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;
|
const timeAvgMins = blocksInEpoch ? diff / blocksInEpoch / 60 : 10;
|
||||||
|
|
||||||
let timeAvgMins = 10;
|
|
||||||
if (timeAvgDiff > 0) {
|
|
||||||
timeAvgMins -= Math.abs(timeAvgDiff);
|
|
||||||
} else {
|
|
||||||
timeAvgMins += Math.abs(timeAvgDiff);
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeAvg = timeAvgMins.toFixed(0);
|
const timeAvg = timeAvgMins.toFixed(0);
|
||||||
const remainingTime = (remainingBlocks * timeAvgMins * 60 * 1000) + (now * 1000);
|
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>
|
<app-time-until [time]="(1 * i) + now + 61000" [fastRender]="false" [fixedRender]="true"></app-time-until>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template #timeDiffMainnet>
|
<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>
|
</ng-template>
|
||||||
</div>
|
</div>
|
||||||
<ng-template #mergedBlock>
|
<ng-template #mergedBlock>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy {
|
|||||||
networkSubscription: Subscription;
|
networkSubscription: Subscription;
|
||||||
network = '';
|
network = '';
|
||||||
now = new Date().getTime();
|
now = new Date().getTime();
|
||||||
|
lastBlockTime: number;
|
||||||
showMiningInfo = false;
|
showMiningInfo = false;
|
||||||
|
|
||||||
blockWidth = 125;
|
blockWidth = 125;
|
||||||
@@ -129,24 +130,22 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy {
|
|||||||
this.stateService.lastDifficultyAdjustment$
|
this.stateService.lastDifficultyAdjustment$
|
||||||
])),
|
])),
|
||||||
map(([block, DATime]) => {
|
map(([block, DATime]) => {
|
||||||
|
this.lastBlockTime = block.timestamp * 1000;
|
||||||
|
|
||||||
this.now = new Date().getTime();
|
this.now = new Date().getTime();
|
||||||
const now = new Date().getTime() / 1000;
|
const now = new Date().getTime() / 1000;
|
||||||
const diff = now - DATime;
|
const diff = now - DATime;
|
||||||
const blocksInEpoch = block.height % 2016;
|
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;
|
let timeAvg = blocksInEpoch ? diff / blocksInEpoch : 600;
|
||||||
if (timeAvgDiff > 0 ){
|
|
||||||
timeAvgMins -= Math.abs(timeAvgDiff);
|
// testnet difficulty is set to 1 after 20 minutes of no blockSize
|
||||||
} else {
|
// therefore the time between blocks will always be below 20 minutes (1200s)
|
||||||
timeAvgMins += Math.abs(timeAvgDiff);
|
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