Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.example
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ coverage.html
logs.txt

# just for example
id_rsa
id_rsa

# env file
.env
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ help:
AGGREGATOR_ECDSA_PRIV_KEY=0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6
CHALLENGER_ECDSA_PRIV_KEY=0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a

ETH_RPC_URL=http://localhost:8545
ETH_WS_URL=ws://localhost:8545

AGGREGATOR_SERVER_IP_PORT_ADDRESS=localhost:8090
Comment on lines +10 to +13
Copy link
Collaborator

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.


CHAINID=31337
# Make sure to update this if the strategy address changes
# check in contracts/script/output/${CHAINID}/credible_squaring_avs_deployment_output.json
Expand Down Expand Up @@ -68,7 +73,8 @@ send-fund: ## sends fund to the operator saved in tests/keys/test.ecdsa.key.json
# TODO: piping to zap-pretty only works when zapper environment is set to production, unsure why
____OFFCHAIN_SOFTWARE___: ##
start-aggregator: ##
go run aggregator/cmd/main.go --config config-files/aggregator.yaml \
set -a && source .env && set +a && \
go run aggregator/cmd/main.go --environment production \
--credible-squaring-deployment ${DEPLOYMENT_FILES_DIR}/credible_squaring_avs_deployment_output.json \
--ecdsa-private-key ${AGGREGATOR_ECDSA_PRIV_KEY} \
2>&1 | zap-pretty
Expand Down
84 changes: 57 additions & 27 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Copy link
Collaborator

Choose a reason for hiding this comment

The 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, ListenHost and ListenPort? This makes it more obvious that ip can be a hostname, plus feel like separating them is more canonical from what I've seen.

Also you can make the default ListenHost 0.0.0.0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So which one of them should I pass in config.AggregatorServerIpPortAddr ? If you want both to be passed then the config struct needs to be refactored which I think I could do in a different PR to reduce complexity. (as I would have to make changes in aggregator.go as well)

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...)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ require (
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ github.com/iris-contrib/pongo2 v0.0.1/go.mod h1:Ssh+00+3GAZqSQb30AvBRNxBx7rf0Gqw
github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw=
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
Expand Down
27 changes: 15 additions & 12 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,26 @@ func TestIntegration(t *testing.T) {
}

/* Prepare the config file for aggregator */
var aggConfigRaw config.ConfigRaw
aggConfigFilePath := "../../config-files/aggregator.yaml"
sdkutils.ReadYamlConfig(aggConfigFilePath, &aggConfigRaw)
aggConfigRaw.EthRpcUrl = "http://" + anvilEndpoint
aggConfigRaw.EthWsUrl = "ws://" + anvilEndpoint
// aggConfigFilePath := "../../config-files/aggregator.yaml"
// sdkutils.ReadYamlConfig(aggConfigFilePath, &aggConfigRaw)
Environment := sdklogging.LogLevel("production")
EthRpcUrl := "http://" + anvilEndpoint
EthWsUrl := "ws://" + anvilEndpoint
AggregatorServerIpPortAddr := "localhost:8090"

var credibleSquaringDeploymentRaw config.IncredibleSquaringDeploymentRaw
credibleSquaringDeploymentFilePath := "../../contracts/script/output/31337/credible_squaring_avs_deployment_output.json"
sdkutils.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw)

logger, err := sdklogging.NewZapLogger(aggConfigRaw.Environment)
logger, err := sdklogging.NewZapLogger(Environment)
if err != nil {
t.Fatalf("Failed to create logger: %s", err.Error())
}
ethRpcClient, err := eth.NewClient(aggConfigRaw.EthRpcUrl)
ethRpcClient, err := eth.NewClient(EthRpcUrl)
if err != nil {
t.Fatalf("Failed to create eth client: %s", err.Error())
}
ethWsClient, err := eth.NewClient(aggConfigRaw.EthWsUrl)
ethWsClient, err := eth.NewClient(EthWsUrl)
if err != nil {
t.Fatalf("Failed to create eth client: %s", err.Error())
}
Expand Down Expand Up @@ -97,17 +98,19 @@ func TestIntegration(t *testing.T) {
}
txMgr := txmgr.NewSimpleTxManager(skWallet, ethRpcClient, logger, aggregatorAddr)

RegisterOperatorOnStartup := true // default value

config := &config.Config{
EcdsaPrivateKey: aggregatorEcdsaPrivateKey,
Logger: logger,
EthHttpRpcUrl: aggConfigRaw.EthRpcUrl,
EthHttpRpcUrl: EthRpcUrl,
EthHttpClient: ethRpcClient,
EthWsRpcUrl: aggConfigRaw.EthWsUrl,
EthWsRpcUrl: EthWsUrl,
EthWsClient: ethWsClient,
OperatorStateRetrieverAddr: common.HexToAddress(credibleSquaringDeploymentRaw.Addresses.OperatorStateRetrieverAddr),
IncredibleSquaringRegistryCoordinatorAddr: common.HexToAddress(credibleSquaringDeploymentRaw.Addresses.RegistryCoordinatorAddr),
AggregatorServerIpPortAddr: aggConfigRaw.AggregatorServerIpPortAddr,
RegisterOperatorOnStartup: aggConfigRaw.RegisterOperatorOnStartup,
AggregatorServerIpPortAddr: AggregatorServerIpPortAddr,
RegisterOperatorOnStartup: RegisterOperatorOnStartup,
TxMgr: txMgr,
AggregatorAddress: aggregatorAddr,
}
Expand Down