From cd8e30887001517ed114a5ee337190ffe8fc08ab Mon Sep 17 00:00:00 2001 From: Miguel Medeiros Date: Sat, 24 Jul 2021 19:26:48 -0300 Subject: [PATCH] Add previous adjustment retarget. (#655) * Add previous adjustment retarget. * Fix green color. Add + symbol to difficulty change. * Add previousRetarget to websocket. * Add previous retarget. --- .../src/app/dashboard/dashboard.component.html | 4 ++-- .../src/app/dashboard/dashboard.component.ts | 18 +++++++----------- .../src/app/interfaces/node-api.interface.ts | 9 +++++++++ frontend/src/app/services/api.service.ts | 6 +++++- frontend/src/app/services/state.service.ts | 1 + frontend/src/app/services/websocket.service.ts | 6 +++++- 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/dashboard/dashboard.component.html b/frontend/src/app/dashboard/dashboard.component.html index f98779fda..30d6a3f89 100644 --- a/frontend/src/app/dashboard/dashboard.component.html +++ b/frontend/src/app/dashboard/dashboard.component.html @@ -215,8 +215,8 @@
Estimate
-
{{ epochData.change | number: '1.2-2' }} %
-
~{{ epochData.timeAvg }} mins per block
+
{{epochData.change > 0 ? '+' : ''}}{{ epochData.change | number: '1.2-2' }} %
+
Previous: {{epochData.previousRetarget > 0 ? '+' : ''}}{{ epochData.previousRetarget | number: '1.2-2' }} %
Current Period
diff --git a/frontend/src/app/dashboard/dashboard.component.ts b/frontend/src/app/dashboard/dashboard.component.ts index 92fadecbf..dd9890a6b 100644 --- a/frontend/src/app/dashboard/dashboard.component.ts +++ b/frontend/src/app/dashboard/dashboard.component.ts @@ -19,8 +19,6 @@ interface MempoolBlocksData { interface EpochProgress { base: string; - green: string; - red: string; change: number; progress: string; remainingBlocks: number; @@ -28,6 +26,7 @@ interface EpochProgress { colorAdjustments: string; timeAvg: string; remainingTime: number; + previousRetarget: number; } interface MempoolInfoData { @@ -118,9 +117,10 @@ export class DashboardComponent implements OnInit { .pipe( switchMap(() => combineLatest([ this.stateService.blocks$.pipe(map(([block]) => block)), - this.stateService.lastDifficultyAdjustment$ + this.stateService.lastDifficultyAdjustment$, + this.stateService.previousRetarget$ ])), - map(([block, DATime]) => { + map(([block, DATime, previousRetarget]) => { const now = new Date().getTime() / 1000; const diff = now - DATime; const blocksInEpoch = block.height % 2016; @@ -131,15 +131,11 @@ export class DashboardComponent implements OnInit { } let base = 0; - let green = 0; - let red = 0; if (blocksInEpoch >= estimatedBlocks) { base = estimatedBlocks / 2016 * 100; - green = (blocksInEpoch - estimatedBlocks) / 2016 * 100; } else { base = blocksInEpoch / 2016 * 100; - red = Math.min((estimatedBlocks - blocksInEpoch) / 2016 * 100, 100 - base); } let colorAdjustments = '#dc3545'; @@ -162,8 +158,6 @@ export class DashboardComponent implements OnInit { return { base: base + '%', - green: green + '%', - red: red + '%', change: difficultyChange, progress: base.toFixed(2), remainingBlocks, @@ -171,11 +165,13 @@ export class DashboardComponent implements OnInit { colorAdjustments, blocksInEpoch, newDifficultyHeight: block.height + remainingBlocks, - remainingTime: remainingBlocsMilliseconds + nowMilliseconds + remainingTime: remainingBlocsMilliseconds + nowMilliseconds, + previousRetarget }; }) ); + this.mempoolBlocksData$ = this.stateService.mempoolBlocks$ .pipe( map((mempoolBlocks) => { diff --git a/frontend/src/app/interfaces/node-api.interface.ts b/frontend/src/app/interfaces/node-api.interface.ts index 24e6bf35d..190aa08ab 100644 --- a/frontend/src/app/interfaces/node-api.interface.ts +++ b/frontend/src/app/interfaces/node-api.interface.ts @@ -25,3 +25,12 @@ export interface CpfpInfo { ancestors: Ancestor[]; bestDescendant: BestDescendant | null; } + +export interface DifficultyAdjustment { + difficultyChange: number; + estimatedRetargetDate: number; + previousRetarget: number; + progressPercent: number; + remainingBlocks: number; + remainingTime: number; +} diff --git a/frontend/src/app/services/api.service.ts b/frontend/src/app/services/api.service.ts index 32ff8b092..0c543e786 100644 --- a/frontend/src/app/services/api.service.ts +++ b/frontend/src/app/services/api.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; -import { CpfpInfo, OptimizedMempoolStats } from '../interfaces/node-api.interface'; +import { CpfpInfo, OptimizedMempoolStats, DifficultyAdjustment } from '../interfaces/node-api.interface'; import { Observable } from 'rxjs'; import { StateService } from './state.service'; import { WebsocketResponse } from '../interfaces/websocket.interface'; @@ -92,4 +92,8 @@ export class ApiService { getCpfpinfo$(txid: string): Observable { return this.httpClient.get(this.apiBaseUrl + this.apiBasePath + '/api/v1/cpfp/' + txid); } + + getDifficultyAdjustment$(): Observable { + return this.httpClient.get(this.apiBaseUrl + this.apiBasePath + '/api/v1/difficulty-adjustment'); + } } diff --git a/frontend/src/app/services/state.service.ts b/frontend/src/app/services/state.service.ts index bd5acf91c..042a0433e 100644 --- a/frontend/src/app/services/state.service.ts +++ b/frontend/src/app/services/state.service.ts @@ -71,6 +71,7 @@ export class StateService { isLoadingWebSocket$ = new ReplaySubject(1); vbytesPerSecond$ = new ReplaySubject(1); lastDifficultyAdjustment$ = new ReplaySubject(1); + previousRetarget$ = new ReplaySubject(1); backendInfo$ = new ReplaySubject(1); loadingIndicators$ = new ReplaySubject(1); diff --git a/frontend/src/app/services/websocket.service.ts b/frontend/src/app/services/websocket.service.ts index f36c85b39..cdcbf5cbe 100644 --- a/frontend/src/app/services/websocket.service.ts +++ b/frontend/src/app/services/websocket.service.ts @@ -47,7 +47,7 @@ export class WebsocketService { this.network = this.stateService.network === 'bisq' && !this.stateService.env.BISQ_SEPARATE_BACKEND ? '' : this.stateService.network; this.websocketSubject = webSocket(this.webSocketUrl.replace('{network}', this.network ? '/' + this.network : '')); - const theInitData = this.transferState.get(initData, null); + const theInitData = this.transferState.get(initData, null); if (theInitData) { this.handleResponse(theInitData.body); this.startSubscription(false, true); @@ -290,6 +290,10 @@ export class WebsocketService { this.stateService.lastDifficultyAdjustment$.next(response.lastDifficultyAdjustment); } + if (response.previousRetarget !== undefined) { + this.stateService.previousRetarget$.next(response.previousRetarget); + } + if (response['git-commit']) { this.stateService.backendInfo$.next(response['git-commit']); }