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 statistics: StratumV1ClientStatistics;
|
||||||
private stratumInitialized = false;
|
private stratumInitialized = false;
|
||||||
private usedSuggestedDifficulty = false;
|
private usedSuggestedDifficulty = false;
|
||||||
private sessionDifficulty: number = 32768;
|
private sessionDifficulty: number = 16384;
|
||||||
private entity: ClientEntity;
|
private entity: ClientEntity;
|
||||||
|
|
||||||
public extraNonceAndSessionId: string;
|
public extraNonceAndSessionId: string;
|
||||||
|
|
||||||
|
public sessionStart: Date;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly promiseSocket: PromiseSocket<Socket>,
|
public readonly promiseSocket: PromiseSocket<Socket>,
|
||||||
private readonly stratumV1JobsService: StratumV1JobsService,
|
private readonly stratumV1JobsService: StratumV1JobsService,
|
||||||
@@ -56,6 +58,8 @@ export class StratumV1Client extends EasyUnsubscribe {
|
|||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
this.sessionStart = new Date();
|
||||||
|
|
||||||
this.statistics = new StratumV1ClientStatistics(this.clientStatisticsService);
|
this.statistics = new StratumV1ClientStatistics(this.clientStatisticsService);
|
||||||
this.extraNonceAndSessionId = this.getRandomHexString();
|
this.extraNonceAndSessionId = this.getRandomHexString();
|
||||||
|
|
||||||
@@ -277,11 +281,27 @@ export class StratumV1Client extends EasyUnsubscribe {
|
|||||||
await this.sendNewMiningJob(jobTemplate);
|
await this.sendNewMiningJob(jobTemplate);
|
||||||
|
|
||||||
await this.checkDifficulty();
|
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) {
|
private async sendNewMiningJob(jobTemplate: IJobTemplate) {
|
||||||
|
|
||||||
const hashRate = await this.clientStatisticsService.getHashRateForSession(this.clientAuthorization.address, this.clientAuthorization.worker, this.extraNonceAndSessionId);
|
const hashRate = await this.clientStatisticsService.getHashRateForSession(this.clientAuthorization.address, this.clientAuthorization.worker, this.extraNonceAndSessionId);
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ export class StratumV1ClientStatistics {
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public getLastSubmissionTime(): Date | null {
|
||||||
|
return this.submissionCache[0]?.time;
|
||||||
|
}
|
||||||
public getSuggestedDifficulty(clientDifficulty: number) {
|
public getSuggestedDifficulty(clientDifficulty: number) {
|
||||||
|
|
||||||
// miner hasn't submitted shares in one minute
|
// miner hasn't submitted shares in one minute
|
||||||
|
|||||||
Reference in New Issue
Block a user