improve testnet block time estimations
This commit is contained in:
		
							parent
							
								
									211e5ab3fe
								
							
						
					
					
						commit
						2be18fe179
					
				| @ -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) + now + timeAvg + timeOffset" [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(); | ||||||
|  |   timeOffset = 0; | ||||||
|   showMiningInfo = false; |   showMiningInfo = false; | ||||||
| 
 | 
 | ||||||
|   blockWidth = 125; |   blockWidth = 125; | ||||||
| @ -146,6 +147,15 @@ export class MempoolBlocksComponent implements OnInit, OnDestroy { | |||||||
|             timeAvgMins += Math.abs(timeAvgDiff); |             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; |           return timeAvgMins * 60 * 1000; | ||||||
|         }) |         }) | ||||||
|       ); |       ); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user