diff --git a/docs/config.md b/docs/config.md index b93d811a4..000474505 100644 --- a/docs/config.md +++ b/docs/config.md @@ -151,7 +151,7 @@ All other log configurations are ignored. ## `CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_ENABLED` -When enabled, the node does not start the authority-claimer service and the Redis server, thus not making claims. +When enabled, the node does not enable the reader mode and does not start the authority-claimer service and the Redis server. * **Type:** `bool` * **Default:** `"false"` @@ -164,7 +164,7 @@ External Redis endpoint for the node when running in the experimental sunodo val ## `CARTESI_FEATURE_DISABLE_CLAIMER` -If set to true, the node will not make claims. +If set to true, the authority-claimer service is disabled. * **Type:** `bool` * **Default:** `"false"` @@ -187,6 +187,13 @@ 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, thus not generating claims. + +* **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..c0c88e6de 100644 --- a/internal/node/config/generate/Config.toml +++ b/internal/node/config/generate/Config.toml @@ -28,11 +28,17 @@ 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, thus not generating claims.""" + [features.CARTESI_FEATURE_DISABLE_CLAIMER] default = "false" go-type = "bool" description = """ -If set to true, the node will not make claims.""" +If set to true, the authority-claimer service is disabled.""" [features.CARTESI_FEATURE_DISABLE_MACHINE_HASH_CHECK] default = "false" @@ -225,7 +231,7 @@ The node will also use the 20 ports after this one for internal services.""" default = "false" go-type = "bool" description = """ -When enabled, the node does not start the authority-claimer service and the Redis server, thus not making claims.""" +When enabled, the node does not enable the reader mode and does not start the authority-claimer service and the Redis server.""" [experimental.CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_REDIS_ENDPOINT] go-type = "string" 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") }