cosmos-sdk icon indicating copy to clipboard operation
cosmos-sdk copied to clipboard

Server TOML config template can get out of sync with config.go

Open gibson042 opened this issue 1 year ago • 4 comments
trafficstars

Is there an existing issue for this?

  • [X] I have searched the existing issues

What happened?

server/config/toml.go includes contents that are similar to those of server/config/config.go, but any synchronization between the two locations is manual so there are undesirable differences (and some undesirable similarities, such as using the CamelCase Go names to comment on TOML settings like halt-height).

To remedy this, I would recommend programmatically deriving the TOML template from the Go config structs and their doc comments in a build step. Here's a proof of concept that parses Go source text and emits TOML template text: https://go.dev/play/p/W74nda-DQKZ

Cosmos SDK Version

main

How to reproduce?

No response

gibson042 avatar Apr 19 '24 07:04 gibson042

Yes 100% agree, we are going to use struct annotations and github.com/pelletier/go-toml/v2 library for server/v2: https://github.com/cosmos/cosmos-sdk/blob/605b724/server/v2/api/grpc/config.go#L19-L34 I don't think it makes sense to refactor the server v0 config.

julienrbrt avatar Apr 19 '24 08:04 julienrbrt

Could you please point me where you see a missing field between the config.go and the toml.go? I cannot find any. Removing the bug label as it is more a suggestion / refactor request than a bug.

julienrbrt avatar Apr 19 '24 08:04 julienrbrt

Could you please point me where you see a missing field between the config.go and the toml.go? I cannot find any. Removing the bug label as it is more a suggestion / refactor request than a bug.

I don't see any missing fields, but I do see bugs:

  • Many TOML comments use Go field names. Example: https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/toml.go#L38-L42 (HaltHeight vs. halt-height)
  • Many TOML comments are missing from Go doc comments. Examples:
    • https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/toml.go#L34-L36 vs. https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/config.go#L45-L47
    • https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/toml.go#L84-L87 vs. https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/config.go#L91-L93
    • https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/toml.go#L221-L235 vs. https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/config.go#L178-L182

gibson042 avatar Apr 19 '24 15:04 gibson042

Could you please point me where you see a missing field between the config.go and the toml.go? I cannot find any. Removing the bug label as it is more a suggestion / refactor request than a bug.

I don't see any missing fields, but I do see bugs:

  • Many TOML comments use Go field names. Example: https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/toml.go#L38-L42 (HaltHeight vs. halt-height)

  • Many TOML comments are missing from Go doc comments. Examples:

    • https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/toml.go#L34-L36 vs. https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/config.go#L45-L47

    • https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/toml.go#L84-L87 vs. https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/config.go#L91-L93

    • https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/toml.go#L221-L235 vs. https://github.com/cosmos/cosmos-sdk/blob/fb29045fe0bbd726d8961ed5d9d09ca8b3a948c3/server/config/config.go#L178-L182

Right, I see. We could fix those inconsistencies indeed regarding the comments.

julienrbrt avatar Apr 19 '24 15:04 julienrbrt