-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGethSyncingProgress_2TimeEstimate.js
More file actions
75 lines (59 loc) · 3.03 KB
/
GethSyncingProgress_2TimeEstimate.js
File metadata and controls
75 lines (59 loc) · 3.03 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
/**
* GETH SYNCING PROGRESS - TIME ESTIMATE
* a script to estimate how much time is left to fully sync the Ethereum Blockchain with Geth
*
* If it takes too long, consider restarting geth with
* the '--fast' option (not suggested for developers),
* or better the '--cache=1024' or '--cache=2048 option that will assign more RAM to geth and make it faster
*
* (c) Lyricalpolymath 2016. MIT Licence
* http://github.com/lyricalpolymath
*/
// run like this
// $ geth --exec "loadScript('GethSyncingProgress_2TimeEstimate.js')" attach
//number of blocks to test before we give a timing estimate
var resolution = 10;
var startDate = new Date();
var endDate;
var s = eth.syncing;
var block1 = s.currentBlock
var blockLast = block1 + resolution
// convert the duration for the stats
function msToTime(duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = parseInt((duration / 1000) % 60),
minutes = parseInt((duration / (1000 * 60)) % 60),
hours = parseInt((duration / (1000 * 60 * 60)) % 24),
days = parseInt((duration / (1000 * 60 * 60 * 24)) % 365);
var h = (hours < 10) ? "0" + hours : hours;
var m = (minutes < 10) ? "0" + minutes : minutes;
var s = (seconds < 10) ? "0" + seconds : seconds;
return days + "d :" + hours + "h :" + minutes + "m :" + seconds + "s." + milliseconds;
}
function displayTimeEstimate() {
s = eth.syncing;
var blocksLeft = (s.highestBlock-s.currentBlock)
var time_duration = endDate - startDate //returns amount of milliseconds passed
var time_duration_readable = msToTime(time_duration);
var time_left = msToTime( (time_duration / resolution) * blocksLeft );
console.log("------------ GETH SYNCING PROGRESS - Time estimate")
console.log("progress: " + (s.currentBlock/s.highestBlock*100));
console.log("Estimated Time left*: " + time_left);
console.log("Time it took to parse " + resolution + " blocks: " + time_duration_readable);
console.log("blocks left to parse: " + blocksLeft );
if(time_duration_readable.indexOf("0d") != -1) {
console.log("--------------------------------------------------")
console.log("*WARNING: this is just an ESTIMATE based on how much time it took to parse " + resolution + " blocks. But each block is different, some take longer than others because they have more transactions, and also, new blocks are continuously added");
console.log("If it takes too long, consider restarting geth with the '--fast' option (not suggested for developers), or better the '--cache=1024' or '--cache=2048 option that will assign more RAM to geth and make it faster");
}
}
// wait untill the number of Blocks isn't like the BlockLast
// and then calculate the time difference and show it on the console
console.log("\nGeth Syncing progress Time Estimate - STARTED - be patient, this might take ≈" + (resolution*5) + " seconds approximately")
do {
var cb = eth.syncing.currentBlock;
if (cb >= blockLast) {
endDate = new Date();
displayTimeEstimate()
}
} while(cb < blockLast)