Skip to content

Commit

Permalink
Dynamic Templatized WebSite, Optimized GetBlockTemplate, optimized Me…
Browse files Browse the repository at this point in the history
…rgeMining Block Construction, Solo mining and merged mining
  • Loading branch information
muscleman committed Nov 16, 2019
1 parent f6a69f5 commit 9ea5155
Show file tree
Hide file tree
Showing 49 changed files with 3,768 additions and 8,321 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ build/
logs/ logs/
website/ website/
custom_coins/ custom_coins/
*.swp
4 changes: 1 addition & 3 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ Explanation for each field:
"cnAlgorithm": "cryptonight", "cnAlgorithm": "cryptonight",
"cnVariant": 1, "cnVariant": 1,
"cnBlobType": 0, "cnBlobType": 0,
"includeHeight":false, /*true to include block.height in job to miner*/
"includeAlgo":"cn/wow", /*wownero specific change to include algo in job to miner*/
/* Logging */ /* Logging */
"logging": { "logging": {


Expand Down Expand Up @@ -410,7 +409,6 @@ Explanation for each field:
"wallet": { "wallet": {
"host": "127.0.0.1", "host": "127.0.0.1",
"port": 18982, "port": 18982,
"username": "--rpc-username", //monero based wallet authentication
"password": "--rpc-password" "password": "--rpc-password"
}, },


Expand Down
104 changes: 102 additions & 2 deletions init.js
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
/** /**
* Cryptonite Node.JS Pool * Cryptonite Node.JS Pool
* https://github.com/dvandal/cryptonote-nodejs-pool * https://github.com/dvandal/cryptonote-nodejs-pool
* *
Expand All @@ -22,12 +22,21 @@ var redis = require('redis');
var redisDB = (config.redis.db && config.redis.db > 0) ? config.redis.db : 0; var redisDB = (config.redis.db && config.redis.db > 0) ? config.redis.db : 0;
global.redisClient = redis.createClient(config.redis.port, config.redis.host, { db: redisDB, auth_pass: config.redis.auth }); global.redisClient = redis.createClient(config.redis.port, config.redis.host, { db: redisDB, auth_pass: config.redis.auth });


if (typeof config.childPools !== 'undefined')
config.childPools = config.childPools.filter(pool => pool.enabled)

// Load pool modules // Load pool modules
if (cluster.isWorker){ if (cluster.isWorker){
switch(process.env.workerType){ switch(process.env.workerType){
case 'pool': case 'pool':
require('./lib/pool.js'); require('./lib/pool.js');
break; break;
case 'daemon':
require('./lib/daemon.js')
break
case 'childDaemon':
require('./lib/childDaemon.js')
break
case 'blockUnlocker': case 'blockUnlocker':
require('./lib/blockUnlocker.js'); require('./lib/blockUnlocker.js');
break; break;
Expand Down Expand Up @@ -79,6 +88,9 @@ var singleModule = (function(){
log('info', logSystem, 'Running in single module mode: %s', [singleModule]); log('info', logSystem, 'Running in single module mode: %s', [singleModule]);


switch(singleModule){ switch(singleModule){
case 'daemon':
spawnDaemon()
break
case 'pool': case 'pool':
spawnPoolWorkers(); spawnPoolWorkers();
break; break;
Expand All @@ -101,6 +113,9 @@ var singleModule = (function(){
} }
else{ else{
spawnPoolWorkers(); spawnPoolWorkers();
spawnDaemon();
if (config.poolServer.mergedMining)
spawnChildDaemons();
spawnBlockUnlocker(); spawnBlockUnlocker();
spawnPaymentProcessor(); spawnPaymentProcessor();
spawnApi(); spawnApi();
Expand Down Expand Up @@ -154,7 +169,6 @@ function spawnPoolWorkers(){
log('error', logSystem, 'Pool server enabled but no ports specified'); log('error', logSystem, 'Pool server enabled but no ports specified');
return; return;
} }

var numForks = (function(){ var numForks = (function(){
if (!config.poolServer.clusterForks) if (!config.poolServer.clusterForks)
return 1; return 1;
Expand Down Expand Up @@ -204,6 +218,92 @@ function spawnPoolWorkers(){
}, 10); }, 10);
} }


/**
* Spawn pool workers module
**/
function spawnChildDaemons(){
if (!config.poolServer || !config.poolServer.enabled || !config.poolServer.ports || config.poolServer.ports.length === 0) return;

if (config.poolServer.ports.length === 0){

This comment has been minimized.

Copy link
@trasherdk

trasherdk Nov 17, 2019

Contributor

Looks like dead code to me.
The line 225 contains the same check.

log('error', logSystem, 'Pool server enabled but no ports specified');
return;
}

var numForks = (function(){
if (!config.poolServer.mergedMining)
return 0;
if (typeof config.childPools !== 'undefined') {
return config.childPools.length
}
return 0;
})();
var daemonWorkers = {};

var createDaemonWorker = function(poolId){
var worker = cluster.fork({
workerType: 'childDaemon',
poolId: poolId
});
worker.poolId = poolId;
worker.type = 'childDaemon';
daemonWorkers[poolId] = worker;
worker.on('exit', function(code, signal){
log('error', logSystem, 'Child Daemon fork %s died, spawning replacement worker...', [poolId]);
setTimeout(function(){
createDaemonWorker(poolId);
}, 2000);
}).on('message', function(msg){
switch(msg.type){
case 'ChildBlockTemplate':
Object.keys(cluster.workers).forEach(function(id) {
if (cluster.workers[id].type === 'pool'){
cluster.workers[id].send({type: 'ChildBlockTemplate', block: msg.block, poolIndex: msg.poolIndex});
}
});
break;
}
});
};

var i = 0;
var spawnInterval = setInterval(function(){
createDaemonWorker(i.toString())
i++
if (i === numForks){
clearInterval(spawnInterval);
log('info', logSystem, 'Child Daemon spawned on %d thread(s)', [numForks]);
}
}, 10);
}


/**
* Spawn daemon module
**/
function spawnDaemon(){
if (!config.poolServer || !config.poolServer.enabled || !config.poolServer.ports || config.poolServer.ports.length === 0) return;

var worker = cluster.fork({
workerType: 'daemon'
});
worker.on('exit', function(code, signal){
log('error', logSystem, 'Daemon died, spawning replacement...');
setTimeout(function(){
spawnDaemon();
}, 10);
}).on('message', function(msg){
switch(msg.type){
case 'BlockTemplate':
Object.keys(cluster.workers).forEach(function(id) {
if (cluster.workers[id].type === 'pool'){
cluster.workers[id].send({type: 'BlockTemplate', block: msg.block});
}
});
break;
}
});
}

/** /**
* Spawn block unlocker module * Spawn block unlocker module
**/ **/
Expand Down
Loading

0 comments on commit 9ea5155

Please sign in to comment.