From 1c84693b90ef335fbeee04d45e23b245a92c35d7 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Wed, 1 Nov 2017 10:30:22 -0700 Subject: [PATCH] Replacing cleanShareDB. --- lib/local_comms.js | 103 +------------------------------------------ lib/longRunnerNew.js | 10 ----- 2 files changed, 1 insertion(+), 112 deletions(-) delete mode 100644 lib/longRunnerNew.js diff --git a/lib/local_comms.js b/lib/local_comms.js index 7d37e5e..7a256a6 100644 --- a/lib/local_comms.js +++ b/lib/local_comms.js @@ -517,107 +517,6 @@ function Database(){ txn.commit(); }; - this.cleanShareDB = function() { - /* - This function takes the difficulty of the current block, and the last PPS block. If it's 0, save everything, - UNLESS global.config.pps.enable is FALSE, then feel free to trash it. - Due to LMDB under current config, we must delete entire keys, due to this, we save diff * shareMultiLog * 1.5 - global.config.pplns.shareMultiLog should be at least 1.5x your shareMulti, in case of diff spikiing - */ - let lastPPSBlock = this.getLastBlock(); - if (global.config.pps.enable){ - lastPPSBlock = this.getLastBlock(global.protos.POOLTYPE.PPS); - if (lastPPSBlock === 0){ - return; - } - } - let lastPPLNSBlock = this.getLastBlock(global.protos.POOLTYPE.PPLNS); - debug("Last PPS block: "+lastPPSBlock); - // Hopping into async, we need the current block height to know where to start our indexing... - async.waterfall([ - function(callback){ - global.coinFuncs.getLastBlockHeader(function(err, body){ - if (err) { - return callback(true, body); - } - return callback(null, body.height, Math.floor(body.difficulty * 1.5 * global.config.pplns.shareMultiLog)); - }); - }, - function (lastBlock, difficulty, callback) { - let shareCount = 0; - let ppsFound = false; - let pplnsFound = false; - let blockList = []; - debug("Scanning from: "+lastBlock + " for more than: " + difficulty + " shares"); - range.range(0, lastBlock+1).forEach(function (blockID) { - blockID = (blockID - lastBlock+1) * -1; - if (blockID < 0){ - return; - } - debug("Scanning block: " + blockID); - let txn = global.database.env.beginTxn({readOnly: true}); - let cursor = new global.database.lmdb.Cursor(txn, global.database.shareDB); - for (let found = (cursor.goToRange(blockID) === blockID); found; found = cursor.goToNextDup()) { - if (ppsFound && pplnsFound){ - cursor.getCurrentBinary(function(key, data) { // jshint ignore:line - if (blockList.indexOf(key) === -1){ - blockList.push(key); - } - }); - } else { - cursor.getCurrentBinary(function(key, data) { // jshint ignore:line - if (key < lastPPSBlock){ - ppsFound = true; - } - try{ - let shareData = global.protos.Share.decode(data); - if (shareData.poolType === global.protos.POOLTYPE.PPLNS){ - shareCount = shareCount + shareData.shares; - } - } catch(e){ - console.error("Invalid share"); - } - }); - if (shareCount >= difficulty){ - pplnsFound = true; - } - } - } - cursor.close(); - txn.abort(); - }); - callback(null, blockList); - } - ], function(err, data){ - if (err === null && global.config.general.blockCleaner === true){ - if(data.length > 0){ - global.database.refreshEnv(); - let blockList = global.database.getBlockList(); - debug("Got the block list"); - let totalDeleted = 0; - data.forEach(function(block){ - if ((blockList.indexOf(block) !== -1 && !blockList.unlocked) || block > lastPPLNSBlock){ - // Don't delete locked blocks. ffs. - // Don't delete blocks that could contain shares. Even if it's unlikely as all getout. - debug("Skipped deleting block: " + block); - return; - } - totalDeleted += 1; - let txn = global.database.env.beginTxn(); - txn.del(global.database.shareDB, block); - txn.commit(); - debug("Deleted block: " + block); - }); - console.log("Block cleaning enabled. Removed: " +totalDeleted+ " block share records"); - } - global.database.env.sync(function(){ - }); - } else { - console.log("Block cleaning disabled. Would of removed: " + JSON.stringify(data)); - } - }); - }; - this.getOldestLockedBlock = function(){ /* 6-29-2017 - Snipa - @@ -650,7 +549,7 @@ function Database(){ return highestBlock; }; - this.cleanShareDBNew = function() { + this.cleanShareDB = function() { /* This function takes the difficulty of the current block, and the last PPS block. If it's 0, save everything, UNLESS global.config.pps.enable is FALSE, then feel free to trash it. diff --git a/lib/longRunnerNew.js b/lib/longRunnerNew.js deleted file mode 100644 index b14ce20..0000000 --- a/lib/longRunnerNew.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; - -console.log("Cleaning up the share DB"); -global.database.cleanShareDBNew(); -console.log("Done cleaning up the shareDB"); -setInterval(function(){ - console.log("Cleaning up the share DB"); - global.database.cleanShareDBNew(); - console.log("Done cleaning up the shareDB"); -}, 3600000); \ No newline at end of file