mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2025-04-13 06:19:26 +02:00
address best diff
This commit is contained in:
parent
8369e9eef2
commit
a4b4e517cb
@ -8,6 +8,9 @@ export class AddressSettingsEntity extends TrackedEntity {
|
||||
@PrimaryColumn({ length: 62, type: 'varchar' })
|
||||
address: string;
|
||||
|
||||
@Column({ type: 'real', default: 0 })
|
||||
bestDifficulty: number
|
||||
|
||||
@Column()
|
||||
miscCoinbaseScriptData: string;
|
||||
|
||||
|
@ -14,4 +14,15 @@ export class AddressSettingsService {
|
||||
|
||||
}
|
||||
|
||||
public async getSettings(address: string) {
|
||||
return await this.addressSettingsRepository.findOne({ where: { address } });
|
||||
}
|
||||
|
||||
public async updateBestDifficulty(address: string, bestDifficulty: number) {
|
||||
return await this.addressSettingsRepository.update({ address }, { bestDifficulty });
|
||||
}
|
||||
|
||||
public async createNew(address: string) {
|
||||
return await this.addressSettingsRepository.save({ address });
|
||||
}
|
||||
}
|
@ -45,14 +45,6 @@ export class ClientService {
|
||||
return await this.clientRepository.count();
|
||||
}
|
||||
|
||||
public async getBestDiff(address: string) {
|
||||
const res = await this.clientRepository.createQueryBuilder('client')
|
||||
.select('MAX(client.bestDifficulty)', 'bestDifficulty')
|
||||
.where('client.address = :address', { address })
|
||||
.withDeleted()
|
||||
.getRawOne();
|
||||
return res?.bestDifficulty;
|
||||
}
|
||||
public async getByAddress(address: string): Promise<ClientEntity[]> {
|
||||
return await this.clientRepository.find({
|
||||
where: {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Controller, Get, NotFoundException, Param } from '@nestjs/common';
|
||||
|
||||
import { AddressSettingsService } from '../../ORM/address-settings/address-settings.service';
|
||||
import { ClientStatisticsService } from '../../ORM/client-statistics/client-statistics.service';
|
||||
import { ClientService } from '../../ORM/client/client.service';
|
||||
|
||||
@ -9,7 +10,8 @@ export class ClientController {
|
||||
|
||||
constructor(
|
||||
private readonly clientService: ClientService,
|
||||
private readonly clientStatisticsService: ClientStatisticsService
|
||||
private readonly clientStatisticsService: ClientStatisticsService,
|
||||
private readonly addressSettingsService: AddressSettingsService
|
||||
) { }
|
||||
|
||||
|
||||
@ -20,10 +22,12 @@ export class ClientController {
|
||||
|
||||
const chartData = await this.clientStatisticsService.getChartDataForAddress(address);
|
||||
|
||||
const bestDifficulty = await this.clientService.getBestDiff(address);
|
||||
const addressSettings = await this.addressSettingsService.getSettings(address);
|
||||
|
||||
|
||||
|
||||
return {
|
||||
bestDifficulty,
|
||||
bestDifficulty: addressSettings?.bestDifficulty,
|
||||
workersCount: workers.length,
|
||||
workers: await Promise.all(
|
||||
workers.map(async (worker) => {
|
||||
|
@ -6,6 +6,8 @@ import { BehaviorSubject } from 'rxjs';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
import { MockRecording1 } from '../../test/models/MockRecording1';
|
||||
import { AddressSettingsModule } from '../ORM/address-settings/address-settings.module';
|
||||
import { AddressSettingsService } from '../ORM/address-settings/address-settings.service';
|
||||
import { BlocksService } from '../ORM/blocks/blocks.service';
|
||||
import { ClientStatisticsEntity } from '../ORM/client-statistics/client-statistics.entity';
|
||||
import { ClientStatisticsModule } from '../ORM/client-statistics/client-statistics.module';
|
||||
@ -65,7 +67,8 @@ describe('StratumV1Client', () => {
|
||||
logging: false
|
||||
}),
|
||||
ClientModule,
|
||||
ClientStatisticsModule
|
||||
ClientStatisticsModule,
|
||||
AddressSettingsModule
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
@ -119,6 +122,8 @@ describe('StratumV1Client', () => {
|
||||
|
||||
promiseSocket.end = jest.fn();
|
||||
|
||||
const addressSettings = moduleRef.get<AddressSettingsService>(AddressSettingsService);
|
||||
|
||||
|
||||
client = new StratumV1Client(
|
||||
promiseSocket,
|
||||
@ -128,7 +133,8 @@ describe('StratumV1Client', () => {
|
||||
clientStatisticsService,
|
||||
notificationService,
|
||||
blocksService,
|
||||
configService
|
||||
configService,
|
||||
addressSettings
|
||||
);
|
||||
|
||||
client.extraNonceAndSessionId = MockRecording1.EXTRA_NONCE;
|
||||
|
@ -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,
|
||||
|
@ -4,6 +4,7 @@ import { Server, Socket } from 'net';
|
||||
import { PromiseSocket } from 'promise-socket';
|
||||
|
||||
import { StratumV1Client } from '../models/StratumV1Client';
|
||||
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 { ClientService } from '../ORM/client/client.service';
|
||||
@ -22,7 +23,8 @@ export class StratumV1Service implements OnModuleInit {
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly blocksService: BlocksService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly stratumV1JobsService: StratumV1JobsService
|
||||
private readonly stratumV1JobsService: StratumV1JobsService,
|
||||
private readonly addressSettingsService: AddressSettingsService
|
||||
) {
|
||||
|
||||
}
|
||||
@ -49,7 +51,8 @@ export class StratumV1Service implements OnModuleInit {
|
||||
this.clientStatisticsService,
|
||||
this.notificationService,
|
||||
this.blocksService,
|
||||
this.configService
|
||||
this.configService,
|
||||
this.addressSettingsService
|
||||
);
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user