mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2025-04-14 23:09:26 +02:00
session watchdog
This commit is contained in:
parent
73de187cd9
commit
688eb644ba
@ -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);
|
||||
|
@ -33,7 +33,9 @@ export class StratumV1ClientStatistics {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public getLastSubmissionTime(): Date | null {
|
||||
return this.submissionCache[0]?.time;
|
||||
}
|
||||
public getSuggestedDifficulty(clientDifficulty: number) {
|
||||
|
||||
// miner hasn't submitted shares in one minute
|
||||
|
Loading…
x
Reference in New Issue
Block a user