Skip to content

Commit

Permalink
Minimize requests when node is not synchronized
Browse files Browse the repository at this point in the history
  • Loading branch information
everoddandeven committed Oct 15, 2024
1 parent 6caf8d2 commit 96f0aca
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/core/services/daemon/daemon-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export class DaemonDataService {

await this.refreshMiningStatus();

await this.refreshMinerData();
if (this._daemonInfo.synchronized) await this.refreshMinerData();

this._gettingPeerList = true;
this._peerList = await this.daemonService.getPeerList();
Expand Down
9 changes: 8 additions & 1 deletion src/app/pages/blockchain/blockchain.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ export class BlockchainComponent implements AfterViewInit {
return this.daemonData.lastBlockHeader;
}

public getLastBlockError: string = '';
public get daemonSynchronized(): boolean {
return this.daemonData.info ? this.daemonData.info.synchronized : false;
}

public get getLastBlockError(): string {
return this.daemonSynchronized ? '' : 'Last block header not available, blockchain is not synchronized';
}

public block?: Block;
public getBlockByHash: boolean = false;
public getBlockHash: string = '';
Expand Down
17 changes: 12 additions & 5 deletions src/app/pages/mining/mining.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ <h1 class="h2">Mining</h1>

<div *ngIf="daemonRunning && !daemonStopping" class="tab-content" id="pills-tabContent">
<div class="tab-pane fade show active" id="pills-mining-status" role="tabpanel" aria-labelledby="pills-mining-status-tab" tabindex="0">
<div *ngIf="miningStatusLoading">
<div *ngIf="coreBusy" class="alert alert-danger d-flex align-items-center justify-content-center text-center" role="alert">
<h4><i class="bi bi-exclamation-triangle m-2"></i></h4>&nbsp;&nbsp;
<div>
Mining status not available, node is not synchronized
</div>
</div>

<div *ngIf="!coreBusy && miningStatusLoading">
<!-- Placeholder per il caricamento -->
<div class="card">
<div class="card-body">
Expand All @@ -31,7 +38,7 @@ <h5 class="card-title placeholder-glow">
</div>
</div>

<div *ngIf="miningStatus && miningStatus.active" class="card">
<div *ngIf="!coreBusy && miningStatus && miningStatus.active" class="card">
<div class="card-header bg-primary text-white">
<h4>Mining Status</h4>
</div>
Expand Down Expand Up @@ -78,7 +85,7 @@ <h5 class="card-title">{{ miningStatus.active ? 'Mining Active' : 'Mining Inacti
</div>
</div>

<div *ngIf="miningStatus && !miningStatus.active" class="row g-5 p-2">
<div *ngIf="!coreBusy && miningStatus && !miningStatus.active" class="row g-5 p-2">
<div class="cold-md-7 col-lg-12">
<div class="row gy-3">
<h4 class="mb-3">Start mining on the daemon</h4>
Expand Down Expand Up @@ -128,7 +135,7 @@ <h4 class="mb-3">Necessary data to create a custom block template, used by p2poo
<div *ngIf="coreBusy" class="alert alert-danger d-flex align-items-center justify-content-center text-center" role="alert">
<h4><i class="bi bi-exclamation-triangle m-2"></i></h4>&nbsp;&nbsp;
<div>
Core is busy: miner data is not available during blockchain sync
Miner data is not available, node is not synchronized
</div>
</div>

Expand Down Expand Up @@ -371,7 +378,7 @@ <h4 class="mb-3">Submit a mined block to the network</h4>

<hr class="my-4">

<button *ngIf="!submittingBlock" class="w-100 btn btn-primary btn-lg" type="button" (click)="submitBlock()">Submit Block</button>
<button *ngIf="!submittingBlock" class="w-100 btn btn-primary btn-lg" type="button" (click)="submitBlock()" [disabled]="!validBlobData()">Submit Block</button>
<button *ngIf="submittingBlock" class="w-100 btn btn-primary btn-lg" type="button" disabled>Submitting Block ...</button>
</div>

Expand Down
3 changes: 2 additions & 1 deletion src/app/pages/mining/mining.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import { DaemonDataService } from '../../core/services';
export class MiningComponent implements AfterViewInit {

public readonly navbarLinks: NavbarLink[];

public get coreBusy(): boolean {
return this.daemonData.minerDataCoreBusyError;
return this.daemonData.info? !this.daemonData.info.synchronized : true;
}

public get miningStatus(): MiningStatus | undefined {
Expand Down

0 comments on commit 96f0aca

Please sign in to comment.