arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
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
 72## Building
 73
 74*All commands assume you are at the `cli/node` directory.*
 75
 76Building the node requires using the packr utility to bundle the database
 77migrations inside the resulting binary.  Install the packr utility with:
 78```shell
 79cd /tmp && go get -u github.com/gobuffalo/packr/v2/packr2 && cd -
 80```
 81
 82Make sure your `$PATH` contains `$GOPATH/bin`, otherwise the packr utility will
 83not be found.
 84
 85Now build the node executable:
 86```shell
 87cd ../../db && packr2 && cd -
 88go build .
 89cd ../../db && packr2 clean && cd -
 90```
 91
 92The executable is `node`.
 93
 94## Usage Examples
 95
 96The following commands assume you have built the node previously.  You can also
 97run the following examples by replacing `./node` with `go run .` and executing
 98them in the `cli/node` directory to build from source and run at the same time.
 99
100Run the node in mode synchronizer:
101```shell
102./node run --mode sync --cfg cfg.buidler.toml
103```
104
105Run the node in mode coordinator:
106```shell
107./node run --mode coord --cfg cfg.buidler.toml
108```
109
110Import an ethereum private key into the keystore:
111```shell
112./node importkey --mode coord --cfg cfg.buidler.toml --privatekey  0x618b35096c477aab18b11a752be619f0023a539bb02dd6c813477a6211916cde
113```
114
115Generate a new BabyJubJub key pair:
116```shell
117./node genbjj
118```
119
120Check the binary version:
121```shell
122./node version
123```
124
125Wipe the entier SQL database (this will destroy all synchronized and pool
126data):
127```shell
128./node wipesql --mode coord --cfg cfg.buidler.toml 
129```
130
131Discard all synchronized blocks and associated state up to a given block
132number.  This command is useful in case the synchronizer reaches an invalid
133state and you want to roll back a few blocks and try again (maybe with some
134fixes in the code).
135```shell
136./node discard --mode coord --cfg cfg.buidler.toml --block 8061330
137```