Fixed a couple of bugs that were preventing the thing to start in case of POS
This commit is contained in:
parent
863c8bbf5f
commit
4fdd4fcf51
52
lib/pool.js
52
lib/pool.js
|
@ -81,6 +81,10 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||||
_this.daemon.cmd('submitblock',
|
_this.daemon.cmd('submitblock',
|
||||||
[blockHex],
|
[blockHex],
|
||||||
function(error, result){
|
function(error, result){
|
||||||
|
console.log(JSON.stringify([error,result]));
|
||||||
|
emitLog('submitblock', JSON.stringify([error,result]));
|
||||||
|
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
emitErrorLog('submitblock', 'rpc error when submitting block with submitblock')
|
emitErrorLog('submitblock', 'rpc error when submitting block with submitblock')
|
||||||
else
|
else
|
||||||
|
@ -92,6 +96,7 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||||
_this.daemon.cmd('getblocktemplate',
|
_this.daemon.cmd('getblocktemplate',
|
||||||
[{'mode': 'submit', 'data': blockHex}],
|
[{'mode': 'submit', 'data': blockHex}],
|
||||||
function(error, result){
|
function(error, result){
|
||||||
|
console.log(error, result);
|
||||||
if (error)
|
if (error)
|
||||||
emitErrorLog('submitblock', 'rpc error when submitting block with getblocktemplate')
|
emitErrorLog('submitblock', 'rpc error when submitting block with getblocktemplate')
|
||||||
else
|
else
|
||||||
|
@ -182,32 +187,37 @@ var pool = module.exports = function pool(options, authorizeFn){
|
||||||
|
|
||||||
emitLog('system','Connected to daemon');
|
emitLog('system','Connected to daemon');
|
||||||
options.hasSubmitMethod = results.submitMethod;
|
options.hasSubmitMethod = results.submitMethod;
|
||||||
|
if (options.reward === 'POS' && typeof(results.addressInfo.pubkey) == 'undefined') {
|
||||||
|
// address provided is not of the wallet.
|
||||||
|
emitErrorLog('system', 'The address provided is not from the daemon wallet.');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
publicKeyBuffer = options.reward === 'POW' ?
|
||||||
|
util.script_to_address(results.addressInfo.address) :
|
||||||
|
util.script_to_pubkey(results.addressInfo.pubkey);
|
||||||
|
|
||||||
publicKeyBuffer = options.reward === 'POW' ?
|
if (options.difficulty > results.networkDifficulty && options.difficulty > 16){
|
||||||
util.script_to_address(results.addressInfo.address) :
|
var newDiff = results.networkDifficulty > 16 ? results.networkDifficulty : 16;
|
||||||
util.script_to_pubkey(results.addressInfo.pubkey);
|
emitWarningLog('system', 'pool difficulty was set higher than network difficulty of ' + results.networkDifficulty);
|
||||||
|
emitWarningLog('system', 'lowering pool diff from ' + options.difficulty + ' to ' + newDiff);
|
||||||
|
|
||||||
if (options.difficulty > results.networkDifficulty && options.difficulty > 16){
|
options.difficulty = newDiff
|
||||||
var newDiff = results.networkDifficulty > 16 ? results.networkDifficulty : 16;
|
|
||||||
emitWarningLog('system', 'pool difficulty was set higher than network difficulty of ' + results.networkDifficulty);
|
|
||||||
emitWarningLog('system', 'lowering pool diff from ' + options.difficulty + ' to ' + newDiff);
|
|
||||||
|
|
||||||
options.difficulty = newDiff
|
if (options.varDiff.enabled)
|
||||||
|
_this.varDiff.setPoolDifficulty(options.difficulty);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.varDiff.enabled)
|
GetBlockTemplate(function(error, result){
|
||||||
_this.varDiff.setPoolDifficulty(options.difficulty);
|
if (error){
|
||||||
|
console.error(error);
|
||||||
|
emitErrorLog('system', 'Error with initial getblocktemplate');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
SetupBlockPolling();
|
||||||
|
StartStratumServer();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
GetBlockTemplate(function(error, result){
|
|
||||||
if (error){
|
|
||||||
console.error(error);
|
|
||||||
emitErrorLog('system', 'Error with initial getblocktemplate');
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
SetupBlockPolling();
|
|
||||||
StartStratumServer();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}).on('startFailed', function(){
|
}).on('startFailed', function(){
|
||||||
|
|
|
@ -210,7 +210,7 @@ exports.address_to_pubkeyhash = function(addr){
|
||||||
*/
|
*/
|
||||||
exports.script_to_pubkey = function(key){
|
exports.script_to_pubkey = function(key){
|
||||||
if (key.length === 66) key = new Buffer(key, 'hex');
|
if (key.length === 66) key = new Buffer(key, 'hex');
|
||||||
if (key !== 33) throw 'Invalid address';
|
if (key.length !== 33) throw 'Invalid address';
|
||||||
var pubkey = new Buffer(35);
|
var pubkey = new Buffer(35);
|
||||||
pubkey[0] = 0x21;
|
pubkey[0] = 0x21;
|
||||||
pubkey[34] = 0xac;
|
pubkey[34] = 0xac;
|
||||||
|
|
Loading…
Reference in New Issue