mirror of
https://github.com/jwinterm/nodejs-pool.git
synced 2026-12-01 11:43:58 +01:00
blockManager fix for payout verification to properly flag blocks as orphans.
This commit is contained in:
+13
-26
@@ -390,27 +390,6 @@ function calculateSoloPayments(blockHeader) {
|
|||||||
console.log("Solo payout cycle complete on block: " + blockHeader.height + " Block Value: " + global.support.coinToDecimal(blockHeader.reward) + " Block Payouts: " + global.support.coinToDecimal(totalPayments) + " Payout Percentage: " + (totalPayments / blockHeader.reward) * 100 + "%");
|
console.log("Solo payout cycle complete on block: " + blockHeader.height + " Block Value: " + global.support.coinToDecimal(blockHeader.reward) + " Block Payouts: " + global.support.coinToDecimal(totalPayments) + " Payout Percentage: " + (totalPayments / blockHeader.reward) * 100 + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
function blockInvalidator() {
|
|
||||||
if (scanInProgress) {
|
|
||||||
debug("Skipping block invalidator run as there's a scan in progress");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
debug("Running block invalidator");
|
|
||||||
global.mysql.query("SELECT id, hex FROM block_log ORDER BY find_time DESC LIMIT ?", [global.config.payout.blocksRequired]).then(function (rows) {
|
|
||||||
rows.forEach(function (row) {
|
|
||||||
global.support.rpcDaemon('getblockheaderbyheight', {"height": row.id}, function (body) {
|
|
||||||
// DO NOT TRUST THIS. GET THE BLOCK HEADER BY HEIGHT AND VERIFY THAT THE HASHES MATCH.
|
|
||||||
if (body.result.block_header.hash !== row.hex) {
|
|
||||||
global.database.invalidateBlock(row.id);
|
|
||||||
global.mysql.query("UPDATE block_log SET orphan = true WHERE hex = ?", [row.hex]);
|
|
||||||
blockIDCache.splice(blockIDCache.indexOf(body.result.block_header.height));
|
|
||||||
console.log("Invalidating block " + body.result.block_header.height + " due to being an orphan block");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function blockUnlocker() {
|
function blockUnlocker() {
|
||||||
if (scanInProgress) {
|
if (scanInProgress) {
|
||||||
debug("Skipping block unlocker run as there's a scan in progress");
|
debug("Skipping block unlocker run as there's a scan in progress");
|
||||||
@@ -421,9 +400,19 @@ function blockUnlocker() {
|
|||||||
global.support.rpcDaemon('getlastblockheader', [], function (body) {
|
global.support.rpcDaemon('getlastblockheader', [], function (body) {
|
||||||
let blockHeight = body.result.block_header.height;
|
let blockHeight = body.result.block_header.height;
|
||||||
blockList.forEach(function (row) {
|
blockList.forEach(function (row) {
|
||||||
if (blockHeight - row.height > global.config.payout.blocksRequired) {
|
global.support.rpcDaemon('getblockheaderbyheight', {"height": row.height}, function (body) {
|
||||||
blockPayments(row);
|
if (body.result.block_header.hash !== row.hash) {
|
||||||
}
|
global.database.invalidateBlock(row.height);
|
||||||
|
global.mysql.query("UPDATE block_log SET orphan = true WHERE hex = ?", [row.hash]);
|
||||||
|
blockIDCache.splice(blockIDCache.indexOf(body.result.block_header.height));
|
||||||
|
console.log("Invalidating block " + body.result.block_header.height + " due to being an orphan block");
|
||||||
|
} else {
|
||||||
|
if (blockHeight - row.height > global.config.payout.blocksRequired) {
|
||||||
|
blockPayments(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -497,9 +486,7 @@ function initial_sync() {
|
|||||||
// Enable block scanning for 1 seconds to update the block log.
|
// Enable block scanning for 1 seconds to update the block log.
|
||||||
blockScanner();
|
blockScanner();
|
||||||
// Scan every 120 seconds for invalidated blocks
|
// Scan every 120 seconds for invalidated blocks
|
||||||
setInterval(blockInvalidator, 120000);
|
|
||||||
setInterval(blockUnlocker, 120000);
|
setInterval(blockUnlocker, 120000);
|
||||||
blockInvalidator();
|
|
||||||
blockUnlocker();
|
blockUnlocker();
|
||||||
debug("Blocks loaded from SQL: " + blockIDCache.length);
|
debug("Blocks loaded from SQL: " + blockIDCache.length);
|
||||||
console.log("Boot-sync from SQL complete. Pending completion of queued jobs to get back to work.");
|
console.log("Boot-sync from SQL complete. Pending completion of queued jobs to get back to work.");
|
||||||
|
|||||||
Reference in New Issue
Block a user