Skip to content
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

fix(config): ignore abci section on seeds #785

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 22 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,36 @@ func (cfg *Config) SetRoot(root string) *Config {
// ValidateBasic performs basic validation (checking param bounds, etc.) and
// returns an error if any check fails.
func (cfg *Config) ValidateBasic() error {
var errs error

if err := cfg.Abci.ValidateBasic(); err != nil {
return fmt.Errorf("error in [abci] section: %w", err)
}
if err := cfg.BaseConfig.ValidateBasic(); err != nil {
return err
errs = multierror.Append(errs, err)
}

// ignore [abci] section on seed nodes
if cfg.Mode != ModeSeed {
if err := cfg.Abci.ValidateBasic(); err != nil {
errs = multierror.Append(errs, fmt.Errorf("error in [abci] section: %w", err))
}
}

if err := cfg.RPC.ValidateBasic(); err != nil {
return fmt.Errorf("error in [rpc] section: %w", err)
errs = multierror.Append(errs, fmt.Errorf("error in [rpc] section: %w", err))
}
if err := cfg.Mempool.ValidateBasic(); err != nil {
return fmt.Errorf("error in [mempool] section: %w", err)
errs = multierror.Append(errs, fmt.Errorf("error in [mempool] section: %w", err))
}
if err := cfg.StateSync.ValidateBasic(); err != nil {
return fmt.Errorf("error in [statesync] section: %w", err)
errs = multierror.Append(errs, fmt.Errorf("error in [statesync] section: %w", err))
}
if err := cfg.Consensus.ValidateBasic(); err != nil {
return fmt.Errorf("error in [consensus] section: %w", err)
errs = multierror.Append(errs, fmt.Errorf("error in [consensus] section: %w", err))
}
if err := cfg.Instrumentation.ValidateBasic(); err != nil {
return fmt.Errorf("error in [instrumentation] section: %w", err)
errs = multierror.Append(errs, fmt.Errorf("error in [instrumentation] section: %w", err))
}
return nil

return errs
}

func (cfg *Config) DeprecatedFieldWarning() error {
Expand Down Expand Up @@ -466,6 +473,11 @@ func TestAbciConfig() *AbciConfig {
func (cfg *AbciConfig) ValidateBasic() error {
var err error

if cfg == nil {
err = multierror.Append(err, errors.New("[abci] config section is nil"))
return err
}

for key := range cfg.Other {
err = multierror.Append(err, fmt.Errorf("unknown field: %s", key))
}
Expand Down
59 changes: 59 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,65 @@ func TestConfigValidateBasic(t *testing.T) {
assert.Error(t, cfg.ValidateBasic())
}

func TestAbciConfigValidation(t *testing.T) {
type testCase struct {
name string
*AbciConfig
expectErr string // empty when no error, or error message to expect
}
// negative test cases that should fail on validator, but pass on seeds
invalidCases := []testCase{
{
name: "no abci config",
expectErr: "",
},
{
name: "unexpected data",
AbciConfig: &AbciConfig{Other: map[string]interface{}{"foo": "bar"}},
expectErr: "",
},
{
name: "invalid transport",
AbciConfig: &AbciConfig{
Transport: "invalid",
Address: "tcp://127.0.0.1:1234",
},
expectErr: "",
},
{
name: "missing address",
AbciConfig: &AbciConfig{
Transport: "invalid",
Address: "",
},
expectErr: "",
},
}

for _, tc := range invalidCases {
tc := tc

t.Run(tc.name+" on validator", func(t *testing.T) {
cfg := DefaultConfig()
cfg.Mode = ModeValidator
cfg.Abci = nil

err := cfg.ValidateBasic()
if tc.expectErr != "" {
assert.ErrorContains(t, err, tc.expectErr)
}
})
t.Run(tc.name+" on seed", func(t *testing.T) {
cfg := DefaultConfig()
cfg.Mode = ModeSeed
cfg.Abci = nil

err := cfg.ValidateBasic()
assert.NoError(t, err)
})
}
}

func TestTLSConfiguration(t *testing.T) {
cfg := DefaultConfig()
cfg.SetRoot("/home/user")
Expand Down