diff --git a/cmd/cartesi-rollups-node/handlers.go b/cmd/cartesi-rollups-node/handlers.go index 329e76935..89b13fcc5 100644 --- a/cmd/cartesi-rollups-node/handlers.go +++ b/cmd/cartesi-rollups-node/handlers.go @@ -12,31 +12,31 @@ import ( "github.com/cartesi/rollups-node/internal/config" ) -func newHttpServiceHandler() http.Handler { +func newHttpServiceHandler(nodeConfig config.NodeConfig) http.Handler { handler := http.NewServeMux() handler.Handle("/healthz", http.HandlerFunc(healthcheckHandler)) - graphqlProxy, err := newReverseProxy(getPort(portOffsetGraphQLServer)) + graphqlProxy, err := newReverseProxy(nodeConfig, getPort(nodeConfig, portOffsetGraphQLServer)) if err != nil { config.ErrorLogger.Fatal(err) } handler.Handle("/graphql", graphqlProxy) - dispatcherProxy, err := newReverseProxy(getPort(portOffsetDispatcher)) + dispatcherProxy, err := newReverseProxy(nodeConfig, getPort(nodeConfig, portOffsetDispatcher)) if err != nil { config.ErrorLogger.Fatal(err) } handler.Handle("/metrics", dispatcherProxy) - inspectProxy, err := newReverseProxy(getPort(portOffsetInspectServer)) + inspectProxy, err := newReverseProxy(nodeConfig, getPort(nodeConfig, portOffsetInspectServer)) if err != nil { config.ErrorLogger.Fatal(err) } handler.Handle("/inspect", inspectProxy) handler.Handle("/inspect/", inspectProxy) - if config.GetCartesiFeatureHostMode() { - hostProxy, err := newReverseProxy(getPort(portOffsetHostRunnerRollups)) + if nodeConfig.CartesiFeatureHostMode { + hostProxy, err := newReverseProxy(nodeConfig, getPort(nodeConfig, portOffsetHostRunnerRollups)) if err != nil { config.ErrorLogger.Fatal(err) } @@ -50,10 +50,10 @@ func healthcheckHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } -func newReverseProxy(port int) (*httputil.ReverseProxy, error) { +func newReverseProxy(nodeConfig config.NodeConfig, port int) (*httputil.ReverseProxy, error) { urlStr := fmt.Sprintf( "http://%v:%v/", - config.GetCartesiHttpAddress(), + nodeConfig.CartesiHttpAddress, port, ) diff --git a/cmd/cartesi-rollups-node/main.go b/cmd/cartesi-rollups-node/main.go index b9b7cab68..40ce218c2 100644 --- a/cmd/cartesi-rollups-node/main.go +++ b/cmd/cartesi-rollups-node/main.go @@ -20,35 +20,37 @@ func main() { ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer stop() - sunodoValidatorEnabled := config.GetCartesiExperimentalSunodoValidatorEnabled() + nodeConfig := config.NewNodeConfigFromEnv() + + sunodoValidatorEnabled := nodeConfig.CartesiExperimentalSunodoValidatorEnabled if !sunodoValidatorEnabled { // add Redis first - s = append(s, newRedis()) + s = append(s, newRedis(nodeConfig)) } // add services without dependencies - s = append(s, newGraphQLServer()) - s = append(s, newIndexer()) - s = append(s, newStateServer()) + s = append(s, newGraphQLServer(nodeConfig)) + s = append(s, newIndexer(nodeConfig)) + s = append(s, newStateServer(nodeConfig)) // start either the server manager or host runner - if config.GetCartesiFeatureHostMode() { - s = append(s, newHostRunner()) + if nodeConfig.CartesiFeatureHostMode { + s = append(s, newHostRunner(nodeConfig)) } else { - s = append(s, newServerManager()) + s = append(s, newServerManager(nodeConfig)) } // enable claimer if reader mode and sunodo validator mode are disabled - if !config.GetCartesiFeatureDisableClaimer() && !sunodoValidatorEnabled { - s = append(s, newAuthorityClaimer()) + if !nodeConfig.CartesiFeatureDisableClaimer && !sunodoValidatorEnabled { + s = append(s, newAuthorityClaimer(nodeConfig)) } // add services with dependencies - s = append(s, newAdvanceRunner()) // Depends on the server-manager/host-runner - s = append(s, newDispatcher()) // Depends on the state server - s = append(s, newInspectServer()) // Depends on the server-manager/host-runner + s = append(s, newAdvanceRunner(nodeConfig)) // Depends on the server-manager/host-runner + s = append(s, newDispatcher(nodeConfig)) // Depends on the state server + s = append(s, newInspectServer(nodeConfig)) // Depends on the server-manager/host-runner - s = append(s, newHttpService()) + s = append(s, newHttpService(nodeConfig)) ready := make(chan struct{}, 1) // logs startup time diff --git a/cmd/cartesi-rollups-node/services.go b/cmd/cartesi-rollups-node/services.go index ad5395d2f..77459feec 100644 --- a/cmd/cartesi-rollups-node/services.go +++ b/cmd/cartesi-rollups-node/services.go @@ -37,23 +37,23 @@ const ( ) // Get the port of the given service. -func getPort(offset portOffset) int { - return config.GetCartesiHttpPort() + int(offset) +func getPort(nodeConfig config.NodeConfig, offset portOffset) int { + return nodeConfig.CartesiHttpPort + int(offset) } // Get the redis endpoint based on whether the experimental sunodo validator mode is enabled. -func getRedisEndpoint() string { - if config.GetCartesiExperimentalSunodoValidatorEnabled() { - return config.GetCartesiExperimentalSunodoValidatorRedisEndpoint() +func getRedisEndpoint(nodeConfig config.NodeConfig) string { + if nodeConfig.CartesiExperimentalSunodoValidatorEnabled { + return nodeConfig.CartesiExperimentalSunodoValidatorRedisEndpoint } else { - return fmt.Sprintf("redis://%v:%v", localhost, getPort(portOffsetRedis)) + return fmt.Sprintf("redis://%v:%v", localhost, getPort(nodeConfig, portOffsetRedis)) } } // Create the RUST_LOG variable using the config log level. // If the log level is set to debug, set tracing log for the given rust module. -func getRustLog(rustModule string) string { - switch config.GetCartesiLogLevel() { +func getRustLog(nodeConfig config.NodeConfig, rustModule string) string { + switch nodeConfig.CartesiLogLevel { case config.LogLevelDebug: return fmt.Sprintf("RUST_LOG=info,%v=trace", rustModule) case config.LogLevelInfo: @@ -67,71 +67,71 @@ func getRustLog(rustModule string) string { } } -func newAdvanceRunner() services.CommandService { +func newAdvanceRunner(nodeConfig config.NodeConfig) services.CommandService { var s services.CommandService s.Name = "advance-runner" - s.HealthcheckPort = getPort(portOffsetAdvanceRunner) + s.HealthcheckPort = getPort(nodeConfig, portOffsetAdvanceRunner) s.Path = "cartesi-rollups-advance-runner" s.Env = append(s.Env, "LOG_ENABLE_TIMESTAMP=false") s.Env = append(s.Env, "LOG_ENABLE_COLOR=false") - s.Env = append(s.Env, getRustLog("advance_runner")) + s.Env = append(s.Env, getRustLog(nodeConfig, "advance_runner")) s.Env = append(s.Env, fmt.Sprintf("SERVER_MANAGER_ENDPOINT=http://%v:%v", localhost, - getPort(portOffsetServerManager))) + getPort(nodeConfig, portOffsetServerManager))) s.Env = append(s.Env, fmt.Sprintf("SESSION_ID=%v", serverManagerSessionId)) s.Env = append(s.Env, - fmt.Sprintf("REDIS_ENDPOINT=%v", getRedisEndpoint())) + fmt.Sprintf("REDIS_ENDPOINT=%v", getRedisEndpoint(nodeConfig))) s.Env = append(s.Env, - fmt.Sprintf("CHAIN_ID=%v", config.GetCartesiBlockchainId())) + fmt.Sprintf("CHAIN_ID=%v", nodeConfig.CartesiBlockchainId)) s.Env = append(s.Env, - fmt.Sprintf("DAPP_CONTRACT_ADDRESS=%v", config.GetCartesiContractsApplicationAddress())) + fmt.Sprintf("DAPP_CONTRACT_ADDRESS=%v", nodeConfig.CartesiContractsApplicationAddress)) s.Env = append(s.Env, - fmt.Sprintf("PROVIDER_HTTP_ENDPOINT=%v", config.GetCartesiBlockchainHttpEndpoint())) + fmt.Sprintf("PROVIDER_HTTP_ENDPOINT=%v", nodeConfig.CartesiBlockchainHttpEndpoint)) s.Env = append(s.Env, - fmt.Sprintf("ADVANCE_RUNNER_HEALTHCHECK_PORT=%v", getPort(portOffsetAdvanceRunner))) + fmt.Sprintf("ADVANCE_RUNNER_HEALTHCHECK_PORT=%v", getPort(nodeConfig, portOffsetAdvanceRunner))) s.Env = append(s.Env, - fmt.Sprintf("READER_MODE=%v", config.GetCartesiFeatureDisableClaimer())) - if config.GetCartesiFeatureHostMode() || config.GetCartesiFeatureDisableMachineHashCheck() { + fmt.Sprintf("READER_MODE=%v", nodeConfig.CartesiFeatureDisableClaimer)) + if nodeConfig.CartesiFeatureHostMode || nodeConfig.CartesiFeatureDisableMachineHashCheck { s.Env = append(s.Env, "SNAPSHOT_VALIDATION_ENABLED=false") } - if !config.GetCartesiFeatureHostMode() { + if !nodeConfig.CartesiFeatureHostMode { s.Env = append(s.Env, - fmt.Sprintf("MACHINE_SNAPSHOT_PATH=%v", config.GetCartesiSnapshotDir())) + fmt.Sprintf("MACHINE_SNAPSHOT_PATH=%v", nodeConfig.CartesiSnapshotDir)) } s.Env = append(s.Env, os.Environ()...) return s } -func newAuthorityClaimer() services.CommandService { +func newAuthorityClaimer(nodeConfig config.NodeConfig) services.CommandService { var s services.CommandService s.Name = "authority-claimer" - s.HealthcheckPort = getPort(portOffsetAuthorityClaimer) + s.HealthcheckPort = getPort(nodeConfig, portOffsetAuthorityClaimer) s.Path = "cartesi-rollups-authority-claimer" s.Env = append(s.Env, "LOG_ENABLE_TIMESTAMP=false") s.Env = append(s.Env, "LOG_ENABLE_COLOR=false") - s.Env = append(s.Env, getRustLog("authority_claimer")) + s.Env = append(s.Env, getRustLog(nodeConfig, "authority_claimer")) s.Env = append(s.Env, - fmt.Sprintf("TX_PROVIDER_HTTP_ENDPOINT=%v", config.GetCartesiBlockchainHttpEndpoint())) + fmt.Sprintf("TX_PROVIDER_HTTP_ENDPOINT=%v", nodeConfig.CartesiBlockchainHttpEndpoint)) s.Env = append(s.Env, - fmt.Sprintf("TX_CHAIN_ID=%v", config.GetCartesiBlockchainId())) + fmt.Sprintf("TX_CHAIN_ID=%v", nodeConfig.CartesiBlockchainId)) s.Env = append(s.Env, - fmt.Sprintf("TX_CHAIN_IS_LEGACY=%v", config.GetCartesiBlockchainIsLegacy())) + fmt.Sprintf("TX_CHAIN_IS_LEGACY=%v", nodeConfig.CartesiBlockchainIsLegacy)) s.Env = append(s.Env, - fmt.Sprintf("TX_DEFAULT_CONFIRMATIONS=%v", config.GetCartesiBlockchainFinalityOffset())) + fmt.Sprintf("TX_DEFAULT_CONFIRMATIONS=%v", nodeConfig.CartesiBlockchainFinalityOffset)) s.Env = append(s.Env, - fmt.Sprintf("REDIS_ENDPOINT=%v", getRedisEndpoint())) + fmt.Sprintf("REDIS_ENDPOINT=%v", getRedisEndpoint(nodeConfig))) s.Env = append(s.Env, - fmt.Sprintf("HISTORY_ADDRESS=%v", config.GetCartesiContractsHistoryAddress())) + fmt.Sprintf("HISTORY_ADDRESS=%v", nodeConfig.CartesiContractsHistoryAddress)) s.Env = append(s.Env, - fmt.Sprintf("AUTHORITY_ADDRESS=%v", config.GetCartesiContractsAuthorityAddress())) + fmt.Sprintf("AUTHORITY_ADDRESS=%v", nodeConfig.CartesiContractsAuthorityAddress)) s.Env = append(s.Env, - fmt.Sprintf("INPUT_BOX_ADDRESS=%v", config.GetCartesiContractsInputBoxAddress())) + fmt.Sprintf("INPUT_BOX_ADDRESS=%v", nodeConfig.CartesiContractsInputBoxAddress)) s.Env = append(s.Env, - fmt.Sprintf("GENESIS_BLOCK=%v", config.GetCartesiContractsInputBoxDeploymentBlockNumber())) + fmt.Sprintf("GENESIS_BLOCK=%v", nodeConfig.CartesiContractsInputBoxDeploymentBlockNumber)) s.Env = append(s.Env, - fmt.Sprintf("AUTHORITY_CLAIMER_HTTP_SERVER_PORT=%v", getPort(portOffsetAuthorityClaimer))) + fmt.Sprintf("AUTHORITY_CLAIMER_HTTP_SERVER_PORT=%v", getPort(nodeConfig, portOffsetAuthorityClaimer))) switch auth := config.GetAuth().(type) { case config.AuthMnemonic: s.Env = append(s.Env, @@ -150,128 +150,128 @@ func newAuthorityClaimer() services.CommandService { return s } -func newDispatcher() services.CommandService { +func newDispatcher(nodeConfig config.NodeConfig) services.CommandService { var s services.CommandService s.Name = "dispatcher" - s.HealthcheckPort = getPort(portOffsetDispatcher) + s.HealthcheckPort = getPort(nodeConfig, portOffsetDispatcher) s.Path = "cartesi-rollups-dispatcher" s.Env = append(s.Env, "LOG_ENABLE_TIMESTAMP=false") s.Env = append(s.Env, "LOG_ENABLE_COLOR=false") - s.Env = append(s.Env, getRustLog("dispatcher")) + s.Env = append(s.Env, getRustLog(nodeConfig, "dispatcher")) s.Env = append(s.Env, - fmt.Sprintf("SC_GRPC_ENDPOINT=http://%v:%v", localhost, getPort(portOffsetStateServer))) + fmt.Sprintf("SC_GRPC_ENDPOINT=http://%v:%v", localhost, getPort(nodeConfig, portOffsetStateServer))) s.Env = append(s.Env, - fmt.Sprintf("SC_DEFAULT_CONFIRMATIONS=%v", config.GetCartesiBlockchainFinalityOffset())) + fmt.Sprintf("SC_DEFAULT_CONFIRMATIONS=%v", nodeConfig.CartesiBlockchainFinalityOffset)) s.Env = append(s.Env, - fmt.Sprintf("REDIS_ENDPOINT=%v", getRedisEndpoint())) + fmt.Sprintf("REDIS_ENDPOINT=%v", getRedisEndpoint(nodeConfig))) s.Env = append(s.Env, - fmt.Sprintf("DAPP_ADDRESS=%v", config.GetCartesiContractsApplicationAddress())) + fmt.Sprintf("DAPP_ADDRESS=%v", nodeConfig.CartesiContractsApplicationAddress)) s.Env = append(s.Env, fmt.Sprintf("DAPP_DEPLOYMENT_BLOCK_NUMBER=%v", - config.GetCartesiContractsApplicationDeploymentBlockNumber())) + nodeConfig.CartesiContractsApplicationDeploymentBlockNumber)) s.Env = append(s.Env, - fmt.Sprintf("HISTORY_ADDRESS=%v", config.GetCartesiContractsHistoryAddress())) + fmt.Sprintf("HISTORY_ADDRESS=%v", nodeConfig.CartesiContractsHistoryAddress)) s.Env = append(s.Env, - fmt.Sprintf("AUTHORITY_ADDRESS=%v", config.GetCartesiContractsAuthorityAddress())) + fmt.Sprintf("AUTHORITY_ADDRESS=%v", nodeConfig.CartesiContractsAuthorityAddress)) s.Env = append(s.Env, - fmt.Sprintf("INPUT_BOX_ADDRESS=%v", config.GetCartesiContractsInputBoxAddress())) + fmt.Sprintf("INPUT_BOX_ADDRESS=%v", nodeConfig.CartesiContractsInputBoxAddress)) s.Env = append(s.Env, - fmt.Sprintf("RD_EPOCH_DURATION=%v", int(config.GetCartesiEpochDuration().Seconds()))) + fmt.Sprintf("RD_EPOCH_DURATION=%v", int(nodeConfig.CartesiEpochDuration.Seconds()))) s.Env = append(s.Env, - fmt.Sprintf("CHAIN_ID=%v", config.GetCartesiBlockchainId())) + fmt.Sprintf("CHAIN_ID=%v", nodeConfig.CartesiBlockchainId)) s.Env = append(s.Env, - fmt.Sprintf("DISPATCHER_HTTP_SERVER_PORT=%v", getPort(portOffsetDispatcher))) + fmt.Sprintf("DISPATCHER_HTTP_SERVER_PORT=%v", getPort(nodeConfig, portOffsetDispatcher))) s.Env = append(s.Env, os.Environ()...) return s } -func newGraphQLServer() services.CommandService { +func newGraphQLServer(nodeConfig config.NodeConfig) services.CommandService { var s services.CommandService s.Name = "graphql-server" - s.HealthcheckPort = getPort(portOffsetGraphQLHealthcheck) + s.HealthcheckPort = getPort(nodeConfig, portOffsetGraphQLHealthcheck) s.Path = "cartesi-rollups-graphql-server" s.Env = append(s.Env, "LOG_ENABLE_TIMESTAMP=false") s.Env = append(s.Env, "LOG_ENABLE_COLOR=false") - s.Env = append(s.Env, getRustLog("graphql_server")) + s.Env = append(s.Env, getRustLog(nodeConfig, "graphql_server")) s.Env = append(s.Env, - fmt.Sprintf("POSTGRES_ENDPOINT=%v", config.GetCartesiPostgresEndpoint())) + fmt.Sprintf("POSTGRES_ENDPOINT=%v", nodeConfig.CartesiPostgresEndpoint)) s.Env = append(s.Env, fmt.Sprintf("GRAPHQL_HOST=%v", localhost)) s.Env = append(s.Env, - fmt.Sprintf("GRAPHQL_PORT=%v", getPort(portOffsetGraphQLServer))) + fmt.Sprintf("GRAPHQL_PORT=%v", getPort(nodeConfig, portOffsetGraphQLServer))) s.Env = append(s.Env, - fmt.Sprintf("GRAPHQL_HEALTHCHECK_PORT=%v", getPort(portOffsetGraphQLHealthcheck))) + fmt.Sprintf("GRAPHQL_HEALTHCHECK_PORT=%v", getPort(nodeConfig, portOffsetGraphQLHealthcheck))) s.Env = append(s.Env, os.Environ()...) return s } -func newHostRunner() services.CommandService { +func newHostRunner(nodeConfig config.NodeConfig) services.CommandService { var s services.CommandService s.Name = "host-runner" - s.HealthcheckPort = getPort(portOffsetHostRunnerHealthcheck) + s.HealthcheckPort = getPort(nodeConfig, portOffsetHostRunnerHealthcheck) s.Path = "cartesi-rollups-host-runner" s.Env = append(s.Env, "LOG_ENABLE_TIMESTAMP=false") s.Env = append(s.Env, "LOG_ENABLE_COLOR=false") - s.Env = append(s.Env, getRustLog("host_runner")) + s.Env = append(s.Env, getRustLog(nodeConfig, "host_runner")) s.Env = append(s.Env, fmt.Sprintf("GRPC_SERVER_MANAGER_ADDRESS=%v", localhost)) s.Env = append(s.Env, - fmt.Sprintf("GRPC_SERVER_MANAGER_PORT=%v", getPort(portOffsetServerManager))) + fmt.Sprintf("GRPC_SERVER_MANAGER_PORT=%v", getPort(nodeConfig, portOffsetServerManager))) s.Env = append(s.Env, fmt.Sprintf("HTTP_ROLLUP_SERVER_ADDRESS=%v", localhost)) s.Env = append(s.Env, - fmt.Sprintf("HTTP_ROLLUP_SERVER_PORT=%v", getPort(portOffsetHostRunnerRollups))) + fmt.Sprintf("HTTP_ROLLUP_SERVER_PORT=%v", getPort(nodeConfig, portOffsetHostRunnerRollups))) s.Env = append(s.Env, - fmt.Sprintf("HOST_RUNNER_HEALTHCHECK_PORT=%v", getPort(portOffsetHostRunnerHealthcheck))) + fmt.Sprintf("HOST_RUNNER_HEALTHCHECK_PORT=%v", getPort(nodeConfig, portOffsetHostRunnerHealthcheck))) s.Env = append(s.Env, os.Environ()...) return s } -func newIndexer() services.CommandService { +func newIndexer(nodeConfig config.NodeConfig) services.CommandService { var s services.CommandService s.Name = "indexer" - s.HealthcheckPort = getPort(portOffsetIndexer) + s.HealthcheckPort = getPort(nodeConfig, portOffsetIndexer) s.Path = "cartesi-rollups-indexer" s.Env = append(s.Env, "LOG_ENABLE_TIMESTAMP=false") s.Env = append(s.Env, "LOG_ENABLE_COLOR=false") - s.Env = append(s.Env, getRustLog("indexer")) + s.Env = append(s.Env, getRustLog(nodeConfig, "indexer")) s.Env = append(s.Env, - fmt.Sprintf("POSTGRES_ENDPOINT=%v", config.GetCartesiPostgresEndpoint())) + fmt.Sprintf("POSTGRES_ENDPOINT=%v", nodeConfig.CartesiPostgresEndpoint)) s.Env = append(s.Env, - fmt.Sprintf("CHAIN_ID=%v", config.GetCartesiBlockchainId())) + fmt.Sprintf("CHAIN_ID=%v", nodeConfig.CartesiBlockchainId)) s.Env = append(s.Env, - fmt.Sprintf("DAPP_CONTRACT_ADDRESS=%v", config.GetCartesiContractsApplicationAddress())) + fmt.Sprintf("DAPP_CONTRACT_ADDRESS=%v", nodeConfig.CartesiContractsApplicationAddress)) s.Env = append(s.Env, - fmt.Sprintf("REDIS_ENDPOINT=%v", getRedisEndpoint())) + fmt.Sprintf("REDIS_ENDPOINT=%v", getRedisEndpoint(nodeConfig))) s.Env = append(s.Env, - fmt.Sprintf("INDEXER_HEALTHCHECK_PORT=%v", getPort(portOffsetIndexer))) + fmt.Sprintf("INDEXER_HEALTHCHECK_PORT=%v", getPort(nodeConfig, portOffsetIndexer))) s.Env = append(s.Env, os.Environ()...) return s } -func newInspectServer() services.CommandService { +func newInspectServer(nodeConfig config.NodeConfig) services.CommandService { var s services.CommandService s.Name = "inspect-server" - s.HealthcheckPort = getPort(portOffsetInspectHealthcheck) + s.HealthcheckPort = getPort(nodeConfig, portOffsetInspectHealthcheck) s.Path = "cartesi-rollups-inspect-server" s.Env = append(s.Env, "LOG_ENABLE_TIMESTAMP=false") s.Env = append(s.Env, "LOG_ENABLE_COLOR=false") - s.Env = append(s.Env, getRustLog("inspect_server")) + s.Env = append(s.Env, getRustLog(nodeConfig, "inspect_server")) s.Env = append(s.Env, - fmt.Sprintf("INSPECT_SERVER_ADDRESS=%v:%v", localhost, getPort(portOffsetInspectServer))) + fmt.Sprintf("INSPECT_SERVER_ADDRESS=%v:%v", localhost, getPort(nodeConfig, portOffsetInspectServer))) s.Env = append(s.Env, - fmt.Sprintf("SERVER_MANAGER_ADDRESS=%v:%v", localhost, getPort(portOffsetServerManager))) + fmt.Sprintf("SERVER_MANAGER_ADDRESS=%v:%v", localhost, getPort(nodeConfig, portOffsetServerManager))) s.Env = append(s.Env, fmt.Sprintf("SESSION_ID=%v", serverManagerSessionId)) s.Env = append(s.Env, - fmt.Sprintf("INSPECT_SERVER_HEALTHCHECK_PORT=%v", getPort(portOffsetInspectHealthcheck))) + fmt.Sprintf("INSPECT_SERVER_HEALTHCHECK_PORT=%v", getPort(nodeConfig, portOffsetInspectHealthcheck))) s.Env = append(s.Env, os.Environ()...) return s } -func newRedis() services.CommandService { +func newRedis(nodeConfig config.NodeConfig) services.CommandService { var s services.CommandService s.Name = "redis" - s.HealthcheckPort = getPort(portOffsetRedis) + s.HealthcheckPort = getPort(nodeConfig, portOffsetRedis) s.Path = "redis-server" - s.Args = append(s.Args, "--port", fmt.Sprint(getPort(portOffsetRedis))) + s.Args = append(s.Args, "--port", fmt.Sprint(getPort(nodeConfig, portOffsetRedis))) // Disable persistence with --save and --appendonly config s.Args = append(s.Args, "--save", "") s.Args = append(s.Args, "--appendonly", "no") @@ -279,15 +279,15 @@ func newRedis() services.CommandService { return s } -func newServerManager() services.ServerManager { +func newServerManager(nodeConfig config.NodeConfig) services.ServerManager { var s services.ServerManager s.Name = "server-manager" - s.HealthcheckPort = getPort(portOffsetServerManager) + s.HealthcheckPort = getPort(nodeConfig, portOffsetServerManager) s.Path = "server-manager" s.Args = append(s.Args, - fmt.Sprintf("--manager-address=%v:%v", localhost, getPort(portOffsetServerManager))) + fmt.Sprintf("--manager-address=%v:%v", localhost, getPort(nodeConfig, portOffsetServerManager))) s.Env = append(s.Env, "REMOTE_CARTESI_MACHINE_LOG_LEVEL=info") - if config.GetCartesiLogLevel() == config.LogLevelDebug { + if nodeConfig.CartesiLogLevel == config.LogLevelDebug { s.Env = append(s.Env, "SERVER_MANAGER_LOG_LEVEL=info") } else { s.Env = append(s.Env, "SERVER_MANAGER_LOG_LEVEL=warning") @@ -296,28 +296,28 @@ func newServerManager() services.ServerManager { return s } -func newStateServer() services.CommandService { +func newStateServer(nodeConfig config.NodeConfig) services.CommandService { var s services.CommandService s.Name = "state-server" - s.HealthcheckPort = getPort(portOffsetStateServer) + s.HealthcheckPort = getPort(nodeConfig, portOffsetStateServer) s.Path = "cartesi-rollups-state-server" s.Env = append(s.Env, "LOG_ENABLE_TIMESTAMP=false") s.Env = append(s.Env, "LOG_ENABLE_COLOR=false") - s.Env = append(s.Env, getRustLog("state_server")) + s.Env = append(s.Env, getRustLog(nodeConfig, "state_server")) s.Env = append(s.Env, "SF_CONCURRENT_EVENTS_FETCH=1") s.Env = append(s.Env, fmt.Sprintf("SF_GENESIS_BLOCK=%v", - config.GetCartesiContractsInputBoxDeploymentBlockNumber())) + nodeConfig.CartesiContractsInputBoxDeploymentBlockNumber)) s.Env = append(s.Env, - fmt.Sprintf("SF_SAFETY_MARGIN=%v", config.GetCartesiBlockchainFinalityOffset())) + fmt.Sprintf("SF_SAFETY_MARGIN=%v", nodeConfig.CartesiBlockchainFinalityOffset)) s.Env = append(s.Env, - fmt.Sprintf("BH_WS_ENDPOINT=%v", config.GetCartesiBlockchainWsEndpoint())) + fmt.Sprintf("BH_WS_ENDPOINT=%v", nodeConfig.CartesiBlockchainWsEndpoint)) s.Env = append(s.Env, - fmt.Sprintf("BH_HTTP_ENDPOINT=%v", config.GetCartesiBlockchainHttpEndpoint())) + fmt.Sprintf("BH_HTTP_ENDPOINT=%v", nodeConfig.CartesiBlockchainHttpEndpoint)) s.Env = append(s.Env, - fmt.Sprintf("BLOCKCHAIN_BLOCK_TIMEOUT=%v", config.GetCartesiBlockchainBlockTimeout())) + fmt.Sprintf("BLOCKCHAIN_BLOCK_TIMEOUT=%v", nodeConfig.CartesiBlockchainBlockTimeout)) s.Env = append(s.Env, - fmt.Sprintf("SS_SERVER_ADDRESS=%v:%v", localhost, getPort(portOffsetStateServer))) + fmt.Sprintf("SS_SERVER_ADDRESS=%v:%v", localhost, getPort(nodeConfig, portOffsetStateServer))) s.Env = append(s.Env, os.Environ()...) return s } @@ -329,9 +329,9 @@ func newSupervisorService(s []services.Service) services.SupervisorService { } } -func newHttpService() services.HttpService { - addr := fmt.Sprintf("%v:%v", config.GetCartesiHttpAddress(), getPort(portOffsetProxy)) - handler := newHttpServiceHandler() +func newHttpService(nodeConfig config.NodeConfig) services.HttpService { + addr := fmt.Sprintf("%v:%v", nodeConfig.CartesiHttpAddress, getPort(nodeConfig, portOffsetProxy)) + handler := newHttpServiceHandler(nodeConfig) return services.HttpService{ Name: "http", Address: addr, diff --git a/internal/config/configstruct.go b/internal/config/configstruct.go new file mode 100644 index 000000000..88354e69c --- /dev/null +++ b/internal/config/configstruct.go @@ -0,0 +1,285 @@ +// Code generated by internal/config/generate. +// DO NOT EDIT. + +// (c) Cartesi and individual authors (see AUTHORS) +// SPDX-License-Identifier: Apache-2.0 (see LICENSE) + +package config + +import ( + "time" +) + +type ( + Duration = time.Duration +) + +func getCartesiAuthAwsKmsKeyId() (string, bool) { + v, ok := getOptional("CARTESI_AUTH_AWS_KMS_KEY_ID", "", false, true, toString) + return v, ok +} + +func getCartesiAuthAwsKmsRegion() (string, bool) { + v, ok := getOptional("CARTESI_AUTH_AWS_KMS_REGION", "", false, true, toString) + return v, ok +} + +func getCartesiAuthMnemonic() (string, bool) { + v, ok := getOptional("CARTESI_AUTH_MNEMONIC", "", false, true, toString) + return v, ok +} + +func getCartesiAuthMnemonicAccountIndex() (int, bool) { + v, ok := getOptional("CARTESI_AUTH_MNEMONIC_ACCOUNT_INDEX", "0", true, true, toInt) + return v, ok +} + +func getCartesiAuthMnemonicFile() (string, bool) { + v, ok := getOptional("CARTESI_AUTH_MNEMONIC_FILE", "", false, true, toString) + return v, ok +} + +func getCartesiBlockchainBlockTimeout() int { + v := get("CARTESI_BLOCKCHAIN_BLOCK_TIMEOUT", "60", true, false, toInt) + return v +} + +func getCartesiBlockchainFinalityOffset() int { + v := get("CARTESI_BLOCKCHAIN_FINALITY_OFFSET", "10", true, false, toInt) + return v +} + +func getCartesiBlockchainHttpEndpoint() string { + v := get("CARTESI_BLOCKCHAIN_HTTP_ENDPOINT", "", false, false, toString) + return v +} + +func getCartesiBlockchainId() int { + v := get("CARTESI_BLOCKCHAIN_ID", "", false, false, toInt) + return v +} + +func getCartesiBlockchainIsLegacy() bool { + v := get("CARTESI_BLOCKCHAIN_IS_LEGACY", "false", true, false, toBool) + return v +} + +func getCartesiBlockchainWsEndpoint() string { + v := get("CARTESI_BLOCKCHAIN_WS_ENDPOINT", "", false, false, toString) + return v +} + +func getCartesiContractsInputBoxDeploymentBlockNumber() int64 { + v := get("CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER", "", false, false, toInt64) + return v +} + +func getCartesiContractsApplicationAddress() string { + v := get("CARTESI_CONTRACTS_APPLICATION_ADDRESS", "", false, false, toString) + return v +} + +func getCartesiContractsApplicationDeploymentBlockNumber() string { + v := get("CARTESI_CONTRACTS_APPLICATION_DEPLOYMENT_BLOCK_NUMBER", "", false, false, toString) + return v +} + +func getCartesiContractsAuthorityAddress() string { + v := get("CARTESI_CONTRACTS_AUTHORITY_ADDRESS", "", false, false, toString) + return v +} + +func getCartesiContractsHistoryAddress() string { + v := get("CARTESI_CONTRACTS_HISTORY_ADDRESS", "", false, false, toString) + return v +} + +func getCartesiContractsInputBoxAddress() string { + v := get("CARTESI_CONTRACTS_INPUT_BOX_ADDRESS", "", false, false, toString) + return v +} + +func getCartesiExperimentalSunodoValidatorEnabled() bool { + v := get("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_ENABLED", "false", true, false, toBool) + return v +} + +func getCartesiExperimentalSunodoValidatorRedisEndpoint() string { + v := get("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_REDIS_ENDPOINT", "", false, false, toString) + return v +} + +func getCartesiFeatureDisableClaimer() bool { + v := get("CARTESI_FEATURE_DISABLE_CLAIMER", "false", true, false, toBool) + return v +} + +func getCartesiFeatureDisableMachineHashCheck() bool { + v := get("CARTESI_FEATURE_DISABLE_MACHINE_HASH_CHECK", "false", true, false, toBool) + return v +} + +func getCartesiFeatureHostMode() bool { + v := get("CARTESI_FEATURE_HOST_MODE", "false", true, false, toBool) + return v +} + +func getCartesiHttpAddress() string { + v := get("CARTESI_HTTP_ADDRESS", "127.0.0.1", true, false, toString) + return v +} + +func getCartesiHttpPort() int { + v := get("CARTESI_HTTP_PORT", "10000", true, false, toInt) + return v +} + +func getCartesiLogLevel() LogLevel { + v := get("CARTESI_LOG_LEVEL", "info", true, false, toLogLevel) + return v +} + +func getCartesiLogTimestamp() bool { + v := get("CARTESI_LOG_TIMESTAMP", "false", true, false, toBool) + return v +} + +func getCartesiPostgresEndpoint() string { + v := get("CARTESI_POSTGRES_ENDPOINT", "", true, true, toString) + return v +} + +func getCartesiEpochDuration() Duration { + v := get("CARTESI_EPOCH_DURATION", "86400", true, false, toDuration) + return v +} + +func getCartesiSnapshotDir() string { + v := get("CARTESI_SNAPSHOT_DIR", "", false, false, toString) + return v +} + +type NodeConfig struct { + CartesiBlockchainBlockTimeout int + CartesiBlockchainFinalityOffset int + CartesiBlockchainHttpEndpoint string + CartesiBlockchainId int + CartesiBlockchainIsLegacy bool + CartesiBlockchainWsEndpoint string + CartesiContractsInputBoxDeploymentBlockNumber int64 + CartesiContractsApplicationAddress string + CartesiContractsApplicationDeploymentBlockNumber string + CartesiContractsAuthorityAddress string + CartesiContractsHistoryAddress string + CartesiContractsInputBoxAddress string + CartesiExperimentalSunodoValidatorEnabled bool + CartesiExperimentalSunodoValidatorRedisEndpoint string + CartesiFeatureDisableClaimer bool + CartesiFeatureDisableMachineHashCheck bool + CartesiFeatureHostMode bool + CartesiHttpAddress string + CartesiHttpPort int + CartesiLogLevel LogLevel + CartesiLogTimestamp bool + CartesiPostgresEndpoint string + CartesiEpochDuration Duration + CartesiSnapshotDir string + CartesiAuth Auth +} + +func NewNodeConfigFromEnv() NodeConfig { + nodeConfig := NodeConfig{ + CartesiBlockchainBlockTimeout: getCartesiBlockchainBlockTimeout(), + CartesiBlockchainFinalityOffset: getCartesiBlockchainFinalityOffset(), + CartesiBlockchainHttpEndpoint: getCartesiBlockchainHttpEndpoint(), + CartesiBlockchainId: getCartesiBlockchainId(), + CartesiBlockchainIsLegacy: getCartesiBlockchainIsLegacy(), + CartesiBlockchainWsEndpoint: getCartesiBlockchainWsEndpoint(), + CartesiContractsInputBoxDeploymentBlockNumber: getCartesiContractsInputBoxDeploymentBlockNumber(), + CartesiContractsApplicationAddress: getCartesiContractsApplicationAddress(), + CartesiContractsApplicationDeploymentBlockNumber: getCartesiContractsApplicationDeploymentBlockNumber(), + CartesiContractsAuthorityAddress: getCartesiContractsAuthorityAddress(), + CartesiContractsHistoryAddress: getCartesiContractsHistoryAddress(), + CartesiContractsInputBoxAddress: getCartesiContractsInputBoxAddress(), + CartesiExperimentalSunodoValidatorEnabled: getCartesiExperimentalSunodoValidatorEnabled(), + CartesiExperimentalSunodoValidatorRedisEndpoint: getCartesiExperimentalSunodoValidatorRedisEndpoint(), + CartesiFeatureDisableClaimer: getCartesiFeatureDisableClaimer(), + CartesiFeatureDisableMachineHashCheck: getCartesiFeatureDisableMachineHashCheck(), + CartesiFeatureHostMode: getCartesiFeatureHostMode(), + CartesiHttpAddress: getCartesiHttpAddress(), + CartesiHttpPort: getCartesiHttpPort(), + CartesiLogLevel: getCartesiLogLevel(), + CartesiLogTimestamp: getCartesiLogTimestamp(), + CartesiPostgresEndpoint: getCartesiPostgresEndpoint(), + CartesiEpochDuration: getCartesiEpochDuration(), + CartesiSnapshotDir: getCartesiSnapshotDir(), + } + nodeConfig.CartesiAuth = GetAuth() + return nodeConfig +} + +func NewtNodeConfigDefault() NodeConfig { + nodeConfig := NodeConfig{} + cartesiBlockchainBlockTimeout, CartesiBlockchainBlockTimeoutError := toInt("60") + if CartesiBlockchainBlockTimeoutError != nil { + panic(CartesiBlockchainBlockTimeoutError) + } + nodeConfig.CartesiBlockchainBlockTimeout = cartesiBlockchainBlockTimeout + cartesiBlockchainFinalityOffset, CartesiBlockchainFinalityOffsetError := toInt("10") + if CartesiBlockchainFinalityOffsetError != nil { + panic(CartesiBlockchainFinalityOffsetError) + } + nodeConfig.CartesiBlockchainFinalityOffset = cartesiBlockchainFinalityOffset + cartesiBlockchainIsLegacy, CartesiBlockchainIsLegacyError := toBool("false") + if CartesiBlockchainIsLegacyError != nil { + panic(CartesiBlockchainIsLegacyError) + } + nodeConfig.CartesiBlockchainIsLegacy = cartesiBlockchainIsLegacy + cartesiExperimentalSunodoValidatorEnabled, CartesiExperimentalSunodoValidatorEnabledError := toBool("false") + if CartesiExperimentalSunodoValidatorEnabledError != nil { + panic(CartesiExperimentalSunodoValidatorEnabledError) + } + nodeConfig.CartesiExperimentalSunodoValidatorEnabled = cartesiExperimentalSunodoValidatorEnabled + cartesiFeatureDisableClaimer, CartesiFeatureDisableClaimerError := toBool("false") + if CartesiFeatureDisableClaimerError != nil { + panic(CartesiFeatureDisableClaimerError) + } + nodeConfig.CartesiFeatureDisableClaimer = cartesiFeatureDisableClaimer + cartesiFeatureDisableMachineHashCheck, CartesiFeatureDisableMachineHashCheckError := toBool("false") + if CartesiFeatureDisableMachineHashCheckError != nil { + panic(CartesiFeatureDisableMachineHashCheckError) + } + nodeConfig.CartesiFeatureDisableMachineHashCheck = cartesiFeatureDisableMachineHashCheck + cartesiFeatureHostMode, CartesiFeatureHostModeError := toBool("false") + if CartesiFeatureHostModeError != nil { + panic(CartesiFeatureHostModeError) + } + nodeConfig.CartesiFeatureHostMode = cartesiFeatureHostMode + cartesiHttpAddress, CartesiHttpAddressError := toString("127.0.0.1") + if CartesiHttpAddressError != nil { + panic(CartesiHttpAddressError) + } + nodeConfig.CartesiHttpAddress = cartesiHttpAddress + cartesiHttpPort, CartesiHttpPortError := toInt("10000") + if CartesiHttpPortError != nil { + panic(CartesiHttpPortError) + } + nodeConfig.CartesiHttpPort = cartesiHttpPort + cartesiLogLevel, CartesiLogLevelError := toLogLevel("info") + if CartesiLogLevelError != nil { + panic(CartesiLogLevelError) + } + nodeConfig.CartesiLogLevel = cartesiLogLevel + cartesiLogTimestamp, CartesiLogTimestampError := toBool("false") + if CartesiLogTimestampError != nil { + panic(CartesiLogTimestampError) + } + nodeConfig.CartesiLogTimestamp = cartesiLogTimestamp + cartesiEpochDuration, CartesiEpochDurationError := toDuration("86400") + if CartesiEpochDurationError != nil { + panic(CartesiEpochDurationError) + } + nodeConfig.CartesiEpochDuration = cartesiEpochDuration + nodeConfig.CartesiAuth = AuthMnemonic{Mnemonic: "test test test test test test test test test test test junk", AccountIndex: 0} + return nodeConfig +} diff --git a/internal/config/generate/helpers.go b/internal/config/generate/helpers.go index 0e476090b..f377c7941 100644 --- a/internal/config/generate/helpers.go +++ b/internal/config/generate/helpers.go @@ -76,6 +76,7 @@ func addCodeHeader(builder *strings.Builder) { addLine(builder, "") addLine(builder, `package config`) + addLine(builder, `import (`) addLine(builder, `"time"`) addLine(builder, `)`) @@ -86,6 +87,7 @@ func addCodeHeader(builder *strings.Builder) { addLine(builder, `Duration = time.Duration`) addLine(builder, `)`) addLine(builder, "") + } func addDocHeader(builder *strings.Builder) { diff --git a/internal/config/generate/main.go b/internal/config/generate/main.go index ff5346fce..52f487cb9 100644 --- a/internal/config/generate/main.go +++ b/internal/config/generate/main.go @@ -27,20 +27,86 @@ func main() { config := decodeTOML(data) envs := sortConfig(config) + for _, env := range envs { + env.validate() + } + writeDoc(envs) + writeCode(envs) +} + +func writeCode(envs []Env) { var code strings.Builder - var doc strings.Builder addCodeHeader(&code) - addDocHeader(&doc) - addLine(&doc, "") + //Validate envs + for i := range envs { + envs[i].validate() + } + + //Add get functions for _, env := range envs { - env.validate() addLine(&code, env.toFunction()) - addLine(&doc, env.toDoc()) } - writeToFile("get.go", formatCode(code.String())) + //Add NodeConfig Struct + addLine(&code, "type NodeConfig struct{") + for _, env := range envs { + if *env.Export { + addLine(&code, env.toStructMember()) + } + } + addLine(&code, "CartesiAuth Auth") + addLine(&code, "}") + + //Add init function from System Environment + addLine(&code, "") + addLine(&code, "func NewNodeConfigFromEnv() (NodeConfig){") + addLine(&code, "nodeConfig := NodeConfig{") + for _, env := range envs { + if *env.Export { + name := toStructMemberName(env.Name) + addLine(&code, name+": get"+name+"(),") + } + } + addLine(&code, "}") + addLine(&code, "nodeConfig.CartesiAuth = GetAuth()") + addLine(&code, "return nodeConfig") + addLine(&code, "}") + + //Add init function from Default Values + addLine(&code, "") + addLine(&code, "func NewtNodeConfigDefault() (NodeConfig){") + addLine(&code, "nodeConfig := NodeConfig{}") + for _, env := range envs { + if *env.Export && env.Default != nil && *env.Default != "" { + name := toStructMemberName(env.Name) + varName := toVarName(name) + errorName := name + "Error" + addLine(&code, varName+", "+errorName+" := "+toToFuncName(env.GoType)+`("`+*env.Default+`")`) + addLine(&code, "if "+errorName+" != nil {") + addLine(&code, "panic("+errorName+")") + addLine(&code, "}") + addLine(&code, "nodeConfig."+name+" = "+varName) + + } + } + + addLine(&code, `nodeConfig.CartesiAuth = AuthMnemonic{Mnemonic: "test test test test test test test test test test test junk", AccountIndex: 0}`) + addLine(&code, "return nodeConfig") + addLine(&code, "}") + + writeToFile("configstruct.go", formatCode(code.String())) +} + +func writeDoc(envs []Env) { + var doc strings.Builder + + addDocHeader(&doc) + addLine(&doc, "") + for _, env := range envs { + addLine(&doc, env.toDoc()) + } writeToFile("../../docs/config.md", []byte(doc.String())) } @@ -92,7 +158,7 @@ func (e *Env) validate() { // Generates the get function for the environment variable. func (e Env) toFunction() string { - name := toFunctionName(e.Name) + name := toStructMemberName(e.Name) typ := e.GoType get := "get" vars := "v" @@ -103,16 +169,12 @@ func (e Env) toFunction() string { defaultValue = *e.Default } - to_ := []rune(e.GoType) - to_[0] = unicode.ToUpper(to_[0]) - to := "to" + string(to_) + to := toToFuncName(e.GoType) args := fmt.Sprintf(`"%s", "%s", %t, %t, %s`, e.Name, defaultValue, hasDefault, *e.Redact, to) - if *e.Export { - name = "Get" + name - } else { - name = "get" + name + name = "get" + name + if !*e.Export { typ = fmt.Sprintf("(%s, bool)", typ) get += "Optional" vars += ", ok" @@ -123,6 +185,18 @@ func (e Env) toFunction() string { return fmt.Sprintf("func %s() %s { %s }\n", name, typ, body) } +// Generates the Config Struct member for the envrionemnt variable. +func (e Env) toStructMember() string { + name := toStructMemberName(e.Name) + + if !*e.Export { + name = toVarName(name) + } + + return name + " " + e.GoType + +} + // Generates the documentation entry for the environment variable. func (e Env) toDoc() string { s := fmt.Sprintf("## `%s`\n\n%s\n\n", e.Name, e.Description) @@ -134,7 +208,7 @@ func (e Env) toDoc() string { } // Splits the string by "_" and joins each substring with the first letter in upper case. -func toFunctionName(env string) string { +func toStructMemberName(env string) string { caser := cases.Title(language.English) words := strings.Split(env, "_") for i, word := range words { @@ -142,3 +216,15 @@ func toFunctionName(env string) string { } return strings.Join(words, "") } + +func toVarName(name string) string { + name_ := []rune(name) + name_[0] = unicode.ToLower(name_[0]) + return string(name_) +} + +func toToFuncName(goType string) string { + to_ := []rune(goType) + to_[0] = unicode.ToUpper(to_[0]) + return "to" + string(to_) +} diff --git a/internal/config/get.go b/internal/config/get.go deleted file mode 100644 index f3ce1a792..000000000 --- a/internal/config/get.go +++ /dev/null @@ -1,160 +0,0 @@ -// Code generated by internal/config/generate. -// DO NOT EDIT. - -// (c) Cartesi and individual authors (see AUTHORS) -// SPDX-License-Identifier: Apache-2.0 (see LICENSE) - -package config - -import ( - "time" -) - -type ( - Duration = time.Duration -) - -func getCartesiAuthAwsKmsKeyId() (string, bool) { - v, ok := getOptional("CARTESI_AUTH_AWS_KMS_KEY_ID", "", false, true, toString) - return v, ok -} - -func getCartesiAuthAwsKmsRegion() (string, bool) { - v, ok := getOptional("CARTESI_AUTH_AWS_KMS_REGION", "", false, true, toString) - return v, ok -} - -func getCartesiAuthMnemonic() (string, bool) { - v, ok := getOptional("CARTESI_AUTH_MNEMONIC", "", false, true, toString) - return v, ok -} - -func getCartesiAuthMnemonicAccountIndex() (int, bool) { - v, ok := getOptional("CARTESI_AUTH_MNEMONIC_ACCOUNT_INDEX", "0", true, true, toInt) - return v, ok -} - -func getCartesiAuthMnemonicFile() (string, bool) { - v, ok := getOptional("CARTESI_AUTH_MNEMONIC_FILE", "", false, true, toString) - return v, ok -} - -func GetCartesiBlockchainBlockTimeout() int { - v := get("CARTESI_BLOCKCHAIN_BLOCK_TIMEOUT", "60", true, false, toInt) - return v -} - -func GetCartesiBlockchainFinalityOffset() int { - v := get("CARTESI_BLOCKCHAIN_FINALITY_OFFSET", "10", true, false, toInt) - return v -} - -func GetCartesiBlockchainHttpEndpoint() string { - v := get("CARTESI_BLOCKCHAIN_HTTP_ENDPOINT", "", false, false, toString) - return v -} - -func GetCartesiBlockchainId() int { - v := get("CARTESI_BLOCKCHAIN_ID", "", false, false, toInt) - return v -} - -func GetCartesiBlockchainIsLegacy() bool { - v := get("CARTESI_BLOCKCHAIN_IS_LEGACY", "false", true, false, toBool) - return v -} - -func GetCartesiBlockchainWsEndpoint() string { - v := get("CARTESI_BLOCKCHAIN_WS_ENDPOINT", "", false, false, toString) - return v -} - -func GetCartesiContractsInputBoxDeploymentBlockNumber() int64 { - v := get("CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER", "", false, false, toInt64) - return v -} - -func GetCartesiContractsApplicationAddress() string { - v := get("CARTESI_CONTRACTS_APPLICATION_ADDRESS", "", false, false, toString) - return v -} - -func GetCartesiContractsApplicationDeploymentBlockNumber() string { - v := get("CARTESI_CONTRACTS_APPLICATION_DEPLOYMENT_BLOCK_NUMBER", "", false, false, toString) - return v -} - -func GetCartesiContractsAuthorityAddress() string { - v := get("CARTESI_CONTRACTS_AUTHORITY_ADDRESS", "", false, false, toString) - return v -} - -func GetCartesiContractsHistoryAddress() string { - v := get("CARTESI_CONTRACTS_HISTORY_ADDRESS", "", false, false, toString) - return v -} - -func GetCartesiContractsInputBoxAddress() string { - v := get("CARTESI_CONTRACTS_INPUT_BOX_ADDRESS", "", false, false, toString) - return v -} - -func GetCartesiExperimentalSunodoValidatorEnabled() bool { - v := get("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_ENABLED", "false", true, false, toBool) - return v -} - -func GetCartesiExperimentalSunodoValidatorRedisEndpoint() string { - v := get("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_REDIS_ENDPOINT", "", false, false, toString) - return v -} - -func GetCartesiFeatureDisableClaimer() bool { - v := get("CARTESI_FEATURE_DISABLE_CLAIMER", "false", true, false, toBool) - return v -} - -func GetCartesiFeatureDisableMachineHashCheck() bool { - v := get("CARTESI_FEATURE_DISABLE_MACHINE_HASH_CHECK", "false", true, false, toBool) - return v -} - -func GetCartesiFeatureHostMode() bool { - v := get("CARTESI_FEATURE_HOST_MODE", "false", true, false, toBool) - return v -} - -func GetCartesiHttpAddress() string { - v := get("CARTESI_HTTP_ADDRESS", "127.0.0.1", true, false, toString) - return v -} - -func GetCartesiHttpPort() int { - v := get("CARTESI_HTTP_PORT", "10000", true, false, toInt) - return v -} - -func GetCartesiLogLevel() LogLevel { - v := get("CARTESI_LOG_LEVEL", "info", true, false, toLogLevel) - return v -} - -func GetCartesiLogTimestamp() bool { - v := get("CARTESI_LOG_TIMESTAMP", "false", true, false, toBool) - return v -} - -func GetCartesiPostgresEndpoint() string { - v := get("CARTESI_POSTGRES_ENDPOINT", "", true, true, toString) - return v -} - -func GetCartesiEpochDuration() Duration { - v := get("CARTESI_EPOCH_DURATION", "86400", true, false, toDuration) - return v -} - -func GetCartesiSnapshotDir() string { - v := get("CARTESI_SNAPSHOT_DIR", "", false, false, toString) - return v -} diff --git a/internal/config/log.go b/internal/config/log.go index 57a3882f1..0171ebb25 100644 --- a/internal/config/log.go +++ b/internal/config/log.go @@ -23,7 +23,7 @@ func init() { func logInit() { var flags int - if GetCartesiLogTimestamp() { + if getCartesiLogTimestamp() { flags = log.LstdFlags } @@ -32,7 +32,7 @@ func logInit() { InfoLogger = log.New(os.Stdout, "INFO ", flags) DebugLogger = log.New(os.Stdout, "DEBUG ", flags) - switch GetCartesiLogLevel() { + switch getCartesiLogLevel() { case LogLevelError: WarningLogger.SetOutput(io.Discard) fallthrough