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 |
|
package config
import ( "fmt" "io/ioutil" "time"
"github.com/BurntSushi/toml" ethCommon "github.com/ethereum/go-ethereum/common" "github.com/hermeznetwork/hermez-node/common" "gopkg.in/go-playground/validator.v9" )
// Duration is a wrapper type that parses time duration from text.
type Duration struct { time.Duration }
// UnmarshalText unmarshalls time duration from text.
func (d *Duration) UnmarshalText(data []byte) error { duration, err := time.ParseDuration(string(data)) if err != nil { return err } d.Duration = duration return nil }
// ServerProof is the server proof configuration data.
type ServerProof struct { URL string `validate:"required"` }
// Coordinator is the coordinator specific configuration.
type Coordinator struct { ForgerAddress ethCommon.Address `validate:"required"` ForgeLoopInterval Duration `validate:"required"` L2DB struct { SafetyPeriod common.BatchNum `validate:"required"` MaxTxs uint32 `validate:"required"` TTL Duration `validate:"required"` } `validate:"required"` TxSelector struct { Path string `validate:"required"` } `validate:"required"` BatchBuilder struct { Path string `validate:"required"` } `validate:"required"` ServerProofs []ServerProof `validate:"required"` }
// Node is the hermez node configuration.
type Node struct { StateDB struct { Path string } `validate:"required"` PostgreSQL struct { Port int `validate:"required"` Host string `validate:"required"` User string `validate:"required"` Password string `validate:"required"` Name string `validate:"required"` } `validate:"required"` Web3 struct { URL string `validate:"required"` } `validate:"required"` Synchronizer struct { SyncLoopInterval Duration `validate:"required"` } `validate:"required"` SmartContracts struct { Rollup ethCommon.Address `validate:"required"` Auction ethCommon.Address `validate:"required"` TokenHEZ ethCommon.Address `validate:"required"` } `validate:"required"` EthClient struct { CallGasLimit uint64 `validate:"required"` DeployGasLimit uint64 `validate:"required"` GasPriceDiv uint64 `validate:"required"` ReceiptTimeout Duration `validate:"required"` IntervalReceiptLoop Duration `validate:"required"` } `validate:"required"` }
// Load loads a generic config.
func Load(path string, cfg interface{}) error { bs, err := ioutil.ReadFile(path) //nolint:gosec
if err != nil { return err } cfgToml := string(bs) if _, err := toml.Decode(cfgToml, cfg); err != nil { return err } validate := validator.New() if err := validate.Struct(cfg); err != nil { return fmt.Errorf("error validating configuration file: %w", err) } return nil }
// LoadCoordinator loads the Coordinator configuration from path.
func LoadCoordinator(path string) (*Coordinator, error) { var cfg Coordinator if err := Load(path, &cfg); err != nil { return nil, fmt.Errorf("error loading coordinator configuration file: %w", err) } return &cfg, nil }
// LoadNode loads the Node configuration from path.
func LoadNode(path string) (*Node, error) { var cfg Node if err := Load(path, &cfg); err != nil { return nil, fmt.Errorf("error loading node configuration file: %w", err) } return &cfg, nil }
|