Skip to content

Commit 305fbe6

Browse files
committed
Fork detection script
Rename network type to chain type in detector.py
1 parent 92743c3 commit 305fbe6

File tree

3 files changed

+876
-0
lines changed

3 files changed

+876
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Fork detection script, for the extra peace of mind
2+
3+
Here we have `detector.py`, which is a relatively crude way of detecting a permanent fork (split)
4+
in the network if it happens.
5+
6+
The script basically runs the full sync in a loop, checking the node's log output for certain errors
7+
and comparing its mainchain block ids with those obtained from the API server.\
8+
If anything suspicious is detected during the full sync, the script will save the node's data
9+
directory and log file.\
10+
In any case, the script will temporarily ban some of the peers that participated in the sync
11+
(so that the next iteration has a chance to have different ones and to reduce the strain on
12+
the network) and start the full sync all over again, reusing the peerdb from the previous iteration.
13+
14+
The node is always run with checkpoints disabled, so that it has the chance to find older forks too.
15+
16+
The structure of the script's working directory (specified via the command line):
17+
- `current_attempt` - this corresponds to the current sync attempt (iteration).
18+
- `saved_attempts` - this contains subdirectories corresponding to attempts that
19+
are considered suspicious; each subdirectory's name is the datetime of the moment
20+
when the attempt was finished.
21+
- `saved_peer_dbs` - this is where peer dbs from previous attempts are stored; the script
22+
only needs the one from the latest attempt, but, just in case, the penultimate one is
23+
also stored.
24+
- `log.txt` - this is the log of the script itself.
25+
26+
Each attempt's directory has the following structure:
27+
- `flags` - this directory contains flag files (which are usually zero-length) indicating
28+
that certain problems were found during the sync. It is what determines whether the attempt's
29+
directory will be saved in the end (i.e. if the directory is non-empty, the attempt will be saved).
30+
- `node_data` - this is the node's data directory of this attempt.
31+
- `node_log.txt` - the node's log.
32+
33+
Note: currently the script requires Python 3.13 to run, though we may lift this requirement later.

0 commit comments

Comments
 (0)