mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
address best diff
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user