-
Notifications
You must be signed in to change notification settings - Fork 17
/
update_ledger.js
62 lines (49 loc) · 1.58 KB
/
update_ledger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Module dependencies.
*/
var express = require('express'),
extend = require('extend'),
fs = require('fs'),
_ = require('lodash'),
winston = require('winston'),
config = require('./config'),
routes = require('./routes'),
api = require('./routes/api'),
model = require('./model'),
interp = require('./interpreter'),
index = require('./indexes'),
async = require('async');
var Engine = require('./engine').Engine,
Range = require('./range').Range;
var app = module.exports = express();
var ledger_start = process.argv[2] | 0;
var ledger_end = process.argv[3] | 0;
if (!ledger_start) {
console.log("Usage: node update_ledger.js <ledger> [to_ledger]");
process.exit(1);
}
if (!ledger_end) ledger_end = ledger_start;
if ((ledger_end - ledger_start) > 1000000) {
console.error("Error: Range too large");
process.exit(2);
}
if (ledger_start < config.net.genesis_ledger) {
console.error("Error: Ledger ID needs to be >= "+
config.net.genesis_ledger);
process.exit(3);
}
if (ledger_end < ledger_start) {
console.error("Error: Start ledger must be less than end ledger");
process.exit(4);
}
var ledgers = _.range(ledger_start, ledger_end+1);
var engine = new Engine();
engine.startup(function () {
async.eachLimit(ledgers, config.perf.workers, function (ledger_index, callback) {
engine.processor.processLedger(ledger_index, callback);
}, function (err) {
if (err) winston.error("Error processing ledger: " + err.message);
else winston.info("Processing completed successfully");
engine.shutdown();
});
});