optimizations

This commit is contained in:
Ben Wilson
2023-08-04 16:34:49 -04:00
parent 6423e2cb67
commit f85967daf8
6 changed files with 55 additions and 17 deletions
+6 -3
View File
@@ -75,7 +75,7 @@ export class StratumV1Client extends EasyUnsubscribe {
});
this.sessionStart = new Date();
this.statistics = new StratumV1ClientStatistics(this.clientStatisticsService);
this.statistics = new StratumV1ClientStatistics(this.clientStatisticsService, this.clientService);
this.extraNonceAndSessionId = this.getRandomHexString();
console.log(`New client ID: : ${this.extraNonceAndSessionId}`);
}
@@ -349,8 +349,11 @@ export class StratumV1Client extends EasyUnsubscribe {
this.stratumV1JobsService.addJob(job);
await this.promiseSocket.write(job.response(jobTemplate));
try {
await this.promiseSocket.write(job.response(jobTemplate));
} catch (e) {
console.log(e);
}
console.log(`Sent new job to ${this.clientAuthorization.worker}.${this.extraNonceAndSessionId}. (clearJobs: ${jobTemplate.blockData.clearJobs}, fee?: ${!noFee})`)
+8 -1
View File
@@ -1,5 +1,6 @@
import { ClientStatisticsService } from '../ORM/client-statistics/client-statistics.service';
import { ClientEntity } from '../ORM/client/client.entity';
import { ClientService } from '../ORM/client/client.service';
const CACHE_SIZE = 30;
const TARGET_SUBMISSION_PER_SECOND = 10;
@@ -9,7 +10,10 @@ export class StratumV1ClientStatistics {
private submissionCacheStart: Date;
private submissionCache = [];
constructor(private readonly clientStatisticsService: ClientStatisticsService) {
constructor(
private readonly clientStatisticsService: ClientStatisticsService,
private readonly clientService: ClientService
) {
this.submissionCacheStart = new Date();
}
@@ -38,6 +42,9 @@ export class StratumV1ClientStatistics {
submissionHash
});
await this.clientService.heartbeat(client.address, client.clientName, client.sessionId)
}
public getLastSubmissionTime(): Date | null {
return this.submissionCache[this.submissionCache.length - 1]?.time;