mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
session watchdog
This commit is contained in:
@@ -39,11 +39,13 @@ export class StratumV1Client extends EasyUnsubscribe {
|
||||
private statistics: StratumV1ClientStatistics;
|
||||
private stratumInitialized = false;
|
||||
private usedSuggestedDifficulty = false;
|
||||
private sessionDifficulty: number = 32768;
|
||||
private sessionDifficulty: number = 16384;
|
||||
private entity: ClientEntity;
|
||||
|
||||
public extraNonceAndSessionId: string;
|
||||
|
||||
public sessionStart: Date;
|
||||
|
||||
constructor(
|
||||
public readonly promiseSocket: PromiseSocket<Socket>,
|
||||
private readonly stratumV1JobsService: StratumV1JobsService,
|
||||
@@ -56,6 +58,8 @@ export class StratumV1Client extends EasyUnsubscribe {
|
||||
) {
|
||||
super();
|
||||
|
||||
this.sessionStart = new Date();
|
||||
|
||||
this.statistics = new StratumV1ClientStatistics(this.clientStatisticsService);
|
||||
this.extraNonceAndSessionId = this.getRandomHexString();
|
||||
|
||||
@@ -277,11 +281,27 @@ export class StratumV1Client extends EasyUnsubscribe {
|
||||
await this.sendNewMiningJob(jobTemplate);
|
||||
|
||||
await this.checkDifficulty();
|
||||
|
||||
await this.watchdog();
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private async watchdog() {
|
||||
let time = await this.statistics.getLastSubmissionTime();
|
||||
if (time == null) {
|
||||
time = this.sessionStart;
|
||||
}
|
||||
const now = Date.now();
|
||||
const diffSeconds = (now - time.getTime()) / 1000;
|
||||
// two minutes
|
||||
if (diffSeconds > 120) {
|
||||
console.log('Watchdog ending session');
|
||||
this.promiseSocket.end();
|
||||
}
|
||||
}
|
||||
|
||||
private async sendNewMiningJob(jobTemplate: IJobTemplate) {
|
||||
|
||||
const hashRate = await this.clientStatisticsService.getHashRateForSession(this.clientAuthorization.address, this.clientAuthorization.worker, this.extraNonceAndSessionId);
|
||||
|
||||
Reference in New Issue
Block a user