From d131ac918fcd6f410aa7e7caa8424ebe1727b214 Mon Sep 17 00:00:00 2001 From: Marcel Moura <5615598+marcelstanley@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:54:27 -0300 Subject: [PATCH] feat(config): add reader mode This fixes an issue where the advance-runner was being set to run in reader mode whenever the claimer was disabled. --- docs/config.md | 9 +++++++++ internal/node/config/config.go | 7 ++++++- internal/node/config/config_test.go | 17 +++++++++++++---- internal/node/config/generate/Config.toml | 8 ++++++++ internal/node/config/generated.go | 12 ++++++++++++ internal/node/services.go | 2 +- 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/docs/config.md b/docs/config.md index b93d811a4..73e8110ae 100644 --- a/docs/config.md +++ b/docs/config.md @@ -187,6 +187,15 @@ You should only use host mode for development and debugging! * **Type:** `bool` * **Default:** `"false"` +## `CARTESI_FEATURE_READER_MODE_ENABLED` + +If set to true, the node will run in reader mode. + +In reader mode, the authority-claimer is disabled. Thus, no claims are generated. + +* **Type:** `bool` +* **Default:** `"false"` + ## `CARTESI_HTTP_ADDRESS` HTTP address for the node. diff --git a/internal/node/config/config.go b/internal/node/config/config.go index 1331e8997..15cc53786 100644 --- a/internal/node/config/config.go +++ b/internal/node/config/config.go @@ -32,6 +32,7 @@ type NodeConfig struct { HttpAddress string HttpPort int FeatureHostMode bool + FeatureReaderModeEnabled bool FeatureDisableClaimer bool FeatureDisableMachineHashCheck bool ExperimentalServerManagerBypassLog bool @@ -96,13 +97,17 @@ func FromEnv() NodeConfig { config.FeatureDisableMachineHashCheck = getFeatureDisableMachineHashCheck() config.ExperimentalServerManagerBypassLog = getExperimentalServerManagerBypassLog() config.FeatureDisableClaimer = getFeatureDisableClaimer() + config.FeatureReaderModeEnabled = getFeatureReaderModeEnabled() config.ExperimentalSunodoValidatorEnabled = getExperimentalSunodoValidatorEnabled() + // The experimental mode overrides the reader mode and claimer configuration if config.ExperimentalSunodoValidatorEnabled { config.ExperimentalSunodoValidatorRedisEndpoint = Redacted[string]{getExperimentalSunodoValidatorRedisEndpoint()} config.FeatureDisableClaimer = true + config.FeatureReaderModeEnabled = false } - if !config.FeatureDisableClaimer && !getExperimentalSunodoValidatorEnabled() { + // Authentication is only available when the claimer is enabled + if !config.FeatureDisableClaimer { config.Auth = authFromEnv() } return config diff --git a/internal/node/config/config_test.go b/internal/node/config/config_test.go index eaeb88899..76aa178c1 100644 --- a/internal/node/config/config_test.go +++ b/internal/node/config/config_test.go @@ -32,12 +32,17 @@ func TestConfigTest(t *testing.T) { } func (s *ConfigTestSuite) TestExperimentalSunodoValidatorModeDisablesClaimer() { - os.Setenv("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_ENABLED", "true") - os.Setenv("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_REDIS_ENDPOINT", "redis://") + enableSunodoValidatorMode() c := FromEnv() assert.Equal(s.T(), true, c.FeatureDisableClaimer) } +func (s *ConfigTestSuite) TestExperimentalSunodoValidatorModeDisablesReaderMode() { + enableSunodoValidatorMode() + c := FromEnv() + assert.Equal(s.T(), false, c.FeatureReaderModeEnabled) +} + func (s *ConfigTestSuite) TestAuthIsNotSetWhenClaimerIsDisabled() { os.Setenv("CARTESI_FEATURE_DISABLE_CLAIMER", "true") c := FromEnv() @@ -45,9 +50,13 @@ func (s *ConfigTestSuite) TestAuthIsNotSetWhenClaimerIsDisabled() { } func (s *ConfigTestSuite) TestExperimentalSunodoValidatorRedisEndpointIsRedacted() { + enableSunodoValidatorMode() + c := FromEnv() + assert.Equal(s.T(), "[REDACTED]", c.ExperimentalSunodoValidatorRedisEndpoint.String()) +} + +func enableSunodoValidatorMode() { os.Setenv("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_ENABLED", "true") os.Setenv("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_REDIS_ENDPOINT", "redis://username:p@ssw0rd@hostname:9999") - c := FromEnv() - assert.Equal(s.T(), "[REDACTED]", c.ExperimentalSunodoValidatorRedisEndpoint.String()) } diff --git a/internal/node/config/generate/Config.toml b/internal/node/config/generate/Config.toml index 923d7a0be..703f5508e 100644 --- a/internal/node/config/generate/Config.toml +++ b/internal/node/config/generate/Config.toml @@ -28,6 +28,14 @@ If set to true, the node will run in host mode. In host mode, computations will not be performed by the cartesi machine. You should only use host mode for development and debugging!""" +[features.CARTESI_FEATURE_READER_MODE_ENABLED] +default = "false" +go-type = "bool" +description = """ +If set to true, the node will run in reader mode. + +In reader mode, the authority-claimer is disabled. Thus, no claims are generated.""" + [features.CARTESI_FEATURE_DISABLE_CLAIMER] default = "false" go-type = "bool" diff --git a/internal/node/config/generated.go b/internal/node/config/generated.go index bb60cf9d5..e1ff76069 100644 --- a/internal/node/config/generated.go +++ b/internal/node/config/generated.go @@ -401,6 +401,18 @@ func getFeatureHostMode() bool { return val } +func getFeatureReaderModeEnabled() bool { + s, ok := os.LookupEnv("CARTESI_FEATURE_READER_MODE_ENABLED") + if !ok { + s = "false" + } + val, err := toBool(s) + if err != nil { + panic(fmt.Sprintf("failed to parse CARTESI_FEATURE_READER_MODE_ENABLED: %v", err)) + } + return val +} + func getHttpAddress() string { s, ok := os.LookupEnv("CARTESI_HTTP_ADDRESS") if !ok { diff --git a/internal/node/services.go b/internal/node/services.go index bf60efd51..dc8aa68c7 100644 --- a/internal/node/services.go +++ b/internal/node/services.go @@ -87,7 +87,7 @@ func newAdvanceRunner(c config.NodeConfig, workDir string) services.CommandServi c.BlockchainHttpEndpoint.Value)) s.Env = append(s.Env, fmt.Sprintf("ADVANCE_RUNNER_HEALTHCHECK_PORT=%v", getPort(c, portOffsetAdvanceRunner))) - s.Env = append(s.Env, fmt.Sprintf("READER_MODE=%v", c.FeatureDisableClaimer)) + s.Env = append(s.Env, fmt.Sprintf("READER_MODE=%v", c.FeatureReaderModeEnabled)) if c.FeatureHostMode || c.FeatureDisableMachineHashCheck { s.Env = append(s.Env, "SNAPSHOT_VALIDATION_ENABLED=false") }