-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: aggregator uses flags instead of config-file #60
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Example env file to set aggregator configuration | ||
|
||
# ETH Client Config | ||
ETH_RPC_URL=http://localhost:8545 | ||
ETH_WS_URL=ws://localhost:8545 | ||
|
||
# Aggregator Server Config | ||
AGGREGATOR_SERVER_IP_PORT_ADDRESS=localhost:8090 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,7 @@ coverage.html | |
logs.txt | ||
|
||
# just for example | ||
id_rsa | ||
id_rsa | ||
|
||
# env file | ||
.env |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,15 +43,6 @@ type Config struct { | |
AggregatorAddress common.Address | ||
} | ||
|
||
// These are read from ConfigFileFlag | ||
type ConfigRaw struct { | ||
Environment sdklogging.LogLevel `yaml:"environment"` | ||
EthRpcUrl string `yaml:"eth_rpc_url"` | ||
EthWsUrl string `yaml:"eth_ws_url"` | ||
AggregatorServerIpPortAddr string `yaml:"aggregator_server_ip_port_address"` | ||
RegisterOperatorOnStartup bool `yaml:"register_operator_on_startup"` | ||
} | ||
|
||
// These are read from CredibleSquaringDeploymentFileFlag | ||
type IncredibleSquaringDeploymentRaw struct { | ||
Addresses IncredibleSquaringContractsRaw `json:"addresses"` | ||
|
@@ -61,36 +52,47 @@ type IncredibleSquaringContractsRaw struct { | |
OperatorStateRetrieverAddr string `json:"operatorStateRetriever"` | ||
} | ||
|
||
// NewConfig parses config file to read from from flags or environment variables | ||
// NewConfig parses config file to read from flags or environment variables | ||
// Note: This config is shared by challenger and aggregator and so we put in the core. | ||
// Operator has a different config and is meant to be used by the operator CLI. | ||
func NewConfig(ctx *cli.Context) (*Config, error) { | ||
Environment := sdklogging.LogLevel(ctx.GlobalString(EnvironmentFlag.Name)) | ||
logger, err := sdklogging.NewZapLogger(Environment) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
EthRpcUrl := ctx.GlobalString(EthRpcUrlFlag.Name) | ||
if EthRpcUrl == "" { | ||
logger.Errorf("EthRpcUrl is required") | ||
} | ||
|
||
EthWsUrl := ctx.GlobalString(EthWsUrlFlag.Name) | ||
if EthWsUrl == "" { | ||
logger.Errorf("EthWsUrl is required") | ||
} | ||
|
||
var configRaw ConfigRaw | ||
configFilePath := ctx.GlobalString(ConfigFileFlag.Name) | ||
if configFilePath != "" { | ||
sdkutils.ReadYamlConfig(configFilePath, &configRaw) | ||
AggregatorServerIpPortAddr := ctx.GlobalString(AggregatorServerIpPortAddressFlag.Name) | ||
if AggregatorServerIpPortAddr == "" { | ||
logger.Errorf("AggregatorServerIpPortAddress is required") | ||
} | ||
|
||
RegisterOperatorOnStartup := true // default value | ||
|
||
var credibleSquaringDeploymentRaw IncredibleSquaringDeploymentRaw | ||
credibleSquaringDeploymentFilePath := ctx.GlobalString(CredibleSquaringDeploymentFileFlag.Name) | ||
if _, err := os.Stat(credibleSquaringDeploymentFilePath); errors.Is(err, os.ErrNotExist) { | ||
panic("Path " + credibleSquaringDeploymentFilePath + " does not exist") | ||
} | ||
sdkutils.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw) | ||
|
||
logger, err := sdklogging.NewZapLogger(configRaw.Environment) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ethRpcClient, err := eth.NewClient(configRaw.EthRpcUrl) | ||
ethRpcClient, err := eth.NewClient(EthRpcUrl) | ||
if err != nil { | ||
logger.Errorf("Cannot create http ethclient", "err", err) | ||
return nil, err | ||
} | ||
|
||
ethWsClient, err := eth.NewClient(configRaw.EthWsUrl) | ||
ethWsClient, err := eth.NewClient(EthWsUrl) | ||
if err != nil { | ||
logger.Errorf("Cannot create ws ethclient", "err", err) | ||
return nil, err | ||
|
@@ -131,14 +133,14 @@ func NewConfig(ctx *cli.Context) (*Config, error) { | |
config := &Config{ | ||
EcdsaPrivateKey: ecdsaPrivateKey, | ||
Logger: logger, | ||
EthWsRpcUrl: configRaw.EthWsUrl, | ||
EthHttpRpcUrl: configRaw.EthRpcUrl, | ||
EthWsRpcUrl: EthWsUrl, | ||
EthHttpRpcUrl: EthRpcUrl, | ||
EthHttpClient: ethRpcClient, | ||
EthWsClient: ethWsClient, | ||
OperatorStateRetrieverAddr: common.HexToAddress(credibleSquaringDeploymentRaw.Addresses.OperatorStateRetrieverAddr), | ||
IncredibleSquaringRegistryCoordinatorAddr: common.HexToAddress(credibleSquaringDeploymentRaw.Addresses.RegistryCoordinatorAddr), | ||
AggregatorServerIpPortAddr: configRaw.AggregatorServerIpPortAddr, | ||
RegisterOperatorOnStartup: configRaw.RegisterOperatorOnStartup, | ||
AggregatorServerIpPortAddr: AggregatorServerIpPortAddr, | ||
RegisterOperatorOnStartup: RegisterOperatorOnStartup, | ||
SignerFn: signerV2, | ||
TxMgr: txMgr, | ||
AggregatorAddress: aggregatorAddr, | ||
|
@@ -176,15 +178,43 @@ var ( | |
EnvVar: "ECDSA_PRIVATE_KEY", | ||
} | ||
/* Optional Flags */ | ||
EnvironmentFlag = cli.StringFlag{ | ||
Name: "environment", | ||
Required: false, | ||
Usage: "Set the environment (production or development)", | ||
Value: "development", // default value | ||
} | ||
EthRpcUrlFlag = cli.StringFlag{ | ||
Name: "eth-rpc-url", | ||
Required: false, | ||
Usage: "Ethereum RPC URL", | ||
EnvVar: "ETH_RPC_URL", | ||
} | ||
EthWsUrlFlag = cli.StringFlag{ | ||
Name: "eth-ws-url", | ||
Required: false, | ||
Usage: "Ethereum WS URL", | ||
EnvVar: "ETH_WS_URL", | ||
} | ||
AggregatorServerIpPortAddressFlag = cli.StringFlag{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this was the old variable name, but don't like it anymore. Can we separate into two separate flags, Also you can make the default ListenHost 0.0.0.0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So which one of them should I pass in |
||
Name: "aggregator-server-ip-port-address", | ||
Required: false, | ||
Usage: "Aggregator server IP PORT address", | ||
EnvVar: "AGGREGATOR_SERVER_IP_PORT_ADDRESS", | ||
} | ||
) | ||
|
||
var requiredFlags = []cli.Flag{ | ||
ConfigFileFlag, | ||
CredibleSquaringDeploymentFileFlag, | ||
EcdsaPrivateKeyFlag, | ||
} | ||
|
||
var optionalFlags = []cli.Flag{} | ||
var optionalFlags = []cli.Flag{ | ||
EnvironmentFlag, | ||
EthRpcUrlFlag, | ||
EthWsUrlFlag, | ||
AggregatorServerIpPortAddressFlag, | ||
} | ||
|
||
func init() { | ||
Flags = append(requiredFlags, optionalFlags...) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to get out of hands. Let's move the config variables to a .env file that users can source before running make commands. ALso this way we can have an anvil.env file and a holesky.env file, etc.