-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_witnesses.js
44 lines (40 loc) · 1.26 KB
/
check_witnesses.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
/*jslint node: true */
"use strict";
var db = require('bng-core/db.js');
var storage = require('bng-core/storage.js');
var mail = require('bng-core/mail.js');
var conf = require('bng-core/conf.js');
function notifyAdmin(message){
write(message);
if (!conf.admin_email || !conf.from_email)
return write('cannot notify admin as admin_email or from_email are not defined');
mail.sendmail({
to: conf.admin_email,
from: conf.from_email,
subject: message,
body: 'Check witnesses:\n'+message
});
}
function write(str){
console.log(Date().toString()+': '+str);
}
storage.readLastMainChainIndex(function(last_mci){
db.query(
"SELECT my_witnesses.address \n\
FROM my_witnesses \n\
LEFT JOIN ( \n\
SELECT DISTINCT address \n\
FROM units CROSS JOIN unit_authors USING(unit) CROSS JOIN my_witnesses USING(address) \n\
WHERE main_chain_index>? OR main_chain_index IS NULL OR units.creation_date>"+db.addTime('-30 MINUTE')+" \n\
) AS active_witnesses USING(address) \n\
WHERE active_witnesses.address IS NULL",
[last_mci - 100],
function(rows){
if (rows.length === 0)
return process.exit(0);
var arrMissingWitnesses = rows.map(row => row.address);
notifyAdmin('Missing witnesses: '+arrMissingWitnesses.join(', '));
process.exit(0);
}
);
});