Add reindex-last sync option
-Use reindex-last to restore the coinstats.last value, which is the last synced blockindex value
This commit is contained in:
+25
-10
@@ -21,6 +21,7 @@ function usage() {
|
|||||||
console.log('reindex Clears index then resyncs from genesis to current block');
|
console.log('reindex Clears index then resyncs from genesis to current block');
|
||||||
console.log('reindex-rich Clears and recreates the richlist data');
|
console.log('reindex-rich Clears and recreates the richlist data');
|
||||||
console.log('reindex-txcount Rescan and flatten the tx count value for faster access');
|
console.log('reindex-txcount Rescan and flatten the tx count value for faster access');
|
||||||
|
console.log('reindex-last Rescan and flatten the last blockindex value for faster access');
|
||||||
console.log('market Updates market summaries, orderbooks, trade history + charts');
|
console.log('market Updates market summaries, orderbooks, trade history + charts');
|
||||||
console.log('peers Updates peer info based on local wallet connections');
|
console.log('peers Updates peer info based on local wallet connections');
|
||||||
console.log('masternodes Updates the list of active masternodes on the network');
|
console.log('masternodes Updates the list of active masternodes on the network');
|
||||||
@@ -56,6 +57,9 @@ if (process.argv[2] == 'index') {
|
|||||||
case 'reindex-txcount':
|
case 'reindex-txcount':
|
||||||
mode = 'reindex-txcount';
|
mode = 'reindex-txcount';
|
||||||
break;
|
break;
|
||||||
|
case 'reindex-last':
|
||||||
|
mode = 'reindex-last';
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
@@ -368,16 +372,27 @@ if (database == 'peers') {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if (mode == 'reindex-last') {
|
} else if (mode == 'reindex-last') {
|
||||||
console.log('calculating last tx.. please wait..');
|
console.log('finding last blockindex.. please wait..');
|
||||||
// Resetting the last counter requires a single lookup on the txes collection to find all txes that have a positive or zero total and 1 or more vout
|
// Resetting the last blockindex counter requires a single lookup on the txes collection to find the last indexed blockindex
|
||||||
Tx.find({'total': {$gte: 0}, 'vout': { $gte: { $size: 1 }}}).countDocuments(function(err, count) {
|
Tx.find({}, {blockindex:1, _id:0}).sort({blockindex: -1}).limit(1).exec(function(err, tx) {
|
||||||
console.log('found tx count: ' + count.toString());
|
// check if any blocks exists
|
||||||
Stats.updateOne({coin: settings.coin.name}, {
|
if (err != null || tx == null || tx.length == 0) {
|
||||||
txes: count
|
console.log('no blocks found. setting last blockindex to 0.');
|
||||||
}, function() {
|
Stats.updateOne({coin: settings.coin.name}, {
|
||||||
console.log('tx count update complete');
|
last: 0
|
||||||
exit();
|
}, function() {
|
||||||
});
|
console.log('last blockindex update complete');
|
||||||
|
exit();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('found last blockindex: ' + tx[0].blockindex.toString());
|
||||||
|
Stats.updateOne({coin: settings.coin.name}, {
|
||||||
|
last: tx[0].blockindex
|
||||||
|
}, function() {
|
||||||
|
console.log('last blockindex update complete');
|
||||||
|
exit();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ if [ -n "${1}" ]; then
|
|||||||
# Index reindex-txcount
|
# Index reindex-txcount
|
||||||
MODE="index reindex-txcount"
|
MODE="index reindex-txcount"
|
||||||
;;
|
;;
|
||||||
|
"reindex-last")
|
||||||
|
# Index reindex-last
|
||||||
|
MODE="index reindex-last"
|
||||||
|
;;
|
||||||
"market")
|
"market")
|
||||||
# Market update
|
# Market update
|
||||||
MODE="market"
|
MODE="market"
|
||||||
@@ -72,6 +76,10 @@ if [ -n "${1}" ]; then
|
|||||||
# Index reindex-txcount
|
# Index reindex-txcount
|
||||||
MODE="index reindex-txcount"
|
MODE="index reindex-txcount"
|
||||||
;;
|
;;
|
||||||
|
"reindex-last")
|
||||||
|
# Index reindex-last
|
||||||
|
MODE="index reindex-last"
|
||||||
|
;;
|
||||||
"market")
|
"market")
|
||||||
# Market update
|
# Market update
|
||||||
MODE="market"
|
MODE="market"
|
||||||
|
|||||||
Reference in New Issue
Block a user