-
Notifications
You must be signed in to change notification settings - Fork 879
config(state-sync): hide tendermint tuning knobs from template #3352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
62acc0e
simplify state sync config
blindchaser ebc67e8
Merge branch 'main' into yiren/simplify-state-sync-config
blindchaser 9ebe904
Merge branch 'main' into yiren/simplify-state-sync-config
blindchaser 1cf5f35
Merge branch 'main' into yiren/simplify-state-sync-config
masih File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package config_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/spf13/viper" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/sei-protocol/sei-chain/sei-tendermint/cmd/tendermint/commands" | ||
| tmconfig "github.com/sei-protocol/sei-chain/sei-tendermint/config" | ||
| ) | ||
|
|
||
| // This test (and TestFreshStateSyncConfigValidatesWithoutHiddenKnobs) mutate the | ||
| // global viper singleton via commands.ParseConfig, so they must not run in | ||
| // parallel with other tests in this package. | ||
|
|
||
| func TestHiddenStateSyncKnobsStillParseFromExistingConfig(t *testing.T) { | ||
| viper.Reset() | ||
| t.Cleanup(viper.Reset) | ||
|
|
||
| configPath := filepath.Join(t.TempDir(), "config.toml") | ||
| err := os.WriteFile(configPath, []byte(` | ||
| [statesync] | ||
| enable = true | ||
| rpc-servers = "localhost:26657,localhost:26659" | ||
| trust-height = 10 | ||
| trust-hash = "AABB" | ||
| trust-period = "168h0m0s" | ||
| backfill-blocks = "100" | ||
| backfill-duration = "5m0s" | ||
| discovery-time = "20s" | ||
| temp-dir = "/tmp/statesync" | ||
| chunk-request-timeout = "30s" | ||
| fetchers = "5" | ||
| verify-light-block-timeout = "2m0s" | ||
| blacklist-ttl = "10m0s" | ||
| `), 0600) | ||
| require.NoError(t, err) | ||
|
|
||
| viper.SetConfigFile(configPath) | ||
| require.NoError(t, viper.ReadInConfig()) | ||
|
|
||
| cfg, err := commands.ParseConfig(tmconfig.DefaultConfig()) | ||
| require.NoError(t, err) | ||
| require.True(t, cfg.StateSync.Enable) | ||
| require.Equal(t, []string{"localhost:26657", "localhost:26659"}, cfg.StateSync.RPCServers) | ||
| require.Equal(t, int64(10), cfg.StateSync.TrustHeight) | ||
| require.Equal(t, "AABB", cfg.StateSync.TrustHash) | ||
| require.Equal(t, int64(100), cfg.StateSync.BackfillBlocks) | ||
| require.Equal(t, 5*time.Minute, cfg.StateSync.BackfillDuration) | ||
| require.Equal(t, 20*time.Second, cfg.StateSync.DiscoveryTime) | ||
| require.Equal(t, "/tmp/statesync", cfg.StateSync.TempDir) | ||
| require.Equal(t, 30*time.Second, cfg.StateSync.ChunkRequestTimeout) | ||
| require.Equal(t, int32(5), cfg.StateSync.Fetchers) | ||
| require.Equal(t, 2*time.Minute, cfg.StateSync.VerifyLightBlockTimeout) | ||
| require.Equal(t, 10*time.Minute, cfg.StateSync.BlacklistTTL) | ||
| } | ||
|
|
||
| // TestFreshStateSyncConfigValidatesWithoutHiddenKnobs mirrors the freshly-rendered | ||
| // template (no hidden tuning knobs in the file) and verifies that ParseConfig | ||
| // still produces a valid StateSyncConfig that passes ValidateBasic. This guards | ||
| // against future regressions where someone removes or zeros a default in | ||
| // DefaultStateSyncConfig without realizing the template no longer carries it. | ||
| func TestFreshStateSyncConfigValidatesWithoutHiddenKnobs(t *testing.T) { | ||
| viper.Reset() | ||
| t.Cleanup(viper.Reset) | ||
|
|
||
| configPath := filepath.Join(t.TempDir(), "config.toml") | ||
| err := os.WriteFile(configPath, []byte(` | ||
| [statesync] | ||
| enable = true | ||
| rpc-servers = "localhost:26657,localhost:26659" | ||
| trust-height = 10 | ||
| trust-hash = "AABB" | ||
| trust-period = "168h0m0s" | ||
| `), 0600) | ||
| require.NoError(t, err) | ||
|
|
||
| viper.SetConfigFile(configPath) | ||
| require.NoError(t, viper.ReadInConfig()) | ||
|
|
||
| cfg, err := commands.ParseConfig(tmconfig.DefaultConfig()) | ||
| require.NoError(t, err) | ||
|
|
||
| defaults := tmconfig.DefaultStateSyncConfig() | ||
| require.Equal(t, defaults.BackfillBlocks, cfg.StateSync.BackfillBlocks) | ||
| require.Equal(t, defaults.BackfillDuration, cfg.StateSync.BackfillDuration) | ||
| require.Equal(t, defaults.DiscoveryTime, cfg.StateSync.DiscoveryTime) | ||
| require.Equal(t, defaults.ChunkRequestTimeout, cfg.StateSync.ChunkRequestTimeout) | ||
| require.Equal(t, defaults.Fetchers, cfg.StateSync.Fetchers) | ||
| require.Equal(t, defaults.VerifyLightBlockTimeout, cfg.StateSync.VerifyLightBlockTimeout) | ||
| require.Equal(t, defaults.BlacklistTTL, cfg.StateSync.BlacklistTTL) | ||
|
|
||
| require.NoError(t, cfg.StateSync.ValidateBasic()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good but how the code on the latest version behave when these configs are still present?
This is likely the case for most nodes, where they upgrade the binary but rarely change the config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backward compatible: only the rendered template hides these keys. The StateSyncConfig struct fields and their mapstructure tags (backfill-blocks, backfill-duration, discovery-time, temp-dir, chunk-request-timeout, fetchers, verify-light-block-timeout, blacklist-ttl) are unchanged, so existing config.toml files continue to parse and honor those values exactly as before.
Covered by TestHiddenStateSyncKnobsStillParseFromExistingConfig in sei-tendermint/config/statesync_compat_test.go (existing config path) and TestFreshStateSyncConfigValidatesWithoutHiddenKnobs (fresh config falls back to DefaultStateSyncConfig() defaults).