From 428bd0c95d6a48319ff805fcccead20e67dc875b Mon Sep 17 00:00:00 2001 From: Marcel Moura <5615598+marcelstanley@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:00:59 -0300 Subject: [PATCH] fix(config): disable claimer on experimental mode --- CHANGELOG.md | 4 ++ docs/config.md | 2 +- internal/node/config/config.go | 7 ++-- internal/node/config/config_test.go | 45 +++++++++++++++++++++++ internal/node/config/generate/Config.toml | 2 +- 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 internal/node/config/config_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 65fd8639b..896f6cf3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Disabled the `authority-claimer` when `CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_ENABLED` is set to `true`. + ## [1.5.0] 2024-07-22 ### Added diff --git a/docs/config.md b/docs/config.md index a48b45f4e..b93d811a4 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. +When enabled, the node does not start the authority-claimer service and the Redis server, thus not making claims. * **Type:** `bool` * **Default:** `"false"` diff --git a/internal/node/config/config.go b/internal/node/config/config.go index 6f9d6391d..f32a744b3 100644 --- a/internal/node/config/config.go +++ b/internal/node/config/config.go @@ -93,15 +93,16 @@ func FromEnv() NodeConfig { config.HttpAddress = getHttpAddress() config.HttpPort = getHttpPort() config.FeatureHostMode = getFeatureHostMode() - config.FeatureDisableClaimer = getFeatureDisableClaimer() config.FeatureDisableMachineHashCheck = getFeatureDisableMachineHashCheck() config.ExperimentalServerManagerBypassLog = getExperimentalServerManagerBypassLog() + config.FeatureDisableClaimer = getFeatureDisableClaimer() config.ExperimentalSunodoValidatorEnabled = getExperimentalSunodoValidatorEnabled() - if getExperimentalSunodoValidatorEnabled() { + if config.ExperimentalSunodoValidatorEnabled { config.ExperimentalSunodoValidatorRedisEndpoint = getExperimentalSunodoValidatorRedisEndpoint() + config.FeatureDisableClaimer = true } - if !getFeatureDisableClaimer() && !getExperimentalSunodoValidatorEnabled() { + if !config.FeatureDisableClaimer && !getExperimentalSunodoValidatorEnabled() { config.Auth = authFromEnv() } return config diff --git a/internal/node/config/config_test.go b/internal/node/config/config_test.go new file mode 100644 index 000000000..b1c95e08b --- /dev/null +++ b/internal/node/config/config_test.go @@ -0,0 +1,45 @@ +// (c) Cartesi and individual authors (see AUTHORS) +// SPDX-License-Identifier: Apache-2.0 (see LICENSE) + +package config + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +type ConfigTestSuite struct { + suite.Suite +} + +func (s *ConfigTestSuite) SetupSuite() { + os.Setenv("CARTESI_BLOCKCHAIN_ID", "31337") + os.Setenv("CARTESI_BLOCKCHAIN_HTTP_ENDPOINT", "http://localhost:8545") + os.Setenv("CARTESI_BLOCKCHAIN_WS_ENDPOINT", "ws://localhost:8545") + os.Setenv("CARTESI_CONTRACTS_APPLICATION_ADDRESS", "0x") + os.Setenv("CARTESI_CONTRACTS_HISTORY_ADDRESS", "0x") + os.Setenv("CARTESI_CONTRACTS_AUTHORITY_ADDRESS", "0x") + os.Setenv("CARTESI_CONTRACTS_INPUT_BOX_ADDRESS", "0x") + os.Setenv("CARTESI_CONTRACTS_INPUT_BOX_DEPLOYMENT_BLOCK_NUMBER", "0") + os.Setenv("CARTESI_SNAPSHOT_DIR", "/tmp") +} + +func TestConfigTest(t *testing.T) { + suite.Run(t, new(ConfigTestSuite)) +} + +func (s *ConfigTestSuite) TestExperimentalSunodoValidatorModeDisablesClaimer() { + os.Setenv("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_ENABLED", "true") + os.Setenv("CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_REDIS_ENDPOINT", "redis://") + c := FromEnv() + assert.Equal(s.T(), true, c.FeatureDisableClaimer) +} + +func (s *ConfigTestSuite) TestAuthIsNotSetWhenClaimerIsDisabled() { + os.Setenv("CARTESI_FEATURE_DISABLE_CLAIMER", "true") + c := FromEnv() + assert.Nil(s.T(), c.Auth) +} diff --git a/internal/node/config/generate/Config.toml b/internal/node/config/generate/Config.toml index bda385b6c..923d7a0be 100644 --- a/internal/node/config/generate/Config.toml +++ b/internal/node/config/generate/Config.toml @@ -225,7 +225,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.""" +When enabled, the node does not start the authority-claimer service and the Redis server, thus not making claims.""" [experimental.CARTESI_EXPERIMENTAL_SUNODO_VALIDATOR_REDIS_ENDPOINT] go-type = "string"