Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
traysi committed Mar 17, 2020
1 parent 7083126 commit 9fc88a2
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 80 deletions.
4 changes: 2 additions & 2 deletions lib/algoProperties.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var util = require('./util.js');

var diff1 = global.diff1 = 0x00000fffff000000000000000000000000000000000000000000000000000000;
var diff1 = global.diff1 = 0x00000000ff000000000000000000000000000000000000000000000000000000;

var algos = module.exports = global.algos = {
'kawpow': {
multiplier: 1,
diff: parseInt('0x00000fffff000000000000000000000000000000000000000000000000000000'),
diff: parseInt('0x00000000ff000000000000000000000000000000000000000000000000000000'),
hash: function(){
return function(){
return;
Expand Down
3 changes: 2 additions & 1 deletion lib/blockTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var util = require('./util.js');
var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, reward, recipients, poolAddress){

//epoch length
const EPOCH_LENGTH = 100;
const EPOCH_LENGTH = 7500;

//private members
var submits = [];
Expand All @@ -28,6 +28,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, rewa
this.target_hex = rpcData.target;

this.difficulty = parseFloat((diff1 / this.target.toNumber()).toFixed(9));
console.log("In BlockTemplate difficulty is "+this.difficulty);

//nTime
var nTime = util.packUInt32BE(rpcData.curtime).toString('hex');
Expand Down
212 changes: 135 additions & 77 deletions lib/jobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ var JobManager = module.exports = function JobManager(options) {
};

var job = this.validJobs[miner_given_jobId];
console.log("JOB: "+JSON.stringify(job));

if (typeof job === 'undefined' || job.jobId != miner_given_jobId)
return shareError([20, 'job not found']);
Expand Down Expand Up @@ -241,92 +242,149 @@ var JobManager = module.exports = function JobManager(options) {
var blockHash;
var blockHex;


async.series([
function(callback) {
var kawpowd_url = 'http://'+options.kawpow_wrapper_host+":"+options.kawpow_wrapper_port+'/'+'?header_hash='+header_hash+'&mix_hash='+miner_given_mixhash+'&nonce='+miner_given_nonce+'&height='+job.rpcData.height+'&share_boundary='+target_share_hex+'&block_boundary='+job.target_hex;

http.get(kawpowd_url, function (res) {
res.setEncoding("utf8");
let body = "";
res.on("data", data => {
body += data;
});
res.on("end", () => {
body = JSON.parse(body);
// console.log("JSON RESULT FROM KAWPOWD: "+JSON.stringify(body));
console.log("********** INCOMING SHARE FROM WORKER ************");
console.log("header_hash = " + header_hash);
console.log("miner_sent_header_hash = " + miner_given_header);
console.log("miner_sent_mixhash = " + miner_given_mixhash);
console.log("miner_sent_nonce = " + miner_given_nonce);
console.log("height = " + job.rpcData.height);
console.log("BLOCK.target = " + job.target_hex);
console.log('SHARE.target = ' + target_share_hex);
console.log('digest = ' + body.digest);
console.log("miner_sent_jobid = " + miner_given_jobId);
console.log('job = ' + miner_given_jobId);
console.log('worker = ' + workerName);
console.log('height = ' + job.rpcData.height);
console.log('difficulty = ' + difficulty);
console.log('kawpowd_url = ' + kawpowd_url);
console.log("********** END INCOMING SHARE FROM WORKER ************");
if (body.share == false) {
if (body.block == false) {
// It didn't meet either requirement.
callback('kawpow share didn\'t meet job or block difficulty level', false);
return shareError([20, 'kawpow validation failed']);
console.log("Using "+options.kawpow_validator+" for validation.");

if (options.kawpow_validator == "kawpowd") {

async.series([
function(callback) {
var kawpowd_url = 'http://'+options.kawpow_wrapper_host+":"+options.kawpow_wrapper_port+'/'+'?header_hash='+header_hash+'&mix_hash='+miner_given_mixhash+'&nonce='+miner_given_nonce+'&height='+job.rpcData.height+'&share_boundary='+target_share_hex+'&block_boundary='+job.target_hex;

http.get(kawpowd_url, function (res) {
res.setEncoding("utf8");
let body = "";
res.on("data", data => {
body += data;
});
res.on("end", () => {
body = JSON.parse(body);
// console.log("JSON RESULT FROM KAWPOWD: "+JSON.stringify(body));
console.log("********** INCOMING SHARE FROM WORKER ************");
console.log("header_hash = " + header_hash);
console.log("miner_sent_header_hash = " + miner_given_header);
console.log("miner_sent_mixhash = " + miner_given_mixhash);
console.log("miner_sent_nonce = " + miner_given_nonce);
console.log("height = " + job.rpcData.height);
console.log("job.difficulty = " + job.difficulty);
console.log("BLOCK.target = " + job.target_hex);
console.log('SHARE.target = ' + target_share_hex);
console.log('digest = ' + body.digest);
console.log("miner_sent_jobid = " + miner_given_jobId);
console.log('job = ' + miner_given_jobId);
console.log('worker = ' + workerName);
console.log('height = ' + job.rpcData.height);
console.log('difficulty = ' + difficulty);
console.log('kawpowd_url = ' + kawpowd_url);
console.log("********** END INCOMING SHARE FROM WORKER ************");
if (body.share == false) {
if (body.block == false) {
// It didn't meet either requirement.
callback('kawpow share didn\'t meet job or block difficulty level', false);
return shareError([20, 'kawpow validation failed']);
}
}
}

// At this point, either share or block is true (or both)

if (body.block == true) {
// Good block.
blockHex = job.serializeBlock(new Buffer(header_hash, 'hex'), new Buffer(miner_given_nonce, 'hex'), new Buffer(miner_given_mixhash, 'hex')).toString('hex');
blockHash = body.digest;
}

// At this point, either share or block is true (or both)

if (body.block == true) {
// Good block.
blockHex = job.serializeBlock(new Buffer(header_hash, 'hex'), new Buffer(miner_given_nonce, 'hex'), new Buffer(miner_given_mixhash, 'hex')).toString('hex');
blockHash = body.digest;
}
callback(null, true);
return;
});
});
},
function(callback) {

var blockDiffAdjusted = job.difficulty * shareMultiplier
var shareDiffFixed = undefined;

if (blockHash !== undefined) {
var headerBigNum = bignum.fromBuffer(blockHash, {endian: 'little', size: 32});
var shareDiff = diff1 / headerBigNum.toNumber() * shareMultiplier;
shareDiffFixed = shareDiff.toFixed(8);
}
_this.emit('share', {
job: miner_given_jobId,
ip: ipAddress,
port: port,
worker: workerName,
height: job.rpcData.height,
blockReward: job.rpcData.coinbasevalue,
difficulty: difficulty,
shareDiff: shareDiffFixed,
blockDiff: blockDiffAdjusted,
blockDiffActual: job.difficulty,
blockHash: blockHash,
blockHashInvalid: blockHashInvalid
}, blockHex);

callback_parent({result: true, error: null, blockHash: blockHash});
callback(null, true);
return;
});
}
], function(err, results) {
if (err != null) {
emitErrorLog("kawpow verify failed, ERRORS: "+err);
return;
}
});
},
function(callback) {

var blockDiffAdjusted = job.difficulty * shareMultiplier
var shareDiffFixed = undefined;

if (blockHash !== undefined) {
var headerBigNum = bignum.fromBuffer(blockHash, {endian: 'little', size: 32});
var shareDiff = diff1 / headerBigNum.toNumber() * shareMultiplier;
shareDiffFixed = shareDiff.toFixed(8);
} else {

_this.daemon.cmd('getkawpowhash', [ header_hash, miner_given_mixhash, miner_given_nonce, job.rpcData.height, job.target_hex ], function (results) {

var digest = results[0].response.digest;
var result = results[0].response.result;
var mix_hash = results[0].response.mix_hash;
var meets_target = results[0].response.meets_target;

if (result == 'true') {
// console.log("SHARE IS VALID");
let headerBigNum = BigInt(result, 32);
if (job.target.ge(headerBigNum)) {
// console.log("BLOCK CANDIDATE");
var blockHex = job.serializeBlock(new Buffer(header_hash, 'hex'), new Buffer(miner_given_nonce, 'hex'), new Buffer(mix_hash, 'hex')).toString('hex');
var blockHash = digest;
}
var blockDiffAdjusted = job.difficulty * shareMultiplier
var shareDiffFixed = undefined;

if (blockHash !== undefined) {
var shareDiff = diff1 / headerBigNum * shareMultiplier;
shareDiffFixed = shareDiff.toFixed(8);
}

_this.emit('share', {
job: miner_given_jobId,
ip: ipAddress,
port: port,
worker: workerName,
height: job.rpcData.height,
blockReward: job.rpcData.coinbasevalue,
difficulty: difficulty,
shareDiff: shareDiffFixed,
blockDiff: blockDiffAdjusted,
blockDiffActual: job.difficulty,
blockHash: blockHash,
blockHashInvalid: blockHashInvalid
}, blockHex);

// return {result: true, error: null, blockHash: blockHash};
// callback_parent( {error: error, result: null});
callback_parent({result: true, error: null, blockHash: blockHash});

} else {
// console.log("SHARE FAILED");
return shareError([20, 'bad share: invalid hash']);
}

_this.emit('share', {
job: miner_given_jobId,
ip: ipAddress,
port: port,
worker: workerName,
height: job.rpcData.height,
blockReward: job.rpcData.coinbasevalue,
difficulty: difficulty,
shareDiff: shareDiffFixed,
blockDiff: blockDiffAdjusted,
blockDiffActual: job.difficulty,
blockHash: blockHash,
blockHashInvalid: blockHashInvalid
}, blockHex);

callback_parent({result: true, error: null, blockHash: blockHash});
callback(null, true);
return;

});
}
], function(err, results) {
if (err != null) {
emitErrorLog("kawpow verify failed, ERRORS: "+err);
return;
}
});
}
};
JobManager.prototype.__proto__ = events.EventEmitter.prototype;

0 comments on commit 9fc88a2

Please sign in to comment.