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.

123 lines
3.5 KiB

4 years ago
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
Update missing parts, improve til, and more - Node - Updated configuration to initialize the interface to all the smart contracts - Common - Moved BlockData and BatchData types to common so that they can be shared among: historydb, til and synchronizer - Remove hash.go (it was never used) - Remove slot.go (it was never used) - Remove smartcontractparams.go (it was never used, and appropriate structs are defined in `eth/`) - Comment state / status method until requirements of this method are properly defined, and move it to Synchronizer - Synchronizer - Simplify `Sync` routine to only sync one block per call, and return useful information. - Use BlockData and BatchData from common - Check that events belong to the expected block hash - In L1Batch, query L1UserTxs from HistoryDB - Fill ERC20 token information - Test AddTokens with test.Client - HistryDB - Use BlockData and BatchData from common - Add `GetAllTokens` method - Uncomment and update GetL1UserTxs (with corresponding tests) - Til - Rename all instances of RegisterToken to AddToken (to follow the smart contract implementation naming) - Use BlockData and BatchData from common - Move testL1CoordinatorTxs and testL2Txs to a separate struct from BatchData in Context - Start Context with BatchNum = 1 (which the protocol defines to be the first batchNum) - In every Batch, set StateRoot and ExitRoot to a non-nil big.Int (zero). - In all L1Txs, if LoadAmount is not used, set it to 0; if Amount is not used, set it to 0; so that no *big.Int is nil. - In L1UserTx, don't set BatchNum, because when L1UserTxs are created and obtained by the synchronizer, the BatchNum is not known yet (it's a synchronizer job to set it) - In L1UserTxs, set `UserOrigin` and set `ToForgeL1TxsNum`.
4 years ago
  1. package config
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "time"
  6. "github.com/BurntSushi/toml"
  7. ethCommon "github.com/ethereum/go-ethereum/common"
  8. "github.com/hermeznetwork/hermez-node/common"
  9. "gopkg.in/go-playground/validator.v9"
  10. )
  11. // Duration is a wrapper type that parses time duration from text.
  12. type Duration struct {
  13. time.Duration
  14. }
  15. // UnmarshalText unmarshalls time duration from text.
  16. func (d *Duration) UnmarshalText(data []byte) error {
  17. duration, err := time.ParseDuration(string(data))
  18. if err != nil {
  19. return err
  20. }
  21. d.Duration = duration
  22. return nil
  23. }
  24. // ServerProof is the server proof configuration data.
  25. type ServerProof struct {
  26. URL string `validate:"required"`
  27. }
  28. // Coordinator is the coordinator specific configuration.
  29. type Coordinator struct {
  30. ForgerAddress ethCommon.Address `validate:"required"`
  31. ForgeLoopInterval Duration `validate:"required"`
  32. L2DB struct {
  33. SafetyPeriod common.BatchNum `validate:"required"`
  34. MaxTxs uint32 `validate:"required"`
  35. TTL Duration `validate:"required"`
  36. } `validate:"required"`
  37. TxSelector struct {
  38. Path string `validate:"required"`
  39. } `validate:"required"`
  40. BatchBuilder struct {
  41. Path string `validate:"required"`
  42. } `validate:"required"`
  43. ServerProofs []ServerProof `validate:"required"`
  44. }
  45. // Node is the hermez node configuration.
  46. type Node struct {
  47. StateDB struct {
  48. Path string
  49. } `validate:"required"`
  50. PostgreSQL struct {
  51. Port int `validate:"required"`
  52. Host string `validate:"required"`
  53. User string `validate:"required"`
  54. Password string `validate:"required"`
  55. Name string `validate:"required"`
  56. } `validate:"required"`
  57. Web3 struct {
  58. URL string `validate:"required"`
  59. } `validate:"required"`
  60. Synchronizer struct {
  61. SyncLoopInterval Duration `validate:"required"`
  62. StartBlockNum struct {
  63. Rollup int64 `validate:"required"`
  64. Auction int64 `validate:"required"`
  65. WDelayer int64 `validate:"required"`
  66. } `validate:"required"`
  67. } `validate:"required"`
  68. SmartContracts struct {
  69. Rollup ethCommon.Address `validate:"required"`
  70. Auction ethCommon.Address `validate:"required"`
  71. TokenHEZ ethCommon.Address `validate:"required"`
  72. TokenHEZName string `validate:"required"`
  73. } `validate:"required"`
  74. EthClient struct {
  75. CallGasLimit uint64 `validate:"required"`
  76. DeployGasLimit uint64 `validate:"required"`
  77. GasPriceDiv uint64 `validate:"required"`
  78. ReceiptTimeout Duration `validate:"required"`
  79. IntervalReceiptLoop Duration `validate:"required"`
  80. } `validate:"required"`
  81. }
  82. // Load loads a generic config.
  83. func Load(path string, cfg interface{}) error {
  84. bs, err := ioutil.ReadFile(path) //nolint:gosec
  85. if err != nil {
  86. return err
  87. }
  88. cfgToml := string(bs)
  89. if _, err := toml.Decode(cfgToml, cfg); err != nil {
  90. return err
  91. }
  92. validate := validator.New()
  93. if err := validate.Struct(cfg); err != nil {
  94. return fmt.Errorf("error validating configuration file: %w", err)
  95. }
  96. return nil
  97. }
  98. // LoadCoordinator loads the Coordinator configuration from path.
  99. func LoadCoordinator(path string) (*Coordinator, error) {
  100. var cfg Coordinator
  101. if err := Load(path, &cfg); err != nil {
  102. return nil, fmt.Errorf("error loading coordinator configuration file: %w", err)
  103. }
  104. return &cfg, nil
  105. }
  106. // LoadNode loads the Node configuration from path.
  107. func LoadNode(path string) (*Node, error) {
  108. var cfg Node
  109. if err := Load(path, &cfg); err != nil {
  110. return nil, fmt.Errorf("error loading node configuration file: %w", err)
  111. }
  112. return &cfg, nil
  113. }