mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Merge pull request #365 from hermeznetwork/feature/nodecfg
Merge node (sync-only) and coord config
This commit is contained in:
@@ -93,3 +93,46 @@ TokenHEZName = "Hermez Network Token"
|
||||
Withdrawals = 0
|
||||
BlockWithdrawalRate = 0
|
||||
MaxWithdrawals = 0
|
||||
|
||||
|
||||
[Coordinator]
|
||||
ForgerAddress = "0x6BB84Cc84D4A34467aD12a2039A312f7029e2071"
|
||||
ConfirmBlocks = 10
|
||||
L1BatchTimeoutPerc = 0.6
|
||||
ProofServerPollInterval = "1s"
|
||||
SyncRetryInterval = "1s"
|
||||
|
||||
[Coordinator.L2DB]
|
||||
SafetyPeriod = 10
|
||||
MaxTxs = 512
|
||||
TTL = "24h"
|
||||
PurgeBatchDelay = 10
|
||||
InvalidateBatchDelay = 20
|
||||
PurgeBlockDelay = 10
|
||||
InvalidateBlockDelay = 20
|
||||
|
||||
[Coordinator.TxSelector]
|
||||
Path = "/tmp/iden3-test/hermez/txselector"
|
||||
|
||||
[Coordinator.BatchBuilder]
|
||||
Path = "/tmp/iden3-test/hermez/batchbuilder"
|
||||
|
||||
[[Coordinator.ServerProofs]]
|
||||
URL = "http://localhost:3000"
|
||||
|
||||
[Coordinator.EthClient]
|
||||
CallGasLimit = 300000
|
||||
DeployGasLimit = 1000000
|
||||
GasPriceDiv = 100
|
||||
ReceiptTimeout = "60s"
|
||||
ReceiptLoopInterval = "500ms"
|
||||
|
||||
CheckLoopInterval = "500ms"
|
||||
Attempts = 8
|
||||
AttemptsDelay = "200ms"
|
||||
|
||||
[Coordinator.API]
|
||||
Coordinator = true
|
||||
|
||||
[Coordinator.Debug]
|
||||
BatchPath = "/tmp/iden3-test/hermez/batchesdebug"
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
[StateDB]
|
||||
Path = "/tmp/iden3-test/hermez/statedb"
|
||||
|
||||
[PostgreSQL]
|
||||
Port = 5432
|
||||
Host = "localhost"
|
||||
User = "hermez"
|
||||
Password = "yourpasswordhere"
|
||||
Name = "hermez"
|
||||
|
||||
[L2DB]
|
||||
SafetyPeriod = 10
|
||||
MaxTxs = 512
|
||||
TTL = "24h"
|
||||
|
||||
[Web3]
|
||||
URL = "XXX"
|
||||
|
||||
[Synchronizer]
|
||||
SyncLoopInterval = "1s"
|
||||
|
||||
[SmartContracts]
|
||||
Rollup = "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0"
|
||||
Auction = "0x500D1d6A4c7D8Ae28240b47c8FCde034D827fD5e"
|
||||
TokenHEZ = "0xf784709d2317D872237C4bC22f867d1BAe2913AB"
|
||||
TokenHEZName = "Hermez Network Token"
|
||||
|
||||
[EthClient]
|
||||
CallGasLimit = 300000
|
||||
DeployGasLimit = 1000000
|
||||
GasPriceDiv = 100
|
||||
ReceiptTimeout = "60s"
|
||||
IntervalReceiptLoop = "200ms"
|
||||
@@ -1,40 +0,0 @@
|
||||
ForgerAddress = "0x6BB84Cc84D4A34467aD12a2039A312f7029e2071"
|
||||
ConfirmBlocks = 10
|
||||
L1BatchTimeoutPerc = 0.6
|
||||
ProofServerPollInterval = "1s"
|
||||
SyncRetryInterval = "1s"
|
||||
|
||||
[L2DB]
|
||||
SafetyPeriod = 10
|
||||
MaxTxs = 512
|
||||
TTL = "24h"
|
||||
PurgeBatchDelay = 10
|
||||
InvalidateBatchDelay = 20
|
||||
PurgeBlockDelay = 10
|
||||
InvalidateBlockDelay = 20
|
||||
|
||||
[TxSelector]
|
||||
Path = "/tmp/iden3-test/hermez/txselector"
|
||||
|
||||
[BatchBuilder]
|
||||
Path = "/tmp/iden3-test/hermez/batchbuilder"
|
||||
|
||||
[[ServerProofs]]
|
||||
URL = "http://localhost:3000"
|
||||
|
||||
[EthClient]
|
||||
CallGasLimit = 300000
|
||||
DeployGasLimit = 1000000
|
||||
GasPriceDiv = 100
|
||||
ReceiptTimeout = "60s"
|
||||
ReceiptLoopInterval = "500ms"
|
||||
|
||||
CheckLoopInterval = "500ms"
|
||||
Attempts = 8
|
||||
AttemptsDelay = "200ms"
|
||||
|
||||
[API]
|
||||
Coordinator = true
|
||||
|
||||
[Debug]
|
||||
BatchPath = "/tmp/iden3-test/hermez/batchesdebug"
|
||||
@@ -1,14 +0,0 @@
|
||||
ForgerAddress = "0x6BB84Cc84D4A34467aD12a2039A312f7029e2071"
|
||||
ForgerLoopInterval = "500ms"
|
||||
|
||||
[EthClient]
|
||||
CallGasLimit = 300000
|
||||
DeployGasLimit = 1000000
|
||||
GasPriceDiv = 100
|
||||
ReceiptTimeout = "60s"
|
||||
IntervalReceiptLoop = "200ms"
|
||||
|
||||
[L2DB]
|
||||
SafetyPeriod = 10
|
||||
MaxTxs = 512
|
||||
TTL = "24h"
|
||||
@@ -13,11 +13,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
flagCfg = "cfg"
|
||||
flagCoordCfg = "coordcfg"
|
||||
flagMode = "mode"
|
||||
modeSync = "sync"
|
||||
modeCoord = "coord"
|
||||
flagCfg = "cfg"
|
||||
flagMode = "mode"
|
||||
modeSync = "sync"
|
||||
modeCoord = "coord"
|
||||
)
|
||||
|
||||
func cmdInit(c *cli.Context) error {
|
||||
@@ -35,7 +34,7 @@ func cmdRun(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return tracerr.Wrap(fmt.Errorf("error parsing flags and config: %w", err))
|
||||
}
|
||||
node, err := node.NewNode(cfg.mode, cfg.node, cfg.coord)
|
||||
node, err := node.NewNode(cfg.mode, cfg.node)
|
||||
if err != nil {
|
||||
return tracerr.Wrap(fmt.Errorf("error starting node: %w", err))
|
||||
}
|
||||
@@ -61,9 +60,8 @@ func cmdRun(c *cli.Context) error {
|
||||
|
||||
// Config is the configuration of the hermez node execution
|
||||
type Config struct {
|
||||
mode node.Mode
|
||||
node *config.Node
|
||||
coord *config.Coordinator
|
||||
mode node.Mode
|
||||
node *config.Node
|
||||
}
|
||||
|
||||
func parseCli(c *cli.Context) (*Config, error) {
|
||||
@@ -80,36 +78,27 @@ func parseCli(c *cli.Context) (*Config, error) {
|
||||
func getConfig(c *cli.Context) (*Config, error) {
|
||||
var cfg Config
|
||||
mode := c.String(flagMode)
|
||||
switch mode {
|
||||
case modeSync:
|
||||
cfg.mode = node.ModeSynchronizer
|
||||
case modeCoord:
|
||||
cfg.mode = node.ModeCoordinator
|
||||
default:
|
||||
return nil, tracerr.Wrap(fmt.Errorf("invalid mode \"%v\"", mode))
|
||||
}
|
||||
|
||||
if cfg.mode == node.ModeCoordinator {
|
||||
coordCfgPath := c.String(flagCoordCfg)
|
||||
if coordCfgPath == "" {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("required flag \"%v\" not set", flagCoordCfg))
|
||||
}
|
||||
coordCfg, err := config.LoadCoordinator(coordCfgPath)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
cfg.coord = coordCfg
|
||||
}
|
||||
nodeCfgPath := c.String(flagCfg)
|
||||
if nodeCfgPath == "" {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("required flag \"%v\" not set", flagCfg))
|
||||
}
|
||||
nodeCfg, err := config.LoadNode(nodeCfgPath)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
var err error
|
||||
switch mode {
|
||||
case modeSync:
|
||||
cfg.mode = node.ModeSynchronizer
|
||||
cfg.node, err = config.LoadNode(nodeCfgPath)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
case modeCoord:
|
||||
cfg.mode = node.ModeCoordinator
|
||||
cfg.node, err = config.LoadCoordinator(nodeCfgPath)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
default:
|
||||
return nil, tracerr.Wrap(fmt.Errorf("invalid mode \"%v\"", mode))
|
||||
}
|
||||
// nodeCfg.Synchronizer.InitialVariables.WDelayer.HermezRollupAddress = nodeCfg.SmartContracts.Rollup
|
||||
cfg.node = nodeCfg
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
@@ -129,10 +118,6 @@ func main() {
|
||||
Usage: "Node configuration `FILE`",
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: flagCoordCfg,
|
||||
Usage: "Coordinator configuration `FILE`",
|
||||
},
|
||||
}
|
||||
|
||||
app.Commands = []*cli.Command{
|
||||
|
||||
@@ -132,6 +132,7 @@ type Node struct {
|
||||
Debug struct {
|
||||
APIAddress string
|
||||
}
|
||||
Coordinator Coordinator `validate:"-"`
|
||||
}
|
||||
|
||||
// Load loads a generic config.
|
||||
@@ -144,18 +145,21 @@ func Load(path string, cfg interface{}) error {
|
||||
if _, err := toml.Decode(cfgToml, cfg); err != nil {
|
||||
return tracerr.Wrap(err)
|
||||
}
|
||||
validate := validator.New()
|
||||
if err := validate.Struct(cfg); err != nil {
|
||||
return tracerr.Wrap(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
|
||||
func LoadCoordinator(path string) (*Node, error) {
|
||||
var cfg Node
|
||||
if err := Load(path, &cfg); err != nil {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("error loading coordinator configuration file: %w", err))
|
||||
return nil, tracerr.Wrap(fmt.Errorf("error loading node configuration file: %w", err))
|
||||
}
|
||||
validate := validator.New()
|
||||
if err := validate.Struct(cfg); err != nil {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("error validating configuration file: %w", err))
|
||||
}
|
||||
if err := validate.Struct(cfg.Coordinator); err != nil {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("error validating configuration file: %w", err))
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
@@ -166,5 +170,9 @@ func LoadNode(path string) (*Node, error) {
|
||||
if err := Load(path, &cfg); err != nil {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("error loading node configuration file: %w", err))
|
||||
}
|
||||
validate := validator.New()
|
||||
if err := validate.Struct(cfg); err != nil {
|
||||
return nil, tracerr.Wrap(fmt.Errorf("error validating configuration file: %w", err))
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
58
node/node.go
58
node/node.go
@@ -49,8 +49,7 @@ type Node struct {
|
||||
nodeAPI *NodeAPI
|
||||
debugAPI *debugapi.DebugAPI
|
||||
// Coordinator
|
||||
coord *coordinator.Coordinator
|
||||
coordCfg *config.Coordinator
|
||||
coord *coordinator.Coordinator
|
||||
|
||||
// Synchronizer
|
||||
sync *synchronizer.Synchronizer
|
||||
@@ -65,7 +64,7 @@ type Node struct {
|
||||
}
|
||||
|
||||
// NewNode creates a Node
|
||||
func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node, error) {
|
||||
func NewNode(mode Mode, cfg *config.Node) (*Node, error) {
|
||||
// Stablish DB connection
|
||||
db, err := dbUtils.InitSQLDB(
|
||||
cfg.PostgreSQL.Port,
|
||||
@@ -92,11 +91,11 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node,
|
||||
var ethCfg eth.EthereumConfig
|
||||
if mode == ModeCoordinator {
|
||||
ethCfg = eth.EthereumConfig{
|
||||
CallGasLimit: coordCfg.EthClient.CallGasLimit,
|
||||
DeployGasLimit: coordCfg.EthClient.DeployGasLimit,
|
||||
GasPriceDiv: coordCfg.EthClient.GasPriceDiv,
|
||||
ReceiptTimeout: coordCfg.EthClient.ReceiptTimeout.Duration,
|
||||
IntervalReceiptLoop: coordCfg.EthClient.ReceiptLoopInterval.Duration,
|
||||
CallGasLimit: cfg.Coordinator.EthClient.CallGasLimit,
|
||||
DeployGasLimit: cfg.Coordinator.EthClient.DeployGasLimit,
|
||||
GasPriceDiv: cfg.Coordinator.EthClient.GasPriceDiv,
|
||||
ReceiptTimeout: cfg.Coordinator.EthClient.ReceiptTimeout.Duration,
|
||||
IntervalReceiptLoop: cfg.Coordinator.EthClient.ReceiptLoopInterval.Duration,
|
||||
}
|
||||
}
|
||||
client, err := eth.NewClient(ethClient, nil, nil, ð.ClientConfig{
|
||||
@@ -140,45 +139,45 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node,
|
||||
if mode == ModeCoordinator {
|
||||
l2DB = l2db.NewL2DB(
|
||||
db,
|
||||
coordCfg.L2DB.SafetyPeriod,
|
||||
coordCfg.L2DB.MaxTxs,
|
||||
coordCfg.L2DB.TTL.Duration,
|
||||
cfg.Coordinator.L2DB.SafetyPeriod,
|
||||
cfg.Coordinator.L2DB.MaxTxs,
|
||||
cfg.Coordinator.L2DB.TTL.Duration,
|
||||
)
|
||||
// TODO: Get (maxL1UserTxs, maxL1OperatorTxs, maxTxs) from the smart contract
|
||||
txSelector, err := txselector.NewTxSelector(coordCfg.TxSelector.Path, stateDB, l2DB, 10, 10, 10)
|
||||
txSelector, err := txselector.NewTxSelector(cfg.Coordinator.TxSelector.Path, stateDB, l2DB, 10, 10, 10)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
// TODO: Get (configCircuits []ConfigCircuit, batchNum common.BatchNum, nLevels uint64) from smart contract
|
||||
nLevels := uint64(32) //nolint:gomnd
|
||||
batchBuilder, err := batchbuilder.NewBatchBuilder(coordCfg.BatchBuilder.Path, stateDB, nil, 0, nLevels)
|
||||
batchBuilder, err := batchbuilder.NewBatchBuilder(cfg.Coordinator.BatchBuilder.Path, stateDB, nil, 0, nLevels)
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
serverProofs := make([]prover.Client, len(coordCfg.ServerProofs))
|
||||
for i, serverProofCfg := range coordCfg.ServerProofs {
|
||||
serverProofs := make([]prover.Client, len(cfg.Coordinator.ServerProofs))
|
||||
for i, serverProofCfg := range cfg.Coordinator.ServerProofs {
|
||||
serverProofs[i] = prover.NewProofServerClient(serverProofCfg.URL,
|
||||
coordCfg.ProofServerPollInterval.Duration)
|
||||
cfg.Coordinator.ProofServerPollInterval.Duration)
|
||||
}
|
||||
|
||||
coord, err = coordinator.NewCoordinator(
|
||||
coordinator.Config{
|
||||
ForgerAddress: coordCfg.ForgerAddress,
|
||||
ConfirmBlocks: coordCfg.ConfirmBlocks,
|
||||
L1BatchTimeoutPerc: coordCfg.L1BatchTimeoutPerc,
|
||||
SyncRetryInterval: coordCfg.SyncRetryInterval.Duration,
|
||||
EthClientAttempts: coordCfg.EthClient.Attempts,
|
||||
EthClientAttemptsDelay: coordCfg.EthClient.AttemptsDelay.Duration,
|
||||
TxManagerCheckInterval: coordCfg.EthClient.CheckLoopInterval.Duration,
|
||||
DebugBatchPath: coordCfg.Debug.BatchPath,
|
||||
ForgerAddress: cfg.Coordinator.ForgerAddress,
|
||||
ConfirmBlocks: cfg.Coordinator.ConfirmBlocks,
|
||||
L1BatchTimeoutPerc: cfg.Coordinator.L1BatchTimeoutPerc,
|
||||
SyncRetryInterval: cfg.Coordinator.SyncRetryInterval.Duration,
|
||||
EthClientAttempts: cfg.Coordinator.EthClient.Attempts,
|
||||
EthClientAttemptsDelay: cfg.Coordinator.EthClient.AttemptsDelay.Duration,
|
||||
TxManagerCheckInterval: cfg.Coordinator.EthClient.CheckLoopInterval.Duration,
|
||||
DebugBatchPath: cfg.Coordinator.Debug.BatchPath,
|
||||
Purger: coordinator.PurgerCfg{
|
||||
PurgeBatchDelay: coordCfg.L2DB.PurgeBatchDelay,
|
||||
InvalidateBatchDelay: coordCfg.L2DB.InvalidateBatchDelay,
|
||||
PurgeBlockDelay: coordCfg.L2DB.PurgeBlockDelay,
|
||||
InvalidateBlockDelay: coordCfg.L2DB.InvalidateBlockDelay,
|
||||
PurgeBatchDelay: cfg.Coordinator.L2DB.PurgeBatchDelay,
|
||||
InvalidateBatchDelay: cfg.Coordinator.L2DB.InvalidateBatchDelay,
|
||||
PurgeBlockDelay: cfg.Coordinator.L2DB.PurgeBlockDelay,
|
||||
InvalidateBlockDelay: cfg.Coordinator.L2DB.InvalidateBlockDelay,
|
||||
},
|
||||
},
|
||||
historyDB,
|
||||
@@ -211,7 +210,7 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node,
|
||||
server := gin.Default()
|
||||
coord := false
|
||||
if mode == ModeCoordinator {
|
||||
coord = coordCfg.API.Coordinator
|
||||
coord = cfg.Coordinator.API.Coordinator
|
||||
}
|
||||
var err error
|
||||
nodeAPI, err = NewNodeAPI(
|
||||
@@ -243,7 +242,6 @@ func NewNode(mode Mode, cfg *config.Node, coordCfg *config.Coordinator) (*Node,
|
||||
nodeAPI: nodeAPI,
|
||||
debugAPI: debugAPI,
|
||||
coord: coord,
|
||||
coordCfg: coordCfg,
|
||||
sync: sync,
|
||||
cfg: cfg,
|
||||
mode: mode,
|
||||
|
||||
Reference in New Issue
Block a user