sync clinets

This commit is contained in:
Ben Wilson
2023-07-24 22:43:31 -04:00
parent f3860b7a76
commit e05beaf915
2 changed files with 7 additions and 10 deletions
@@ -15,7 +15,11 @@ export class AddressSettingsService {
} }
public async getSettings(address: string) { public async getSettings(address: string) {
return await this.addressSettingsRepository.findOne({ where: { address } }); const settings = await this.addressSettingsRepository.findOne({ where: { address } });
if (settings == null) {
return await this.createNew(address);
}
return settings;
} }
public async updateBestDifficulty(address: string, bestDifficulty: number) { public async updateBestDifficulty(address: string, bestDifficulty: number) {
+2 -9
View File
@@ -8,7 +8,6 @@ import { Socket } from 'net';
import PromiseSocket from 'promise-socket'; import PromiseSocket from 'promise-socket';
import { firstValueFrom, takeUntil } from 'rxjs'; import { firstValueFrom, takeUntil } from 'rxjs';
import { AddressSettingsEntity } from '../ORM/address-settings/address-settings.entity';
import { AddressSettingsService } from '../ORM/address-settings/address-settings.service'; import { AddressSettingsService } from '../ORM/address-settings/address-settings.service';
import { BlocksService } from '../ORM/blocks/blocks.service'; import { BlocksService } from '../ORM/blocks/blocks.service';
import { ClientStatisticsService } from '../ORM/client-statistics/client-statistics.service'; import { ClientStatisticsService } from '../ORM/client-statistics/client-statistics.service';
@@ -43,7 +42,6 @@ export class StratumV1Client extends EasyUnsubscribe {
private usedSuggestedDifficulty = false; private usedSuggestedDifficulty = false;
private sessionDifficulty: number = 16384; private sessionDifficulty: number = 16384;
private entity: ClientEntity; private entity: ClientEntity;
private addressSettings: AddressSettingsEntity;
public extraNonceAndSessionId: string; public extraNonceAndSessionId: string;
@@ -263,10 +261,6 @@ export class StratumV1Client extends EasyUnsubscribe {
this.stratumInitialized = true; this.stratumInitialized = true;
this.addressSettings = await this.addressSettingsService.getSettings(this.clientAuthorization.address);
if (this.addressSettings == null) {
this.addressSettings = await this.addressSettingsService.createNew(this.clientAuthorization.address);
}
if (this.clientSuggestedDifficulty == null) { if (this.clientSuggestedDifficulty == null) {
console.log(`Setting difficulty to ${this.sessionDifficulty}`) console.log(`Setting difficulty to ${this.sessionDifficulty}`)
@@ -409,9 +403,8 @@ export class StratumV1Client extends EasyUnsubscribe {
if (submissionDifficulty > this.entity.bestDifficulty) { if (submissionDifficulty > this.entity.bestDifficulty) {
await this.clientService.updateBestDifficulty(this.extraNonceAndSessionId, submissionDifficulty); await this.clientService.updateBestDifficulty(this.extraNonceAndSessionId, submissionDifficulty);
this.entity.bestDifficulty = submissionDifficulty; this.entity.bestDifficulty = submissionDifficulty;
if (submissionDifficulty > this.addressSettings.bestDifficulty) { if (submissionDifficulty > (await this.addressSettingsService.getSettings(this.clientAuthorization.address)).bestDifficulty) {
await this.addressSettingsService.updateBestDifficulty(this.addressSettings.address, submissionDifficulty); await this.addressSettingsService.updateBestDifficulty(this.clientAuthorization.address, submissionDifficulty);
this.addressSettings.bestDifficulty = submissionDifficulty;
} }
} }