Skip to content

[TECHDEBT] implement ValidateConfig and ValidateGenesis in all modules #334

@deblasis

Description

@deblasis

Objective

This issue tends to track the implementation of the validations that are currently marked as TODOs without a reference to any actual task.

Specifically, all modules that implement ConfigurableModule and/or GenesisDependentModule have a ValidateConfig(Config) error and/or a ValidateGenesis(GenesisState) error method.

An example of a valid implementation that could apply to all modules is:

func (*persistenceModule) ValidateConfig(cfg modules.Config) error {
	persistenceConfig:= cfg.GetPersistenceConfig()
	if persistenceConfig == (*types.PersistenceConfig)(nil) {
		return fmt.Errorf("persistenceConfig is nil")
	}
        // additional validations
	return nil
}

Here, we are simply verifying that the configuration for the module is set, but we could also validate the individual values such as PostgresUrl (for which we expect a PostgreSQL connection string) by replacing // additional validations in the example above with something similar to:

if !strings.HasPrefix(persistenceConfig.GetPostgresUrl(),"postgres://") {
    return fmt.Errorf("persistenceConfig.postgres_url must be a valid PostgreSQL connection string")
}

The other obvious ones are port numbers (which naturally have lower and upper bounds), paths that must be valid, etc.

Clearly, it's also possible that a particular configuration currently doesn't have any validation rule. It might or might not be defined in the future.

Designing and defining how we address (or not) existing values and future-proofing configs we will add in the future is part of the task.

Origin Document

https://github.com/pokt-network/pocket/pull/176/files#r1012343547

Goals

  • Defining a pattern that all modules will follow for Config and Genesis validation
  • Future-proofing validation for config values we have not created yet
  • Implement validations wherever needed for the modules that implement ConfigurableModule and/or GenesisDependentModule

Deliverable

  • Validation functions for Config and Genesis in every respective module
  • Removal of the TODO items
  • Documenting the pattern for how this should be implemented

Non-goals / Non-deliverables

  • Change the existing logic in the respective modules

General issue deliverables

  • Update the appropriate CHANGELOG
  • Update any relevant READMEs (local and/or global)
  • Update any relevant global documentation & references

[Required] Testing Methodology

  • All tests: make test_all
  • LocalNet: verify a LocalNet is still functioning correctly by following the instructions at docs/development/README.md
  • New tests: Add new unit tests that can be executed via make test_configs to validate all non-genesis configs
  • New tests: Add new unit tests that can be executed via make test_genesis to validate all genesis configurations

Creator: @deblasis
Co-Owners: @Olshansk

Metadata

Metadata

Labels

communityOpen to or owned by a non-core team membercoreCore infrastructure - protocol related

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions