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.

118 lines
3.3 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. } `validate:"required"`
  63. SmartContracts struct {
  64. Rollup ethCommon.Address `validate:"required"`
  65. Auction ethCommon.Address `validate:"required"`
  66. TokenHEZ ethCommon.Address `validate:"required"`
  67. TokenHEZName string `validate:"required"`
  68. } `validate:"required"`
  69. EthClient struct {
  70. CallGasLimit uint64 `validate:"required"`
  71. DeployGasLimit uint64 `validate:"required"`
  72. GasPriceDiv uint64 `validate:"required"`
  73. ReceiptTimeout Duration `validate:"required"`
  74. IntervalReceiptLoop Duration `validate:"required"`
  75. } `validate:"required"`
  76. }
  77. // Load loads a generic config.
  78. func Load(path string, cfg interface{}) error {
  79. bs, err := ioutil.ReadFile(path) //nolint:gosec
  80. if err != nil {
  81. return err
  82. }
  83. cfgToml := string(bs)
  84. if _, err := toml.Decode(cfgToml, cfg); err != nil {
  85. return err
  86. }
  87. validate := validator.New()
  88. if err := validate.Struct(cfg); err != nil {
  89. return fmt.Errorf("error validating configuration file: %w", err)
  90. }
  91. return nil
  92. }
  93. // LoadCoordinator loads the Coordinator configuration from path.
  94. func LoadCoordinator(path string) (*Coordinator, error) {
  95. var cfg Coordinator
  96. if err := Load(path, &cfg); err != nil {
  97. return nil, fmt.Errorf("error loading coordinator configuration file: %w", err)
  98. }
  99. return &cfg, nil
  100. }
  101. // LoadNode loads the Node configuration from path.
  102. func LoadNode(path string) (*Node, error) {
  103. var cfg Node
  104. if err := Load(path, &cfg); err != nil {
  105. return nil, fmt.Errorf("error loading node configuration file: %w", err)
  106. }
  107. return &cfg, nil
  108. }