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.

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