mirror of
https://github.com/mempool/mempool.git
synced 2025-04-22 14:34:47 +02:00
Added indexing progress indicator for hashrates, update logging
This commit is contained in:
parent
802e10e0a9
commit
de7c4774ec
@ -224,7 +224,7 @@ class Blocks {
|
||||
loadingIndicators.setProgress('block-indexing', 0);
|
||||
|
||||
const chunkSize = 10000;
|
||||
let totaIndexed = await blocksRepository.$blockCountBetweenHeight(currentBlockHeight, lastBlockToIndex);
|
||||
let totalIndexed = await blocksRepository.$blockCountBetweenHeight(currentBlockHeight, lastBlockToIndex);
|
||||
let indexedThisRun = 0;
|
||||
let newlyIndexed = 0;
|
||||
const startedAt = new Date().getTime() / 1000;
|
||||
@ -247,17 +247,17 @@ class Blocks {
|
||||
break;
|
||||
}
|
||||
++indexedThisRun;
|
||||
++totaIndexed;
|
||||
++totalIndexed;
|
||||
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - timer));
|
||||
if (elapsedSeconds > 5 || blockHeight === lastBlockToIndex) {
|
||||
const runningFor = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt));
|
||||
const blockPerSeconds = Math.max(1, Math.round(indexedThisRun / elapsedSeconds));
|
||||
const progress = Math.round(totaIndexed / indexingBlockAmount * 100);
|
||||
const timeLeft = Math.round((indexingBlockAmount - totaIndexed) / blockPerSeconds);
|
||||
logger.debug(`Indexing block #${blockHeight} | ~${blockPerSeconds} blocks/sec | total: ${totaIndexed}/${indexingBlockAmount} (${progress}%) | elapsed: ${runningFor} seconds | left: ~${timeLeft} seconds`);
|
||||
const progress = Math.round(totalIndexed / indexingBlockAmount * 10000) / 100;
|
||||
const timeLeft = Math.round((indexingBlockAmount - totalIndexed) / blockPerSeconds);
|
||||
logger.debug(`Indexing block #${blockHeight} | ~${blockPerSeconds.toFixed(2)} blocks/sec | total: ${totalIndexed}/${indexingBlockAmount} (${progress}%) | elapsed: ${runningFor} seconds | left: ~${timeLeft} seconds`);
|
||||
timer = new Date().getTime() / 1000;
|
||||
indexedThisRun = 0;
|
||||
loadingIndicators.setProgress('block-indexing', progress);
|
||||
loadingIndicators.setProgress('block-indexing', progress, false);
|
||||
}
|
||||
const blockHash = await bitcoinApi.$getBlockHash(blockHeight);
|
||||
const block = BitcoinApi.convertBlock(await bitcoinClient.getBlock(blockHash));
|
||||
|
@ -12,8 +12,8 @@ class LoadingIndicators {
|
||||
this.progressChangedCallback = fn;
|
||||
}
|
||||
|
||||
public setProgress(name: string, progressPercent: number) {
|
||||
const newProgress = Math.round(progressPercent);
|
||||
public setProgress(name: string, progressPercent: number, rounded: boolean = true) {
|
||||
const newProgress = rounded === true ? Math.round(progressPercent) : progressPercent;
|
||||
if (newProgress >= 100) {
|
||||
delete this.loadingIndicators[name];
|
||||
} else {
|
||||
|
@ -6,6 +6,7 @@ import bitcoinClient from './bitcoin/bitcoin-client';
|
||||
import logger from '../logger';
|
||||
import blocks from './blocks';
|
||||
import { Common } from './common';
|
||||
import loadingIndicators from './loading-indicators';
|
||||
|
||||
class Mining {
|
||||
hashrateIndexingStarted = false;
|
||||
@ -131,7 +132,7 @@ class Mining {
|
||||
* [INDEXING] Generate weekly mining pool hashrate history
|
||||
*/
|
||||
public async $generatePoolHashrateHistory(): Promise<void> {
|
||||
if (!blocks.blockIndexingCompleted || this.weeklyHashrateIndexingStarted) {
|
||||
if (!blocks.blockIndexingCompleted || this.hashrateIndexingStarted || this.weeklyHashrateIndexingStarted) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -167,7 +168,10 @@ class Mining {
|
||||
let indexedThisRun = 0;
|
||||
let totalIndexed = 0;
|
||||
let newlyIndexed = 0;
|
||||
let startedAt = new Date().getTime();
|
||||
const startedAt = new Date().getTime() / 1000;
|
||||
let timer = new Date().getTime() / 1000;
|
||||
|
||||
loadingIndicators.setProgress('weekly-hashrate-indexing', 0);
|
||||
|
||||
while (toTimestamp > genesisTimestamp) {
|
||||
const fromTimestamp = toTimestamp - 604800000;
|
||||
@ -214,14 +218,17 @@ class Mining {
|
||||
await HashratesRepository.$saveHashrates(hashrates);
|
||||
hashrates.length = 0;
|
||||
|
||||
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime()) - startedAt)) / 1000;
|
||||
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - timer));
|
||||
if (elapsedSeconds > 1) {
|
||||
const weeksPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2);
|
||||
const runningFor = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt));
|
||||
const weeksPerSeconds = Math.max(1, Math.round(indexedThisRun / elapsedSeconds));
|
||||
const progress = Math.round(totalIndexed / totalWeekIndexed * 10000) / 100;
|
||||
const timeLeft = Math.round((totalWeekIndexed - totalIndexed) / weeksPerSeconds);
|
||||
const formattedDate = new Date(fromTimestamp).toUTCString();
|
||||
const weeksLeft = Math.round(totalWeekIndexed - totalIndexed);
|
||||
logger.debug(`Getting weekly pool hashrate for ${formattedDate} | ~${weeksPerSeconds} weeks/sec | ~${weeksLeft} weeks left to index`);
|
||||
startedAt = new Date().getTime();
|
||||
logger.debug(`Getting weekly pool hashrate for ${formattedDate} | ~${weeksPerSeconds.toFixed(2)} weeks/sec | total: ~${totalIndexed}/${Math.round(totalWeekIndexed)} (${progress}%) | elapsed: ${runningFor} seconds | left: ~${timeLeft} seconds`);
|
||||
timer = new Date().getTime() / 1000;
|
||||
indexedThisRun = 0;
|
||||
loadingIndicators.setProgress('weekly-hashrate-indexing', progress, false);
|
||||
}
|
||||
|
||||
toTimestamp -= 604800000;
|
||||
@ -233,7 +240,9 @@ class Mining {
|
||||
if (newlyIndexed > 0) {
|
||||
logger.info(`Indexed ${newlyIndexed} pools weekly hashrate`);
|
||||
}
|
||||
loadingIndicators.setProgress('weekly-hashrate-indexing', 100);
|
||||
} catch (e) {
|
||||
loadingIndicators.setProgress('weekly-hashrate-indexing', 100);
|
||||
this.weeklyHashrateIndexingStarted = false;
|
||||
throw e;
|
||||
}
|
||||
@ -273,7 +282,10 @@ class Mining {
|
||||
let indexedThisRun = 0;
|
||||
let totalIndexed = 0;
|
||||
let newlyIndexed = 0;
|
||||
let startedAt = new Date().getTime();
|
||||
const startedAt = new Date().getTime() / 1000;
|
||||
let timer = new Date().getTime() / 1000;
|
||||
|
||||
loadingIndicators.setProgress('daily-hashrate-indexing', 0);
|
||||
|
||||
while (toTimestamp > genesisTimestamp) {
|
||||
const fromTimestamp = toTimestamp - 86400000;
|
||||
@ -312,15 +324,17 @@ class Mining {
|
||||
hashrates.length = 0;
|
||||
}
|
||||
|
||||
const elapsedSeconds = Math.max(1, Math.round(new Date().getTime() - startedAt)) / 1000;
|
||||
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - timer));
|
||||
if (elapsedSeconds > 1) {
|
||||
const daysPerSeconds = (indexedThisRun / elapsedSeconds).toFixed(2);
|
||||
const runningFor = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt));
|
||||
const daysPerSeconds = Math.max(1, Math.round(indexedThisRun / elapsedSeconds));
|
||||
const progress = Math.round(totalIndexed / totalDayIndexed * 10000) / 100;
|
||||
const timeLeft = Math.round((totalDayIndexed - totalIndexed) / daysPerSeconds);
|
||||
const formattedDate = new Date(fromTimestamp).toUTCString();
|
||||
const daysLeft = Math.round(totalDayIndexed - totalIndexed);
|
||||
logger.debug(`Getting network daily hashrate for ${formattedDate} | ~${daysPerSeconds} days/sec | ` +
|
||||
`~${daysLeft} days left to index`);
|
||||
startedAt = new Date().getTime();
|
||||
logger.debug(`Getting network daily hashrate for ${formattedDate} | ~${daysPerSeconds.toFixed(2)} days/sec | total: ~${totalIndexed}/${Math.round(totalDayIndexed)} (${progress}%) | elapsed: ${runningFor} seconds | left: ~${timeLeft} seconds`);
|
||||
timer = new Date().getTime() / 1000;
|
||||
indexedThisRun = 0;
|
||||
loadingIndicators.setProgress('daily-hashrate-indexing', progress);
|
||||
}
|
||||
|
||||
toTimestamp -= 86400000;
|
||||
@ -346,7 +360,9 @@ class Mining {
|
||||
if (newlyIndexed > 0) {
|
||||
logger.info(`Indexed ${newlyIndexed} day of network hashrate`);
|
||||
}
|
||||
loadingIndicators.setProgress('daily-hashrate-indexing', 100);
|
||||
} catch (e) {
|
||||
loadingIndicators.setProgress('daily-hashrate-indexing', 100);
|
||||
this.hashrateIndexingStarted = false;
|
||||
throw e;
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ import { BlockFeesGraphComponent } from './components/block-fees-graph/block-fee
|
||||
import { BlockRewardsGraphComponent } from './components/block-rewards-graph/block-rewards-graph.component';
|
||||
import { BlockFeeRatesGraphComponent } from './components/block-fee-rates-graph/block-fee-rates-graph.component';
|
||||
import { LoadingIndicatorComponent } from './components/loading-indicator/loading-indicator.component';
|
||||
import { IndexingProgressComponent } from './components/indexing-progress/indexing-progress.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@ -134,6 +135,7 @@ import { LoadingIndicatorComponent } from './components/loading-indicator/loadin
|
||||
BlockRewardsGraphComponent,
|
||||
BlockFeeRatesGraphComponent,
|
||||
LoadingIndicatorComponent,
|
||||
IndexingProgressComponent,
|
||||
],
|
||||
imports: [
|
||||
BrowserModule.withServerTransition({ appId: 'serverApp' }),
|
||||
|
@ -1,4 +1,4 @@
|
||||
<app-loading-indicator [name]="'block-indexing'"></app-loading-indicator>
|
||||
<app-indexing-progress></app-indexing-progress>
|
||||
|
||||
<div class="full-container">
|
||||
<div class="card-header mb-0 mb-md-4">
|
||||
|
@ -1,4 +1,4 @@
|
||||
<app-loading-indicator [name]="'block-indexing'"></app-loading-indicator>
|
||||
<app-indexing-progress></app-indexing-progress>
|
||||
|
||||
<div class="full-container">
|
||||
<div class="card-header mb-0 mb-md-4">
|
||||
|
@ -1,4 +1,4 @@
|
||||
<app-loading-indicator [name]="'block-indexing'"></app-loading-indicator>
|
||||
<app-indexing-progress></app-indexing-progress>
|
||||
|
||||
<div class="full-container">
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<app-loading-indicator [name]="'block-indexing'"></app-loading-indicator>
|
||||
<app-indexing-progress></app-indexing-progress>
|
||||
|
||||
<div class="container-xl" [class]="widget ? 'widget' : 'full-height'">
|
||||
<h1 *ngIf="!widget" class="float-left" i18n="latest-blocks.blocks">Blocks</h1>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<app-loading-indicator [name]="'block-indexing'"></app-loading-indicator>
|
||||
<app-indexing-progress></app-indexing-progress>
|
||||
|
||||
<div [class]="widget === false ? 'full-container' : ''">
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<app-loading-indicator [name]="'block-indexing'"></app-loading-indicator>
|
||||
<app-indexing-progress></app-indexing-progress>
|
||||
|
||||
<div class="full-container">
|
||||
|
||||
|
@ -0,0 +1,3 @@
|
||||
<app-loading-indicator [name]="'block-indexing'" [label]="'Indexing blocks'"></app-loading-indicator>
|
||||
<app-loading-indicator [name]="'daily-hashrate-indexing'" [label]="'Indexing network hashrate'"></app-loading-indicator>
|
||||
<app-loading-indicator [name]="'weekly-hashrate-indexing'" [label]="'Indexing pools hashrate'"></app-loading-indicator>
|
@ -0,0 +1,14 @@
|
||||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-indexing-progress',
|
||||
templateUrl: './indexing-progress.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class IndexingProgressComponent implements OnInit {
|
||||
constructor(
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
<div *ngIf="this.indexingProgress$ | async as progress" class="sticky-loading">
|
||||
<span *ngIf="progress >= 0" class="mr-auto badge badge-pill badge-warning">Indexing blocks ({{ progress }}%)</span>
|
||||
<span *ngIf="progress >= 0" class="mr-auto badge badge-pill badge-warning">{{ this.label }} ({{ progress }}%)</span>
|
||||
</div>
|
@ -1,14 +1,18 @@
|
||||
.sticky-loading {
|
||||
position: fixed;
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
z-index: 100;
|
||||
@media (width > 991px) {
|
||||
bottom: 15px;
|
||||
font-size: 14px;
|
||||
@media (width >= 992px) {
|
||||
left: 32px;
|
||||
top: 55px;
|
||||
}
|
||||
@media (576px <= width <= 991px) {
|
||||
bottom: 60px;
|
||||
@media (576px <= width < 992px ) {
|
||||
left: 18px;
|
||||
top: 55px;
|
||||
}
|
||||
@media (width <= 575px) {
|
||||
top: 17px;
|
||||
left: 18px;
|
||||
top: 100px;
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ import { WebsocketService } from 'src/app/services/websocket.service';
|
||||
})
|
||||
export class LoadingIndicatorComponent implements OnInit {
|
||||
@Input() name: string;
|
||||
@Input() label: string;
|
||||
|
||||
public indexingProgress$: Observable<number>;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<app-loading-indicator [name]="'block-indexing'"></app-loading-indicator>
|
||||
<app-indexing-progress></app-indexing-progress>
|
||||
|
||||
<div class="container-xl dashboard-container">
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<app-loading-indicator [name]="'block-indexing'"></app-loading-indicator>
|
||||
<app-indexing-progress></app-indexing-progress>
|
||||
|
||||
<div [class]="widget === false ? 'full-container' : ''">
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<app-loading-indicator [name]="'block-indexing'"></app-loading-indicator>
|
||||
<app-indexing-progress></app-indexing-progress>
|
||||
|
||||
<div class="container-xl">
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user