mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
improvements
This commit is contained in:
@@ -3,7 +3,7 @@ import { plainToInstance } from 'class-transformer';
|
|||||||
import { validate, ValidatorOptions } from 'class-validator';
|
import { validate, ValidatorOptions } from 'class-validator';
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import { Socket } from 'net';
|
import { Socket } from 'net';
|
||||||
import { combineLatest, firstValueFrom, interval, startWith } from 'rxjs';
|
import { combineLatest, firstValueFrom, interval, startWith, takeUntil } from 'rxjs';
|
||||||
|
|
||||||
import { ClientStatisticsService } from '../ORM/client-statistics/client-statistics.service';
|
import { ClientStatisticsService } from '../ORM/client-statistics/client-statistics.service';
|
||||||
import { ClientEntity } from '../ORM/client/client.entity';
|
import { ClientEntity } from '../ORM/client/client.entity';
|
||||||
@@ -85,6 +85,7 @@ export class StratumV1Client extends EasyUnsubscribe {
|
|||||||
parsedMessage = JSON.parse(message);
|
parsedMessage = JSON.parse(message);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
this.socket.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (parsedMessage.method) {
|
switch (parsedMessage.method) {
|
||||||
@@ -229,27 +230,29 @@ export class StratumV1Client extends EasyUnsubscribe {
|
|||||||
|
|
||||||
let lastIntervalCount = undefined;
|
let lastIntervalCount = undefined;
|
||||||
let skipNext = false;
|
let skipNext = false;
|
||||||
combineLatest([this.blockTemplateService.currentBlockTemplate$, interval(60000).pipe(startWith(-1))]).subscribe(async ([{ blockTemplate }, interValCount]) => {
|
combineLatest([this.blockTemplateService.currentBlockTemplate$, interval(60000).pipe(startWith(-1))])
|
||||||
let clearJobs = false;
|
.pipe(takeUntil(this.easyUnsubscribe))
|
||||||
if (lastIntervalCount === interValCount) {
|
.subscribe(async ([{ blockTemplate }, interValCount]) => {
|
||||||
clearJobs = true;
|
let clearJobs = false;
|
||||||
skipNext = true;
|
if (lastIntervalCount === interValCount) {
|
||||||
console.log('new block')
|
clearJobs = true;
|
||||||
}
|
skipNext = true;
|
||||||
|
console.log('new block')
|
||||||
|
}
|
||||||
|
|
||||||
if (skipNext == true && clearJobs == false) {
|
if (skipNext == true && clearJobs == false) {
|
||||||
skipNext = false;
|
skipNext = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastIntervalCount = interValCount;
|
lastIntervalCount = interValCount;
|
||||||
|
|
||||||
this.sendNewMiningJob(blockTemplate, clearJobs);
|
this.sendNewMiningJob(blockTemplate, clearJobs);
|
||||||
|
|
||||||
await this.checkDifficulty();
|
await this.checkDifficulty();
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,8 +72,16 @@ export class StratumV1ClientStatistics {
|
|||||||
x = x | (x >> 32);
|
x = x | (x >> 32);
|
||||||
const res = x - (x >> 1);
|
const res = x - (x >> 1);
|
||||||
if (res < 1) {
|
if (res < 1) {
|
||||||
return 1;
|
if (val < 0.01) {
|
||||||
//return this.blpo2(val * 100) / 100;
|
return 0.01;
|
||||||
|
}
|
||||||
|
let y = (val * 100) | ((val * 100) >> 1);
|
||||||
|
y = y | (y >> 2);
|
||||||
|
y = y | (y >> 4);
|
||||||
|
y = y | (y >> 8);
|
||||||
|
y = y | (y >> 16);
|
||||||
|
y = y | (y >> 32);
|
||||||
|
return (y - (y >> 1)) / 100;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
|
|
||||||
socket.on('end', async () => {
|
socket.on('end', async () => {
|
||||||
// Handle socket disconnection
|
// Handle socket disconnection
|
||||||
|
client.destroy();
|
||||||
await this.clientService.delete(client.extraNonce);
|
await this.clientService.delete(client.extraNonce);
|
||||||
|
|
||||||
const clientCount = await this.clientService.connectedClientCount();
|
const clientCount = await this.clientService.connectedClientCount();
|
||||||
@@ -55,8 +56,8 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
|
|
||||||
socket.on('error', async (error: Error) => {
|
socket.on('error', async (error: Error) => {
|
||||||
|
|
||||||
|
client.destroy();
|
||||||
await this.clientService.delete(client.extraNonce);
|
await this.clientService.delete(client.extraNonce);
|
||||||
|
|
||||||
const clientCount = await this.clientService.connectedClientCount();
|
const clientCount = await this.clientService.connectedClientCount();
|
||||||
console.error(`Socket error:`, error);
|
console.error(`Socket error:`, error);
|
||||||
console.log(`Client disconnected: ${socket.remoteAddress}, ${clientCount} total clients`);
|
console.log(`Client disconnected: ${socket.remoteAddress}, ${clientCount} total clients`);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Subject } from 'rxjs';
|
|||||||
export class EasyUnsubscribe {
|
export class EasyUnsubscribe {
|
||||||
protected easyUnsubscribe = new Subject<void>();
|
protected easyUnsubscribe = new Subject<void>();
|
||||||
|
|
||||||
public unsubscribeAll(): void {
|
public destroy(): void {
|
||||||
this.easyUnsubscribe.next();
|
this.easyUnsubscribe.next();
|
||||||
this.easyUnsubscribe.complete();
|
this.easyUnsubscribe.complete();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user