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
};