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

Replace tools/proto-compiler with buf gen and protoc-gen-prost #2184

Open
hdevalence opened this issue Mar 17, 2023 · 9 comments
Open

Replace tools/proto-compiler with buf gen and protoc-gen-prost #2184

hdevalence opened this issue Mar 17, 2023 · 9 comments
Assignees
Labels
_P-low Priority: low

Comments

@hdevalence
Copy link
Member

Is your feature request related to a problem? Please describe.

As described in #1867, we have two different variants of protobuf generation tooling, one using Buf and the other using prost/tonic. That issue described a strategy for trying to hack together prost and the Buf cache. An almost-certainly better alternative would be to use Buf to generate both kinds of code, and instruct it on how to generate Rust code using https://github.com/neoeinstein/protoc-gen-prost (details on Buf integration here: https://github.com/neoeinstein/protoc-gen-prost/blob/main/protoc-gen-prost-serde/README.md#usage-with-buf )

Describe the solution you'd like

  • Replace tools/proto-compiler with Buf generate
  • We'll need a combination of
    • protoc-gen-prost (replicating our existing configs with the options it provides)
    • protoc-gen-prost-serde (replicating our invocation of pbjson-build)
    • protoc-gen-tonic (replicating our existing configs, in particular replicating the cfg-module options we use to feature-gate the tonic server code)
  • The output location and file structure might be slightly different; I suspect it will be easier to update the include! paths where we arrange the generated code into the module tree rather than trying to exactly match what we currently do with tools/proto-compiler
@plaidfinch
Copy link
Collaborator

plaidfinch commented May 5, 2023

"This is going to bite us eventually, so the sooner we do it, the better."

The way it's going to bite us is that eventually we might have a divergence in parts of the protos that we actually do use, because our vendored go protos are not kept up to date, but buf does dependency management. So, then we would have a problem.

@conorsch conorsch moved this from Next to In Progress in Testnets May 22, 2023
@conorsch
Copy link
Contributor

Picking this up. Given the recent crate reorg, our plan is currently:

  1. Move all .proto files to top-level proto/ directory.
  2. Use buf-compatible tooling for all stages of the codegen.
  3. Continue to store output of the generated rust code inside crates/proto/src/gen/, updating include paths as necessary.

First attempt in branch 2184-let-there-be-buf shows progress. Currently having trouble sorting out how to use prost-gen-serde correctly: without it, some of the deserialization impls are missing, which makes sense. But enabling prost-gen-serde causes conflicting duplicate impls of deserialize, which clearly isn't right either. Will keep wrestling with it.

@conorsch
Copy link
Contributor

Updated the feature branch to use generated protos for go and rust, entirely via buf/prost plugins. All hardcoded vendored protos have been removed. The major regression right now is that gRPC server reflection is broken. Haven't yet figured out how to cobble together the file descriptor info and expose that to tonic during service construction, but it seems to be possible. Will try on that a bit longer.

@hdevalence
Copy link
Member Author

Sick! I think if we can't get reflection working via the same proto descriptor file approach as before it would be an OK regression, at least temporarily — and maybe we could upstream changes required to restore it later. I don't think anything is currently critically reliant on it, it's just a nice to have.

conorsch added a commit that referenced this issue May 24, 2023
Overhauls the protobuf codegen by standardizing on `buf`,
along with associated tooling like `protoc-gen-prost` and
`proto-gen-tonic`. The output dirs for the supported langs are now:

  * Rust: ./crates/proto/src/gen/
  * Go: ./proto/go/gen/

We've removed the proto-compiler tool from the repo. Also, we no longer
vendor upstream protos by committing directly to our repo; instead,
we declare dependencies in the buf yaml files and offload the resolution
to `buf generate`.

One major regression is that gRPC server reflection no longer works.
These changes remove the `proto_descriptor.bin` build.rs logic, with no
replacement in the new buf logic. As of right now, preview supports
reflection:

    ❯ grpcurl grpc.testnet-preview.penumbra.zone:443 list
    cosmos.base.tendermint.v1beta1.Service
    grpc.reflection.v1alpha.ServerReflection
    penumbra.client.v1alpha1.ObliviousQueryService
    penumbra.client.v1alpha1.SpecificQueryService
    penumbra.client.v1alpha1.TendermintProxyService
    penumbra.custody.v1alpha1.CustodyProtocolService
    penumbra.narsil.ledger.v1alpha1.LedgerService
    penumbra.view.v1alpha1.ViewAuthService
    penumbra.view.v1alpha1.ViewProtocolService

but this code does not:

    ❯ grpcurl -plaintext localhost:8080 list
    Failed to list services: server does not support the reflection API

We'll circle back on reflection support.

Notably the tonic rpc defs are now in their own files, a side-effect of
using the `prost-gen-tonic` plugin for buf. The original proto files,
without the `.tonic.proto` suffix, now automatically `include!` their
tonic neighbors, so the interface hasn't changed.

Refs #2184.
conorsch added a commit that referenced this issue May 24, 2023
Overhauls the protobuf codegen by standardizing on `buf`,
along with associated tooling like `protoc-gen-prost` and
`proto-gen-tonic`. The output dirs for the supported langs are now:

  * Rust: ./crates/proto/src/gen/
  * Go: ./proto/go/gen/

We've removed the proto-compiler tool from the repo. Also, we no longer
vendor upstream protos by committing directly to our repo; instead,
we declare dependencies in the buf yaml files and offload the resolution
to `buf generate`.

One major regression is that gRPC server reflection no longer works.
These changes remove the `proto_descriptor.bin` build.rs logic, with no
replacement in the new buf logic. As of right now, preview supports
reflection:

    ❯ grpcurl grpc.testnet-preview.penumbra.zone:443 list
    cosmos.base.tendermint.v1beta1.Service
    grpc.reflection.v1alpha.ServerReflection
    penumbra.client.v1alpha1.ObliviousQueryService
    penumbra.client.v1alpha1.SpecificQueryService
    penumbra.client.v1alpha1.TendermintProxyService
    penumbra.custody.v1alpha1.CustodyProtocolService
    penumbra.narsil.ledger.v1alpha1.LedgerService
    penumbra.view.v1alpha1.ViewAuthService
    penumbra.view.v1alpha1.ViewProtocolService

but this code does not:

    ❯ grpcurl -plaintext localhost:8080 list
    Failed to list services: server does not support the reflection API

We'll circle back on reflection support.

Notably the tonic rpc defs are now in their own files, a side-effect of
using the `prost-gen-tonic` plugin for buf. The original proto files,
without the `.tonic.proto` suffix, now automatically `include!` their
tonic neighbors, so the interface hasn't changed.

Refs #2184.
hdevalence pushed a commit that referenced this issue May 24, 2023
Overhauls the protobuf codegen by standardizing on `buf`,
along with associated tooling like `protoc-gen-prost` and
`proto-gen-tonic`. The output dirs for the supported langs are now:

  * Rust: ./crates/proto/src/gen/
  * Go: ./proto/go/gen/

We've removed the proto-compiler tool from the repo. Also, we no longer
vendor upstream protos by committing directly to our repo; instead,
we declare dependencies in the buf yaml files and offload the resolution
to `buf generate`.

One major regression is that gRPC server reflection no longer works.
These changes remove the `proto_descriptor.bin` build.rs logic, with no
replacement in the new buf logic. As of right now, preview supports
reflection:

    ❯ grpcurl grpc.testnet-preview.penumbra.zone:443 list
    cosmos.base.tendermint.v1beta1.Service
    grpc.reflection.v1alpha.ServerReflection
    penumbra.client.v1alpha1.ObliviousQueryService
    penumbra.client.v1alpha1.SpecificQueryService
    penumbra.client.v1alpha1.TendermintProxyService
    penumbra.custody.v1alpha1.CustodyProtocolService
    penumbra.narsil.ledger.v1alpha1.LedgerService
    penumbra.view.v1alpha1.ViewAuthService
    penumbra.view.v1alpha1.ViewProtocolService

but this code does not:

    ❯ grpcurl -plaintext localhost:8080 list
    Failed to list services: server does not support the reflection API

We'll circle back on reflection support.

Notably the tonic rpc defs are now in their own files, a side-effect of
using the `prost-gen-tonic` plugin for buf. The original proto files,
without the `.tonic.proto` suffix, now automatically `include!` their
tonic neighbors, so the interface hasn't changed.

Refs #2184.
@conorsch
Copy link
Contributor

Filed follow-up in #2629, closing.

@github-project-automation github-project-automation bot moved this from In Progress to Testnet 53: Himalia in Testnets May 24, 2023
@conorsch
Copy link
Contributor

Reopening to try again, since we backed out the incomplete changes in #2639.

@conorsch conorsch reopened this May 26, 2023
@conorsch conorsch moved this from Testnet 53: Himalia to In Progress in Testnets May 26, 2023
conorsch added a commit that referenced this issue May 30, 2023
Reimplementing changes from #2632, which were backed out due to an
incomplete rewrite of the protobuf build story. See #2184 for details.

This change doesn't alter the versions of buf dependencies, it just
freezes them at "current" so the lockfile won't flap anymore.

Refs #2321.
@conorsch
Copy link
Contributor

conorsch commented Jun 6, 2023

Fallback position here is to retain some directories of vendored protos, but standardize on the use of buf for versioning, so we're using the same proto files as input for golang and rustlang codegen. That's not currently the case: we use extremely recent version of cosmos/cosmos-sdk and cosmos/ibc for the golang codegen, which runs in CI, and quite dated versions of those deps for use with the rust proto-compiler tool. By using buf export, we can pull the proto defs from BSR and place them in local directories, ensuring our vendored protos match what's specified in the buf lockfiles. That'll be a win of over the mismatch we have today.

conorsch added a commit that referenced this issue Jun 6, 2023
Updates the protobuf build process to use `buf` to pull in the relevant
upstream proto definitions from BSR. We intentionally pin older versions
of the cosmos deps, cosmos-sdk & ibc, for compatibility. The most recent
version of cosmos/ibc doesn't integrate with our existing tooling, due
to introduction of new "extension" and "extension_signature" attributes
on the tendermint::vote type, but we'll tackle updating that later.

Only a single change was made to our proto compiler tool: excising a
manual import of a tendermint "query.rs" codegen file, which is no
longer exported from the sdk protos. Removing it did not break the
build, so we weren't using the functionality in that file. The rest of
the diff to proto-compiler is updating relpaths.

The proto specs now live at a top-level `proto/` dir, and alongside
the vendored protos. Those directories are used as inputs to the build.
Relevant docs have been updated.

Towards #2184.
conorsch added a commit that referenced this issue Jun 6, 2023
Updates the protobuf build process to use `buf` to pull in the relevant
upstream proto definitions from BSR. We intentionally pin older versions
of the cosmos deps, cosmos-sdk & ibc, for compatibility. The most recent
version of cosmos/ibc doesn't integrate with our existing tooling, due
to introduction of new "extension" and "extension_signature" attributes
on the tendermint::vote type, but we'll tackle updating that later.

Only a single change was made to our proto compiler tool: excising a
manual import of a tendermint "query.rs" codegen file, which is no
longer exported from the sdk protos. Removing it did not break the
build, so we weren't using the functionality in that file. The rest of
the diff to proto-compiler is updating relpaths.

The proto specs now live at a top-level `proto/` dir, and alongside
the vendored protos. Those directories are used as inputs to the build.
Relevant docs have been updated.

Towards #2184.
conorsch added a commit that referenced this issue Jun 6, 2023
Updates the protobuf build process to use `buf` to pull in the relevant
upstream proto definitions from BSR. We intentionally pin older versions
of the cosmos deps, cosmos-sdk & ibc, for compatibility. The most recent
version of cosmos/ibc doesn't integrate with our existing tooling, due
to introduction of new "extension" and "extension_signature" attributes
on the tendermint::vote type, but we'll tackle updating that later.

Only a single change was made to our proto compiler tool: excising a
manual import of a tendermint "query.rs" codegen file, which is no
longer exported from the sdk protos. Removing it did not break the
build, so we weren't using the functionality in that file. The rest of
the diff to proto-compiler is updating relpaths.

The proto specs now live at a top-level `proto/` dir, and alongside
the vendored protos. Those directories are used as inputs to the build.
Relevant docs have been updated.

Towards #2184.
@conorsch
Copy link
Contributor

conorsch commented Jun 8, 2023

The primary goal of this ticket is not accomplished—we're still using two different tools to perform codegen—but we've made solid progress in terms of terms of shoring up our codegen and using explicit versions consistently across all targets. For now, I'm moving this ticket back into Next because I'd like to revisit it, but I'm calling the recent gains good enough at present, and will focus on other tasks next sprint.

@conorsch conorsch moved this from In Progress to Next in Testnets Jun 8, 2023
@conorsch
Copy link
Contributor

This is worth revisiting after we move to CometBFT 0.38 and fully support Vote Extensions. Until then, kicking into next. Also, we should consider removing the generate go code from the repo entirely, and allow other people like SL to maintain go codegen where it's needed.

@conorsch conorsch moved this from Next to Future in Testnets Oct 18, 2023
@aubrika aubrika added this to Penumbra Oct 30, 2023
@github-project-automation github-project-automation bot moved this to 🗄️ Backlog in Penumbra Oct 30, 2023
conorsch added a commit that referenced this issue Feb 6, 2024
We originally added the golang codegen to provide first-class support to
downstream integrators. This is no longer necessary, as those same
integrators, e.g. Strangelove, are performing their own codegen in the
respective repos. These codepaths in the Penumbra monorepo are unused
and largely unmaintained, so I'm culling them.

Refs #2184. Moots and therefore closes #2731.
conorsch added a commit that referenced this issue Feb 6, 2024
We originally added the golang codegen to provide first-class support to
downstream integrators. This is no longer necessary, as those same
integrators, e.g. Strangelove, are performing their own codegen in the
respective repos. These codepaths in the Penumbra monorepo are unused
and largely unmaintained, so I'm culling them.

Refs #2184. Moots and therefore closes #2731.
conorsch added a commit that referenced this issue Feb 7, 2024
We originally added the golang codegen to provide first-class support to
downstream integrators. This is no longer necessary, as those same
integrators, e.g. Strangelove, are performing their own codegen in the
respective repos. These codepaths in the Penumbra monorepo are unused
and largely unmaintained, so I'm culling them.

Refs #2184. Moots and therefore closes #2731.
TalDerei pushed a commit that referenced this issue Feb 8, 2024
We originally added the golang codegen to provide first-class support to
downstream integrators. This is no longer necessary, as those same
integrators, e.g. Strangelove, are performing their own codegen in the
respective repos. These codepaths in the Penumbra monorepo are unused
and largely unmaintained, so I'm culling them.

Refs #2184. Moots and therefore closes #2731.
@hdevalence hdevalence added the _P-low Priority: low label Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
_P-low Priority: low
Projects
Status: Backlog
Status: Future
Development

No branches or pull requests

3 participants