Skip to content

proto: Implement versioning #95

Closed
Closed

Description

@thanethomson

Relates to tendermint/tendermint#9197

Depends on #94

In order to better support integrators, we need to version our Protobuf definitions as per Buf's guidelines. The goal here is to have:

Activity

  1. added
    protobuf
    tracking
    on Jan 11, 2023
  2. added this to the 2023-Q1 milestone on Mar 1, 2023
  3. mzabaluev commented on Mar 6, 2023

    @mzabaluev
    Contributor

    After discussion with @thanethomson, I understand that we need to take care of snapshots of proto definitions going back to 0.34.

    The proposed packaging versioning schema should look as follows:

    • Any message definitions that exist in v0.34.x get packaged with the suffix .v1 appended to their domain package name.
    • Message definitions that have changed in subsequent release streams (v0.37.x and feature/abci++vef at the moment) in ways that introduce breaking changes to generated code in strictly typed languages (our primary concern being Go and Rust), are put into packages with incremental suffixes .v2, .v3, and so on. There is no direct correspondence between a package versioning suffix and any CometBFT protocol version; the suffixes are only to track evolution of message types.
    • Messages newly introduced since 0.34 may land into .v1 or later packages. This depends on which versioned package looks more natural considering type cross-references and changes to adjacent message types in the same domain package.
  4. added
    P:integrator-experience
    on Mar 7, 2023
  5. mzabaluev commented on Mar 15, 2023

    @mzabaluev
    Contributor

    @thanethomson Regarding the output folder for the generated files, I'd prefer a single location including the ABCI stubs.
    This would make buf.gen.yaml the single source of truth for the protobuf generation process, removing the tricky post-build Makefile actions.

  6. thanethomson commented on Mar 15, 2023

    @thanethomson
    ContributorAuthor

    Regarding the output folder for the generated files, I'd prefer a single location including the ABCI stubs.
    This would make buf.gen.yaml the single source of truth for the protobuf generation process, removing the tricky post-build Makefile actions.

    This is precisely the idea.

  7. mzabaluev commented on Mar 30, 2023

    @mzabaluev
    Contributor

    I've hit a problem in #495 with the Wrap interface method that is manually implemented for generated variant types of oneof content fields for types like Message, e.g. in consensus.

    This method (permalink), for example, has to be defined in consensus/v1, because VoteSetBits is defined in the corresponding proto package and the generated struct ends up in consensus/v1/types.pb.go:

    func (m *VoteSetBits) Wrap() proto.Message {
    	cm := &Message{}
    	cm.Sum = &Message_VoteSetBits{VoteSetBits: m}
    	return cm
    }

    However, it needs to produce a dynamically wrapped Message from consensus/v2 for the value to actually work with other code that uses the latest version of Message (sorry I discovered it this late, being new to these parts, and the compiler could not help because the actual type is only checked dynamically). The problem is, we cannot use v2 here because the code generated for v2 itself imports v1: v2.Message refers to field types defined in v1 to avoid duplicating their definitions in v2.

    I can see the following ways to solve this:

    1. Duplicate message types in versioned proto packages to eliminate cross-package references in such oneof message definitions. This is bad because duplication is made in the proto spec to work around issues in one particular language binding (Golang/gogoproto). On the other hand, we may have other reasons to duplicate everything relevant in the latest vN, rather than backreferencing to older versions, as discussed in Versioned protobuf files #495 (comment).
    2. Rework the wrapper offending code to not use dynamic dispatch. The result will be less elegant and convenient to use, but I see only two call sites for .Wrap() in non-test code of CometBFT, so maybe that's OK.
      • The only problematic use downcasts the returned interface pointer to an expected Message type. We can consider this to be a misuse of the Wrapper interface and amend its contract, so that the returned value is only used for marshalling into the (correct) wire format.
    3. Use compiler overrides or Golang-specific annotations to selectively affect package placement of generated code. I would need some expert help or extensive documentation digging for that. Does output for other types need to be similarly customized in order for the result to be somewhat consistent? Some users might want the legacy v1 bindings to ensure backward compatibility, so we cannot just mash the latest definitions together in one happy unversioned Go package.
    4. Create newtypes for VoteSetBits and the rest of the variant structs in the hand-coded consensus package, wrapping the generated types, and implement the Wrapper interface on these newtypes. Some amount of tedious coding is needed, perhaps exceeding the cost of option 2. In my view, this is only worth it the long run, if we generally want domain types to supplant proto-generated structs in the API.
  8. mzabaluev commented on Mar 31, 2023

    @mzabaluev
    Contributor

    Resolved the above with a modification of the approach described in point 2.

  9. mzabaluev commented on Mar 31, 2023

    @mzabaluev
    Contributor

    The /api folder must effectively be a standalone Go module (i.e. have its own go.mod file, module github.com/cometbft/cometbft/api).

    I don't see other go.mod files besides the one at the root of the repository, and package imports across the subdirectories work at least inside the CometBFT codebase. What are the benefits of the proposed organization? Do we get to cut the dependencies to only the ones required by the proto bindings? Can this work with the other go.mod remaining at the top, or should every Go source folder under root get its own go.mod with a trimmed down list of dependencies? I still need to hone my Go skills on this.

    Meanwhile, I'm making the move of *.pb.go and associated manually-written method code into the ./api folder, and it's the easiest thing to do in this whole enterprise.

  10. modified the milestones: 2023-Q1, 2023-Q2 on Apr 13, 2023
  11. mzabaluev commented on Apr 20, 2023

    @mzabaluev
    Contributor

    What are the benefits of the proposed organization?

    As we have established in a meeting about versioning, we want the proto-derived module versioned separately from module(s) that wrap or alias the proto-generated types into the versionless API for clients to work with.

  12. self-assigned this
    on Jul 5, 2023
  13. modified the milestones: 2023-Q2, 2023-Q3 on Jul 5, 2023
  14. sergio-mena commented on Jul 5, 2023

    @sergio-mena
    Collaborator

    Moved to Q3. The goal is to coordinate with the main stake holders (IBC teams, SDK) to make sure they will plan their integration properly to minimize disruption. I will be doing that

  15. sergio-mena commented on Sep 26, 2023

    @sergio-mena
    Collaborator

    After examination with @mzabaluev all tasks here are complete. Some tasks that were remaining have been moved to the parent issue (#1330), in order to make tracking them easier.

  16. added a commit that references this issue on Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P:integrator-experienceprotobuftracking

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions