From 37a65e43b29ce73df0efdf39def270b38f273355 Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Wed, 28 Jun 2023 10:23:54 -0400 Subject: [PATCH] reduce minimum diff --- src/models/StratumV1Client.ts | 17 ++++++++++------- src/models/StratumV1ClientStatistics.ts | 12 ++++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/models/StratumV1Client.ts b/src/models/StratumV1Client.ts index 78acf16..98800a5 100644 --- a/src/models/StratumV1Client.ts +++ b/src/models/StratumV1Client.ts @@ -77,7 +77,7 @@ export class StratumV1Client extends EasyUnsubscribe { private async handleMessage(socket: Socket, message: string) { - console.log('Received:', message); + //console.log('Received:', message); // Parse the message and check if it's the initial subscription message let parsedMessage = null; @@ -233,6 +233,7 @@ export class StratumV1Client extends EasyUnsubscribe { let clearJobs = false; if (lastIntervalCount === interValCount) { clearJobs = true; + console.log('new block') } lastIntervalCount = interValCount; @@ -263,7 +264,7 @@ export class StratumV1Client extends EasyUnsubscribe { this.socket.write(job.response + '\n'); - + console.log(`Sent new job to ${this.extraNonce}. (clearJobs: ${clearJobs})`) } @@ -284,7 +285,7 @@ export class StratumV1Client extends EasyUnsubscribe { ); const submissionDifficulty = this.calculateDifficulty(updatedJobBlock.toBuffer(true)); - console.log(`DIFF: ${submissionDifficulty} of ${this.sessionDifficulty}`); + console.log(`DIFF: ${Math.round(submissionDifficulty)} of ${this.sessionDifficulty} from ${this.clientAuthorization.worker + '.' + this.extraNonce}`); if (submissionDifficulty >= this.sessionDifficulty) { @@ -323,14 +324,16 @@ export class StratumV1Client extends EasyUnsubscribe { method: eResponseMethod.SET_DIFFICULTY, params: [targetDiff] } - ) + '\n'); + ) + '\n', () => { - // we need to clear the jobs so that the difficulty set takes effect. Otherwise the different miner implementations can cause issues - this.blockTemplateService.currentBlockTemplate$.pipe(take(1)).subscribe(({ blockTemplate }) => { - this.sendNewMiningJob(blockTemplate, true); + // we need to clear the jobs so that the difficulty set takes effect. Otherwise the different miner implementations can cause issues + this.blockTemplateService.currentBlockTemplate$.pipe(take(1)).subscribe(({ blockTemplate }) => { + this.sendNewMiningJob(blockTemplate, true); + }); }); + } } diff --git a/src/models/StratumV1ClientStatistics.ts b/src/models/StratumV1ClientStatistics.ts index b61ddea..ed55644 100644 --- a/src/models/StratumV1ClientStatistics.ts +++ b/src/models/StratumV1ClientStatistics.ts @@ -63,18 +63,18 @@ export class StratumV1ClientStatistics { } - private blpo2(x) { - x = x | (x >> 1); + private blpo2(val) { + let x = val | (val >> 1); x = x | (x >> 2); x = x | (x >> 4); x = x | (x >> 8); x = x | (x >> 16); x = x | (x >> 32); - const val = x - (x >> 1); - if (val < 1) { - return 1; + const res = x - (x >> 1); + if (res < 1) { + return this.blpo2(val * 100) / 100; } - return val; + return res; }