address best diff

This commit is contained in:
Ben Wilson
2023-07-24 22:23:29 -04:00
parent 8369e9eef2
commit a4b4e517cb
7 changed files with 48 additions and 16 deletions
+14 -1
View File
@@ -8,6 +8,8 @@ import { Socket } from 'net';
import PromiseSocket from 'promise-socket';
import { firstValueFrom, takeUntil } from 'rxjs';
import { AddressSettingsEntity } from '../ORM/address-settings/address-settings.entity';
import { AddressSettingsService } from '../ORM/address-settings/address-settings.service';
import { BlocksService } from '../ORM/blocks/blocks.service';
import { ClientStatisticsService } from '../ORM/client-statistics/client-statistics.service';
import { ClientEntity } from '../ORM/client/client.entity';
@@ -41,6 +43,7 @@ export class StratumV1Client extends EasyUnsubscribe {
private usedSuggestedDifficulty = false;
private sessionDifficulty: number = 16384;
private entity: ClientEntity;
private addressSettings: AddressSettingsEntity;
public extraNonceAndSessionId: string;
@@ -54,7 +57,8 @@ export class StratumV1Client extends EasyUnsubscribe {
private readonly clientStatisticsService: ClientStatisticsService,
private readonly notificationService: NotificationService,
private readonly blocksService: BlocksService,
private readonly configService: ConfigService
private readonly configService: ConfigService,
private readonly addressSettingsService: AddressSettingsService
) {
super();
@@ -259,6 +263,11 @@ export class StratumV1Client extends EasyUnsubscribe {
this.stratumInitialized = true;
this.addressSettings = await this.addressSettingsService.getSettings(this.clientAuthorization.address);
if (this.addressSettings == null) {
this.addressSettingsService.createNew(this.clientAuthorization.address);
}
if (this.clientSuggestedDifficulty == null) {
console.log(`Setting difficulty to ${this.sessionDifficulty}`)
const setDifficulty = JSON.stringify(new SuggestDifficulty().response(this.sessionDifficulty));
@@ -402,6 +411,10 @@ export class StratumV1Client extends EasyUnsubscribe {
this.entity.bestDifficulty = submissionDifficulty;
}
if (submissionDifficulty > this.addressSettings.bestDifficulty) {
await this.addressSettingsService.updateBestDifficulty(this.extraNonceAndSessionId, submissionDifficulty);
}
} else {
const err = new StratumErrorMessage(
submission.id,