Skip to content

Commit

Permalink
Merge pull request #22 from ROZ-MOFUMOFU-ME/dev
Browse files Browse the repository at this point in the history
Simplify ExtraNonceCounter in jobManager.js and refactor hashing method for VIPSTAR algorithm in algoProperties.js
  • Loading branch information
ROZ-MOFUMOFU-ME authored Dec 14, 2024
2 parents 2ae537d + 9ab64d6 commit 01be991
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/algoProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ var algos = module.exports = global.algos = {
'vipstar': {
hash: function () {
return function () {
return multiHashing.sha256d.apply(this, arguments);
return multiHashing.vipstar.apply(this, arguments);
}
}
}
Expand Down
20 changes: 2 additions & 18 deletions lib/jobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ var blockTemplate = require('./blockTemplate.js');
// Unique extranonce per subscriber
var ExtraNonceCounter = function (configInstanceId) {
var instanceId = configInstanceId || crypto.randomBytes(4).readUInt32LE(0);
var counter = BigInt(instanceId) << BigInt(27);
var counter = instanceId << 27;

this.next = function () {
counter++;
// Ensure counter is within a safe range
if (counter > BigInt('0xFFFFFFFF')) {
counter = BigInt(instanceId) << BigInt(27);
}
var extraNonce = util.packUInt32BE(Number(counter & BigInt('0xFFFFFFFF')));
var extraNonce = util.packUInt32BE(Math.abs(counter++));
return extraNonce.toString('hex');
};

Expand Down Expand Up @@ -48,16 +43,12 @@ var JobManager = module.exports = function JobManager(options) {
var jobCounter = new JobCounter();
var emitErrorLog = function (text) { _this.emit('log', 'error', text); };

// Initialize extranonce counter
this.extraNonceCounter = new ExtraNonceCounter(options.instanceId);
this.extraNoncePlaceholder = Buffer.from('f000000ff111111f', 'hex');
this.extraNonce2Size = this.extraNoncePlaceholder.length - this.extraNonceCounter.size;
this.currentJob;
this.validJobs = {};

// Initialize shareMultiplier, with a default value if not provided
this.shareMultiplier = options.shareMultiplier || 1;

var hashDigest = algos[options.coin.algorithm].hash(options.coin);

var coinbaseHasher = (function () {
Expand Down Expand Up @@ -264,13 +255,6 @@ var JobManager = module.exports = function JobManager(options) {
return shareError([24, `Algorithm properties not found for ${algorithm}`]);
}

var diff1;
try {
// Ensure algoProps.diff is defined; if not, set a default value
diff1 = BigInt(algoProps.diff || '0x00000000ffff0000000000000000000000000000000000000000000000000000');
} catch (e) {
return shareError([25, 'Cannot convert diff to BigInt: ' + e.message]);
}
var multiplier = algoProps.multiplier || 1;

var shareDiff = Number(diff1) / Number(headerBigNum) * multiplier;
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stratum-pool",
"version": "0.2.8",
"version": "0.2.9",
"description": "High performance Stratum poolserver in Node.js",
"keywords": [
"stratum",
Expand Down Expand Up @@ -33,9 +33,9 @@
"url": "https://github.com/ROZ-MOFUMOFU-ME/node-stratum-pool.git"
},
"dependencies": {
"@exodus/bitcoinjs-lib-zcash": "^0.0.13",
"@exodus/bitcoinjs-lib-zcash": "^0.0.14",
"async": "^3.2.6",
"bitcoinjs-lib": "^7.0.0-rc.0",
"bitcoinjs-lib": "^6.1.7",
"multi-hashing": "git+https://github.com/ROZ-MOFUMOFU-ME/node-multi-hashing.git"
},
"engines": {
Expand Down

0 comments on commit 01be991

Please sign in to comment.