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.

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