Skip to content

Commit

Permalink
resolve some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
vorujack committed Jan 1, 2021
1 parent a312325 commit 979796a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/blockTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ var BlockTemplate = module.exports = function BlockTemplate(jobId, rpcData, pool
var b = JSONbig.stringify(rpcData.b);
this.jobParams = [
this.jobId,
"",//this.prevHashReversed,
this.rpcData.height,//this.prevHashReversed,
this.rpcData.msg,// this.generationTransaction[0].toString('hex'),
"",// this.generationTransaction[1].toString('hex'),
"",// this.merkleBranch,
Expand Down
26 changes: 15 additions & 11 deletions lib/jobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ var events = require('events');
var crypto = require('crypto');
var blake2 = require('blake2');
var bignum = require('bignum');
var uint64be = require('uint64be')

// var BigInt = require('bigint-buffer/helper/bigint');
const BigIntBuffer = require('bigint-buffer');

const N = BigInt(Math.pow(2, 26));
const M = Buffer.concat(Array(1024).fill().map((_, i) => uint64be.encode(i)));


var util = require('./util.js');
Expand Down Expand Up @@ -193,8 +197,6 @@ var JobManager = module.exports = function JobManager(options){
return {error: error, result: null};
};

var submitTime = Date.now() / 1000 | 0;

if (extraNonce2.length / 2 !== _this.extraNonce2Size)
return shareError([20, 'incorrect size of extranonce2']);

Expand Down Expand Up @@ -228,16 +230,18 @@ var JobManager = module.exports = function JobManager(options){

var coinbaseBuffer = job.serializeCoinbase(extraNonce1Buffer, extraNonce2Buffer);
var h = BigIntBuffer.toBufferBE(BigInt(job.rpcData.height), 8);
var i = BigIntBuffer.toBigIntBE(blake2b(coinbaseBuffer).slice(0, 8)) % N;
var i = BigIntBuffer.toBufferBE(BigIntBuffer.toBigIntBE(blake2b(coinbaseBuffer).slice(24, 32)) % N, 4);
var e = blake2b(Buffer.concat([
BigIntBuffer.toBufferBE(i, 8),
h
])).slice(0, 31);
var J = genIndexes(Buffer.concat([e, coinbaseBuffer]));
var f = J.map(item => BigIntBuffer.toBigIntBE(blake2b(Buffer.concat([
BigIntBuffer.toBufferBE(BigInt(item), 8),
h
])).slice(0, 31))).reduce((a, b) => a + b);
i,
h,
M
])).slice(1, 32);
var J = genIndexes(Buffer.concat([e, coinbaseBuffer])).map(item=>BigIntBuffer.toBufferBE(BigInt(item), 4));
var f = J.map(item => BigIntBuffer.toBigIntBE(
blake2b(
Buffer.concat([item, h, M])
).slice(1, 32)
)).reduce((a, b) => a + b);

var fh = BigIntBuffer.toBigIntBE(blake2b(BigIntBuffer.toBufferBE(f, 32)));
// var coinbaseHash = coinbaseHasher(coinbaseBuffer);
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"bignum": "0.13.1",
"blake2": "^4.0.2",
"json-bigint": "^1.0.0",
"multi-hashing": "git://github.com/zone117x/node-multi-hashing.git"
"multi-hashing": "git://github.com/zone117x/node-multi-hashing.git",
"uint64be": "^3.0.0"
},
"engines": {
"node": ">=0.10"
Expand Down
2 changes: 2 additions & 0 deletions start.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,6 @@ pool.on('log', function(severity, logKey, logText){
console.log(severity + ': ' + '[' + logKey + '] ' + logText);
});

var uint64be = require('uint64be')

pool.start();
Empty file added test.js
Empty file.

0 comments on commit 979796a

Please sign in to comment.