Skip to content

Commit

Permalink
feat(config): add reader mode
Browse files Browse the repository at this point in the history
While here, fix advance-runner configuration
  • Loading branch information
marcelstanley committed Aug 16, 2024
1 parent e8d91bc commit 466bf1d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
9 changes: 9 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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())
}
8 changes: 8 additions & 0 deletions internal/node/config/generate/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 466bf1d

Please sign in to comment.