(miner, job, blockTemplate, params)
| 587 | } |
| 588 | |
| 589 | function processShare(miner, job, blockTemplate, params) { |
| 590 | let nonce = params.nonce; |
| 591 | let resultHash = params.result; |
| 592 | let template = new Buffer(blockTemplate.buffer.length); |
| 593 | if (!miner.proxy) { |
| 594 | blockTemplate.buffer.copy(template); |
| 595 | template.writeUInt32BE(job.extraNonce, blockTemplate.reserveOffset); |
| 596 | } else { |
| 597 | blockTemplate.buffer.copy(template); |
| 598 | template.writeUInt32BE(job.extraNonce, blockTemplate.reserveOffset); |
| 599 | template.writeUInt32BE(params.poolNonce, job.clientPoolLocation); |
| 600 | template.writeUInt32BE(params.workerNonce, job.clientNonceLocation); |
| 601 | } |
| 602 | let shareBuffer = global.coinFuncs.constructNewBlob(template, new Buffer(nonce, 'hex')); |
| 603 | |
| 604 | let convertedBlob; |
| 605 | let hash; |
| 606 | let shareType; |
| 607 | |
| 608 | if (global.config.pool.trustedMiners && miner.trust.threshold <= 0 && miner.trust.penalty <= 0 && |
| 609 | crypto.randomBytes(1).readUIntBE(0, 1) > miner.trust.probability) { |
| 610 | hash = new Buffer(resultHash, 'hex'); |
| 611 | shareType = true; |
| 612 | } |
| 613 | else { |
| 614 | convertedBlob = global.coinFuncs.convertBlob(shareBuffer); |
| 615 | hash = global.coinFuncs.cryptoNight(convertedBlob); |
| 616 | shareType = false; |
| 617 | } |
| 618 | if (hash.toString('hex') !== resultHash) { |
| 619 | console.error(threadName + "Bad share from miner " + miner.logString); |
| 620 | process.send({type: 'invalidShare'}); |
| 621 | if (miner.incremented === false) { |
| 622 | miner.newDiff = miner.difficulty + 1; |
| 623 | miner.incremented = true; |
| 624 | } else { |
| 625 | miner.newDiff = miner.difficulty - 1; |
| 626 | miner.incremented = false; |
| 627 | } |
| 628 | miner.sendNewJob(); |
| 629 | return false; |
| 630 | } |
| 631 | |
| 632 | let hashArray = hash.toByteArray().reverse(); |
| 633 | let hashNum = bignum.fromBuffer(new Buffer(hashArray)); |
| 634 | let hashDiff = baseDiff.div(hashNum); |
| 635 | |
| 636 | |
| 637 | if (hashDiff.ge(blockTemplate.difficulty)) { |
| 638 | // Submit block to the RPC Daemon. |
| 639 | // Todo: Implement within the coins/<coin>.js file. |
| 640 | global.support.rpcDaemon('submitblock', [shareBuffer.toString('hex')], function (rpcResult) { |
| 641 | if (rpcResult.error) { |
| 642 | // Did not manage to submit a block. Log and continue on. |
| 643 | console.error(threadName + "Error submitting block at height " + job.height + " from " + miner.logString + ", share type: " + shareType + " error: " + JSON.stringify(rpcResult.error)); |
| 644 | recordShareData(miner, job, hashDiff.toString(), false, null, shareType); |
| 645 | // Error on submit, so we'll submit a sanity check for good measure. |
| 646 | templateUpdate(); |
no test coverage detected