improve testnet block time estimations

This commit is contained in:
Antoni Spaanderman 2022-03-09 17:38:37 +01:00
parent 211e5ab3fe
commit 2be18fe179
No known key found for this signature in database
GPG Key ID: AE0B68E552E5DF8C
2 changed files with 11 additions and 1 deletions

View File

@ -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) + now + timeAvg + timeOffset" [fastRender]="false" [fixedRender]="true" [forceFloorOnTimeIntervals]="['hour']"></app-time-until>
</ng-template>
</div>
<ng-template #mergedBlock>

View File

@ -33,6 +33,7 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy {
networkSubscription: Subscription;
network = '';
now = new Date().getTime();
timeOffset = 0;
showMiningInfo = false;
blockWidth = 125;
@ -146,6 +147,15 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy {
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)
if (this.stateService.network === 'testnet' && now - block.timestamp + timeAvgMins * 60 > 1200) {
this.timeOffset = -Math.min(now - block.timestamp, 1200) * 1000;
timeAvgMins = 20;
} else {
this.timeOffset = 0;
}
return timeAvgMins * 60 * 1000;
})
);