Skip to content

feat(antd-py): gRPC external-signer prepare/finalize parity with REST - #143

Closed
Nic-dorman wants to merge 1 commit into
nic/v2-284-grpc-external-signer-prepare-finalizefrom
nic/v2-284-antd-py-grpc-external-signer
Closed

feat(antd-py): gRPC external-signer prepare/finalize parity with REST#143
Nic-dorman wants to merge 1 commit into
nic/v2-284-grpc-external-signer-prepare-finalizefrom
nic/v2-284-antd-py-grpc-external-signer

Conversation

@Nic-dorman

Copy link
Copy Markdown
Collaborator

Summary

Replaces the three NotImplementedError stubs on GrpcClient / AsyncGrpcClient for prepare_upload / prepare_data_upload / finalize_upload with real implementations, and adds four new methods mirroring the REST client surface. Sync + async parity.

Depends on #140 (antd-side UploadService + chunks prepare/finalize).

Methods

method purpose
prepare_upload(path, visibility=None) external-signer prepare for a file
prepare_upload_public(path) convenience wrapper for visibility="public"
prepare_data_upload(data, visibility=None) external-signer prepare for in-memory bytes
finalize_upload(upload_id, tx_hashes) finalize wave-batch upload
finalize_merkle_upload(upload_id, winner_pool_hash, store_data_map=False) finalize merkle-batch upload
prepare_chunk_upload(data) single-chunk external-signer prepare
finalize_chunk_upload(upload_id, tx_hashes) -> str single-chunk finalize, returns address

14 total method impls (7 each on sync and async clients).

Wallet stubs (wallet_address / wallet_balance / wallet_approve) are out of scope here — they belong to the separate WalletService-over-gRPC work and will land in a follow-up PR.

Proto regen

python scripts/generate_proto.py regenerated all stubs under src/antd/_proto/antd/v1/:

  • New upload_pb2.py / upload_pb2.pyi / upload_pb2_grpc.py
  • chunks_pb2.* gain PrepareChunk / FinalizeChunk
  • common_pb2.* adds PaymentEntry
  • Other *_pb2_grpc.py files: header-only protobuf-version diff

Implementation notes

  • New self._upload = upload_pb2_grpc.UploadServiceStub(...) field on both clients.
  • Helpers _prepare_upload_result_from_resp, _finalize_upload_result_from_resp, _prepare_chunk_result_from_resp map proto messages to the existing REST-style dataclasses. Merkle fields (depth, pool_commitments, merkle_payment_timestamp) populated only when payment_type == "merkle".

Tests

New tests/test_grpc_client.py:

  • In-process mock servers: grpc.server (sync) and grpc.aio.server (async), one per test on random 127.0.0.1:0 port.
  • MockChunkServicer covers PrepareChunk (new + already-stored) and FinalizeChunk (echo upload_id).
  • New MockUploadServicer covers PrepareFileUpload / PrepareDataUpload / FinalizeUpload with visibility round-trip via upload_id encoding and merkle vs wave-batch branches.
  • 20 test cases parallel to the antd-rust / antd-go suites.

Gates passed on dev2

  • pytest tests/ — 81/81 passing (61 existing + 20 new)
  • antd-py has no CI workflow and no ruff/mypy config in pyproject.toml; the dev2 sweep is the gate (per project convention).
  • Pre-existing E402 warnings in _grpc.py (imports after helpers) are the file's prior style; not introduced by this PR.

Replaces the three `NotImplementedError` stubs on `GrpcClient` /
`AsyncGrpcClient` for `prepare_upload` / `prepare_data_upload` /
`finalize_upload` with real implementations, and adds four new methods
mirroring the REST client surface:

* `prepare_upload(path, visibility=None)` + `prepare_upload_public(path)`
* `prepare_data_upload(data, visibility=None)`
* `finalize_upload(upload_id, tx_hashes)` (wave-batch)
* `finalize_merkle_upload(upload_id, winner_pool_hash, store_data_map=False)`
* `prepare_chunk_upload(data)` (new, no prior stub)
* `finalize_chunk_upload(upload_id, tx_hashes) -> str` (new)

Sync + async parity (14 method impls total).

Wallet stubs (`wallet_address` / `wallet_balance` / `wallet_approve`) are
out of scope here — they belong to the separate WalletService-over-gRPC
work and will land in a follow-up.

Proto regen:

* `python scripts/generate_proto.py` regenerated all stubs under
  `src/antd/_proto/antd/v1/`. New `upload_pb2.py` / `upload_pb2.pyi` /
  `upload_pb2_grpc.py`. `chunks_pb2.*` gain `PrepareChunk` /
  `FinalizeChunk`. `common_pb2.*` adds `PaymentEntry`. Other `*_pb2_grpc.py`
  files have header-only protobuf-version diffs.

Client (`src/antd/_grpc.py`):

* New `self._upload = upload_pb2_grpc.UploadServiceStub(...)` field on
  both clients.
* Helpers `_prepare_upload_result_from_resp`, `_finalize_upload_result_from_resp`,
  `_prepare_chunk_result_from_resp` map proto messages to the existing
  REST-style dataclasses. Merkle fields (`depth`, `pool_commitments`,
  `merkle_payment_timestamp`) populated only when `payment_type == "merkle"`.

Tests (`tests/test_grpc_client.py`):

* New file: in-process mock servers using `grpc.server` (sync) and
  `grpc.aio.server` (async). `MockChunkServicer` covers
  `PrepareChunk` / `FinalizeChunk`; new `MockUploadServicer` covers
  `PrepareFileUpload` / `PrepareDataUpload` / `FinalizeUpload`.
* 20 test cases parallel to the antd-rust / antd-go suites, covering
  visibility forwarded/omitted, wave-batch vs merkle, `data_map_address`
  presence on public, merkle `store_data_map` toggle, chunk already-stored
  short-circuit, chunk finalize body forwarding. Both sync and async
  paths.

Gates on dev2:

* `pytest tests/` — 81/81 passing (61 existing + 20 new).
* No ruff/mypy config exists in the project (dev2 sweep is the gate);
  pytest is the only enforced check.

Depends on the antd-side daemon PR landing first.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant