diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..9432d5d8 --- /dev/null +++ b/.env.example @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 75f95977..abb267f8 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,7 @@ coverage.html logs.txt # just for example -id_rsa \ No newline at end of file +id_rsa + +# env file +.env \ No newline at end of file diff --git a/Makefile b/Makefile index 97a79f53..683be29c 100644 --- a/Makefile +++ b/Makefile @@ -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 + CHAINID=31337 # Make sure to update this if the strategy address changes # check in contracts/script/output/${CHAINID}/credible_squaring_avs_deployment_output.json @@ -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 diff --git a/core/config/config.go b/core/config/config.go index 70f54548..ad3a0f0e 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -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,17 +52,33 @@ 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) { @@ -79,18 +86,13 @@ func NewConfig(ctx *cli.Context) (*Config, error) { } 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{ + 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...) diff --git a/go.mod b/go.mod index 476190da..4a5529c1 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index a6a98f47..50bc3498 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 963cc173..54d72e1d 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -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()) } @@ -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, }