Update with fixes to finish getting AEON working and to block things from blocking when I don't expect them to.

AEON has a block on the way it does chain saving, which can lock up many portions of the blockManager daemon.  This is now patched in blockmanager.
This commit is contained in:
Alexander Blair
2017-10-13 12:01:19 -07:00
parent 5d31708abf
commit 667bc5a029
7 changed files with 81 additions and 51 deletions
+38 -25
View File
@@ -421,22 +421,29 @@ function blockPayments(block) {
switch (block.poolType) {
case global.protos.POOLTYPE.PPS:
// PPS is paid out per share find per block, so this is handled in the main block-find loop.
global.database.unlockBlock(block.hash);
break;
case global.protos.POOLTYPE.PPLNS:
global.coinFuncs.getBlockHeaderByHash(block.hash, function (header) {
calculatePPLNSPayments(header);
global.coinFuncs.getBlockHeaderByHash(block.hash, function (err, header) {
if (err === null){
calculatePPLNSPayments(header);
global.database.unlockBlock(block.hash);
}
});
break;
case global.protos.POOLTYPE.SOLO:
global.coinFuncs.getBlockHeaderByHash(block.hash, function (header) {
calculateSoloPayments(header);
global.coinFuncs.getBlockHeaderByHash(block.hash, function (err, header) {
if (err === null){
calculateSoloPayments(header);
global.database.unlockBlock(block.hash);
}
});
break;
default:
console.log("Unknown payment type. FREAKOUT");
global.database.unlockBlock(block.hash);
break;
}
global.database.unlockBlock(block.hash);
}
function blockScanner() {
@@ -446,27 +453,33 @@ function blockScanner() {
return;
}
scanInProgress = true;
global.coinFuncs.getLastBlockHeader(function (blockHeader) {
if (lastBlock === blockHeader.height) {
debug("No new work to be performed, block header matches last block");
scanInProgress = false;
return;
}
debug("Parsing data for new blocks");
lastBlock = blockHeader.height;
range.range(0, (blockHeader.height - Math.floor(global.config.payout.blocksRequired/2))).forEach(function (blockID) {
if (!blockIDCache.hasOwnProperty(blockID)) {
inc_check += 1;
blockQueue.push({blockID: blockID}, function (err) {
debug("Completed block scan on " + blockID);
if (err) {
console.error("Error processing " + blockID);
}
});
global.coinFuncs.getLastBlockHeader(function (err, blockHeader) {
if (err === null){
if (lastBlock === blockHeader.height) {
debug("No new work to be performed, block header matches last block");
scanInProgress = false;
return;
}
});
if (inc_check === 0) {
debug("No new work to be performed, initial scan complete");
debug("Parsing data for new blocks");
lastBlock = blockHeader.height;
range.range(0, (blockHeader.height - Math.floor(global.config.payout.blocksRequired/2))).forEach(function (blockID) {
if (!blockIDCache.hasOwnProperty(blockID)) {
inc_check += 1;
blockQueue.push({blockID: blockID}, function (err) {
debug("Completed block scan on " + blockID);
if (err) {
console.error("Error processing " + blockID);
}
});
}
});
if (inc_check === 0) {
debug("No new work to be performed, initial scan complete");
scanInProgress = false;
blockScannerTask = setInterval(blockScanner, 1000);
}
} else {
console.error(`Upstream error from the block daemon. Resetting scanner due to: ${JSON.stringify(blockHeader)}`);
scanInProgress = false;
blockScannerTask = setInterval(blockScanner, 1000);
}
+6 -4
View File
@@ -31,9 +31,10 @@ function Coin(data){
this.getBlockHeaderByID = function(blockId, callback){
global.support.rpcDaemon('getblockheaderbyheight', {"height": blockId}, function (body) {
if (body.hasOwnProperty('result')){
return callback(body.result.block_header);
return callback(null, body.result.block_header);
} else {
console.error(JSON.stringify(body));
callback(true, body);
}
});
};
@@ -41,10 +42,10 @@ function Coin(data){
this.getBlockHeaderByHash = function(blockHash, callback){
global.support.rpcDaemon('getblockheaderbyhash', {"hash": blockHash}, function (body) {
if (typeof(body) !== 'undefined' && body.hasOwnProperty('result')){
return callback(body.result.block_header);
return callback(null, body.result.block_header);
} else {
console.error(JSON.stringify(body));
return callback(false);
return callback(true, body);
}
});
};
@@ -52,9 +53,10 @@ function Coin(data){
this.getLastBlockHeader = function(callback){
global.support.rpcDaemon('getlastblockheader', [], function (body) {
if (typeof(body) !== 'undefined' && body.hasOwnProperty('result')){
return callback(body.result.block_header);
return callback(null, body.result.block_header);
} else {
console.error(JSON.stringify(body));
return callback(true, body);
}
});
};
+6 -4
View File
@@ -31,9 +31,10 @@ function Coin(data){
this.getBlockHeaderByID = function(blockId, callback){
global.support.rpcDaemon('getblockheaderbyheight', {"height": blockId}, function (body) {
if (body.hasOwnProperty('result')){
return callback(body.result.block_header);
return callback(null, body.result.block_header);
} else {
console.error(JSON.stringify(body));
return callback(true, body);
}
});
};
@@ -41,10 +42,10 @@ function Coin(data){
this.getBlockHeaderByHash = function(blockHash, callback){
global.support.rpcDaemon('getblockheaderbyhash', {"hash": blockHash}, function (body) {
if (typeof(body) !== 'undefined' && body.hasOwnProperty('result')){
return callback(body.result.block_header);
return callback(null, body.result.block_header);
} else {
console.error(JSON.stringify(body));
return callback(false);
return callback(true, body);
}
});
};
@@ -52,9 +53,10 @@ function Coin(data){
this.getLastBlockHeader = function(callback){
global.support.rpcDaemon('getlastblockheader', [], function (body) {
if (typeof(body) !== 'undefined' && body.hasOwnProperty('result')){
return callback(body.result.block_header);
return callback(null, body.result.block_header);
} else {
console.error(JSON.stringify(body));
return callback(true, body);
}
});
};
+7 -5
View File
@@ -45,9 +45,10 @@ function Coin(data){
this.getBlockHeaderByID = function(blockId, callback){
global.support.rpcDaemon('getblockheaderbyheight', {"height": blockId}, function (body) {
if (body.hasOwnProperty('result')){
return callback(body.result.block_header);
return callback(null, body.result.block_header);
} else {
console.error(JSON.stringify(body));
return callback(true, body);
}
});
};
@@ -55,10 +56,10 @@ function Coin(data){
this.getBlockHeaderByHash = function(blockHash, callback){
global.support.rpcDaemon('getblockheaderbyhash', {"hash": blockHash}, function (body) {
if (typeof(body) !== 'undefined' && body.hasOwnProperty('result')){
return callback(body.result.block_header);
return callback(null, body.result.block_header);
} else {
console.error(JSON.stringify(body));
return callback(false);
return callback(true, body);
}
});
};
@@ -66,9 +67,10 @@ function Coin(data){
this.getLastBlockHeader = function(callback){
global.support.rpcDaemon('getlastblockheader', [], function (body) {
if (typeof(body) !== 'undefined' && body.hasOwnProperty('result')){
return callback(body.result.block_header);
return callback(null, body.result.block_header);
} else {
console.error(JSON.stringify(body));
return callback(true, body);
}
});
};
@@ -78,7 +80,7 @@ function Coin(data){
reserve_size: 17,
wallet_address: walletAddress
}, function(body){
return callback(body);
return callback(err, body);
});
};
+10 -8
View File
@@ -375,8 +375,8 @@ function Database(){
this.refreshEnv();
try{
let blockDataDecoded = global.protos.Block.decode(blockData);
global.coinFuncs.getBlockHeaderByHash(blockDataDecoded.hash, function(header){
if (typeof(header) === 'undefined' || !header){
global.coinFuncs.getBlockHeaderByHash(blockDataDecoded.hash, function(err, header){
if (err || typeof(header) === 'undefined' || !header){
return callback(false);
}
blockDataDecoded.value = header.reward;
@@ -409,12 +409,14 @@ function Database(){
let blockData = txn.getBinary(global.database.blockDB, blockId);
txn.abort();
let blockDataDecoded = global.protos.Block.decode(blockData);
global.coinFuncs.getBlockHeaderByHash(blockDataDecoded.hash, function(header){
blockDataDecoded.value = header.reward;
blockData = global.database.calculateShares(blockDataDecoded, blockId);
let txn = global.database.env.beginTxn();
txn.putBinary(global.database.blockDB, blockId, blockData);
txn.commit();
global.coinFuncs.getBlockHeaderByHash(blockDataDecoded.hash, function(err, header){
if (err === null) {
blockDataDecoded.value = header.reward;
blockData = global.database.calculateShares(blockDataDecoded, blockId);
let txn = global.database.env.beginTxn();
txn.putBinary(global.database.blockDB, blockId, blockData);
txn.commit();
}
});
};
+4 -2
View File
@@ -155,8 +155,8 @@ function checkAliveMiners() {
}
function templateUpdate(repeating) {
global.coinFuncs.getBlockTemplate(global.config.pool.address, function (rpcResponse) {
if (rpcResponse) {
global.coinFuncs.getBlockTemplate(global.config.pool.address, function (err, rpcResponse) {
if (rpcResponse && typeof rpcResponse.result !== 'undefined') {
rpcResponse = rpcResponse.result;
let buffer = new Buffer(rpcResponse.blocktemplate_blob, 'hex');
let new_hash = new Buffer(32);
@@ -174,6 +174,8 @@ function templateUpdate(repeating) {
if (repeating !== false) {
setTimeout(templateUpdate, 300);
}
} else {
setTimeout(templateUpdate, 300);
}
});
}
+10 -3
View File
@@ -16,7 +16,10 @@ function updateShareStats() {
let activeAddresses = [];
async.waterfall([
function (callback) {
global.coinFuncs.getLastBlockHeader(function (body) {
global.coinFuncs.getLastBlockHeader(function (err, body) {
if (err !== null){
return callback(err, "Invalid block header");
}
callback(null, body.height + 1);
});
},
@@ -493,8 +496,12 @@ function updateWalletStats() {
}
function monitorNodes() {
global.mysql.query("SELECT blockID FROM pools WHERE last_checkin > date_sub(now(), interval 30 minute)").then(function (rows) {
global.coinFuncs.getLastBlockHeader(function (block) {
global.mysql.query("SELECT blockID, hostname, ip FROM pools WHERE last_checkin > date_sub(now(), interval 30 minute)").then(function (rows) {
global.coinFuncs.getLastBlockHeader(function (err, block) {
if (err !== null){
console.error("Issue in getting block header. Skipping node monitor");
return;
}
rows.forEach(function (row) {
if (row.blockID < block.height - 3) {
global.support.sendEmail(global.config.general.adminEmail, "Pool server behind in blocks", "The pool server: "+row.hostname+" with IP: "+row.ip+" is "+block.height - row.blockID+ " blocks behind");