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

Add --build-tonic flag to proto-compiler, sync protobuf script, and generate protobuf for std and no_std mode #1439

Merged
merged 7 commits into from
Jan 20, 2022

Conversation

soareschen
Copy link
Contributor

Part of #1158

Description

  • Add a --build-tonic flag to proto-compiler to allow generation of protobuf definitions without tonic client for no_std.
  • Add ci/sync-protobuf.sh script to reliably re-generate the protobuf Rust definitions. Note however that the current protobuf-compiler is non-reproducible, so multiple calls to ci/sync-protobuf.sh may yield different results.
  • Add std feature flag in ibc-proto to include tonic as dependency when activated.
  • Make ibc-proto load protobuf definitions from either proto/src/prost/std or proto/src/prost/no_std depending on the std feature flag.
  • The commits document detailed step to arrive to the current protobuf generation, to convince the reviewer that there is indeed no change in the protobuf definition. This is necessary because the proto-compiler being non-reproducible makes it difficult to check the diff and verify that there is indeed no changes in the generated files.

For contributor use:

  • Added a changelog entry, using unclog.
  • If applicable: Unit tests written, added test to CI.
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Updated relevant documentation (docs/) and code comments.
  • Re-reviewed Files changed in the Github PR explorer.

Copy link
Member

@romac romac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Thanks for including the script as well, which allows us to skip the slow libgit2 clone step and call compile directly :)

@romac
Copy link
Member

romac commented Oct 27, 2021

@adizere @soareschen Do we want to include this in 0.8.0?

@soareschen
Copy link
Contributor Author

soareschen commented Oct 27, 2021

Do we want to include this in 0.8.0?

I think this should be merged after we switched to the official versions of prost and tonic in #1502. Right now it seems like the protobuf definitions regenerated using our forked tonic-build contain errors like:

error[E0277]: the trait bound `tendermint_proto::types::Header: informalsystems_prost::Message` is not satisfied                                                             
    --> proto/src/prost/std/cosmos.staking.v1beta1.rs:5:28                                                                                                                   
     |                                                                                                                                                                       
5    | #[derive(Clone, PartialEq, ::prost::Message)]                                                                                                                         
     |                            ^^^^^^^^^^^^^^^^ the trait `informalsystems_prost::Message` is not implemented for `tendermint_proto::types::Header`                       
     |                                                                                                                                                                       
note: required by a bound in `informalsystems_prost::encoding::message::encode`                                                                                              
    --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/informalsystems-prost-0.8.1/src/encoding.rs:1043:12                                                     
     |                                                                                                                                                                       
1043 |         M: Message,
     |            ^^^^^^^ required by this bound in `informalsystems_prost::encoding::message::encode`
     = note: this error originates in the derive macro `::prost::Message` (in Nightly builds, run with -Z macro-backtrace for more info)

@adizere adizere requested a review from romac November 2, 2021 13:05
@adizere adizere marked this pull request as draft November 2, 2021 13:05
@adizere
Copy link
Member

adizere commented Nov 2, 2021

Leaving this as draft until it gets prioritized again.

@soareschen soareschen force-pushed the soares/proto-compiler-tonic-flag branch from a08566b to 1129c43 Compare November 23, 2021 10:17
Comment on lines 24 to 25
COSMOS_SDK_GIT=${COSMOS_SDK_GIT:-/tmp/cosmos-sdk.git}
IBC_GO_GIT=${IBC_GO_GIT:-/tmp/ibc-go.git}

This comment was marked as outdated.

Copy link
Contributor

@mzabaluev mzabaluev Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I've read further to understand that these are just mirrors and they are fetched from the remote every time the script is invoked. Still, the point about trusting well-known file paths in /tmp stands. Maybe mirror these repos under ${XDG_CACHE_HOME:-$HOME/.cache}/ibc-rs.build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could work as well. Compared to the original, we want to use a local git bare repository as cache instead of trying to clone the entire remote repository every time the command is run.

Right now I still have the problem that if a bare repository has already been cloned before, I can't find simple way to update it other than having to reclone the entire bare repository. So it is still a little problematic to set a persistent location at $HOME by default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of non-randomized paths in /tmp also assumes that only a single user will ever run this script (over the host's uptime before /tmp is cleared). This is probably OK for a typical developer's workstation, but using a location at $HOME by convention gives you better isolation.

Right now I still have the problem that if a bare repository has already been cloned before, I can't find simple way to update it

I've tried locally and git fetch or git fetch origin seem to work. What's the problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried locally and git fetch or git fetch origin seem to work. What's the problem?

Hmm I might have cloned the bare repository inappropriately. That seems to work now!

I have updated the script as you suggested. It stores the git cache at ~/.cache/cosmos.

Copy link
Contributor

@mzabaluev mzabaluev Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It stores the git cache at ~/.cache/cosmos.

This might conceivably clash with some Cosmos client in the future (or just an unrelated app named cosmos), I'd rather use something identifying the ibc-rs build scripts as the well-known directory under ~/.cache and put everything cached by the scripts in there. But this is mostly pedantry, thanks for fixing the main issue.

@soareschen soareschen marked this pull request as ready for review November 24, 2021 09:26
Copy link
Member

@adizere adizere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be preferable to merge this after #1582.

Not sure what our merge strategy could be to help prevent regressions or problems, since manually reviewing it is impossible. Any thoughts?

@@ -0,0 +1,2538 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to maintain this file under revision?

ci/sync-protobuf.sh Outdated Show resolved Hide resolved
@romac romac requested a review from adizere January 14, 2022 14:22
@romac
Copy link
Member

romac commented Jan 19, 2022

Are we ready to merge this?

@mzabaluev
Copy link
Contributor

Needs a merge from master at least.

@romac romac merged commit 773e50c into master Jan 20, 2022
@romac romac deleted the soares/proto-compiler-tonic-flag branch January 20, 2022 15:23
hu55a1n1 pushed a commit to hu55a1n1/hermes that referenced this pull request Sep 13, 2022
… generate protobuf for std and no_std mode (informalsystems#1439)

* Generate std and no_std versions of protobuf

* Improve sync protobuf script and Cargo.toml

* Re-sync protobuf files

* Move sync-protobuf.sh to scripts/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E: no-std External: support for no_std compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants