mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
sum hashrate
This commit is contained in:
@@ -29,7 +29,8 @@ export class ClientEntity extends TrackedEntity {
|
||||
@Column({ type: 'real', default: 0 })
|
||||
bestDifficulty: number
|
||||
|
||||
|
||||
@Column({ default: 0 })
|
||||
hashRate: number;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ export class ClientService {
|
||||
.execute();
|
||||
}
|
||||
|
||||
public async heartbeat(address: string, clientName: string, sessionId: string) {
|
||||
return await this.clientRepository.update({ address, clientName, sessionId }, { deletedAt: null, updatedAt: new Date() });
|
||||
public async heartbeat(address: string, clientName: string, sessionId: string, hashRate: number) {
|
||||
return await this.clientRepository.update({ address, clientName, sessionId }, { hashRate, deletedAt: null, updatedAt: new Date() });
|
||||
}
|
||||
|
||||
// public async save(client: Partial<ClientEntity>) {
|
||||
@@ -111,6 +111,7 @@ export class ClientService {
|
||||
.select('client.userAgent as userAgent')
|
||||
.addSelect('COUNT(client.userAgent)', 'count')
|
||||
.addSelect('MAX(client.bestDifficulty)', 'bestDifficulty')
|
||||
.addSelect('SUM(client.hashRate)', 'totalHashRate')
|
||||
.groupBy('client.userAgent')
|
||||
.orderBy('count', 'DESC')
|
||||
.getRawMany();
|
||||
|
||||
@@ -31,8 +31,9 @@ export class ClientController {
|
||||
sessionId: worker.sessionId,
|
||||
name: worker.clientName,
|
||||
bestDifficulty: worker.bestDifficulty.toFixed(2),
|
||||
hashRate: (await this.clientStatisticsService.getHashRateForSession(worker.address, worker.clientName, worker.sessionId)).toFixed(2),
|
||||
startTime: worker.startTime
|
||||
hashRate: worker.hashRate,
|
||||
startTime: worker.startTime,
|
||||
lastSeen: worker.updatedAt
|
||||
};
|
||||
})
|
||||
)
|
||||
|
||||
@@ -44,8 +44,9 @@ export class StratumV1Client {
|
||||
private entity: ClientEntity;
|
||||
|
||||
public extraNonceAndSessionId: string;
|
||||
|
||||
public sessionStart: Date;
|
||||
public noFee: boolean;
|
||||
public hashRate: number;
|
||||
|
||||
|
||||
constructor(
|
||||
@@ -326,7 +327,6 @@ export class StratumV1Client {
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.entity = await this.clientService.insert({
|
||||
sessionId: this.extraNonceAndSessionId,
|
||||
address: this.clientAuthorization.address,
|
||||
@@ -348,35 +348,20 @@ export class StratumV1Client {
|
||||
|
||||
this.backgroundWork = setInterval(async () => {
|
||||
await this.checkDifficulty();
|
||||
//await this.watchdog();
|
||||
}, 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) {
|
||||
|
||||
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;
|
||||
const devFeeAddress = this.configService.get('DEV_FEE_ADDRESS');
|
||||
//50Th/s
|
||||
const noFee = hashRate != 0 && hashRate < 50000000000000;
|
||||
if (noFee || devFeeAddress == null || devFeeAddress.length < 1) {
|
||||
this.noFee = this.hashRate != 0 && this.hashRate < 50000000000000;
|
||||
if (this.noFee || devFeeAddress == null || devFeeAddress.length < 1) {
|
||||
payoutInformation = [
|
||||
{ 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 {
|
||||
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) {
|
||||
console.log(e);
|
||||
const err = new StratumErrorMessage(
|
||||
|
||||
@@ -42,9 +42,6 @@ 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;
|
||||
|
||||
Reference in New Issue
Block a user