Skip to content

Commit 71f4934

Browse files
merge: sync release-2.5 protobuf migration into main
Signed-off-by: kmilo <kmilo.denis.glez@yandex.com>
2 parents 93ce112 + 1a2f5d0 commit 71f4934

118 files changed

Lines changed: 200 additions & 4700 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ permissions:
2020
jobs:
2121
test:
2222
runs-on: ubuntu-latest
23-
timeout-minutes: 15
23+
timeout-minutes: 25
2424
# Run steps at the repository root (no custom working-directory)
2525
steps:
2626
- uses: actions/checkout@v4
@@ -58,6 +58,11 @@ jobs:
5858
python -m pip install --upgrade pip
5959
python -m pip install -r requirements.txt pytest pytest-asyncio
6060
61+
- name: Install official Fabric protobuf bindings
62+
run: |
63+
chmod +x scripts/install_fabric_protos.sh
64+
PYTHON_BIN=python ./scripts/install_fabric_protos.sh
65+
6166
- name: Run tests
6267
run: |
6368
python -m pytest -q

‎.gitignore‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ dmypy.json
149149
*.sh text eol=lf
150150

151151
# Generated protobuf/python bindings (src/protos is still ignored)
152-
# If you want to commit generated bindings at top-level, do not ignore `fabric_protos_python/` or `protos/`.
153-
# (We will generate into `fabric_protos_python/` and track it in git.)
152+
# Optional local generation can target `fabric_protos/` for debugging,
153+
# but runtime dependencies should come from official `hyperledger/fabric-protos` bindings.
154154

155155
# Secrets and certificates
156156
*.pem

‎PROTOS.md‎

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,57 @@
1-
Protobufs / How to handle `fabric-protos`
2-
=========================================
1+
Protobufs / How this project uses `fabric-protos`
2+
===============================================
33

4-
Summary
5-
-------
6-
7-
Hyperledger Fabric defines its gRPC interfaces in the `fabric-protos` repository
8-
(Apache-2.0). When implementing a Python shim you generally have two practical
9-
options:
10-
11-
1. "Submodule and generate": Add `fabric-protos` as a submodule (or reference a
12-
fixed tag) and generate Python bindings (`*_pb2.py`, `*_pb2_grpc.py`) using
13-
`grpc_tools.protoc` or `protoc` with a Python plugin. The provided
14-
`scripts/gen_protos.sh` can be used for this. Optionally include the
15-
generated files in the package for releases to simplify consumers' setup.
16-
17-
2. "Package pre-generated protos": Commit the generated Python bindings into
18-
the repository/package and document the exact `fabric-protos` version used to
19-
generate them. This avoids requiring consumers to generate bindings locally.
20-
21-
Recommendation (practical balance)
22-
----------------------------------
23-
24-
- Use `fabric-protos` as a submodule pinned to the exact tag you support. This
25-
preserves provenance and makes regenerating bindings reproducible.
26-
- Keep `scripts/gen_protos.sh` in the repo as a canonical way to regenerate
27-
bindings. Commit generated bindings for release artifacts (or for ease of
28-
testing), but avoid mixing `.proto` sources into the runtime package unless
29-
required.
30-
- In CI, either regenerate the bindings and compare them with the committed
31-
files, or regenerate them as part of the release build to ensure consistency.
32-
- Avoid publishing a PyPI package name that could be confused with an official
33-
upstream package (e.g. `fabric-protos-python`). If publishing generated
34-
bindings, choose a clear, distinct package name and document compatibility.
35-
36-
Practical steps (example)
4+
Current integration model
375
-------------------------
386

39-
1. Add `fabric-protos` as a submodule and pin to a tag:
7+
This project now consumes official Python protobuf bindings from
8+
`hyperledger/fabric-protos`.
9+
10+
- Package name: `hyperledger-fabric-protos`
11+
- Import namespace used by this repository: `fabric_protos`
12+
13+
Install with:
4014

4115
```bash
42-
git submodule add --depth 1 -b v2.5.0 https://github.com/hyperledger/fabric-protos.git protos/fabric-protos
43-
git submodule update --init --recursive
16+
PYTHON_BIN=python ./scripts/install_fabric_protos.sh
4417
```
4518

46-
2. Generate Python bindings (run from the repository root):
19+
Why this model
20+
--------------
21+
22+
- Avoids vendored generated protobuf drift inside this repository.
23+
- Keeps protocol bindings aligned with the upstream Fabric protobuf source.
24+
- Simplifies release and maintenance for `fabric-chaincode-python`.
25+
26+
Version compatibility
27+
---------------------
28+
29+
Use dependency ranges compatible with upstream Python bindings:
30+
31+
- `protobuf>=5.27.0,<6.0.0`
32+
- `grpcio>=1.83.1,<2.0.0`
33+
34+
The installer script uses the following order:
35+
36+
1. Local `../fabric-protos` checkout (runs `make pythonbindings`)
37+
2. PyPI `hyperledger-fabric-protos` package (if complete)
38+
3. Official `hyperledger/fabric-protos` git checkout at pinned commit,
39+
then local build/install of `bindings/python`
40+
41+
Local regeneration (optional)
42+
-----------------------------
43+
44+
For debugging or contributor workflows, bindings can still be generated from
45+
a local `fabric-protos` checkout:
4746

4847
```bash
49-
cd ./fabric-chaincode-python
50-
PROTO_SRC=protos/fabric-protos bash scripts/gen_protos.sh
51-
# generated files will be placed where the script is configured (e.g. fabric_protos_python/)
48+
PROTO_SRC=/path/to/fabric-protos OUT_DIR=$PWD/fabric_protos bash scripts/gen_protos.sh
5249
```
5350

54-
3. In CI: either regenerate and `git diff` against committed bindings to detect
55-
drift, or regenerate in the build environment so wheel artifacts include the
56-
bindings.
51+
This is optional and should not be required for normal runtime use.
5752

5853
License
5954
-------
6055

61-
`fabric-protos` is licensed under Apache-2.0. If you include `.proto` files or
62-
generated bindings from that repository in your project, retain the original
63-
license notice (do not remove the `LICENSE` files from the `fabric-protos`
64-
source when copying). This is important if you plan to contribute or migrate the
65-
project to Hyperledger Labs.
56+
`fabric-protos` is Apache-2.0. If distributing generated bindings yourself,
57+
keep original licensing notices intact.

‎README.md‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ Requirements
1212
- Python 3.10+ (3.11 recommended)
1313
- See `requirements.txt` for runtime dependencies. Key packages:
1414
- `grpcio==1.83.1`
15-
- `protobuf>=7.35.1`
15+
- `protobuf>=5.27.0,<6.0.0`
1616
- `grpclib==0.4.3`
17+
- `hyperledger-fabric-protos` (installed via `scripts/install_fabric_protos.sh`)
1718

1819
Quick start (development)
1920
-------------------------
@@ -26,6 +27,7 @@ python3 -m venv .venv
2627
source .venv/bin/activate
2728
python -m pip install --upgrade pip
2829
pip install -r requirements.txt
30+
PYTHON_BIN=python ./scripts/install_fabric_protos.sh
2931
```
3032

3133
Run tests:
@@ -46,14 +48,25 @@ python -m build --wheel --no-isolation
4648

4749
Protobuf bindings
4850
-----------------
49-
This repository contains generated Python protobuf bindings for Hyperledger
50-
Fabric under the `fabric_protos_python/` package. The project also includes a
51-
`scripts/gen_protos.sh` helper to regenerate bindings from the `fabric-protos`
52-
source (recommended to use a pinned tag/submodule for reproducible results).
51+
This repository consumes the official Python bindings published from
52+
`hyperledger/fabric-protos`:
5353

54-
If you regenerate protos in CI or locally, ensure the `protobuf` runtime used
55-
to generate the files is compatible with the installed `protobuf` package
56-
(see `requirements.txt`).
54+
- Package name: `hyperledger-fabric-protos`
55+
- Import namespace: `fabric_protos`
56+
57+
Bindings are installed from official `hyperledger/fabric-protos` sources by
58+
`scripts/install_fabric_protos.sh`, with validation that required generated
59+
modules are present.
60+
61+
Install or refresh official bindings with:
62+
63+
```bash
64+
PYTHON_BIN=python ./scripts/install_fabric_protos.sh
65+
```
66+
67+
No vendored protobuf runtime package is required in this repository.
68+
If you need to regenerate bindings locally for debugging, use
69+
`scripts/gen_protos.sh` and keep generated/runtime versions compatible.
5770

5871
Running a chaincode service (example)
5972
------------------------------------
@@ -67,7 +80,7 @@ export CHAINCODE_SERVER_ADDRESS=127.0.0.1:9999
6780
Then start the example service (if `main.py` or an example is present):
6881

6982
```bash
70-
python main.py
83+
./.venv/bin/python examples/ccaas/asset-transfer-basic/main.py
7184
```
7285

7386
Contributing

‎examples/ccaas/asset-transfer-basic/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ cd /path/to/fabric-chaincode-python
2828
python3 -m venv .venv
2929
source .venv/bin/activate
3030
pip install -r requirements.txt
31+
PYTHON_BIN=python ./scripts/install_fabric_protos.sh
3132
```
3233

3334
### 2. Package the Chaincode
@@ -186,8 +187,9 @@ Tells Fabric that this is a CCAAS package:
186187
### Server won't start
187188
- Ensure `CHAINCODE_ID` matches the package-id from `peer lifecycle chaincode install`
188189
- Check that `connection.json` address is accessible from the peer
189-
- Verify dependencies are installed: `pip install -r requirements.txt`
190+
- Verify dependencies are installed: `pip install -r requirements.txt && PYTHON_BIN=python ./scripts/install_fabric_protos.sh`
190191
- Verify you're using the project venv: `./.venv/bin/python -c "import grpc; print(grpc.__version__)"`
192+
- Verify Fabric protobuf bindings are importable: `./.venv/bin/python -c "from fabric_protos.peer import chaincode_shim_pb2"`
191193

192194
### Peer can't reach chaincode
193195
- Check firewall rules allowing port 9999

‎examples/ccaas/asset-transfer-basic/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from src.fabric_shim.interfaces import Chaincode, ChaincodeStubInterface
2828
from src.fabric_shim.server import start
2929
from src.fabric_shim.response import ResponseCode
30-
from fabric_protos_python.peer import proposal_response_pb2 as pb
30+
from fabric_protos.peer import proposal_response_pb2 as pb
3131

3232

3333
class Asset:

‎examples/ccaas/asset-transfer-sbe/README.md‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,22 @@ cd /path/to/fabric-chaincode-python
4040
python3 -m venv .venv
4141
source .venv/bin/activate
4242
pip install -r requirements.txt
43+
PYTHON_BIN=python ./scripts/install_fabric_protos.sh
4344
```
4445

45-
### 2. Install Example Dependencies
46-
47-
```bash
48-
cd examples/ccaas/asset-transfer-sbe
49-
pip install -r requirements.txt
50-
```
51-
52-
### 3. Run the Chaincode Server
46+
### 2. Run the Chaincode Server
5347

5448
```bash
49+
cd /path/to/fabric-chaincode-python/examples/ccaas/asset-transfer-sbe
5550
export CHAINCODE_ID=asset_transfer_sbe_1:<package_hash>
5651
export CHAINCODE_SERVER_ADDRESS=127.0.0.1:9999
5752

58-
python main.py
53+
../../../.venv/bin/python main.py
5954
```
6055

6156
The chaincode server will start and wait for connections from a Fabric peer.
6257

63-
### 4. Invoke Chaincode Functions
58+
### 3. Invoke Chaincode Functions
6459

6560
**Create asset:**
6661
```bash

‎examples/ccaas/asset-transfer-sbe/main.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
if str(REPO_ROOT) not in sys.path:
1717
sys.path.insert(0, str(REPO_ROOT))
1818

19-
from fabric_protos_python.peer import proposal_response_pb2 as pb
19+
from fabric_protos.peer import proposal_response_pb2 as pb
2020
from src.fabric_shim.interfaces import Chaincode, ChaincodeStubInterface
2121
from src.fabric_shim.response import ResponseCode
2222
from src.fabric_shim.server import start

‎fabric_protos_python/__init__.py‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎fabric_protos_python/common/__init__.py‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)