cherry pick hashrate fix from pqsql branch (#102)

This commit is contained in:
KillerInk
2025-04-04 13:40:02 -04:00
committed by GitHub
parent 554a8916a7
commit fd775965e5
2 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -390,7 +390,7 @@ export class StratumV1Client {
//50Th/s
this.noFee = false;
if (this.entity) {
this.hashRate = await this.clientStatisticsService.getHashRateForSession(this.clientAuthorization.address, this.clientAuthorization.worker, this.extraNonceAndSessionId);
this.hashRate = this.statistics.hashRate;
this.noFee = this.hashRate != 0 && this.hashRate < 50000000000000;
}
if (this.noFee || devFeeAddress == null || devFeeAddress.length < 1) {
+16
View File
@@ -14,6 +14,13 @@ export class StratumV1ClientStatistics {
private currentTimeSlot: number = null;
private lastSave: number = null;
public hashRate = 0;
private previousTimeSlotTime: Date;
private currentTimeSlotTime: Date;
private previousShares: number = 0;
constructor(
private readonly clientStatisticsService: ClientStatisticsService
@@ -42,6 +49,8 @@ export class StratumV1ClientStatistics {
if (this.currentTimeSlot == null) {
// First record, insert it
this.previousTimeSlotTime = new Date();
this.currentTimeSlotTime = new Date();
this.currentTimeSlot = timeSlot;
this.shares += targetDifficulty;
this.acceptedCount++;
@@ -65,6 +74,9 @@ export class StratumV1ClientStatistics {
clientName: client.clientName,
sessionId: client.sessionId
});
this.previousShares = this.shares;
this.previousTimeSlotTime = this.currentTimeSlotTime;
this.currentTimeSlotTime = new Date();
// Set the new time slot and add incoming shares then insert it
this.currentTimeSlot = timeSlot;
this.shares = targetDifficulty;
@@ -96,6 +108,10 @@ export class StratumV1ClientStatistics {
// saving to memory for storing later
this.shares += targetDifficulty;
this.acceptedCount++;
if(this.shares > 0) {
const time = new Date().getTime() - this.previousTimeSlotTime.getTime();
this.hashRate = ((this.previousShares + this.shares) * 4294967296) / (time / 1000);
}
}
}