node-open-mining-portal/libs/shareProcessor.js
Matthew Little 67254f63ba
Update dev branch (#598)
* modified for my repositry

* Revert

* add lf

* Fixed bug in parsing balances for payment processing

* Added fixminer.com pool

* New pool

Another one using NOMP

* Update 21coin.json

Added peerMagic needed for p2p block notifications

* Update alphacoin.json

Added peerMagic. Needed for p2p block notifications

* Update benjamins.json

Added peerMagic for p2p block notifications

* Update mazacoin.json

Added peerMagic for p2p block notifications

* Update bottlecaps.json

* Update bottlecaps.json

* Create bunnycoin.json

* Update bunnycoin.json

* Update casinocoin.json

* Create coino.json

* Update coino.json

* Create cryptogenicbullion.json

* Update coino.json

* Update bunnycoin.json

* Update cryptogenicbullion.json

* Create cryptographicanomaly.json

* Update cryptographicanomaly.json

* Update cryptographicanomaly.json

* Fix switching port showing

Fix reading of config file to show active switching ports

* Update alphacoin.json

* Update README.md

fixed typo on line 529 node-statum-pool to node-stratum-pool

* Update README.md

* Valid json to Readme example coin conf

* Minor readme change

* Marked emark as POS type coin since auto detection fails

* created infinitecoin.conf

Adding infinitecoin.conf to the coin list.
https://github.com/infinitecoin/infinitecoin/blob/master/src/main.cpp#L2524

* fixed capitolization

Adjusted InfiniteCoin to Infinitecoin to match the naming practice of all the other coins.

* update symbol for Coino

* Wrong hashrate calculation

Hashes are not bytes:
> 1 byte = 8 bits
> 1 kilobyte = 1024 bytes

Hashes are the units, and so therefore - as `k`,  `m` only mean *10^3 and *10^6
> 1 hash = 1 hash
> 1 kh     = 1000 hashes

* Add Viacoin support

Support for Viacoin - viacoin.org

* Add FlutterCoin to coins

* Rename viacoin.conf to viacoin.json

* 42 coin

* Update poolWorker.js

var created above is spelled as initalPool not initialPool.

* http://poollo.com "service unavailable"

* Removed the links to dead pools

* http://poollo.com
* http://fixminer.com
* http://pool.trademybit.com/ (all wallets disabled)
* http://www.omargpools.ca/pools.html (dead link)
* http://mining.theminingpools.com (now called "ad depo", no sign of a mining pool).
* http://minr.es (dead link)
* http://onebtcplace.com (link leads nowhere)
* http://uberpools.org (Apache Test Page)
* http://miningwith.us (domain for sale)
* http://teamdoge.com (blank page)
* http://rapidhash.net (domain for sale)
* http://chunkypools.com

Left these three. Are they still nomp?
* http://miningpoolhub.com (Donations to this project are going directly to TheSerapher, the original author of this project. (https://github.com/MPOS/php-mpos) ###
* http://hashfaster.com (MPOS, sign up) ###
* http://suchpool.pw ###

* Removed " LiveChains UK offers full hosting, setup and management of NOMP pools with several different configurations. [...] LiveChains UK however does offer this feature as part of there own customised NOMP called LivePool." Paid Solution." from 'Paid  Solution'. The  company no longer exists and the links lead to a generic type of forum about software.

* Added some log info and fixed a typo

* Pinned some package versions - included async package

Should fix https://github.com/zone117x/node-open-mining-portal/pull/479

* Update litecoin testnet magic

Litecoin testnet has been reset

2fcf8079ef (diff-64cbe1ad5465e13bc59ee8bb6f3de2e7R207)

* fix orphan stat source

* API does not set the proper header

* Update api.js

Fix : #554

* Update package.json

Pin request npm package version

* Update README.md

* Update README.md

* Updated to new Core 0.16 Format (getaddressinfo)

Since the new Wallet release of Bitcoin Core, they introduced a new Validation format for addresses.
Validateaddress is not longer working.

* Update paymentProcessor.js

* Final change

* Added GLT Coin

* add peer magic for DGB (#592)
2018-05-13 14:02:08 -07:00

120 lines
4.5 KiB
JavaScript

var redis = require('redis');
var Stratum = require('stratum-pool');
/*
This module deals with handling shares when in internal payment processing mode. It connects to a redis
database and inserts shares with the database structure of:
key: coin_name + ':' + block_height
value: a hash with..
key:
*/
module.exports = function(logger, portalConfig, poolConfig, singleCoinPayoutPorts){
var redisConfig = poolConfig.redis;
var coin = poolConfig.coin.name;
var forkId = process.env.forkId;
var logSystem = 'Pool';
var logComponent = coin;
var logSubCat = 'Thread ' + (parseInt(forkId) + 1);
var connection = redis.createClient(redisConfig.port, redisConfig.host);
connection.on('ready', function(){
logger.debug(logSystem, logComponent, logSubCat, 'Share processing setup with redis (' + redisConfig.host +
':' + redisConfig.port + ')');
});
connection.on('error', function(err){
logger.error(logSystem, logComponent, logSubCat, 'Redis client had an error: ' + JSON.stringify(err))
});
connection.on('end', function(){
logger.error(logSystem, logComponent, logSubCat, 'Connection to redis database has been ended');
});
connection.info(function(error, response){
if (error){
logger.error(logSystem, logComponent, logSubCat, 'Redis version check failed');
return;
}
var parts = response.split('\r\n');
var version;
var versionString;
for (var i = 0; i < parts.length; i++){
if (parts[i].indexOf(':') !== -1){
var valParts = parts[i].split(':');
if (valParts[0] === 'redis_version'){
versionString = valParts[1];
version = parseFloat(versionString);
break;
}
}
}
if (!version){
logger.error(logSystem, logComponent, logSubCat, 'Could not detect redis version - but be super old or broken');
}
else if (version < 2.6){
logger.error(logSystem, logComponent, logSubCat, "You're using redis version " + versionString + " the minimum required version is 2.6. Follow the damn usage instructions...");
}
});
this.handleShare = function(isValidShare, isValidBlock, shareData){
/*var shareKey = (function(){
var port = shareData.port.toString();
for (var switchName in portalConfig.switching){
if (!portalConfig.switching[switchName]['singleCoinPayout']) continue;
var ports = Object.keys(portalConfig.switching[switchName].ports);
if (ports.indexOf(port) !== -1) return switchName;
}
return coin;
})();*/
var shareKey = singleCoinPayoutPorts[shareData.port] || coin;
console.log('share key ' + shareKey);
var redisCommands = [];
if (isValidShare){
redisCommands.push(['hincrbyfloat', shareKey + ':shares:roundCurrent', shareData.worker, shareData.difficulty]);
redisCommands.push(['hincrby', coin + ':stats', 'validShares', 1]);
}
else{
redisCommands.push(['hincrby', coin + ':stats', 'invalidShares', 1]);
}
/* Stores share diff, worker, and unique value with a score that is the timestamp. Unique value ensures it
doesn't overwrite an existing entry, and timestamp as score lets us query shares from last X minutes to
generate hashrate for each worker and pool. */
var dateNow = Date.now();
var hashrateData = [ isValidShare ? shareData.difficulty : -shareData.difficulty, shareData.worker, dateNow];
redisCommands.push(['zadd', coin + ':hashrate', dateNow / 1000 | 0, hashrateData.join(':')]);
if (isValidBlock){
redisCommands.push(['rename', coin + ':shares:roundCurrent', coin + ':shares:round' + shareData.height]);
redisCommands.push(['sadd', coin + ':blocksPending', [shareData.blockHash, shareData.txHash, shareData.height].join(':')]);
redisCommands.push(['hincrby', coin + ':stats', 'validBlocks', 1]);
}
else if (shareData.blockHash){
redisCommands.push(['hincrby', coin + ':stats', 'invalidBlocks', 1]);
}
connection.multi(redisCommands).exec(function(err, replies){
if (err)
logger.error(logSystem, logComponent, logSubCat, 'Error with share processor multi ' + JSON.stringify(err));
});
};
};