Added low share diff tolerance.

This commit is contained in:
Matthew Little 2014-04-03 14:38:40 -06:00
parent 90cd9baf69
commit 54b73dd0df
2 changed files with 18 additions and 6 deletions

View File

@ -153,6 +153,12 @@ var pool = Stratum.createPool({
/* Sometimes you want the block hashes even for shares that aren't block candidates. */ /* Sometimes you want the block hashes even for shares that aren't block candidates. */
"emitInvalidBlockHashes": false, "emitInvalidBlockHashes": false,
/* We use proper maximum algorithm difficulties found in the coin daemon source code. Most
miners/pools that deal with scrypt use a guesstimated one that is about 5.86% off from the
actual one. So here we can set a tolerable threshold for if a share is slightly too low
due to mining apps using incorrect max diffs and this pool using correct max diffs. */
"shareVariancePercent": 10,
/* If a worker is submitting a good deal of invalid shares we can temporarily ban them to /* If a worker is submitting a good deal of invalid shares we can temporarily ban them to
reduce system/network load. Also useful to fight against flooding attacks. */ reduce system/network load. Also useful to fight against flooding attacks. */
"banning": { "banning": {

View File

@ -182,8 +182,9 @@ var JobManager = module.exports = function JobManager(maxDifficulty, hashDigest,
var blockHash; var blockHash;
var blockHex; var blockHex;
var shareDiff = maxDifficulty.div(headerBigNum).toString(); var shareDiff = maxDifficulty.div(headerBigNum);
//Check if share is a block candidate (matched network difficulty)
if (job.target.ge(headerBigNum)){ if (job.target.ge(headerBigNum)){
blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex'); blockHex = job.serializeBlock(headerBuffer, coinbaseBuffer).toString('hex');
blockHash = util.reverseBuffer(util.sha256d(headerBuffer)).toString('hex'); blockHash = util.reverseBuffer(util.sha256d(headerBuffer)).toString('hex');
@ -192,20 +193,25 @@ var JobManager = module.exports = function JobManager(maxDifficulty, hashDigest,
if (options.emitInvalidBlockHashes) if (options.emitInvalidBlockHashes)
blockHashInvalid = util.reverseBuffer(util.sha256d(headerBuffer)).toString('hex'); blockHashInvalid = util.reverseBuffer(util.sha256d(headerBuffer)).toString('hex');
//Difficulty the miner is set to
var targetUser = maxDifficulty.div(difficulty); var targetUser = maxDifficulty.div(difficulty);
//Check if share didn't reached the miner's difficulty)
if (headerBigNum.gt(targetUser)){ if (headerBigNum.gt(targetUser)){
//Check if share matched a previous difficulty from before vardiff retarget
//Check if share matched a previous difficulty from before a vardiff retarget
if (previousDifficulty && !headerBigNum.gt(maxDifficulty.div(previousDifficulty))){ if (previousDifficulty && !headerBigNum.gt(maxDifficulty.div(previousDifficulty))){
difficulty = previousDifficulty; difficulty = previousDifficulty;
} }
else{ else{
var offPercent = targetUser.div(headerBigNum).toNumber() * 100; var offPercent = 100 - (shareDiff.toNumber() / difficulty) * 100;
if (offPercent > options.shareVariancePercent){ //Check to see if low diff share is within acceptable configured range
return shareError([23, 'low difficulty share of ' + shareDiff]); if (offPercent > (options.shareVariancePercent || 0)){
return shareError([23, 'low difficulty share of ' + shareDiff.toString()]);
} }
else{ else{
_this.emit('log', 'warning', 'Share accepted a low diff ' + shareDiff + ' off by ' + (100 - offPercent).toFixed(2) + '%'); _this.emit('log', 'warning', 'Share accepted a low diff ' + shareDiff + ' off by ' + offPercent.toFixed(2) + '%');
} }
} }