Skip to content

Commit a079d62

Browse files
committed
resolve protobuf generation bloat with sparse mode filtering
1 parent 8e0eead commit a079d62

File tree

4 files changed

+991
-1838
lines changed

4 files changed

+991
-1838
lines changed

packages/xchain-mayachain/genMsgs.sh

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,36 @@ set -e # Exit on any error
66
MSG_COMPILED_OUTPUTFILE=src/types/proto/MsgCompiled.js
77
MSG_COMPILED_TYPES_OUTPUTFILE=src/types/proto/MsgCompiled.d.ts
88

9-
# Using local minimal proto files - no need to clone mayanode repository
9+
TMP_DIR=$(mktemp -d)
1010

11-
# Download cosmos/base/v1beta1/coin.proto from cosmossdk
12-
COSMOS_COIN_PROTO="proto/cosmos/base/v1beta1/coin.proto"
13-
if [ ! -f "$COSMOS_COIN_PROTO" ]; then
14-
tput setaf 2
15-
echo "Downloading cosmos/base/v1beta1/coin.proto from cosmossdk"
16-
tput sgr0
17-
mkdir -p "proto/cosmos/base/v1beta1"
18-
if ! curl -f -o "$COSMOS_COIN_PROTO" \
19-
"https://raw.githubusercontent.com/cosmos/cosmos-sdk/main/proto/cosmos/base/v1beta1/coin.proto"; then
20-
echo "Error: Failed to download cosmos coin.proto"
21-
exit 1
11+
# Cleanup function
12+
cleanup() {
13+
if [ -d "$TMP_DIR" ]; then
14+
tput setaf 2
15+
echo "Cleaning up $TMP_DIR"
16+
tput sgr0
17+
rm -rf "$TMP_DIR"
2218
fi
23-
echo "✓ Downloaded cosmos coin.proto"
24-
else
25-
echo "✓ cosmos coin.proto already exists"
19+
}
20+
trap cleanup EXIT
21+
22+
tput setaf 2
23+
echo "Checking out https://gitlab.com/mayachain/mayanode to $TMP_DIR"
24+
tput sgr0
25+
if ! (cd "$TMP_DIR" && git clone https://gitlab.com/mayachain/mayanode); then
26+
echo "Error: Failed to clone mayanode repository"
27+
exit 1
2628
fi
2729

28-
# Verify our minimal proto files exist
30+
# Verify proto files exist
2931
tput setaf 2
30-
echo "Checking minimal proto files"
32+
echo "Checking proto files"
3133
tput sgr0
3234
MISSING_FILES=0
3335
for proto_file in \
34-
"proto/common/minimal_common.proto" \
35-
"proto/types/minimal_msg_deposit.proto" \
36-
"proto/types/minimal_msg_send.proto" \
37-
"$COSMOS_COIN_PROTO"; do
36+
"$TMP_DIR/mayanode/proto/mayachain/v1/common/common.proto" \
37+
"$TMP_DIR/mayanode/proto/mayachain/v1/x/mayachain/types/msg_deposit.proto" \
38+
"$TMP_DIR/mayanode/proto/mayachain/v1/x/mayachain/types/msg_send.proto"; do
3839
if [ ! -f "$proto_file" ]; then
3940
echo "Error: $(basename "$proto_file") missing"
4041
MISSING_FILES=1
@@ -48,16 +49,33 @@ if [ $MISSING_FILES -eq 1 ]; then
4849
exit 1
4950
fi
5051

51-
# Generate Protobuf JS bindings using minimal proto files to prevent over-inclusion
52+
# Download cosmos/base/v1beta1/coin.proto from cosmossdk if not exists
53+
COSMOS_COIN_PROTO="$TMP_DIR/mayanode/third_party/proto/cosmos/base/v1beta1/coin.proto"
54+
if [ ! -f "$COSMOS_COIN_PROTO" ]; then
55+
tput setaf 2
56+
echo "Downloading cosmos/base/v1beta1/coin.proto from cosmossdk"
57+
tput sgr0
58+
mkdir -p "$TMP_DIR/mayanode/third_party/proto/cosmos/base/v1beta1"
59+
if ! curl -f -o "$COSMOS_COIN_PROTO" \
60+
"https://raw.githubusercontent.com/cosmos/cosmos-sdk/main/proto/cosmos/base/v1beta1/coin.proto"; then
61+
echo "Error: Failed to download cosmos coin.proto"
62+
exit 1
63+
fi
64+
echo "✓ Downloaded cosmos coin.proto"
65+
else
66+
echo "✓ cosmos coin.proto already exists"
67+
fi
68+
69+
# Generate Protobuf JS bindings using sparse mode to only include referenced types
5270
tput setaf 2
53-
echo "Generating $MSG_COMPILED_OUTPUTFILE"
71+
echo "Generating $MSG_COMPILED_OUTPUTFILE (using sparse mode to avoid bloat)"
5472
tput sgr0
55-
if ! yarn pbjs -w commonjs -t static-module \
56-
-p proto \
57-
"proto/common/minimal_common.proto" \
58-
"proto/types/minimal_msg_deposit.proto" \
59-
"proto/types/minimal_msg_send.proto" \
60-
"$COSMOS_COIN_PROTO" \
73+
if ! yarn pbjs -w commonjs -t static-module --sparse \
74+
-p "$TMP_DIR/mayanode/proto" \
75+
-p "$TMP_DIR/mayanode/third_party/proto" \
76+
"$TMP_DIR/mayanode/proto/mayachain/v1/common/common.proto" \
77+
"$TMP_DIR/mayanode/proto/mayachain/v1/x/mayachain/types/msg_deposit.proto" \
78+
"$TMP_DIR/mayanode/proto/mayachain/v1/x/mayachain/types/msg_send.proto" \
6179
-o "$MSG_COMPILED_OUTPUTFILE" 2>pbjs_errors.txt; then
6280
echo "Error: Failed to generate JavaScript bindings"
6381
cat pbjs_errors.txt
@@ -71,7 +89,7 @@ sed -i -E 's|"(protobufjs/minimal)"|"\1.js"|' "$MSG_COMPILED_OUTPUTFILE"
7189
tput setaf 2
7290
echo "Generating $MSG_COMPILED_TYPES_OUTPUTFILE"
7391
tput sgr0
74-
if ! yarn pbts "$MSG_COMPILED_OUTPUTFILE" -o "$MSG_COMPILED_TYPES_OUTPUTFILE" 2>pbts_errors.txt; then
92+
if ! yarn pbts --name types "$MSG_COMPILED_OUTPUTFILE" -o "$MSG_COMPILED_TYPES_OUTPUTFILE" 2>pbts_errors.txt; then
7593
echo "Error: Failed to generate TypeScript definitions"
7694
cat pbts_errors.txt
7795
exit 1

0 commit comments

Comments
 (0)