mirror of
https://github.com/mempool/mempool.git
synced 2025-02-23 14:40:38 +01:00
Merge pull request #5508 from mempool/mononaut/stratum
stratum job visualization
This commit is contained in:
commit
6e8579363d
19 changed files with 628 additions and 6 deletions
|
@ -155,6 +155,10 @@
|
|||
"API": "https://mempool.space/api/v1/services",
|
||||
"ACCELERATIONS": false
|
||||
},
|
||||
"STRATUM": {
|
||||
"ENABLED": false,
|
||||
"API": "http://localhost:1234"
|
||||
},
|
||||
"FIAT_PRICE": {
|
||||
"ENABLED": true,
|
||||
"PAID": false,
|
||||
|
|
|
@ -151,5 +151,9 @@
|
|||
"ENABLED": true,
|
||||
"PAID": false,
|
||||
"API_KEY": "__MEMPOOL_CURRENCY_API_KEY__"
|
||||
},
|
||||
"STRATUM": {
|
||||
"ENABLED": false,
|
||||
"API": "http://localhost:1234"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,6 +159,11 @@ describe('Mempool Backend Config', () => {
|
|||
PAID: false,
|
||||
API_KEY: '',
|
||||
});
|
||||
|
||||
expect(config.STRATUM).toStrictEqual({
|
||||
ENABLED: false,
|
||||
API: 'http://localhost:1234',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
105
backend/src/api/services/stratum.ts
Normal file
105
backend/src/api/services/stratum.ts
Normal file
|
@ -0,0 +1,105 @@
|
|||
import { WebSocket } from 'ws';
|
||||
import logger from '../../logger';
|
||||
import config from '../../config';
|
||||
import websocketHandler from '../websocket-handler';
|
||||
|
||||
export interface StratumJob {
|
||||
pool: number;
|
||||
height: number;
|
||||
coinbase: string;
|
||||
scriptsig: string;
|
||||
reward: number;
|
||||
jobId: string;
|
||||
extraNonce: string;
|
||||
extraNonce2Size: number;
|
||||
prevHash: string;
|
||||
coinbase1: string;
|
||||
coinbase2: string;
|
||||
merkleBranches: string[];
|
||||
version: string;
|
||||
bits: string;
|
||||
time: string;
|
||||
timestamp: number;
|
||||
cleanJobs: boolean;
|
||||
received: number;
|
||||
}
|
||||
|
||||
function isStratumJob(obj: any): obj is StratumJob {
|
||||
return obj
|
||||
&& typeof obj === 'object'
|
||||
&& 'pool' in obj
|
||||
&& 'prevHash' in obj
|
||||
&& 'height' in obj
|
||||
&& 'received' in obj
|
||||
&& 'version' in obj
|
||||
&& 'timestamp' in obj
|
||||
&& 'bits' in obj
|
||||
&& 'merkleBranches' in obj
|
||||
&& 'cleanJobs' in obj;
|
||||
}
|
||||
|
||||
class StratumApi {
|
||||
private ws: WebSocket | null = null;
|
||||
private runWebsocketLoop: boolean = false;
|
||||
private startedWebsocketLoop: boolean = false;
|
||||
private websocketConnected: boolean = false;
|
||||
private jobs: Record<string, StratumJob> = {};
|
||||
|
||||
public constructor() {}
|
||||
|
||||
public getJobs(): Record<string, StratumJob> {
|
||||
return this.jobs;
|
||||
}
|
||||
|
||||
private handleWebsocketMessage(msg: any): void {
|
||||
if (isStratumJob(msg)) {
|
||||
this.jobs[msg.pool] = msg;
|
||||
websocketHandler.handleNewStratumJob(this.jobs[msg.pool]);
|
||||
}
|
||||
}
|
||||
|
||||
public async connectWebsocket(): Promise<void> {
|
||||
if (!config.STRATUM.ENABLED) {
|
||||
return;
|
||||
}
|
||||
this.runWebsocketLoop = true;
|
||||
if (this.startedWebsocketLoop) {
|
||||
return;
|
||||
}
|
||||
while (this.runWebsocketLoop) {
|
||||
this.startedWebsocketLoop = true;
|
||||
if (!this.ws) {
|
||||
this.ws = new WebSocket(`${config.STRATUM.API}`);
|
||||
this.websocketConnected = true;
|
||||
|
||||
this.ws.on('open', () => {
|
||||
logger.info('Stratum websocket opened');
|
||||
});
|
||||
|
||||
this.ws.on('error', (error) => {
|
||||
logger.err('Stratum websocket error: ' + error);
|
||||
this.ws = null;
|
||||
this.websocketConnected = false;
|
||||
});
|
||||
|
||||
this.ws.on('close', () => {
|
||||
logger.info('Stratum websocket closed');
|
||||
this.ws = null;
|
||||
this.websocketConnected = false;
|
||||
});
|
||||
|
||||
this.ws.on('message', (data, isBinary) => {
|
||||
try {
|
||||
const parsedMsg = JSON.parse((isBinary ? data : data.toString()) as string);
|
||||
this.handleWebsocketMessage(parsedMsg);
|
||||
} catch (e) {
|
||||
logger.warn('Failed to parse stratum websocket message: ' + (e instanceof Error ? e.message : e));
|
||||
}
|
||||
});
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new StratumApi();
|
|
@ -38,6 +38,7 @@ interface AddressTransactions {
|
|||
import bitcoinSecondClient from './bitcoin/bitcoin-second-client';
|
||||
import { calculateMempoolTxCpfp } from './cpfp';
|
||||
import { getRecentFirstSeen } from '../utils/file-read';
|
||||
import stratumApi, { StratumJob } from './services/stratum';
|
||||
|
||||
// valid 'want' subscriptions
|
||||
const wantable = [
|
||||
|
@ -403,6 +404,16 @@ class WebsocketHandler {
|
|||
delete client['track-mempool'];
|
||||
}
|
||||
|
||||
if (parsedMessage && parsedMessage['track-stratum'] != null) {
|
||||
if (parsedMessage['track-stratum']) {
|
||||
const sub = parsedMessage['track-stratum'];
|
||||
client['track-stratum'] = sub;
|
||||
response['stratumJobs'] = this.socketData['stratumJobs'];
|
||||
} else {
|
||||
client['track-stratum'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(response).length) {
|
||||
client.send(this.serializeResponse(response));
|
||||
}
|
||||
|
@ -1384,6 +1395,23 @@ class WebsocketHandler {
|
|||
await statistics.runStatistics();
|
||||
}
|
||||
|
||||
public handleNewStratumJob(job: StratumJob): void {
|
||||
this.updateSocketDataFields({ 'stratumJobs': stratumApi.getJobs() });
|
||||
|
||||
for (const server of this.webSocketServers) {
|
||||
server.clients.forEach((client) => {
|
||||
if (client.readyState !== WebSocket.OPEN) {
|
||||
return;
|
||||
}
|
||||
if (client['track-stratum'] && (client['track-stratum'] === 'all' || client['track-stratum'] === job.pool)) {
|
||||
client.send(JSON.stringify({
|
||||
'stratumJob': job
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// takes a dictionary of JSON serialized values
|
||||
// and zips it together into a valid JSON object
|
||||
private serializeResponse(response): string {
|
||||
|
|
|
@ -165,6 +165,10 @@ interface IConfig {
|
|||
WALLETS: {
|
||||
ENABLED: boolean;
|
||||
WALLETS: string[];
|
||||
},
|
||||
STRATUM: {
|
||||
ENABLED: boolean;
|
||||
API: string;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,6 +336,10 @@ const defaults: IConfig = {
|
|||
'ENABLED': false,
|
||||
'WALLETS': [],
|
||||
},
|
||||
'STRATUM': {
|
||||
'ENABLED': false,
|
||||
'API': 'http://localhost:1234',
|
||||
}
|
||||
};
|
||||
|
||||
class Config implements IConfig {
|
||||
|
@ -354,6 +362,7 @@ class Config implements IConfig {
|
|||
REDIS: IConfig['REDIS'];
|
||||
FIAT_PRICE: IConfig['FIAT_PRICE'];
|
||||
WALLETS: IConfig['WALLETS'];
|
||||
STRATUM: IConfig['STRATUM'];
|
||||
|
||||
constructor() {
|
||||
const configs = this.merge(configFromFile, defaults);
|
||||
|
@ -376,6 +385,7 @@ class Config implements IConfig {
|
|||
this.REDIS = configs.REDIS;
|
||||
this.FIAT_PRICE = configs.FIAT_PRICE;
|
||||
this.WALLETS = configs.WALLETS;
|
||||
this.STRATUM = configs.STRATUM;
|
||||
}
|
||||
|
||||
merge = (...objects: object[]): IConfig => {
|
||||
|
|
|
@ -48,6 +48,7 @@ import accelerationRoutes from './api/acceleration/acceleration.routes';
|
|||
import aboutRoutes from './api/about.routes';
|
||||
import mempoolBlocks from './api/mempool-blocks';
|
||||
import walletApi from './api/services/wallets';
|
||||
import stratumApi from './api/services/stratum';
|
||||
|
||||
class Server {
|
||||
private wss: WebSocket.Server | undefined;
|
||||
|
@ -320,6 +321,9 @@ class Server {
|
|||
loadingIndicators.setProgressChangedCallback(websocketHandler.handleLoadingChanged.bind(websocketHandler));
|
||||
|
||||
accelerationApi.connectWebsocket();
|
||||
if (config.STRATUM.ENABLED) {
|
||||
stratumApi.connectWebsocket();
|
||||
}
|
||||
}
|
||||
|
||||
setUpHttpApiRoutes(): void {
|
||||
|
|
|
@ -148,6 +148,10 @@
|
|||
"API": "__MEMPOOL_SERVICES_API__",
|
||||
"ACCELERATIONS": __MEMPOOL_SERVICES_ACCELERATIONS__
|
||||
},
|
||||
"STRATUM": {
|
||||
"ENABLED": __STRATUM_ENABLED__,
|
||||
"API": "__STRATUM_API__"
|
||||
},
|
||||
"REDIS": {
|
||||
"ENABLED": __REDIS_ENABLED__,
|
||||
"UNIX_SOCKET_PATH": "__REDIS_UNIX_SOCKET_PATH__",
|
||||
|
|
|
@ -149,6 +149,10 @@ __REPLICATION_SERVERS__=${REPLICATION_SERVERS:=[]}
|
|||
__MEMPOOL_SERVICES_API__=${MEMPOOL_SERVICES_API:="https://mempool.space/api/v1/services"}
|
||||
__MEMPOOL_SERVICES_ACCELERATIONS__=${MEMPOOL_SERVICES_ACCELERATIONS:=false}
|
||||
|
||||
# STRATUM
|
||||
__STRATUM_ENABLED__=${STRATUM_ENABLED:=false}
|
||||
__STRATUM_API__=${STRATUM_API:="http://localhost:1234"}
|
||||
|
||||
# REDIS
|
||||
__REDIS_ENABLED__=${REDIS_ENABLED:=false}
|
||||
__REDIS_UNIX_SOCKET_PATH__=${REDIS_UNIX_SOCKET_PATH:=""}
|
||||
|
@ -300,6 +304,10 @@ sed -i "s!__REPLICATION_SERVERS__!${__REPLICATION_SERVERS__}!g" mempool-config.j
|
|||
sed -i "s!__MEMPOOL_SERVICES_API__!${__MEMPOOL_SERVICES_API__}!g" mempool-config.json
|
||||
sed -i "s!__MEMPOOL_SERVICES_ACCELERATIONS__!${__MEMPOOL_SERVICES_ACCELERATIONS__}!g" mempool-config.json
|
||||
|
||||
# STRATUM
|
||||
sed -i "s!__STRATUM_ENABLED__!${__STRATUM_ENABLED__}!g" mempool-config.json
|
||||
sed -i "s!__STRATUM_API__!${__STRATUM_API__}!g" mempool-config.json
|
||||
|
||||
# REDIS
|
||||
sed -i "s!__REDIS_ENABLED__!${__REDIS_ENABLED__}!g" mempool-config.json
|
||||
sed -i "s!__REDIS_UNIX_SOCKET_PATH__!${__REDIS_UNIX_SOCKET_PATH__}!g" mempool-config.json
|
||||
|
|
|
@ -27,5 +27,6 @@
|
|||
"ACCELERATOR": false,
|
||||
"ACCELERATOR_BUTTON": true,
|
||||
"PUBLIC_ACCELERATIONS": false,
|
||||
"STRATUM_ENABLED": false,
|
||||
"SERVICES_API": "https://mempool.space/api/v1/services"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<div class="container-xl" style="min-height: 335px">
|
||||
<h1 class="float-left" i18n="master-page.blocks">Stratum Jobs</h1>
|
||||
|
||||
<div class="clearfix"></div>
|
||||
|
||||
<div style="min-height: 295px">
|
||||
<table *ngIf="poolsReady && (rows$ | async) as rows;" class="stratum-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="height">Height</td>
|
||||
<td class="reward">Reward</td>
|
||||
<td class="tag">Coinbase Tag</td>
|
||||
<td class="merkle" [attr.colspan]="rows[0]?.merkleCells?.length || 4">
|
||||
Merkle Branches
|
||||
</td>
|
||||
<td class="pool">Pool</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (row of rows; track row.job.pool) {
|
||||
<tr>
|
||||
<td class="height">
|
||||
{{ row.job.height }}
|
||||
</td>
|
||||
<td class="reward">
|
||||
<app-amount [satoshis]="row.job.reward"></app-amount>
|
||||
</td>
|
||||
<td class="tag">
|
||||
{{ row.job.tag }}
|
||||
</td>
|
||||
@for (cell of row.merkleCells; track $index) {
|
||||
<td class="merkle" [style.background-color]="cell.hash ? '#' + cell.hash.slice(0, 6) : ''">
|
||||
<div class="pipe-segment" [class]="pipeToClass(cell.type)"></div>
|
||||
</td>
|
||||
}
|
||||
<td class="pool">
|
||||
@if (pools[row.job.pool]) {
|
||||
<a class="badge" [routerLink]="[('/mining/pool/' + pools[row.job.pool].slug) | relativeUrl]">
|
||||
<img class="pool-logo" [src]="'/resources/mining-pools/' + pools[row.job.pool].slug + '.svg'" onError="this.src = '/resources/mining-pools/default.svg'" [alt]="'Logo of ' + pools[row.job.pool].name + ' mining pool'">
|
||||
{{ pools[row.job.pool].name}}
|
||||
</a>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,108 @@
|
|||
.stratum-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
td {
|
||||
position: relative;
|
||||
height: 2em;
|
||||
|
||||
&.height, &.reward, &.tag {
|
||||
padding: 0 5px;
|
||||
}
|
||||
|
||||
&.tag {
|
||||
max-width: 180px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&.pool {
|
||||
padding-left: 5px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
&.merkle {
|
||||
width: 100px;
|
||||
.pipe-segment {
|
||||
position: absolute;
|
||||
border-color: white;
|
||||
box-sizing: content-box;
|
||||
|
||||
&.vertical {
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
border-left: solid 4px;
|
||||
}
|
||||
&.horizontal {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 50%;
|
||||
border-top: solid 4px;
|
||||
}
|
||||
&.branch-top {
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
height: 50%;
|
||||
border-top: solid 4px;
|
||||
&::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
box-sizing: content-box;
|
||||
top: -4px;
|
||||
right: 0px;
|
||||
bottom: 0;
|
||||
width: 50%;
|
||||
border-top: solid 4px;
|
||||
border-left: solid 4px;
|
||||
border-top-left-radius: 5px;
|
||||
}
|
||||
}
|
||||
&.branch-mid {
|
||||
bottom: 0;
|
||||
right: 0px;
|
||||
width: 50%;
|
||||
height: 100%;
|
||||
border-left: solid 4px;
|
||||
&::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
box-sizing: content-box;
|
||||
top: -4px;
|
||||
left: -4px;
|
||||
width: 100%;
|
||||
height: 50%;
|
||||
border-bottom: solid 4px;
|
||||
border-left: solid 4px;
|
||||
border-bottom-left-radius: 5px;
|
||||
}
|
||||
}
|
||||
&.branch-end {
|
||||
top: -4px;
|
||||
right: 0;
|
||||
width: 50%;
|
||||
height: 50%;
|
||||
border-bottom-left-radius: 5px;
|
||||
border-bottom: solid 4px;
|
||||
border-left: solid 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.badge {
|
||||
position: relative;
|
||||
color: #FFF;
|
||||
}
|
||||
|
||||
.pool-logo {
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
position: relative;
|
||||
top: -1px;
|
||||
margin-right: 2px;
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
import { Component, OnInit, ChangeDetectionStrategy, OnDestroy, ChangeDetectorRef } from '@angular/core';
|
||||
import { StateService } from '../../../services/state.service';
|
||||
import { WebsocketService } from '../../../services/websocket.service';
|
||||
import { map, Observable } from 'rxjs';
|
||||
import { StratumJob } from '../../../interfaces/websocket.interface';
|
||||
import { MiningService } from '../../../services/mining.service';
|
||||
import { SinglePoolStats } from '../../../interfaces/node-api.interface';
|
||||
|
||||
type MerkleCellType = ' ' | '┬' | '├' | '└' | '│' | '─' | 'leaf';
|
||||
|
||||
interface TaggedStratumJob extends StratumJob {
|
||||
tag: string;
|
||||
}
|
||||
|
||||
interface MerkleCell {
|
||||
hash: string;
|
||||
type: MerkleCellType;
|
||||
job?: TaggedStratumJob;
|
||||
}
|
||||
|
||||
interface MerkleTree {
|
||||
hash?: string;
|
||||
job: string;
|
||||
size: number;
|
||||
children?: MerkleTree[];
|
||||
}
|
||||
|
||||
interface PoolRow {
|
||||
job: TaggedStratumJob;
|
||||
merkleCells: MerkleCell[];
|
||||
}
|
||||
|
||||
function parseTag(scriptSig: string): string {
|
||||
const hex = scriptSig.slice(8).replace(/6d6d.{64}/, '');
|
||||
const bytes: number[] = [];
|
||||
for (let i = 0; i < hex.length; i += 2) {
|
||||
bytes.push(parseInt(hex.substr(i, 2), 16));
|
||||
}
|
||||
const ascii = new TextDecoder('utf8').decode(Uint8Array.from(bytes)).replace(/\uFFFD/g, '').replace(/\\0/g, '');
|
||||
if (ascii.includes('/ViaBTC/')) {
|
||||
return '/ViaBTC/';
|
||||
} else if (ascii.includes('SpiderPool/')) {
|
||||
return 'SpiderPool/';
|
||||
}
|
||||
return ascii.match(/\/.*\//)?.[0] || ascii;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-stratum-list',
|
||||
templateUrl: './stratum-list.component.html',
|
||||
styleUrls: ['./stratum-list.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class StratumList implements OnInit, OnDestroy {
|
||||
rows$: Observable<PoolRow[]>;
|
||||
pools: { [id: number]: SinglePoolStats } = {};
|
||||
poolsReady: boolean = false;
|
||||
|
||||
constructor(
|
||||
private stateService: StateService,
|
||||
private websocketService: WebsocketService,
|
||||
private miningService: MiningService,
|
||||
private cd: ChangeDetectorRef,
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.websocketService.want(['stats', 'blocks', 'mempool-blocks']);
|
||||
this.miningService.getPools().subscribe(pools => {
|
||||
this.pools = {};
|
||||
for (const pool of pools) {
|
||||
this.pools[pool.unique_id] = pool;
|
||||
}
|
||||
this.poolsReady = true;
|
||||
this.cd.markForCheck();
|
||||
});
|
||||
this.rows$ = this.stateService.stratumJobs$.pipe(
|
||||
map((jobs) => this.processJobs(jobs)),
|
||||
);
|
||||
this.websocketService.startTrackStratum('all');
|
||||
}
|
||||
|
||||
processJobs(rawJobs: Record<string, StratumJob>): PoolRow[] {
|
||||
const jobs: Record<string, TaggedStratumJob> = {};
|
||||
for (const [id, job] of Object.entries(rawJobs)) {
|
||||
jobs[id] = { ...job, tag: parseTag(job.scriptsig) };
|
||||
}
|
||||
if (Object.keys(jobs).length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const numBranches = Math.max(...Object.values(jobs).map(job => job.merkleBranches.length));
|
||||
|
||||
let trees: MerkleTree[] = Object.keys(jobs).map(job => ({
|
||||
job,
|
||||
size: 1,
|
||||
}));
|
||||
|
||||
// build tree from bottom up
|
||||
for (let col = numBranches - 1; col >= 0; col--) {
|
||||
const groups: Record<string, MerkleTree[]> = {};
|
||||
for (const tree of trees) {
|
||||
const hash = jobs[tree.job].merkleBranches[col];
|
||||
if (!groups[hash]) {
|
||||
groups[hash] = [];
|
||||
}
|
||||
groups[hash].push(tree);
|
||||
}
|
||||
trees = Object.values(groups).map(group => ({
|
||||
hash: jobs[group[0].job].merkleBranches[col],
|
||||
job: group[0].job,
|
||||
children: group,
|
||||
size: group.reduce((acc, tree) => acc + tree.size, 0),
|
||||
}));
|
||||
}
|
||||
|
||||
// initialize grid of cells
|
||||
const rows: (MerkleCell | null)[][] = [];
|
||||
for (let i = 0; i < Object.keys(jobs).length; i++) {
|
||||
const row: (MerkleCell | null)[] = [];
|
||||
for (let j = 0; j <= numBranches; j++) {
|
||||
row.push(null);
|
||||
}
|
||||
rows.push(row);
|
||||
}
|
||||
|
||||
// fill in the cells
|
||||
let colTrees = [trees.sort((a, b) => {
|
||||
if (a.size !== b.size) {
|
||||
return b.size - a.size;
|
||||
}
|
||||
return a.job.localeCompare(b.job);
|
||||
})];
|
||||
for (let col = 0; col <= numBranches; col++) {
|
||||
let row = 0;
|
||||
const nextTrees: MerkleTree[][] = [];
|
||||
for (let g = 0; g < colTrees.length; g++) {
|
||||
for (let t = 0; t < colTrees[g].length; t++) {
|
||||
const tree = colTrees[g][t];
|
||||
const isFirstTree = (t === 0);
|
||||
const isLastTree = (t === colTrees[g].length - 1);
|
||||
for (let i = 0; i < tree.size; i++) {
|
||||
const isFirstCell = (i === 0);
|
||||
const isLeaf = (col === numBranches);
|
||||
rows[row][col] = {
|
||||
hash: tree.hash,
|
||||
job: isLeaf ? jobs[tree.job] : undefined,
|
||||
type: 'leaf',
|
||||
};
|
||||
if (col > 0) {
|
||||
rows[row][col - 1].type = getCellType(isFirstCell, isFirstTree, isLastTree);
|
||||
}
|
||||
row++;
|
||||
}
|
||||
if (tree.children) {
|
||||
nextTrees.push(tree.children.sort((a, b) => {
|
||||
if (a.size !== b.size) {
|
||||
return b.size - a.size;
|
||||
}
|
||||
return a.job.localeCompare(b.job);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
colTrees = nextTrees;
|
||||
}
|
||||
return rows.map(row => ({
|
||||
job: row[row.length - 1].job,
|
||||
merkleCells: row.slice(0, -1),
|
||||
}));
|
||||
}
|
||||
|
||||
pipeToClass(type: MerkleCellType): string {
|
||||
return {
|
||||
' ': 'empty',
|
||||
'┬': 'branch-top',
|
||||
'├': 'branch-mid',
|
||||
'└': 'branch-end',
|
||||
'│': 'vertical',
|
||||
'─': 'horizontal',
|
||||
'leaf': 'leaf'
|
||||
}[type];
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.websocketService.stopTrackStratum();
|
||||
}
|
||||
}
|
||||
|
||||
function getCellType(isFirstCell, isFirstTree, isLastTree): MerkleCellType {
|
||||
if (isFirstCell) {
|
||||
if (isFirstTree) {
|
||||
if (isLastTree) {
|
||||
return '─';
|
||||
} else {
|
||||
return '┬';
|
||||
}
|
||||
} else if (isLastTree) {
|
||||
return '└';
|
||||
} else {
|
||||
return '├';
|
||||
}
|
||||
} else {
|
||||
if (isLastTree) {
|
||||
return ' ';
|
||||
} else {
|
||||
return '│';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,6 +21,8 @@ export interface WebsocketResponse {
|
|||
rbfInfo?: RbfTree;
|
||||
rbfLatest?: RbfTree[];
|
||||
rbfLatestSummary?: ReplacementInfo[];
|
||||
stratumJob?: StratumJob;
|
||||
stratumJobs?: Record<number, StratumJob>;
|
||||
utxoSpent?: object;
|
||||
transactions?: TransactionStripped[];
|
||||
loadingIndicators?: ILoadingIndicators;
|
||||
|
@ -37,6 +39,7 @@ export interface WebsocketResponse {
|
|||
'track-rbf-summary'?: boolean;
|
||||
'track-accelerations'?: boolean;
|
||||
'track-wallet'?: string;
|
||||
'track-stratum'?: string | number;
|
||||
'watch-mempool'?: boolean;
|
||||
'refresh-blocks'?: boolean;
|
||||
}
|
||||
|
@ -150,3 +153,24 @@ export interface HealthCheckHost {
|
|||
electrs?: string;
|
||||
}
|
||||
}
|
||||
|
||||
export interface StratumJob {
|
||||
pool: number;
|
||||
height: number;
|
||||
coinbase: string;
|
||||
scriptsig: string;
|
||||
reward: number;
|
||||
jobId: string;
|
||||
extraNonce: string;
|
||||
extraNonce2Size: number;
|
||||
prevHash: string;
|
||||
coinbase1: string;
|
||||
coinbase2: string;
|
||||
merkleBranches: string[];
|
||||
version: string;
|
||||
bits: string;
|
||||
time: string;
|
||||
timestamp: number;
|
||||
cleanJobs: boolean;
|
||||
received: number;
|
||||
}
|
||||
|
|
|
@ -10,9 +10,10 @@ import { TestTransactionsComponent } from '@components/test-transactions/test-tr
|
|||
import { CalculatorComponent } from '@components/calculator/calculator.component';
|
||||
import { BlocksList } from '@components/blocks-list/blocks-list.component';
|
||||
import { RbfList } from '@components/rbf-list/rbf-list.component';
|
||||
import { StratumList } from '@components/stratum/stratum-list/stratum-list.component';
|
||||
import { ServerHealthComponent } from '@components/server-health/server-health.component';
|
||||
import { ServerStatusComponent } from '@components/server-health/server-status.component';
|
||||
import { FaucetComponent } from '@components/faucet/faucet.component'
|
||||
import { FaucetComponent } from '@components/faucet/faucet.component';
|
||||
|
||||
const browserWindow = window || {};
|
||||
// @ts-ignore
|
||||
|
@ -56,6 +57,16 @@ const routes: Routes = [
|
|||
path: 'rbf',
|
||||
component: RbfList,
|
||||
},
|
||||
...(browserWindowEnv.STRATUM_ENABLED ? [{
|
||||
path: 'stratum',
|
||||
component: StartComponent,
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
component: StratumList,
|
||||
}
|
||||
]
|
||||
}] : []),
|
||||
{
|
||||
path: 'terms-of-service',
|
||||
loadChildren: () => import('@components/terms-of-service/terms-of-service.module').then(m => m.TermsOfServiceModule),
|
||||
|
|
|
@ -64,8 +64,8 @@ export class MiningService {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Get names and slugs of all pools
|
||||
*/
|
||||
public getPools(): Observable<any[]> {
|
||||
|
@ -75,7 +75,6 @@ export class MiningService {
|
|||
return this.poolsData;
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
/**
|
||||
* Set the hashrate power of ten we want to display
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Inject, Injectable, PLATFORM_ID, LOCALE_ID } from '@angular/core';
|
||||
import { ReplaySubject, BehaviorSubject, Subject, fromEvent, Observable } from 'rxjs';
|
||||
import { AddressTxSummary, Transaction } from '@interfaces/electrs.interface';
|
||||
import { AccelerationDelta, HealthCheckHost, IBackendInfo, MempoolBlock, MempoolBlockUpdate, MempoolInfo, Recommendedfees, ReplacedTransaction, ReplacementInfo, isMempoolState } from '@interfaces/websocket.interface';
|
||||
import { Transaction } from '@interfaces/electrs.interface';
|
||||
import { AccelerationDelta, HealthCheckHost, IBackendInfo, MempoolBlock, MempoolBlockUpdate, MempoolInfo, Recommendedfees, ReplacedTransaction, ReplacementInfo, StratumJob, isMempoolState } from '@interfaces/websocket.interface';
|
||||
import { Acceleration, AccelerationPosition, BlockExtended, CpfpInfo, DifficultyAdjustment, MempoolPosition, OptimizedMempoolStats, RbfTree, TransactionStripped } from '@interfaces/node-api.interface';
|
||||
import { Router, NavigationStart } from '@angular/router';
|
||||
import { isPlatformBrowser } from '@angular/common';
|
||||
|
@ -81,6 +81,7 @@ export interface Env {
|
|||
ADDITIONAL_CURRENCIES: boolean;
|
||||
GIT_COMMIT_HASH_MEMPOOL_SPACE?: string;
|
||||
PACKAGE_JSON_VERSION_MEMPOOL_SPACE?: string;
|
||||
STRATUM_ENABLED: boolean;
|
||||
SERVICES_API?: string;
|
||||
customize?: Customization;
|
||||
PROD_DOMAINS: string[];
|
||||
|
@ -123,6 +124,7 @@ const defaultEnv: Env = {
|
|||
'ACCELERATOR_BUTTON': true,
|
||||
'PUBLIC_ACCELERATIONS': false,
|
||||
'ADDITIONAL_CURRENCIES': false,
|
||||
'STRATUM_ENABLED': false,
|
||||
'SERVICES_API': 'https://mempool.space/api/v1/services',
|
||||
'PROD_DOMAINS': [],
|
||||
};
|
||||
|
@ -159,6 +161,8 @@ export class StateService {
|
|||
liveMempoolBlockTransactions$: Observable<{ block: number, transactions: { [txid: string]: TransactionStripped} }>;
|
||||
accelerations$ = new Subject<AccelerationDelta>();
|
||||
liveAccelerations$: Observable<Acceleration[]>;
|
||||
stratumJobUpdate$ = new Subject<{ state: Record<string, StratumJob> } | { job: StratumJob }>();
|
||||
stratumJobs$ = new BehaviorSubject<Record<string, StratumJob>>({});
|
||||
txConfirmed$ = new Subject<[string, BlockExtended]>();
|
||||
txReplaced$ = new Subject<ReplacedTransaction>();
|
||||
txRbfInfo$ = new Subject<RbfTree>();
|
||||
|
@ -303,6 +307,24 @@ export class StateService {
|
|||
map((accMap) => Object.values(accMap).sort((a,b) => b.added - a.added))
|
||||
);
|
||||
|
||||
this.stratumJobUpdate$.pipe(
|
||||
scan((acc: Record<string, StratumJob>, update: { state: Record<string, StratumJob> } | { job: StratumJob }) => {
|
||||
if ('state' in update) {
|
||||
// Replace the entire state
|
||||
return update.state;
|
||||
} else {
|
||||
// Update or create a single job entry
|
||||
return {
|
||||
...acc,
|
||||
[update.job.pool]: update.job
|
||||
};
|
||||
}
|
||||
}, {}),
|
||||
shareReplay(1)
|
||||
).subscribe(val => {
|
||||
this.stratumJobs$.next(val);
|
||||
});
|
||||
|
||||
this.networkChanged$.subscribe((network) => {
|
||||
this.transactions$ = new BehaviorSubject<TransactionStripped[]>(null);
|
||||
this.blocksSubject$.next([]);
|
||||
|
|
|
@ -36,6 +36,7 @@ export class WebsocketService {
|
|||
private isTrackingAccelerations: boolean = false;
|
||||
private isTrackingWallet: boolean = false;
|
||||
private trackingWalletName: string;
|
||||
private isTrackingStratum: string | number | false = false;
|
||||
private trackingMempoolBlock: number;
|
||||
private trackingMempoolBlockNetwork: string;
|
||||
private stoppingTrackMempoolBlock: any | null = null;
|
||||
|
@ -143,6 +144,9 @@ export class WebsocketService {
|
|||
if (this.isTrackingWallet) {
|
||||
this.startTrackingWallet(this.trackingWalletName);
|
||||
}
|
||||
if (this.isTrackingStratum !== false) {
|
||||
this.startTrackStratum(this.isTrackingStratum);
|
||||
}
|
||||
this.stateService.connectionState$.next(2);
|
||||
}
|
||||
|
||||
|
@ -289,6 +293,18 @@ export class WebsocketService {
|
|||
}
|
||||
}
|
||||
|
||||
startTrackStratum(pool: number | string) {
|
||||
this.websocketSubject.next({ 'track-stratum': pool });
|
||||
this.isTrackingStratum = pool;
|
||||
}
|
||||
|
||||
stopTrackStratum() {
|
||||
if (this.isTrackingStratum) {
|
||||
this.websocketSubject.next({ 'track-stratum': null });
|
||||
this.isTrackingStratum = false;
|
||||
}
|
||||
}
|
||||
|
||||
fetchStatistics(historicalDate: string) {
|
||||
this.websocketSubject.next({ historicalDate });
|
||||
}
|
||||
|
@ -512,6 +528,14 @@ export class WebsocketService {
|
|||
this.stateService.previousRetarget$.next(response.previousRetarget);
|
||||
}
|
||||
|
||||
if (response.stratumJobs) {
|
||||
this.stateService.stratumJobUpdate$.next({ state: response.stratumJobs });
|
||||
}
|
||||
|
||||
if (response.stratumJob) {
|
||||
this.stateService.stratumJobUpdate$.next({ job: response.stratumJob });
|
||||
}
|
||||
|
||||
if (response['tomahawk']) {
|
||||
this.stateService.serverHealth$.next(response['tomahawk']);
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@ import { AmountShortenerPipe } from '@app/shared/pipes/amount-shortener.pipe';
|
|||
import { DifficultyAdjustmentsTable } from '@components/difficulty-adjustments-table/difficulty-adjustments-table.components';
|
||||
import { BlocksList } from '@components/blocks-list/blocks-list.component';
|
||||
import { RbfList } from '@components/rbf-list/rbf-list.component';
|
||||
import { StratumList } from '@components/stratum/stratum-list/stratum-list.component';
|
||||
import { RewardStatsComponent } from '@components/reward-stats/reward-stats.component';
|
||||
import { DataCyDirective } from '@app/data-cy.directive';
|
||||
import { LoadingIndicatorComponent } from '@components/loading-indicator/loading-indicator.component';
|
||||
|
@ -201,6 +202,7 @@ import { OnlyVsizeDirective, OnlyWeightDirective } from '@app/shared/components/
|
|||
DifficultyAdjustmentsTable,
|
||||
BlocksList,
|
||||
RbfList,
|
||||
StratumList,
|
||||
DataCyDirective,
|
||||
RewardStatsComponent,
|
||||
LoadingIndicatorComponent,
|
||||
|
@ -345,6 +347,7 @@ import { OnlyVsizeDirective, OnlyWeightDirective } from '@app/shared/components/
|
|||
AmountShortenerPipe,
|
||||
DifficultyAdjustmentsTable,
|
||||
BlocksList,
|
||||
StratumList,
|
||||
DataCyDirective,
|
||||
RewardStatsComponent,
|
||||
LoadingIndicatorComponent,
|
||||
|
|
Loading…
Add table
Reference in a new issue