-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck-network-hash.js
More file actions
83 lines (74 loc) · 2.53 KB
/
Copy pathcheck-network-hash.js
File metadata and controls
83 lines (74 loc) · 2.53 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const lineReader = require('reverse-line-reader')
const shell = require('shelljs')
const path = require('path')
const instances = shell.ls('-d', 'instances/shardus-instance-*')
let ports = instances.map(i => parseInt(i.split('-')[2]))
async function readLogFile (port, cycleCount) {
return new Promise(resolve => {
let hashCollector = {}
lineReader.eachLine(`instances/shardus-instance-${port}/logs/out.log`, function (line, last) {
const textToFind = 'DBG SNAPSHOT Network State Hash for cycle'
if (line.includes(textToFind)) {
const cycle = parseInt(line.split(' ')[7])
const hash = line.split(' ')[8]
hashCollector[cycle] = hash
}
if (last || (cycleCount && Object.keys(hashCollector).length >= cycleCount)) {
resolve(hashCollector)
return false // stop reading
}
})
})
}
let prevCycle = 0
async function watch () {
let latestCycle = 0
let collector = {}
for (let port of ports) {
let hashCollector = await readLogFile(port, 5)
let cycle = Object.keys(hashCollector)[Object.keys(hashCollector).length - 1]
if (cycle > latestCycle) latestCycle = cycle
collector[port] = hashCollector
}
// if (latestCycle > prevCycle) {
// console.log(collector)
console.log('lastest cycle', latestCycle)
for (let i = 9001; i < 9021; i++) {
console.log(`Node ${i} => cycle ${latestCycle} =>`, collector[i][latestCycle])
}
prevCycle = latestCycle
// }
}
async function check (earliestCycleToCheck = 10) {
let lastCycle = 0
let collector = {}
let emptyHashCollector = {}
for (let port of ports) {
let hashCollector = await readLogFile(port, null)
lastCycle = Object.keys(hashCollector)[Object.keys(hashCollector).length - 1]
collector[port] = hashCollector
}
if (lastCycle > 0 && lastCycle > 10) {
for (let counter = earliestCycleToCheck; counter <= lastCycle; counter++) {
for (let port of ports) {
if (!collector[port][counter]) {
// console.log(`Node ${port} does not have network hash for ${counter}`)
if (emptyHashCollector[port]) {
emptyHashCollector[port].push(counter)
} else {
emptyHashCollector[port] = [counter]
}
} else {
// console.log(collector[port][counter])
}
}
}
console.log('emptyHashCollector', emptyHashCollector)
}
}
async function startWatching () {
watch()
setInterval(watch, 10000)
}
if (process.argv[2] === '--watch') startWatching()
else if (process.argv[2] === '--check') check(50)