diff --git a/src/models/MiningJob.ts b/src/models/MiningJob.ts index 50ce6ae..387ad1f 100644 --- a/src/models/MiningJob.ts +++ b/src/models/MiningJob.ts @@ -58,9 +58,9 @@ export class MiningJob { } - public copyAndUpdateBlock(jobTemplate: IJobTemplate, versionMask: number, nonce: number, extraNonce: string, extraNonce2: string, timestamp: number): bitcoinjs.Block { + public copyAndUpdateBlock(jobTemplate: { data: IJobTemplate, blockBuffer: Buffer }, versionMask: number, nonce: number, extraNonce: string, extraNonce2: string, timestamp: number): bitcoinjs.Block { - const testBlock = bitcoinjs.Block.fromBuffer(jobTemplate.block.toBuffer()); + const testBlock = bitcoinjs.Block.fromBuffer(jobTemplate.blockBuffer); testBlock.transactions[0] = this.coinbaseTransaction; @@ -77,7 +77,7 @@ export class MiningJob { testBlock.transactions[0].ins[0].script = Buffer.from(`${nonceScript.substring(0, nonceScript.length - 16)}${extraNonce}${extraNonce2}`, 'hex'); //recompute the root since we updated the coinbase script with the nonces - testBlock.merkleRoot = this.calculateMerkleRootHash(testBlock.transactions[0].getHash(false), jobTemplate.merkle_branch); + testBlock.merkleRoot = this.calculateMerkleRootHash(testBlock.transactions[0].getHash(false), jobTemplate.data.merkle_branch); testBlock.timestamp = timestamp; diff --git a/src/models/StratumV1Client.ts b/src/models/StratumV1Client.ts index a18c991..c746fd1 100644 --- a/src/models/StratumV1Client.ts +++ b/src/models/StratumV1Client.ts @@ -90,7 +90,7 @@ export class StratumV1Client extends EasyUnsubscribe { private async handleMessage(message: string) { - console.log(`Received from ${this.extraNonceAndSessionId}`, message); + //console.log(`Received from ${this.extraNonceAndSessionId}`, message); // Parse the message and check if it's the initial subscription message let parsedMessage = null; @@ -291,8 +291,8 @@ export class StratumV1Client extends EasyUnsubscribe { await this.checkDifficulty(); - //await this.watchdog(); - }) + await this.watchdog(); + }); } } @@ -377,24 +377,24 @@ export class StratumV1Client extends EasyUnsubscribe { const header = updatedJobBlock.toBuffer(true); const { submissionDifficulty, submissionHash } = this.calculateDifficulty(header); - console.log(`DIFF: ${submissionDifficulty} of ${this.sessionDifficulty} from ${this.clientAuthorization.worker + '.' + this.extraNonceAndSessionId}`); + //console.log(`DIFF: ${submissionDifficulty} of ${this.sessionDifficulty} from ${this.clientAuthorization.worker + '.' + this.extraNonceAndSessionId}`); if (submissionDifficulty >= this.sessionDifficulty) { - if (submissionDifficulty >= jobTemplate.blockData.networkDifficulty) { + if (submissionDifficulty >= jobTemplate.data.blockData.networkDifficulty) { console.log('!!! BLOCK FOUND !!!'); const blockHex = updatedJobBlock.toHex(false); const result = await this.bitcoinRpcService.SUBMIT_BLOCK(blockHex); await this.blocksService.save({ - height: jobTemplate.blockData.height, + height: jobTemplate.data.blockData.height, minerAddress: this.clientAuthorization.address, worker: this.clientAuthorization.worker, sessionId: this.extraNonceAndSessionId, blockData: blockHex }); - await this.notificationService.notifySubscribersBlockFound(this.clientAuthorization.address, jobTemplate.blockData.height, updatedJobBlock, result); + await this.notificationService.notifySubscribersBlockFound(this.clientAuthorization.address, jobTemplate.data.blockData.height, updatedJobBlock, result); //success if (result == null) { await this.addressSettingsService.resetBestDifficultyAndShares(); diff --git a/src/services/stratum-v1-jobs.service.ts b/src/services/stratum-v1-jobs.service.ts index 92de707..e128ab5 100644 --- a/src/services/stratum-v1-jobs.service.ts +++ b/src/services/stratum-v1-jobs.service.ts @@ -34,7 +34,7 @@ export class StratumV1JobsService { public jobs: MiningJob[] = []; - public blocks: { [id: number]: IJobTemplate } = {}; + public blocks: { [id: number]: { data: IJobTemplate, blockBuffer: Buffer } } = {}; private currentBlockTemplate$: Observable<{ blockTemplate: IBlockTemplate }>; @@ -131,7 +131,10 @@ export class StratumV1JobsService { this.blocks = {}; this.jobs = []; } - this.blocks[data.blockData.id] = data; + this.blocks[data.blockData.id] = { + data, + blockBuffer: data.block.toBuffer() + }; }), shareReplay({ refCount: true, bufferSize: 1 }) ) @@ -154,7 +157,7 @@ export class StratumV1JobsService { return bytes; } - public getJobTemplateById(jobTemplateId: string): IJobTemplate { + public getJobTemplateById(jobTemplateId: string): { data: IJobTemplate, blockBuffer: Buffer } { return this.blocks[jobTemplateId]; }