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.

126 lines
3.7 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. "github.com/hermeznetwork/hermez-node/synchronizer"
  10. "gopkg.in/go-playground/validator.v9"
  11. )
  12. // Duration is a wrapper type that parses time duration from text.
  13. type Duration struct {
  14. time.Duration
  15. }
  16. // UnmarshalText unmarshalls time duration from text.
  17. func (d *Duration) UnmarshalText(data []byte) error {
  18. duration, err := time.ParseDuration(string(data))
  19. if err != nil {
  20. return err
  21. }
  22. d.Duration = duration
  23. return nil
  24. }
  25. // ServerProof is the server proof configuration data.
  26. type ServerProof struct {
  27. URL string `validate:"required"`
  28. }
  29. // Coordinator is the coordinator specific configuration.
  30. type Coordinator struct {
  31. ForgerAddress ethCommon.Address `validate:"required"`
  32. ForgeLoopInterval Duration `validate:"required"`
  33. L2DB struct {
  34. SafetyPeriod common.BatchNum `validate:"required"`
  35. MaxTxs uint32 `validate:"required"`
  36. TTL Duration `validate:"required"`
  37. } `validate:"required"`
  38. TxSelector struct {
  39. Path string `validate:"required"`
  40. } `validate:"required"`
  41. BatchBuilder struct {
  42. Path string `validate:"required"`
  43. } `validate:"required"`
  44. ServerProofs []ServerProof `validate:"required"`
  45. }
  46. // Node is the hermez node configuration.
  47. type Node struct {
  48. StateDB struct {
  49. Path string
  50. } `validate:"required"`
  51. PostgreSQL struct {
  52. Port int `validate:"required"`
  53. Host string `validate:"required"`
  54. User string `validate:"required"`
  55. Password string `validate:"required"`
  56. Name string `validate:"required"`
  57. } `validate:"required"`
  58. Web3 struct {
  59. URL string `validate:"required"`
  60. } `validate:"required"`
  61. Synchronizer struct {
  62. SyncLoopInterval Duration `validate:"required"`
  63. StatsRefreshPeriod Duration `validate:"required"`
  64. StartBlockNum synchronizer.ConfigStartBlockNum `validate:"required"`
  65. InitialVariables synchronizer.SCVariables `validate:"required"`
  66. } `validate:"required"`
  67. SmartContracts struct {
  68. Rollup ethCommon.Address `validate:"required"`
  69. Auction ethCommon.Address `validate:"required"`
  70. WDelayer 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. Debug struct {
  82. APIAddress string
  83. }
  84. }
  85. // Load loads a generic config.
  86. func Load(path string, cfg interface{}) error {
  87. bs, err := ioutil.ReadFile(path) //nolint:gosec
  88. if err != nil {
  89. return err
  90. }
  91. cfgToml := string(bs)
  92. if _, err := toml.Decode(cfgToml, cfg); err != nil {
  93. return err
  94. }
  95. validate := validator.New()
  96. if err := validate.Struct(cfg); err != nil {
  97. return fmt.Errorf("error validating configuration file: %w", err)
  98. }
  99. return nil
  100. }
  101. // LoadCoordinator loads the Coordinator configuration from path.
  102. func LoadCoordinator(path string) (*Coordinator, error) {
  103. var cfg Coordinator
  104. if err := Load(path, &cfg); err != nil {
  105. return nil, fmt.Errorf("error loading coordinator configuration file: %w", err)
  106. }
  107. return &cfg, nil
  108. }
  109. // LoadNode loads the Node configuration from path.
  110. func LoadNode(path string) (*Node, error) {
  111. var cfg Node
  112. if err := Load(path, &cfg); err != nil {
  113. return nil, fmt.Errorf("error loading node configuration file: %w", err)
  114. }
  115. return &cfg, nil
  116. }