mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-24 05:18:15 -05:00
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> Co-authored-by: colinlyguo <colinlyguo@gmail.com>
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
db_config "scroll-tech/database"
|
|
)
|
|
|
|
// RollerManagerConfig loads sequencer configuration items.
|
|
type RollerManagerConfig struct {
|
|
// asc or desc (default: asc)
|
|
OrderSession string `json:"order_session,omitempty"`
|
|
// The amount of rollers to pick per proof generation session.
|
|
RollersPerSession uint8 `json:"rollers_per_session"`
|
|
// Zk verifier config.
|
|
Verifier *VerifierConfig `json:"verifier,omitempty"`
|
|
// Proof collection time (in minutes).
|
|
CollectionTime int `json:"collection_time"`
|
|
// Token time to live (in seconds)
|
|
TokenTimeToLive int `json:"token_time_to_live"`
|
|
}
|
|
|
|
// Config load configuration items.
|
|
type Config struct {
|
|
RollerManagerConfig *RollerManagerConfig `json:"roller_manager_config"`
|
|
DBConfig *db_config.DBConfig `json:"db_config"`
|
|
}
|
|
|
|
// VerifierConfig load zk verifier config.
|
|
type VerifierConfig struct {
|
|
MockMode bool `json:"mock_mode"`
|
|
ParamsPath string `json:"params_path"`
|
|
AggVkPath string `json:"agg_vk_path"`
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// Check roller's order session
|
|
order := strings.ToUpper(cfg.RollerManagerConfig.OrderSession)
|
|
if len(order) > 0 && !(order == "ASC" || order == "DESC") {
|
|
return nil, errors.New("roller config's order session is invalid")
|
|
}
|
|
cfg.RollerManagerConfig.OrderSession = order
|
|
|
|
return cfg, nil
|
|
}
|