Phase 2: fee gate gRPC proxy
还没有人认领这个 Issue。
评估
调研方向
开始前阅读 docs/fee-module-design.md §6,并检查 pkg/cantonsdk/fee 中的 Phase 1 fee engine。然后梳理 pkg/feegate 和 cmd/feegate 下所需的服务,先从 CommandService 和 InteractiveSubmissionService 开始,再处理 passthrough 和 forwarding 行为。完成的标准是满足验收标准,包括 JWT forwarding、staging 模式、deployment 文档以及 proxy 集成测试。
由索引模型根据 Issue 内容生成。
描述
Part of the Fee Module epic (#366). Depends on #368 (the engine). Design: docs/fee-module-design.md §6.
Front the same pkg/cantonsdk/fee engine with a deployable gRPC service (pkg/feegate) that speaks the Canton Ledger API. Write submissions get a CC fee leg injected; every other call is a transparent passthrough. Any service, in any language, points its endpoint at the proxy and authenticates with the same JWT it would use against Canton. This is a front-end over the engine — not a rewrite.
Why a proxy in addition to the library
| Phase 1 — library | Phase 2 — proxy | |
|---|---|---|
| Integration | import a Go package | change one endpoint |
| Languages | Go only | any language |
| "No bypass" enforcement | discipline (use wrapped client) | network isolation (node reachable only via proxy) |
| API coverage | calls the middleware makes | all Ledger API calls, incl. future ones |
| Best when | Go-only, minimize moving parts | polyglot services, or fee guaranteed org-wide |
Design
The proxy registers the Ledger API gRPC services and, for each, either injects a fee leg (writes) or forwards verbatim (everything else). It holds an upstream connection to the real Canton node and reuses the same fee.Gate built in Phase 1.
flowchart TB
IN["Incoming Ledger API call"] --> Q{"write submission?"}
Q -->|yes| INJ["decode -> Gate.Process -> forward augmented tx"]
Q -->|"no — reads, streams, party mgmt, ..."| PASS["transparent passthrough"]
Write interception — CommandService
// pkg/feegate/command_service.go
type commandProxy struct {
lapiv2.UnimplementedCommandServiceServer
upstream lapiv2.CommandServiceClient
gate fee.Gate
}
func (p *commandProxy) SubmitAndWaitForTransaction(
ctx context.Context, req *lapiv2.SubmitAndWaitForTransactionRequest,
) (*lapiv2.SubmitAndWaitForTransactionResponse, error) {
payer := actAs(req.Commands) // acting party
processed, err := p.gate.Process(ctx, payer, req.Commands.Commands)
if err != nil {
return nil, status.Errorf(codes.FailedPrecondition, "fee gate: %v", err)
}
req.Commands.Commands = processed.Commands // augmented with CC fee leg
return p.upstream.SubmitAndWaitForTransaction(forwardCtx(ctx), req)
}
The interactive prepare path (InteractiveSubmissionService.PrepareSubmission) is intercepted the same way, so the fee leg is inside the hash the client signs.
Passthrough — everything else
StateService, UpdateService, PartyManagementService, reads, streams, and any future service are registered as thin forwarders. A generic streaming forwarder covers server-streaming calls (e.g. GetUpdates, GetActiveContracts):
func forwardServerStream[Req any, Resp any](
ctx context.Context, req *Req,
open func(context.Context, *Req, ...grpc.CallOption) (grpc.ServerStreamingClient[Resp], error),
send func(*Resp) error,
) error {
up, err := open(forwardCtx(ctx), req)
if err != nil { return err }
for {
msg, err := up.Recv()
if errors.Is(err, io.EOF) { return nil }
if err != nil { return err }
if err := send(msg); err != nil { return err }
}
}
Auth — JWT passthrough
The caller sends the same bearer JWT it would send to Canton; the proxy copies the authorization metadata onto the upstream context (forwardCtx) and does not mint its own token. The operator's fee-leg settlement relies on the pre-provisioned TransferPreapproval, not on the caller's identity.
func forwardCtx(ctx context.Context) context.Context {
md, _ := metadata.FromIncomingContext(ctx)
return metadata.NewOutgoingContext(ctx, md.Copy())
}
Wiring — cmd/feegate
gate := fee.NewGate(scan.NewOracle(cfg.ScanURL), fee.NewSizer(), cfg.FeeParty, cfg.PreapprovalCID, calcCfg, cfg.Mode)
up := ledger.New(cfg.Upstream) // connection to the real Canton node
s := grpc.NewServer()
lapiv2.RegisterCommandServiceServer(s, &commandProxy{upstream: up.Command(), gate: gate})
lapiv2.RegisterInteractiveSubmissionServiceServer(s, &interactiveProxy{upstream: up.Interactive(), gate: gate})
lapiv2.RegisterStateServiceServer(s, &statePassthrough{upstream: up.State()})
lapiv2.RegisterUpdateServiceServer(s, &updatePassthrough{upstream: up.Update()})
// ...party mgmt, etc. — passthrough
Deployment
Run feegate as its own service; restrict the Canton node's Ledger API so it's reachable only via the proxy (network isolation). Services swap their ledger endpoint to the proxy — no other change. Same fee.mode staging (Observe → Quote-only → Collect) as Phase 1.
Acceptance criteria
-
pkg/feegate+cmd/feegategRPC service reusing the Phase 1fee.Gateunchanged (no engine changes required — if the engine needs edits, that's a Phase 1 gap). -
CommandServiceandInteractiveSubmissionServicewrite paths inject the CC fee leg; fee leg is inside the signed hash on the interactive path. -
StateService,UpdateService, party mgmt, and streaming calls pass through transparently (byte-for-byte responses; streams relayed). - JWT metadata forwarded upstream unchanged; proxy mints no token of its own.
-
fee.modestaging works identically to Phase 1. - Documented deployment with the node reachable only via the proxy (no-bypass network isolation).
- Integration test: a Go client pointed at the proxy completes a transfer with the fee leg present, and a read/stream call returns identical results to hitting the node directly.
- 主要语言
- Go
- 星标
- 1
- 派生
- 1
- 平均合并
- 6 小时 59 分钟
- 30 天内合并 PR
- 6
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ChainSafe/canton-middleware 的其他 Issue
-
难度 5/5 一周以上 新手友好度 25/100
ChainSafe/canton-middleware#390 ·
-
Separate API runtime privileges from Canton administration可能已有人在做 @shibaeff 于 12 天前认领。 未关闭
ChainSafe/canton-middleware#389 · 1 条评论 · 已指派 1 人 ·
-
Type: Maintenance Type: Test
难度 5/5 一周以上 新手友好度 35/100
ChainSafe/canton-middleware#380 ·
-
CIP-0086: Phase 2 Deliverable: D3 Status: On Ice Type: Feature
难度 5/5 一周以上 新手友好度 35/100
ChainSafe/canton-middleware#372 ·
-
Type: Feature
难度 5/5 一周以上 新手友好度 35/100
ChainSafe/canton-middleware#368 ·
查看 ChainSafe/canton-middleware 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
uselagoon/lagoon-cli#501 · 1 个 reaction ·
-
难度 1/5 1 小时以内 新手友好度 85/100
-
难度 1/5 1 小时以内 新手友好度 62/100
slavakurilyak/awesome-ai-agents#1026 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 70/100
Tarektouati/made#197 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100