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```
 12NAME:
 13   hermez-node - A new cli application
 14
 15USAGE:
 16   node [global options] command [command options] [arguments...]
 17
 18VERSION:
 19   0.1.0-alpha
 20
 21COMMANDS:
 22   importkey  Import ethereum private key
 23   genbjj     Generate a new BabyJubJub key
 24   wipesql    Wipe the SQL DB (HistoryDB and L2DB), leaving the DB in a clean state
 25   run        Run the hermez-node in the indicated mode
 26   help, h    Shows a list of commands or help for one command
 27
 28GLOBAL OPTIONS:
 29   --mode MODE    Set node MODE (can be "sync" or "coord")
 30   --cfg FILE     Node configuration FILE
 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```
 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```
 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```
102./node --mode sync --cfg cfg.buidler.toml run
103```
104
105Run the node in mode coordinator:
106```
107./node --mode coord --cfg cfg.buidler.toml run
108```
109
110Import an ethereum private key into the keystore:
111```
112./node --mode coord --cfg cfg.buidler.toml importkey --privatekey  0x618b35096c477aab18b11a752be619f0023a539bb02dd6c813477a6211916cde
113```
114
115Generate a new BabyJubJub key pair:
116```
117./node --mode coord --cfg cfg.buidler.toml genbjj
118```
119
120Wipe the entier SQL database (this will destroy all synchronized and pool
121data):
122```
123./node --mode coord --cfg cfg.buidler.toml wipesql
124```
125
126Discard all synchronized blocks and associated state up to a given block
127number.  This command is useful in case the synchronizer reaches an invalid
128state and you want to roll back a few blocks and try again (maybe with some
129fixes in the code).
130```
131./node --mode coord --cfg cfg.buidler.toml discard --block 8061330
132```