mirror of
https://github.com/jwinterm/nodejs-pool.git
synced 2026-10-17 05:21:27 +02:00
Replacing cleanShareDB.
This commit is contained in:
+1
-102
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user