Fixed block submission hex.

This commit is contained in:
Andrea Baccega 2014-01-12 14:10:40 +01:00
parent 43517a8824
commit cb1e40d8eb
7 changed files with 50 additions and 14 deletions

View File

@ -44,6 +44,12 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
extraNoncePlaceholder extraNoncePlaceholder
); );
/**
* Checks if the rpcData provided as argument contains the same previousblockhash of the current job.
**/
this.isRPCDataFromSameBlock = function(rpcData) {
return this.rpcData.previousblockhash == rpcData.previousblockhash;
}
this.serializeCoinbase = function(extraNonce1, extraNonce2){ this.serializeCoinbase = function(extraNonce1, extraNonce2){
return Buffer.concat([ return Buffer.concat([
this.generationTransaction.coinbase[0], this.generationTransaction.coinbase[0],
@ -71,7 +77,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, publ
this.serializeBlock = function(header, coinbase){ this.serializeBlock = function(header, coinbase){
return Buffer.concat([ return Buffer.concat([
header, header,
util.varIntBuffer(this.rpcData.transaction.length + 1), util.varIntBuffer(this.rpcData.transactions.length + 1),
coinbase, coinbase,
this.transactionData this.transactionData
]); ]);

View File

@ -3,13 +3,13 @@
"symbol": "doge", "symbol": "doge",
"algorithm": "scrypt", "algorithm": "scrypt",
"reward": "POW", "reward": "POW",
"address": "DDt79i6P3Wro3SD3HSnkRLpMgUGUGdiNhS", "address": "mkLyYQ5U8aFQ8aDAF1GS9zXStTzi3m29Tg",
"stratumPort": 3334, "stratumPort": 3334,
"difficulty": 8, "difficulty": 8,
"daemon": { "daemon": {
"host": "localhost", "host": "localhost",
"port": 8332, "port": 19334,
"user": "test", "user": "testnet",
"password": "test" "password": "AHhQYqfSZqzQvkSXAtHtDAbKaZaoPih3wfmJfgCtjRx9"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"blockNotifyListener": { "blockNotifyListener": {
"enabled": true, "enabled": false,
"port": 8117, "port": 8117,
"password": "test" "password": "test"
} }

View File

@ -55,6 +55,11 @@ function DaemonInterface(options){
params: params params: params
}); });
if (method == 'submitblock') {
console.log("SUBMITBLOCK daemon");
console.log(requestJson);
}
var options = { var options = {
hostname: 'localhost', hostname: 'localhost',
port: _this.options.port, port: _this.options.port,

13
init.js
View File

@ -42,6 +42,7 @@ fs.readdir(confFolder, function(err, files){
if (config.blockNotifyListener.enabled){ if (config.blockNotifyListener.enabled){
console.log("ENABLED");
var blockNotifyServer = net.createServer(function(c) { var blockNotifyServer = net.createServer(function(c) {
console.log('server connected'); console.log('server connected');
var data = ''; var data = '';
@ -69,4 +70,16 @@ if (config.blockNotifyListener.enabled){
}); });
}); });
blockNotifyServer.listen(config.blockNotifyListener.port, function() {}); blockNotifyServer.listen(config.blockNotifyListener.port, function() {});
} else {
console.log("NOT ENABLED");
// If blockNotifyListener isn't enabled then we need to set up some polling parameters.
var pollingTime = typeof(config.blockPollingTime) === 'undefined' ? 5000 : parseInt(config.blockPollingTime, 10);
setInterval(
function () {
coins.forEach(function(coin) {
//coin.pool.
});
},
pollingTime
);
} }

View File

@ -145,8 +145,8 @@ var JobManager = module.exports = function JobManager(options){
var headerBigNum = bignum.fromBuffer(headerHash, {endian: 'little', size: 32}); var headerBigNum = bignum.fromBuffer(headerHash, {endian: 'little', size: 32});
if (job.target.ge(headerBigNum)){ if (job.target.ge(headerBigNum)){
var blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer); var blockBuf = job.serializeBlock(headerBuffer, coinbaseBuffer);
_this.emit('blockFound', blockHex); _this.emit('blockFound', blockBuf.toString('hex'));
} }
var targetUser = bignum(diffDividend / difficulty); var targetUser = bignum(diffDividend / difficulty);

22
pool.js
View File

@ -24,20 +24,25 @@ var pool = module.exports = function pool(coin){
_this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams()); _this.stratumServer.broadcastMiningJobs(blockTemplate.getJobParams());
}).on('blockFound', function(blockHex){ }).on('blockFound', function(blockHex){
if (coin.options.hasSubmitMethod) if (coin.options.hasSubmitMethod) {
_this.daemon.cmd('submitblock', _this.daemon.cmd('submitblock',
[blockHex], [blockHex],
function(error, result){ function(error, result){
console.log(JSON.stringify(error));
console.log(JSON.stringify(result));
console.log("submitblock", JSON.stringify(error), JSON.stringify(result));
} }
); );
else } else {
_this.daemon.cmd('getblocktemplate', _this.daemon.cmd('getblocktemplate',
[{'mode': 'submit', 'data': blockHex}], [{'mode': 'submit', 'data': blockHex}],
function(error, result){ function(error, result){
console.log(JSON.stringify(error));
console.log(JSON.stringify(result));
console.log("submitblockgetBlockTEmplate", JSON.stringify(error), JSON.stringify(result));
} }
); );
}
}); });
console.log('Connecting to daemon for ' + coin.options.name); console.log('Connecting to daemon for ' + coin.options.name);
@ -132,11 +137,11 @@ var pool = module.exports = function pool(coin){
} }
function GetBlockTemplate(callback){ function GetBlockTemplate(callback){
console.log("getBlockTemplate");
_this.daemon.cmd('getblocktemplate', _this.daemon.cmd('getblocktemplate',
[{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}], [{"capabilities": [ "coinbasetxn", "workid", "coinbase/append" ]}],
function(error, result){ function(error, result){
if (error){ if (error){
console.log('getblocktemplate rpc error for ' + coin.options.name);
callback(error); callback(error);
} }
else{ else{
@ -146,6 +151,13 @@ var pool = module.exports = function pool(coin){
); );
} }
this.processBlockPolling = function() {
GetBlockTemplate(function(error, result) {
console.log(JSON.stringify(result));
_this.jobManager.newTemplate(result, publicKeyBuffer);
});
}
this.processBlockNotify = function(blockHash){ this.processBlockNotify = function(blockHash){
if (blockHash !== _this.jobManager.currentJob.rpcData.previousblockhash){ if (blockHash !== _this.jobManager.currentJob.rpcData.previousblockhash){
GetBlockTemplate(function(error, result){ GetBlockTemplate(function(error, result){