blockManager fix for payout verification to properly flag blocks as orphans.
This commit is contained in:
parent
0783db81b5
commit
be346609b2
1 changed files with 13 additions and 26 deletions
|
|
@ -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 + "%");
|
||||
}
|
||||
|
||||
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() {
|
||||
if (scanInProgress) {
|
||||
debug("Skipping block unlocker run as there's a scan in progress");
|
||||
|
|
@ -421,9 +400,19 @@ function blockUnlocker() {
|
|||
global.support.rpcDaemon('getlastblockheader', [], function (body) {
|
||||
let blockHeight = body.result.block_header.height;
|
||||
blockList.forEach(function (row) {
|
||||
if (blockHeight - row.height > global.config.payout.blocksRequired) {
|
||||
blockPayments(row);
|
||||
}
|
||||
global.support.rpcDaemon('getblockheaderbyheight', {"height": row.height}, function (body) {
|
||||
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.
|
||||
blockScanner();
|
||||
// Scan every 120 seconds for invalidated blocks
|
||||
setInterval(blockInvalidator, 120000);
|
||||
setInterval(blockUnlocker, 120000);
|
||||
blockInvalidator();
|
||||
blockUnlocker();
|
||||
debug("Blocks loaded from SQL: " + blockIDCache.length);
|
||||
console.log("Boot-sync from SQL complete. Pending completion of queued jobs to get back to work.");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue