You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.3 KiB

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