diff --git a/src/bitcoin-rpc.service.ts b/src/bitcoin-rpc.service.ts index 577d36e..367dd1a 100644 --- a/src/bitcoin-rpc.service.ts +++ b/src/bitcoin-rpc.service.ts @@ -70,6 +70,7 @@ export class BitcoinRpcService { hexdata }); console.log(`BLOCK SUBMISSION RESPONSE: ${res}`); + console.log(hexdata); console.log(JSON.stringify(res)); process.exit(); } catch (e) { diff --git a/src/models/MiningJob.ts b/src/models/MiningJob.ts index da4ccc7..717d5ba 100644 --- a/src/models/MiningJob.ts +++ b/src/models/MiningJob.ts @@ -73,7 +73,7 @@ export class MiningJob { } - public tryBlock(versionMaskString: number, nonce: number, extraNonce: string, extraNonce2: string): bitcoinjs.Block { + public copyAndUpdateBlock(versionMaskString: number, nonce: number, extraNonce: string, extraNonce2: string): bitcoinjs.Block { const testBlock = bitcoinjs.Block.fromBuffer(this.block.toBuffer()); @@ -91,12 +91,8 @@ export class MiningJob { testBlock.transactions[0].ins[0].script = inputScript; //@ts-ignore - // const test = testBlock.transactions[0].__toBuffer(); - // console.log(test.toString('hex')) - - const newRoot = this.calculateMerkleRootHash(testBlock.transactions[0].__toBuffer(), this.merkle_branch); //recompute the root - testBlock.merkleRoot = newRoot; + testBlock.merkleRoot = this.calculateMerkleRootHash(testBlock.transactions[0].__toBuffer(), this.merkle_branch);; return testBlock; } diff --git a/src/models/StratumV1Client.ts b/src/models/StratumV1Client.ts index 8cbf8cc..63d241b 100644 --- a/src/models/StratumV1Client.ts +++ b/src/models/StratumV1Client.ts @@ -244,7 +244,7 @@ export class StratumV1Client extends EasyUnsubscribe { if (job == null) { return; } - const updatedJobBlock = job.tryBlock( + const updatedJobBlock = job.copyAndUpdateBlock( parseInt(submission.versionMask, 16), parseInt(submission.nonce, 16), this.extraNonce, @@ -255,16 +255,18 @@ export class StratumV1Client extends EasyUnsubscribe { if (diff >= this.clientDifficulty) { - await this.statistics.addSubmission(this.entity, this.clientDifficulty); - if (diff > this.entity.bestDifficulty) { - await this.clientService.updateBestDifficulty(this.extraNonce, diff); - this.entity.bestDifficulty = diff; - } if (diff >= (job.networkDifficulty / 2)) { console.log('!!! BOCK FOUND !!!'); const blockHex = updatedJobBlock.toHex(false); this.bitcoinRpcService.SUBMIT_BLOCK(blockHex); } + + await this.statistics.addSubmission(this.entity, this.clientDifficulty); + if (diff > this.entity.bestDifficulty) { + await this.clientService.updateBestDifficulty(this.extraNonce, diff); + this.entity.bestDifficulty = diff; + } + } else { console.log(`Difficulty too low`); }