Skip to content

Commit

Permalink
Use Cosmos SDK protos via the cosmos-sdk-proto crate instead of bun…
Browse files Browse the repository at this point in the history
…dling them in `ibc-proto` (#187)

* Use Cosmos SDK and ICS23 protos via the `cosmos_sdk_proto` crate

* Use our fork of `cosmos-sdk-proto` for now

* Enable `serde` feature on `cosmos-sdk-proto` when needed

* Use patched `tendermint-proto`

* Setup protoc on CI

* Enable `cosmos-sdk-proto/std` when `std` feature is enabled

* Update to cosmos-sdk-proto v0.25.0-pre.1

* Update to cosmos-sdk-proto v0.25.0

* Re-export ICS23 proto definitions from the `ics23` crate

* Remove leftover Cosmos SDK protos

* Add changelog entry
  • Loading branch information
romac authored Sep 13, 2024
1 parent 47f4e50 commit 2257bc6
Show file tree
Hide file tree
Showing 76 changed files with 8,081 additions and 57,942 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Cosmos SDK protos are now re-exported from the `cosmos_sdk_proto`
crate instead of being generated as part of `ibc-proto`
([\#187](https://github.com/cosmos/ibc-proto-rs/pull/187))
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -63,6 +64,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -78,6 +80,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -92,6 +95,7 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v2
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -110,6 +114,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -127,6 +132,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -143,6 +149,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ informalsystems-pbjson = { version = "0.7.0", optional = true, default-features
version = "0.39"
default-features = false

[dependencies.cosmos-sdk-proto]
version = "0.25.0"
default-features = false

[dev-dependencies]
serde_json = "1.0.107"

[features]
default = ["std", "client"]
std = ["prost/std", "bytes/std", "subtle-encoding/std", "base64/std", "flex-error/std", "ics23/std", "informalsystems-pbjson/std"]
serde = ["dep:serde", "ics23/serde", "informalsystems-pbjson"]
client = ["std", "dep:tonic", "tonic/codegen", "tonic/transport", "tonic/prost"]
std = ["cosmos-sdk-proto/std", "prost/std", "bytes/std", "subtle-encoding/std", "base64/std", "flex-error/std", "ics23/std", "informalsystems-pbjson/std"]
serde = ["dep:serde", "dep:informalsystems-pbjson", "ics23/serde", "cosmos-sdk-proto/serde"]
client = ["std", "dep:tonic", "tonic/codegen", "tonic/transport", "tonic/prost", "cosmos-sdk-proto/grpc-transport"]
json-schema = ["std", "serde", "dep:schemars"]
server = ["std", "dep:tonic", "tonic/codegen", "tonic/transport", "tonic/prost"]
parity-scale-codec = ["tendermint-proto/parity-scale-codec"]
Expand Down
65 changes: 7 additions & 58 deletions scripts/sync-protobuf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set -eou pipefail
# syn-protobuf.sh is a bash script to sync the protobuf
# files using ibc-proto-compiler. This script will checkout
# the protobuf files from the git versions specified in
# proto/src/prost/COSMOS_SDK_COMMIT and
# proto/src/prost/IBC_GO_COMMIT. If you want to sync
# the protobuf files to a newer version, modify the
# corresponding of those 2 files by specifying the commit ID
Expand All @@ -23,17 +22,14 @@ set -eou pipefail
# the script is called.

CACHE_PATH="${XDG_CACHE_HOME:-$HOME/.cache}"/ibc-proto-rs-build
COSMOS_SDK_GIT="${COSMOS_SDK_GIT:-$CACHE_PATH/cosmos-sdk.git}"
IBC_GO_GIT="${IBC_GO_GIT:-$CACHE_PATH/ibc-go.git}"
COSMOS_ICS_GIT="${COSMOS_ICS_GIT:-$CACHE_PATH/interchain-security.git}"
NFT_TRANSFER_GIT="${NFT_TRANSFER_GIT:-$CACHE_PATH/nft-transfer.git}"

COSMOS_SDK_COMMIT="$(cat src/COSMOS_SDK_COMMIT)"
IBC_GO_COMMIT="$(cat src/IBC_GO_COMMIT)"
INTERCHAIN_SECURITY_COMMIT="$(cat src/INTERCHAIN_SECURITY_COMMIT)"
NFT_TRANSFER_COMMIT="$(cat src/NFT_TRANSFER_COMMIT)"

echo "COSMOS_SDK_COMMIT: $COSMOS_SDK_COMMIT"
echo "IBC_GO_COMMIT: $IBC_GO_COMMIT"
echo "INTERCHAIN_SECURITY_COMMIT: $INTERCHAIN_SECURITY_COMMIT"
echo "NFT_TRANSFER_COMMIT: $NFT_TRANSFER_COMMIT"
Expand Down Expand Up @@ -61,29 +57,10 @@ else
echo "Using existing interchain-security bare git repository at $COSMOS_ICS_GIT"
fi

# Use either --sdk-commit flag for commit ID,
# or --sdk-tag for git tag. Because we can't modify
# proto-compiler to have smart detection on that.

if [[ "$COSMOS_SDK_COMMIT" =~ ^[a-zA-Z0-9]{40}$ ]]
then
SDK_COMMIT_OPTION="--sdk-commit"
else
SDK_COMMIT_OPTION="--sdk-tag"
fi

# If the git directories does not exist, clone them as
# bare git repositories so that no local modification
# can be done there.

if [[ ! -e "$COSMOS_SDK_GIT" ]]
then
echo "Cloning cosmos-sdk source code to as bare git repository to $COSMOS_SDK_GIT"
git clone --mirror https://github.com/cosmos/cosmos-sdk.git "$COSMOS_SDK_GIT"
else
echo "Using existing cosmos-sdk bare git repository at $COSMOS_SDK_GIT"
fi

if [[ ! -e "$IBC_GO_GIT" ]]
then
echo "Cloning ibc-go source code to as bare git repository to $IBC_GO_GIT"
Expand All @@ -107,10 +84,6 @@ pushd "$COSMOS_ICS_GIT"
git fetch
popd

pushd "$COSMOS_SDK_GIT"
git fetch
popd

pushd "$IBC_GO_GIT"
git fetch
popd
Expand All @@ -135,33 +108,6 @@ buf mod update
buf export -v -o ../proto-include
popd

COSMOS_SDK_DIR=$(mktemp -d /tmp/cosmos-sdk-XXXXXXXX)

pushd "$COSMOS_SDK_DIR"
git clone "$COSMOS_SDK_GIT" .
git checkout "$COSMOS_SDK_COMMIT"

cd proto
buf mod prune
buf mod update
buf export -v -o ../proto-include
popd

cat << "EOF" >> "$COSMOS_SDK_DIR/proto-include/cosmos/staking/v1beta1/staking.proto"
// InfractionType indicates the infraction type a validator commited.
enum InfractionType {
option (gogoproto.goproto_enum_prefix) = false;
// UNSPECIFIED defines an empty infraction type.
INFRACTION_TYPE_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "InfractionEmpty"];
// DOUBLE_SIGN defines a validator that double-signs a block.
INFRACTION_TYPE_DOUBLE_SIGN = 1 [(gogoproto.enumvalue_customname) = "DoubleSign"];
// DOWNTIME defines a validator that missed signing too many blocks.
INFRACTION_TYPE_DOWNTIME = 2 [(gogoproto.enumvalue_customname) = "Downtime"];
}
EOF

IBC_GO_DIR=$(mktemp -d /tmp/ibc-go-XXXXXXXX)

pushd "$IBC_GO_DIR"
Expand Down Expand Up @@ -200,7 +146,6 @@ cargo build

cargo run -- compile \
--ics "$COSMOS_ICS_DIR/proto-include" \
--sdk "$COSMOS_SDK_DIR/proto-include" \
--ibc "$IBC_GO_DIR/proto-include" \
--nft "$NFT_TRANSFER_DIR/proto-include" \
--out ../../src/prost
Expand All @@ -211,15 +156,19 @@ cd ../..
# we instead re-exports the `ics23` crate type definitions.
rm -f src/prost/cosmos.ics23.v1.rs

# Remove `cosmos.base.store` module as it does not compile
# out of the box and we do not have a use for it at the moment.
# Remove leftover Cosmos SDK modules.
rm -f src/prost/cosmos.base.store.v1beta1.rs
rm -f src/prost/cosmos.auth.v1beta1.rs
rm -f src/prost/cosmos.base.query.v1beta1.rs
rm -f src/prost/cosmos.base.v1beta1.rs
rm -f src/prost/cosmos.staking.v1beta1.rs
rm -f src/prost/cosmos.upgrade.v1beta1.rs
rm -f src/prost/cosmos_proto.rs

# The Tendermint ABCI protos are unused from within ibc-proto
rm -f src/prost/tendermint.abci.rs

# Remove the temporary checkouts of the repositories
rm -rf "$COSMOS_ICS_DIR"
rm -rf "$COSMOS_SDK_DIR"
rm -rf "$IBC_GO_DIR"
rm -rf "$NFT_TRANSFER_DIR"
1 change: 0 additions & 1 deletion src/COSMOS_SDK_COMMIT

This file was deleted.

Loading

0 comments on commit 2257bc6

Please sign in to comment.