mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
better way to calculate hashrate
This commit is contained in:
@@ -8,15 +8,12 @@ export class StratumV1ClientStatistics {
|
|||||||
public targetSubmitShareEveryNSeconds: number = 30;
|
public targetSubmitShareEveryNSeconds: number = 30;
|
||||||
public hashRate = 0;
|
public hashRate = 0;
|
||||||
|
|
||||||
private previousTimeSlotTime: Date;
|
|
||||||
private currentTimeSlotTime: Date;
|
|
||||||
|
|
||||||
private previousShares: number = 0;
|
|
||||||
private shares: number = 0;
|
private shares: number = 0;
|
||||||
private acceptedCount: number = 0;
|
private acceptedCount: number = 0;
|
||||||
|
|
||||||
private submissionCacheStart: Date;
|
private submissionCacheStart: Date;
|
||||||
private submissionCache: { time: Date, difficulty: number }[] = [];
|
private submissionCache: { time: Date, difficulty: number }[] = [];
|
||||||
|
private submissionCacheDifficultySum = 0;
|
||||||
|
|
||||||
private currentTimeSlot: number = null;
|
private currentTimeSlot: number = null;
|
||||||
|
|
||||||
@@ -38,17 +35,17 @@ export class StratumV1ClientStatistics {
|
|||||||
var timeSlot = new Date(Math.floor(date.getTime() / coeff) * coeff).getTime();
|
var timeSlot = new Date(Math.floor(date.getTime() / coeff) * coeff).getTime();
|
||||||
|
|
||||||
if (this.submissionCache.length > CACHE_SIZE) {
|
if (this.submissionCache.length > CACHE_SIZE) {
|
||||||
|
this.submissionCacheDifficultySum -= this.submissionCache[0].difficulty;
|
||||||
this.submissionCache.shift();
|
this.submissionCache.shift();
|
||||||
}
|
}
|
||||||
this.submissionCache.push({
|
this.submissionCache.push({
|
||||||
time: date,
|
time: date,
|
||||||
difficulty: targetDifficulty,
|
difficulty: targetDifficulty,
|
||||||
});
|
});
|
||||||
|
this.submissionCacheDifficultySum += targetDifficulty;
|
||||||
|
|
||||||
if (this.currentTimeSlot == null) {
|
if (this.currentTimeSlot == null) {
|
||||||
// First record, insert it
|
// First record, insert it
|
||||||
this.previousTimeSlotTime = new Date();
|
|
||||||
this.currentTimeSlotTime = new Date();
|
|
||||||
this.currentTimeSlot = timeSlot;
|
this.currentTimeSlot = timeSlot;
|
||||||
this.shares += targetDifficulty;
|
this.shares += targetDifficulty;
|
||||||
this.acceptedCount++;
|
this.acceptedCount++;
|
||||||
@@ -70,9 +67,6 @@ export class StratumV1ClientStatistics {
|
|||||||
shares: this.shares,
|
shares: this.shares,
|
||||||
acceptedCount: this.acceptedCount,
|
acceptedCount: this.acceptedCount,
|
||||||
});
|
});
|
||||||
this.previousShares = this.shares;
|
|
||||||
this.previousTimeSlotTime = this.currentTimeSlotTime;
|
|
||||||
this.currentTimeSlotTime = new Date();
|
|
||||||
// Set the new time slot and add incoming shares then insert it
|
// Set the new time slot and add incoming shares then insert it
|
||||||
this.currentTimeSlot = timeSlot;
|
this.currentTimeSlot = timeSlot;
|
||||||
this.shares = targetDifficulty;
|
this.shares = targetDifficulty;
|
||||||
@@ -99,9 +93,9 @@ export class StratumV1ClientStatistics {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const time = new Date().getTime() - this.previousTimeSlotTime.getTime();
|
const time = new Date().getTime() - this.submissionCache[0].time.getTime();
|
||||||
if(this.shares > 0 && time > 60000) {
|
if(time > 60000 && this.submissionCache.length > 2) {
|
||||||
this.hashRate = ((this.previousShares + this.shares) * 4294967296) / (time / 1000);
|
this.hashRate = (this.submissionCacheDifficultySum * 4294967296) / (time / 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user