Orphan block fix + other misc improvements

-The block sync will now remove orphaned block data from the txes collecton,  address balances/sent/received data as well as addresstx data and now stores limited info in a new orphans collection
-Added a new optional page for viewing orphaned block data
-The coinbase address now updates sent totals from POS rewards and other transactions that have vout but no vin addresses
-Block and transaction pages now display a warning when viewing an orphaned block or tx
-Added a couple new fields to the coinstats collection for tracking orphaned blocks
-Added new locale strings for the orphaned block feature
This commit is contained in:
Joe Uhren
2023-05-06 12:36:35 -06:00
parent 208187c293
commit 09fa919686
16 changed files with 1301 additions and 159 deletions
+30 -5
View File
@@ -5,6 +5,7 @@ var mongoose = require('mongoose'),
Address = require('../models/address'),
AddressTx = require('../models/addresstx'),
Tx = require('../models/tx'),
Orphans = require('../models/orphans'),
Richlist = require('../models/richlist'),
Peers = require('../models/peers'),
Heavy = require('../models/heavy'),
@@ -403,7 +404,13 @@ module.exports = {
// collection has data
// determine if last_usd_price field exists
check_add_db_field(Stats, 'last_usd_price', 0, function(exists) {
return cb(true);
// determine if orphan_index field exists
check_add_db_field(Stats, 'orphan_index', 0, function(exists) {
// determine if orphan_current field exists
check_add_db_field(Stats, 'orphan_current', 0, function(exists) {
return cb(true);
});
});
});
} else
return cb(false);
@@ -424,7 +431,9 @@ module.exports = {
if (!skip) {
var newStats = new Stats({
coin: coin,
last: 0
last: 0,
orphan_index: 0,
orphan_current: 0
});
newStats.save(function(err) {
@@ -1068,7 +1077,9 @@ module.exports = {
supply: (supply ? supply : 0),
connections: (connections ? connections : 0),
last: (stats.last ? stats.last : 0),
txes: (stats.txes ? stats.txes : 0)
txes: (stats.txes ? stats.txes : 0),
orphan_index: (stats.orphan_index ? stats.orphan_index : 0),
orphan_current: (stats.orphan_current ? stats.orphan_current : 0)
});
});
} else {
@@ -1511,7 +1522,7 @@ module.exports = {
if (tx && tx != 'There was an error. Check your console.') {
lib.prepare_vin(tx, function(vin, tx_type_vin) {
lib.prepare_vout(tx.vout, txid, vin, ((!settings.blockchain_specific.zksnarks.enabled || typeof tx.vjoinsplit === 'undefined' || tx.vjoinsplit == null) ? [] : tx.vjoinsplit), function(vout, nvin, tx_type_vout) {
lib.syncLoop(vin.length, function (loop) {
lib.syncLoop(nvin.length, function (loop) {
var i = loop.iteration();
// check if address is inside an array
@@ -1556,7 +1567,7 @@ module.exports = {
var newTx = new Tx({
txid: tx.txid,
vin: nvin,
vin: (vin == null || vin.length == 0 ? [] : nvin),
vout: vout,
total: total.toFixed(8),
timestamp: tx.time,
@@ -1582,5 +1593,19 @@ module.exports = {
});
},
// get the list of orphans from local collection
get_orphans: function(start, length, cb) {
// get the count of orphaned blocks
Orphans.find({}).countDocuments(function(err, count) {
// get the actual orphaned block data
Orphans.find({}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function(err, orphans) {
if (err)
return cb([], count);
else
return cb(orphans, count);
});
});
},
fs: fs
};
+21 -1
View File
@@ -1202,7 +1202,27 @@ module.exports = {
arr_vout[0].amount = arr_vout[0].amount - arr_vin[0].amount;
arr_vin.shift();
return cb(arr_vout, arr_vin, tx_type);
// check if any vin remains
if (arr_vin == null || arr_vin.length == 0) {
// empty vin should be linked to coinbase
arr_vin = [{coinbase: "coinbase"}];
var new_vout = [];
// loop through the arr_vout to create a copy of the data with coin amounts only for use with prepare_vin()
for (i = 0; i < arr_vout.length; i++) {
new_vout.push({
value: arr_vout[i].amount / 100000000
});
}
// call the prepare_vin again to populate the vin data correctly
module.exports.prepare_vin({txid: txid, vin: arr_vin, vout: new_vout}, function(return_vin, return_tx_type_vin) {
return cb(arr_vout, return_vin, return_tx_type_vin);
});
} else {
return cb(arr_vout, arr_vin, tx_type);
}
} else
return cb(arr_vout, arr_vin, tx_type);
} else
+11
View File
@@ -16,6 +16,7 @@ exports.menu_movement = "Movement",
exports.menu_node = "Nodes",
exports.menu_network = "Network",
exports.menu_claim_address = "Claim Address",
exports.menu_orphans = "Orphaned Blocks",
exports.ex_title = "{1} Block Explorer",
exports.ex_description = "A listing of all verified {1} transactions",
@@ -166,6 +167,16 @@ exports.mkt_select = "Market Select",
exports.claim_title = "{1} Wallet Address Claim",
exports.claim_description = "Verify ownership of your {1} wallet address and set a custom display name in the explorer",
// Orphans view
exports.orphan_title = "{1} Orphaned Blocks",
exports.orphan_description = "A listing of valid blocks that have been orphaned and do not belong to the main blockchain",
exports.orphan_block_list = "Orphaned Block List",
exports.orphan_block_hash = "Orphaned Block Hash",
exports.orphan_actual_block = "Actual Block",
exports.orphan_prev_block = "Previous Block",
exports.orphan_next_block = "Next Block",
exports.view_orphan = "View Orphaned Block",
// Heavycoin
exports.heavy_vote = "Vote",
// Heavycoin rewards view
+32
View File
@@ -1184,6 +1184,38 @@ exports.claim_address_page = {
"enable_bad_word_filter": true
};
// orphans_page: a collection of settings that pertain to the orphans page
exports.orphans_page = {
// enabled: Enable/disable the orphans page (true/false)
// If set to false, the orphans page will be completely inaccessible
"enabled": false,
// show_panels: Determine whether to show the panels configured in the shared_pages.page_header section across the top of this page (true/false)
"show_panels": false,
// show_nethash_chart: Determine whether to show the network hashrate chart configured in the shared_pages.network_charts.nethash_chart section across the top of this page (true/false)
"show_nethash_chart": false,
// show_difficulty_chart: Determine whether to show the network difficulty chart configured in the shared_pages.network_charts.difficulty_chart section across the top of this page (true/false)
"show_difficulty_chart": false,
// page_header: a collection of settings that pertain to the orphans page header
"page_header": {
// show_img: Determine whether to show the page title image defined in the "shared_pages.page_header.page_title_image" setting (true/false)
"show_img": true,
// show_title: Determine whether to show the page title as defined in "locale.orphan_title" (true/false)
"show_title": true,
// show_last_updated: Determine whether to show a label below the page title with the last updated date (true/false)
"show_last_updated": true,
// show_description: Determine whether to show the page description as defined in "locale.orphan_description" (true/false)
"show_description": true
},
// orphans_table: a collection of settings that pertain to the orphans table on the orphans page
// Table data is populated via the /ext/getorphanlist api
"orphans_table": {
// page_length_options: An array of page length options that determine how many items/records to display in the table at any given time
"page_length_options": [ 10, 25, 50, 75, 100, 250, 500, 1000 ],
// items_per_page: The default amount of items/records to display in the table at any given time
"items_per_page": 10
}
};
// sync: a collection of settings that pertain to the data synchronization process
exports.sync = {
// block_parallel_tasks: Use multiple threads to do blockchain syncing which greatly improves the initial sync speed, but there is a drawback.