sum hashrate

This commit is contained in:
Ben Wilson
2023-08-06 18:16:48 -04:00
parent 24538d34ce
commit 62f528d55f
5 changed files with 15 additions and 30 deletions
+2 -1
View File
@@ -29,7 +29,8 @@ export class ClientEntity extends TrackedEntity {
@Column({ type: 'real', default: 0 }) @Column({ type: 'real', default: 0 })
bestDifficulty: number bestDifficulty: number
@Column({ default: 0 })
hashRate: number;
} }
+3 -2
View File
@@ -30,8 +30,8 @@ export class ClientService {
.execute(); .execute();
} }
public async heartbeat(address: string, clientName: string, sessionId: string) { public async heartbeat(address: string, clientName: string, sessionId: string, hashRate: number) {
return await this.clientRepository.update({ address, clientName, sessionId }, { deletedAt: null, updatedAt: new Date() }); return await this.clientRepository.update({ address, clientName, sessionId }, { hashRate, deletedAt: null, updatedAt: new Date() });
} }
// public async save(client: Partial<ClientEntity>) { // public async save(client: Partial<ClientEntity>) {
@@ -111,6 +111,7 @@ export class ClientService {
.select('client.userAgent as userAgent') .select('client.userAgent as userAgent')
.addSelect('COUNT(client.userAgent)', 'count') .addSelect('COUNT(client.userAgent)', 'count')
.addSelect('MAX(client.bestDifficulty)', 'bestDifficulty') .addSelect('MAX(client.bestDifficulty)', 'bestDifficulty')
.addSelect('SUM(client.hashRate)', 'totalHashRate')
.groupBy('client.userAgent') .groupBy('client.userAgent')
.orderBy('count', 'DESC') .orderBy('count', 'DESC')
.getRawMany(); .getRawMany();
+3 -2
View File
@@ -31,8 +31,9 @@ export class ClientController {
sessionId: worker.sessionId, sessionId: worker.sessionId,
name: worker.clientName, name: worker.clientName,
bestDifficulty: worker.bestDifficulty.toFixed(2), bestDifficulty: worker.bestDifficulty.toFixed(2),
hashRate: (await this.clientStatisticsService.getHashRateForSession(worker.address, worker.clientName, worker.sessionId)).toFixed(2), hashRate: worker.hashRate,
startTime: worker.startTime startTime: worker.startTime,
lastSeen: worker.updatedAt
}; };
}) })
) )
+7 -22
View File
@@ -44,8 +44,9 @@ export class StratumV1Client {
private entity: ClientEntity; private entity: ClientEntity;
public extraNonceAndSessionId: string; public extraNonceAndSessionId: string;
public sessionStart: Date; public sessionStart: Date;
public noFee: boolean;
public hashRate: number;
constructor( constructor(
@@ -326,7 +327,6 @@ export class StratumV1Client {
} }
this.entity = await this.clientService.insert({ this.entity = await this.clientService.insert({
sessionId: this.extraNonceAndSessionId, sessionId: this.extraNonceAndSessionId,
address: this.clientAuthorization.address, address: this.clientAuthorization.address,
@@ -348,35 +348,20 @@ export class StratumV1Client {
this.backgroundWork = setInterval(async () => { this.backgroundWork = setInterval(async () => {
await this.checkDifficulty(); await this.checkDifficulty();
//await this.watchdog();
}, 60 * 1000); }, 60 * 1000);
} }
} }
// 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;
// // one hour
// if (diffSeconds > 60 * 60) {
// console.log(`Watchdog ending session ${this.extraNonceAndSessionId}}`);
// await 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); this.hashRate = await this.clientStatisticsService.getHashRateForSession(this.clientAuthorization.address, this.clientAuthorization.worker, this.extraNonceAndSessionId);
let payoutInformation; let payoutInformation;
const devFeeAddress = this.configService.get('DEV_FEE_ADDRESS'); const devFeeAddress = this.configService.get('DEV_FEE_ADDRESS');
//50Th/s //50Th/s
const noFee = hashRate != 0 && hashRate < 50000000000000; this.noFee = this.hashRate != 0 && this.hashRate < 50000000000000;
if (noFee || devFeeAddress == null || devFeeAddress.length < 1) { if (this.noFee || devFeeAddress == null || devFeeAddress.length < 1) {
payoutInformation = [ payoutInformation = [
{ address: this.clientAuthorization.address, percent: 100 } { address: this.clientAuthorization.address, percent: 100 }
]; ];
@@ -405,7 +390,7 @@ export class StratumV1Client {
} }
console.log(`Sent new job to ${this.clientAuthorization.worker}.${this.extraNonceAndSessionId}. (clearJobs: ${jobTemplate.blockData.clearJobs}, fee?: ${!noFee})`) console.log(`Sent new job to ${this.clientAuthorization.worker}.${this.extraNonceAndSessionId}. (clearJobs: ${jobTemplate.blockData.clearJobs}, fee?: ${!this.noFee})`)
} }
@@ -465,7 +450,7 @@ export class StratumV1Client {
} }
try { try {
await this.statistics.addSubmission(this.entity, submissionHash, this.sessionDifficulty); await this.statistics.addSubmission(this.entity, submissionHash, this.sessionDifficulty);
//await this.addressSettingsService.addShares(this.clientAuthorization.address, this.sessionDifficulty); await this.clientService.heartbeat(this.entity.address, this.entity.clientName, this.entity.sessionId, this.hashRate);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
const err = new StratumErrorMessage( const err = new StratumErrorMessage(
-3
View File
@@ -42,9 +42,6 @@ export class StratumV1ClientStatistics {
submissionHash submissionHash
}); });
await this.clientService.heartbeat(client.address, client.clientName, client.sessionId)
} }
public getLastSubmissionTime(): Date | null { public getLastSubmissionTime(): Date | null {
return this.submissionCache[this.submissionCache.length - 1]?.time; return this.submissionCache[this.submissionCache.length - 1]?.time;