hermez-node/cli/node/README.md
cli/node/README.mdRaw
1# node cli
2
3This is the main cli for the node
4
5## Go version
6
7The `hermez-node` has been tested with go version 1.14
8
9## Usage
10
11```shell
12NAME:
13 hermez-node - A new cli application
14
15USAGE:
16 node [global options] command [command options] [arguments...]
17
18VERSION:
19 v0.1.0-6-gd8a50c5
20
21COMMANDS:
22 version Show the application version
23 importkey Import ethereum private key
24 genbjj Generate a new BabyJubJub key
25 wipesql Wipe the SQL DB (HistoryDB and L2DB) and the StateDBs, leaving the DB in a clean state
26 run Run the hermez-node in the indicated mode
27 discard Discard blocks up to a specified block number
28 help, h Shows a list of commands or help for one command
29
30GLOBAL OPTIONS:
31 --help, -h show help (default: false)
32 --version, -v print the version (default: false)
33```
34
35The node has two main modes of running:
36- `sync`: Synchronizer mode. In this mode the node will only synchronize the
37 state of the hermez smart contracts, mainly processing the transactions in
38 the batches.
39- `coord`: Coordinator mode. In this mode, apart from doing all the
40 synchronization work, the node will also act as a coordinator, accepting L2
41 transactions in the pool, and trying to forge batches when the proper
42 conditions arise.
43
44## Configuration
45
46The node requires a single configuration file to run.
47
48You can find a testing working configuration example at
49[cfg.buidler.toml](./cfg.buidler.toml)
50
51To read the documentation of each configuration parameter, please check the
52`type Node` and `type Coordinator` at
53[config/config.go](../../config/config.go). All the sections that are prefixed
54with `Coordinator` are only used in coord mode, and don't need to be defined
55when running the coordinator in sync mode
56
57### Notes
58
59- The private key corresponding to the parameter `Coordinator.ForgerAddress` needs to be imported in the ethereum keystore
60- The private key corresponding to the parameter `Coordinator.FeeAccount.Address` needs to be imported in the ethereum keystore
61- The public key corresponding to the parameter `Coordinator.FeeAccount.BJJ` can be generated with the command `genbjj`
62- There are two sets of debug parameters (`Debug` for all modes, and
63 `Coordinator.Debug` for `coord` mode). Some of these parameters may not be
64 suitable for production.
65- The parameter `Coordinator.Debug.BatchPath`, when set, causes the coordinator
66 to store dumps of a lot of information related to batches in json files.
67 This files can be around 2MB big. If this parameter is set, be careful to
68 monitor the size of the folder to avoid running out of space.
69- The node requires a PostgreSQL database. The parameters of the server and
70 database must be set in the `PostgreSQL` section.
71- The node requires a web3 RPC server to work. The node has only been tested
72 with geth and may not work correctly with other ethereum nodes
73 implementations.
74
75## Building
76
77*All commands assume you are at the `cli/node` directory.*
78
79Building the node requires using the packr utility to bundle the database
80migrations inside the resulting binary. Install the packr utility with:
81```shell
82cd /tmp && go get -u github.com/gobuffalo/packr/v2/packr2 && cd -
83```
84
85Make sure your `$PATH` contains `$GOPATH/bin`, otherwise the packr utility will
86not be found.
87
88Now build the node executable:
89```shell
90cd ../../db && packr2 && cd -
91go build .
92cd ../../db && packr2 clean && cd -
93```
94
95The executable is `node`.
96
97## Usage Examples
98
99The following commands assume you have built the node previously. You can also
100run the following examples by replacing `./node` with `go run .` and executing
101them in the `cli/node` directory to build from source and run at the same time.
102
103Run the node in mode synchronizer:
104```shell
105./node run --mode sync --cfg cfg.buidler.toml
106```
107
108Run the node in mode coordinator:
109```shell
110./node run --mode coord --cfg cfg.buidler.toml
111```
112
113Import an ethereum private key into the keystore:
114```shell
115./node importkey --mode coord --cfg cfg.buidler.toml --privatekey 0x618b35096c477aab18b11a752be619f0023a539bb02dd6c813477a6211916cde
116```
117
118Generate a new BabyJubJub key pair:
119```shell
120./node genbjj
121```
122
123Check the binary version:
124```shell
125./node version
126```
127
128Wipe the entier SQL database (this will destroy all synchronized and pool
129data):
130```shell
131./node wipesql --mode coord --cfg cfg.buidler.toml
132```
133
134Discard all synchronized blocks and associated state up to a given block
135number. This command is useful in case the synchronizer reaches an invalid
136state and you want to roll back a few blocks and try again (maybe with some
137fixes in the code).
138```shell
139./node discard --mode coord --cfg cfg.buidler.toml --block 8061330
140```