Skip to content

Commit

Permalink
feat(config): add reader mode
Browse files Browse the repository at this point in the history
This fixes an issue where the advance-runner was being set to run in
reader mode whenever the claimer was disabled.

While here, adjust the meaning of configuration parameters related to
the claimet and to the sunodo experimental mode.
  • Loading branch information
marcelstanley committed Aug 16, 2024
1 parent e8d91bc commit 932420e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
11 changes: 9 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand All @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion internal/node/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type NodeConfig struct {
HttpAddress string
HttpPort int
FeatureHostMode bool
FeatureReaderModeEnabled bool
FeatureDisableClaimer bool
FeatureDisableMachineHashCheck bool
ExperimentalServerManagerBypassLog bool
Expand Down Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions internal/node/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,31 @@ 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()
assert.Nil(s.T(), c.Auth)
}

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())
}
10 changes: 8 additions & 2 deletions internal/node/config/generate/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions internal/node/config/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/node/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 932420e

Please sign in to comment.