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
|
//public members
|
||||||
|
|
||||||
@ -179,27 +162,27 @@ var JobManager = module.exports = function JobManager(options){
|
|||||||
var coinbaseBuffer = job.serializeCoinbase(extraNonce1Buffer, extraNonce2Buffer);
|
var coinbaseBuffer = job.serializeCoinbase(extraNonce1Buffer, extraNonce2Buffer);
|
||||||
var coinbaseHash = util.doublesha(coinbaseBuffer);
|
var coinbaseHash = util.doublesha(coinbaseBuffer);
|
||||||
|
|
||||||
var merkleRoot = job.merkleTree.withFirst(coinbaseHash);
|
var merkleRoot = util.reverseBuffer(job.merkleTree.withFirst(coinbaseHash)).toString('hex');
|
||||||
merkleRoot = util.reverseBuffer(merkleRoot).toString('hex');
|
|
||||||
|
|
||||||
var headerBuffer = job.serializeHeader(merkleRoot, nTime, nonce);
|
var headerBuffer = job.serializeHeader(merkleRoot, nTime, nonce);
|
||||||
var headerHash = hashDigest(headerBuffer, nTimeInt);
|
var headerHash = hashDigest(headerBuffer, nTimeInt);
|
||||||
var headerBigNum = bignum.fromBuffer(headerHash, {endian: 'little', size: 32});
|
var headerBigNum = bignum.fromBuffer(headerHash, {endian: 'little', size: 32});
|
||||||
|
|
||||||
|
var blockHash;
|
||||||
|
|
||||||
if (job.target.ge(headerBigNum)){
|
if (job.target.ge(headerBigNum)){
|
||||||
var blockBuf = job.serializeBlock(headerBuffer, coinbaseBuffer);
|
var blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex');
|
||||||
// console.log("EXPECTED BLOCK HASH: "+blockHashHex(headerBuffer)); // NOT WORKING :(?
|
blockHash = util.reverseBuffer(util.doublesha(headerBuffer)).toString('hex');
|
||||||
_this.emit('blockFound', blockBuf.toString('hex'), blockHashHex(headerBuffer));
|
_this.emit('blockFound', blockHex, blockHash);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
var targetUser = bignum(diffDividend / difficulty);
|
var targetUser = bignum(diffDividend / difficulty);
|
||||||
if (headerBigNum.gt(targetUser)){
|
if (headerBigNum.gt(targetUser)){
|
||||||
return {error: [23, 'low difficulty share', null]};
|
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;
|
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');
|
emitLog('system', 'Detected new block');
|
||||||
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
|
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
|
||||||
}
|
}
|
||||||
}).on('blockFound', function(blockHex, headerHex){
|
}).on('blockFound', function(blockHex, blockHash){
|
||||||
if (options.hasSubmitMethod) {
|
if (options.hasSubmitMethod) {
|
||||||
_this.daemon.cmd('submitblock',
|
_this.daemon.cmd('submitblock',
|
||||||
[blockHex],
|
[blockHex],
|
||||||
function(error, result){
|
function(error, result){
|
||||||
emitLog('submitblock', 'Submitted Block using submitblock :'+headerHex);
|
emitLog('submitblock', 'Submitted Block using submitblock :'+blockHash);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
_this.daemon.cmd('getblocktemplate',
|
_this.daemon.cmd('getblocktemplate',
|
||||||
[{'mode': 'submit', 'data': blockHex}],
|
[{'mode': 'submit', 'data': blockHex}],
|
||||||
function(error, result){
|
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.nTime,
|
||||||
params.nonce
|
params.nonce
|
||||||
);
|
);
|
||||||
if (result.error){
|
|
||||||
resultCallback(result.error);
|
resultCallback(result.error, result.result ? true : null);
|
||||||
_this.emit('share', false, {
|
|
||||||
client : client,
|
_this.emit('share', !result.error, {
|
||||||
error : result.error
|
job: params.jobId,
|
||||||
});
|
ip: client.socket.remoteAddress,
|
||||||
} else {
|
worker: params.name,
|
||||||
resultCallback(null, true);
|
solution: result.solution,
|
||||||
_this.emit('share', true, {
|
error: result.error ? result.error[1] : undefined,
|
||||||
client : client,
|
difficulty: client.difficulty,
|
||||||
blockHeaderHex : result.headerHEX,
|
timestamp: Date.now() / 1000 | 0,
|
||||||
workerName : params.name,
|
accepted: !!result.result,
|
||||||
jobId : params.jobId,
|
extraNonce2: params.extraNonce2,
|
||||||
extraNonce2 : params.extraNonce2,
|
nTime: params.nTime,
|
||||||
nTime : params.nTime,
|
nonce: params.nonce
|
||||||
nonce : params.nonce
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}).on('malformedMessage', function (message) {
|
}).on('malformedMessage', function (message) {
|
||||||
emitWarningLog('client', client.workerName+" has sent us a malformed message: "+message);
|
emitWarningLog('client', client.workerName+" has sent us a malformed message: "+message);
|
||||||
}).on('socketError', function() {
|
}).on('socketError', function() {
|
||||||
|
|||||||
@ -28,6 +28,7 @@ var SubscriptionCounter = function(){
|
|||||||
var StratumClient = function(options){
|
var StratumClient = function(options){
|
||||||
|
|
||||||
//private members
|
//private members
|
||||||
|
this.socket = options.socket;
|
||||||
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user