back port some changes from postgres

This commit is contained in:
Ben
2023-12-23 19:30:05 -05:00
parent 8f6eeaba73
commit 38fda85f63
7 changed files with 55 additions and 33 deletions
+3 -3
View File
@@ -479,7 +479,7 @@ export class StratumV1Client {
parseInt(submission.ntime, 16)
);
const header = updatedJobBlock.toBuffer(true);
const { submissionDifficulty, submissionHash } = this.calculateDifficulty(header);
const { submissionDifficulty } = this.calculateDifficulty(header);
//console.log(`DIFF: ${submissionDifficulty} of ${this.sessionDifficulty} from ${this.clientAuthorization.worker + '.' + this.extraNonceAndSessionId}`);
@@ -505,7 +505,7 @@ export class StratumV1Client {
}
}
try {
await this.statistics.addSubmission(this.entity, submissionHash, this.sessionDifficulty);
await this.statistics.addSubmission(this.entity, this.sessionDifficulty);
await this.clientService.heartbeat(this.entity.address, this.entity.clientName, this.entity.sessionId, this.hashRate);
} catch (e) {
console.log(e);
@@ -524,7 +524,7 @@ export class StratumV1Client {
if (submissionDifficulty > this.entity.bestDifficulty) {
await this.clientService.updateBestDifficulty(this.extraNonceAndSessionId, submissionDifficulty);
this.entity.bestDifficulty = submissionDifficulty;
if (submissionDifficulty > (await this.addressSettingsService.getSettings(this.clientAuthorization.address)).bestDifficulty) {
if (submissionDifficulty > (await this.addressSettingsService.getSettings(this.clientAuthorization.address, true)).bestDifficulty) {
await this.addressSettingsService.updateBestDifficulty(this.clientAuthorization.address, submissionDifficulty);
}
}
+3 -4
View File
@@ -17,7 +17,7 @@ export class StratumV1ClientStatistics {
this.submissionCacheStart = new Date();
}
public async addSubmission(client: ClientEntity, submissionHash: string, targetDifficulty: number) {
public async addSubmission(client: ClientEntity, targetDifficulty: number) {
if (this.submissionCache.length > CACHE_SIZE) {
this.submissionCache.shift();
@@ -31,15 +31,14 @@ export class StratumV1ClientStatistics {
// 10 min
var coeff = 1000 * 60 * 10;
var date = new Date();
var rounded = new Date(Math.round(date.getTime() / coeff) * coeff);
var rounded = new Date(Math.floor(date.getTime() / coeff) * coeff);
await this.clientStatisticsService.save({
time: rounded.getTime(),
shares: targetDifficulty,
address: client.address,
clientName: client.clientName,
sessionId: client.sessionId,
submissionHash
sessionId: client.sessionId
});
}