Added proper block hash to share solution. Added members to emitted share data.
This commit is contained in:
parent
61db6d7ea4
commit
cbcaa1cf98
@ -104,24 +104,7 @@ var JobManager = module.exports = function JobManager(options){
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* Tries to estimate the resulting block hash
|
||||
* This is only valid for scrypt apparently.
|
||||
* @author vekexasia
|
||||
**/
|
||||
function blockHashHex(headerBuffer) {
|
||||
var result = new Buffer(80);
|
||||
for (var i=0; i<20; i++) {
|
||||
for (var j=0; j<4; j++) {
|
||||
result[i*4+j] = headerBuffer[i*4+3-j];
|
||||
}
|
||||
}
|
||||
var shaed = util.reverseBuffer(util.doublesha(result));
|
||||
|
||||
|
||||
return shaed.toString('hex'); // return the expected block hash
|
||||
|
||||
}
|
||||
|
||||
|
||||
//public members
|
||||
|
||||
@ -179,27 +162,27 @@ var JobManager = module.exports = function JobManager(options){
|
||||
var coinbaseBuffer = job.serializeCoinbase(extraNonce1Buffer, extraNonce2Buffer);
|
||||
var coinbaseHash = util.doublesha(coinbaseBuffer);
|
||||
|
||||
var merkleRoot = job.merkleTree.withFirst(coinbaseHash);
|
||||
merkleRoot = util.reverseBuffer(merkleRoot).toString('hex');
|
||||
var merkleRoot = util.reverseBuffer(job.merkleTree.withFirst(coinbaseHash)).toString('hex');
|
||||
|
||||
var headerBuffer = job.serializeHeader(merkleRoot, nTime, nonce);
|
||||
var headerHash = hashDigest(headerBuffer, nTimeInt);
|
||||
var headerBigNum = bignum.fromBuffer(headerHash, {endian: 'little', size: 32});
|
||||
|
||||
|
||||
var blockHash;
|
||||
|
||||
if (job.target.ge(headerBigNum)){
|
||||
var blockBuf = job.serializeBlock(headerBuffer, coinbaseBuffer);
|
||||
// console.log("EXPECTED BLOCK HASH: "+blockHashHex(headerBuffer)); // NOT WORKING :(?
|
||||
_this.emit('blockFound', blockBuf.toString('hex'), blockHashHex(headerBuffer));
|
||||
} else {
|
||||
var blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex');
|
||||
blockHash = util.reverseBuffer(util.doublesha(headerBuffer)).toString('hex');
|
||||
_this.emit('blockFound', blockHex, blockHash);
|
||||
}
|
||||
else {
|
||||
var targetUser = bignum(diffDividend / difficulty);
|
||||
if (headerBigNum.gt(targetUser)){
|
||||
return {error: [23, 'low difficulty share', null]};
|
||||
}
|
||||
}
|
||||
|
||||
return {result: true, headerHEX: headerBigNum.toString(16)};
|
||||
return {result: true, error: null, solution: blockHash};
|
||||
};
|
||||
};
|
||||
JobManager.prototype.__proto__ = events.EventEmitter.prototype;
|
||||
41
lib/pool.js
41
lib/pool.js
@ -42,19 +42,19 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
emitLog('system', 'Detected new block');
|
||||
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
|
||||
}
|
||||
}).on('blockFound', function(blockHex, headerHex){
|
||||
}).on('blockFound', function(blockHex, blockHash){
|
||||
if (options.hasSubmitMethod) {
|
||||
_this.daemon.cmd('submitblock',
|
||||
[blockHex],
|
||||
function(error, result){
|
||||
emitLog('submitblock', 'Submitted Block using submitblock :'+headerHex);
|
||||
emitLog('submitblock', 'Submitted Block using submitblock :'+blockHash);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
_this.daemon.cmd('getblocktemplate',
|
||||
[{'mode': 'submit', 'data': blockHex}],
|
||||
function(error, result){
|
||||
emitLog('submitblock', 'Submitted Block using getblocktemplate: '+headerHex);
|
||||
emitLog('submitblock', 'Submitted Block using getblocktemplate: '+blockHash);
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -150,24 +150,23 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||
params.nTime,
|
||||
params.nonce
|
||||
);
|
||||
if (result.error){
|
||||
resultCallback(result.error);
|
||||
_this.emit('share', false, {
|
||||
client : client,
|
||||
error : result.error
|
||||
});
|
||||
} else {
|
||||
resultCallback(null, true);
|
||||
_this.emit('share', true, {
|
||||
client : client,
|
||||
blockHeaderHex : result.headerHEX,
|
||||
workerName : params.name,
|
||||
jobId : params.jobId,
|
||||
extraNonce2 : params.extraNonce2,
|
||||
nTime : params.nTime,
|
||||
nonce : params.nonce
|
||||
});
|
||||
}
|
||||
|
||||
resultCallback(result.error, result.result ? true : null);
|
||||
|
||||
_this.emit('share', !result.error, {
|
||||
job: params.jobId,
|
||||
ip: client.socket.remoteAddress,
|
||||
worker: params.name,
|
||||
solution: result.solution,
|
||||
error: result.error ? result.error[1] : undefined,
|
||||
difficulty: client.difficulty,
|
||||
timestamp: Date.now() / 1000 | 0,
|
||||
accepted: !!result.result,
|
||||
extraNonce2: params.extraNonce2,
|
||||
nTime: params.nTime,
|
||||
nonce: params.nonce
|
||||
});
|
||||
|
||||
}).on('malformedMessage', function (message) {
|
||||
emitWarningLog('client', client.workerName+" has sent us a malformed message: "+message);
|
||||
}).on('socketError', function() {
|
||||
|
||||
@ -28,6 +28,7 @@ var SubscriptionCounter = function(){
|
||||
var StratumClient = function(options){
|
||||
|
||||
//private members
|
||||
this.socket = options.socket;
|
||||
|
||||
var _this = this;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user