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.

153 lines
5.1 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
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. - The node requires a web3 RPC server to work. The node has only been tested
  60. with geth and may not work correctly with other ethereum nodes
  61. implementations.
  62. ## Building
  63. *All commands assume you are at the `cli/node` directory.*
  64. Building the node requires using the packr utility to bundle the database
  65. migrations inside the resulting binary. Install the packr utility with:
  66. ```shell
  67. cd /tmp && go get -u github.com/gobuffalo/packr/v2/packr2 && cd -
  68. ```
  69. Make sure your `$PATH` contains `$GOPATH/bin`, otherwise the packr utility will
  70. not be found.
  71. Now build the node executable:
  72. ```shell
  73. cd ../../db && packr2 && cd -
  74. go build .
  75. cd ../../db && packr2 clean && cd -
  76. ```
  77. The executable is `node`.
  78. ## Usage Examples
  79. The following commands assume you have built the node previously. You can also
  80. run the following examples by replacing `./node` with `go run .` and executing
  81. them in the `cli/node` directory to build from source and run at the same time.
  82. Run the node in mode synchronizer:
  83. ```shell
  84. ./node run --mode sync --cfg cfg.buidler.toml
  85. ```
  86. Run the node in mode coordinator:
  87. ```shell
  88. ./node run --mode coord --cfg cfg.buidler.toml
  89. ```
  90. Serve the API in standalone mode. This command allows serving the API just
  91. with access to the PostgreSQL database that a node is using. Several instances
  92. of `serveapi` can be running at the same time with a single PostgreSQL
  93. database:
  94. ```shell
  95. ./node serveapi --mode coord --cfg cfg.buidler.toml
  96. ```
  97. Import an ethereum private key into the keystore:
  98. ```shell
  99. ./node importkey --mode coord --cfg cfg.buidler.toml --privatekey 0x618b35096c477aab18b11a752be619f0023a539bb02dd6c813477a6211916cde
  100. ```
  101. Generate a new BabyJubJub key pair:
  102. ```shell
  103. ./node genbjj
  104. ```
  105. Check the binary version:
  106. ```shell
  107. ./node version
  108. ```
  109. Wipe the entier SQL database (this will destroy all synchronized and pool
  110. data):
  111. ```shell
  112. ./node wipesql --mode coord --cfg cfg.buidler.toml
  113. ```
  114. Discard all synchronized blocks and associated state up to a given block
  115. number. This command is useful in case the synchronizer reaches an invalid
  116. state and you want to roll back a few blocks and try again (maybe with some
  117. fixes in the code).
  118. ```shell
  119. ./node discard --mode coord --cfg cfg.buidler.toml --block 8061330
  120. ```