session watchdog

This commit is contained in:
Ben Wilson
2023-07-17 00:55:09 -04:00
parent 73de187cd9
commit 688eb644ba
2 changed files with 24 additions and 2 deletions
+21 -1
View File
@@ -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);
+3 -1
View File
@@ -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