mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-10 06:28:04 -05:00
Co-authored-by: Péter Garamvölgyi <peter@scroll.io> Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> Co-authored-by: Thegaram <Thegaram@users.noreply.github.com>
44 lines
899 B
Go
44 lines
899 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"scroll-tech/common/database"
|
|
)
|
|
|
|
// Config load configuration items.
|
|
type Config struct {
|
|
L1Config *L1Config `json:"l1_config"`
|
|
L2Config *L2Config `json:"l2_config"`
|
|
DBConfig *database.Config `json:"db_config"`
|
|
}
|
|
|
|
func (c *Config) validate() error {
|
|
if maxChunkPerBatch := c.L2Config.BatchProposerConfig.MaxChunkNumPerBatch; maxChunkPerBatch <= 0 {
|
|
return fmt.Errorf("Invalid max_chunk_num_per_batch configuration: %v", maxChunkPerBatch)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// NewConfig returns a new instance of Config.
|
|
func NewConfig(file string) (*Config, error) {
|
|
buf, err := os.ReadFile(filepath.Clean(file))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cfg := &Config{}
|
|
err = json.Unmarshal(buf, cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := cfg.validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
return cfg, nil
|
|
}
|