主题
cbdc-chain · 模块详解
本仓库 submodule:cbdc-chain/。路径相对该 submodule 根。
顶层目录
| 路径 | 用途 | 出处 |
|---|---|---|
cbdc-biz/ | 业务服务(独立 go.mod) | cbdc-biz/go.mod:1 |
cbdc-network/ | Fabric-X 网络配置部署(无 go.mod) | cbdc-network/Makefile |
cbdc-infra/ | 基础设施镜像(无 go.mod) | cbdc-infra/README.md:3-6 |
cbdc-stress/ | 压测工具(独立 go.mod) | cbdc-stress/go.mod |
docs/ | 内部设计文档 | — |
open-docs/ | 公开 VitePress 文档 | open-docs/docs/.vitepress/ |
scripts/ | start-kms-system.sh / check-auditor-key.sh | README.md:138-160 |
tests/ | 独立 go.mod cbdc-chain-tests | tests/go.mod |
cbdc-biz/
5 个业务应用
来源:cbdc-biz/app/、各应用 cmd/*/main.go。
| 应用 | 入口(func main()) | gRPC 端口 | 端口出处 |
|---|---|---|---|
endorser | cbdc-biz/app/endorser/cmd/endorser/main.go:56 | 9300 | conf/endorser1/core.yaml:7 |
issuer | cbdc-biz/app/issuer/cmd/issuer/main.go:61 | 9100 | conf/issuer/core.yaml:9 |
auditor | cbdc-biz/app/auditor/cmd/auditor/main.go:67 | 9750 | conf/auditor/core.yaml:16 |
institution | cbdc-biz/app/institution/cmd/institution/main.go:69 | 9500 | conf/institution-001/core.yaml:8 |
bizhub | cbdc-biz/app/bizhub/cmd/bizhub/main.go:58 | 9000 | conf/bizhub/core.yaml:50 |
README 与实际目录不一致
README.md:32-33, 46 提到 retail/ 与 wholesale/,但 cbdc-biz/app/ 下实际只有 auditor / bizhub / endorser / institution / issuer 5 个目录。Wholesale / Retail 应用当前不存在。
各应用共同结构:
cmd/<app>/
├── main.go Kratos app 启动(flag、配置、OTel、FSC、Wire)
└── wire.go Google Wire 依赖注入
internal/
├── biz/ 业务逻辑
├── data/ Repository + Ent ORM
├── service/ gRPC service 实现
└── conf/ 配置 proto
Makefile公共包(cbdc-biz/pkg/)
| 包 | 职责 |
|---|---|
common/nodesdk | FSC 节点启动 SDK |
identity/ | 身份与钱包管理 |
keystore/ | 密钥存储(PKCS#11 + JKS) |
observability/ | OTel tracing 与日志 |
rtgs/ | SWIFT MT298 + SMB RTGS 集成 |
token_selector/ | UTXO 选币 |
utxo_management/ | UTXO 锁定 |
auditor/ | 审计日志、规则树 |
scheduler/ | cron v3 定时任务 |
signet/ | OpenTelemetry 集成 |
views/ | Token SDK View 实现 |
workerpool/ | 工作线程池 |
API(cbdc-biz/api/)
16 个 .proto(proto3,均在 cbdc-biz/api/cbdc-biz/v1/)。顶层服务 EndorserService / IssuerService / AuditorService / InstitutionOpsService;kms/ 下 KmsService / KmsManageService;bizhub/ 下 ManageService / WalletService / ApprovalService / SettlementService / IndexerService / CAService 等。EndorserService.Init(endorser.proto:8)即启动初始化 RPC。
cbdc-biz/go.mod
来源:cbdc-biz/go.mod。
| 依赖 | 版本 | 行 |
|---|---|---|
hyperledger-labs/fabric-smart-client | v0.11.0 | go.mod:16 |
hyperledger-labs/fabric-token-sdk | v0.11.0 | go.mod:17 |
hyperledger/fabric-ca | v1.5.16 | go.mod:18 |
go-kratos/kratos/v2 | v2.9.2 | go.mod:12 |
entgo.io/ent | v0.14.6 | go.mod:6 |
redis/go-redis/v9 | v9.18.0 | go.mod:23 |
lib/pq | v1.10.9 | go.mod:21 |
replace(cbdc-biz/go.mod:309-315)仅固定四个 go.opentelemetry.io/otel/log 相关包到 Record-签名版本(v0.6.0 / v0.5.0),等待 FSC 上游补丁;无 fabric-token-sdk / fabric-smart-client 的 replace。
Docker
来源:cbdc-biz/docker/。
| 文件 | 用途 |
|---|---|
Dockerfile | 各应用共用同一 Dockerfile,通过构建参数 APP_NAME 在编译期选择 cmd/<app> 并产出各自镜像(cbdc-<app>,见 compose-build.yml 的 args.APP_NAME);CMD 对所有应用相同 |
Dockerfile.builder-base | 构建基础镜像(Go 编译) |
Dockerfile.rtgs-mock | RTGS 模拟服务 |
compose-build-base.yml | 构建基础镜像 |
compose-build.yml | 构建应用镜像 |
compose-local-run.yml | 本地开发运行 |
compose-local-run-infra.yml | 仅基础设施(DB / KMS) |
compose-rtgs-mock.yml | RTGS 模拟 |
institution 应用有独立 cbdc-biz/app/institution/Dockerfile。
cbdc-network/
来源:cbdc-network/README.md、cbdc-network/Makefile。
| 文件 / 目录 | 用途 |
|---|---|
README.md | 启动 / 维护命令清单 |
Makefile | setup / setup-kms / start / teardown / create-ns / list-ns / version / build-push |
configs/test-full-kms.yaml | 默认 KMS 模式配置 |
out/docker-compose.yaml | 由 cbdc-tool 镜像内 config-builder gen-compose 生成(运行时) |
.env.example | 环境变量模板 |
详细 make target 见 03-quickstart。
cbdc-infra/
来源:cbdc-infra/Makefile、cbdc-infra/cbdc-tool/Dockerfile。
cbdc-infra/ 下仅 cbdc-tool/ 一个目录。
| 镜像 | 用途 |
|---|---|
cbdc-tool | 基于 ghcr.io/built-by-sign/fabric-x-tool,叠加从 sign-kms 镜像复制的 libkms_pkcs11.so(cbdc-tool/Dockerfile:8,20);提供 config-builder / fxconfig |
cbdc-ca-server-kms | build-all / build-push 一并构建推送(Makefile:15,29) |
| target | 行号 | 用途 |
|---|---|---|
make build-all | Makefile:15 | 构建 cbdc-tool + cbdc-ca-server-kms |
make build-push | Makefile:26 | 构建并推送 |
make version | Makefile:33 | 查 git tag infra/* |
TAG=custom-version make build-push 自定义版本(Makefile:9)。
cbdc-stress/
来源:cbdc-stress/main.go、cbdc-stress/cmd/bootstrap/main.go。
| 路径 | 用途 |
|---|---|
main.go | 压测主程序(flag 在 main.go:26-35) |
cmd/bootstrap/main.go | 钱包批量创建 + 充值(create-mother / create-children / fund-existing) |
data/<env>/ | 预设环境的钱包文件目录(由 bootstrap 生成,被 -env 引用) |
-env 预设(cbdc-stress/main.go:20-21):
| 预设 | URL | 钱包路径 |
|---|---|---|
dev | http://34.60.193.75:9502 | data/dev/wallets.json |
local | http://localhost:9502 | data/local/wallets.json |
tests/
来源:tests/、tests/go.mod(module cbdc-chain-tests)。
| 子目录 | 测试对象 | 主要文件 |
|---|---|---|
auditor_rulesets/ | 审计规则集 | limits_test.go |
e2e/ | 端到端 | endorser_proxy_test.go / ledger_indexer_test.go |
fees/ | 费用收集 | fee_collection_test.go / comprehensive_test.go / category_test.go |
internal/bizclient/ | 业务客户端工具库 | amount.go / walletkit.go / signer.go / conn.go |
marked_tokens/ | 资产标记 | marked_tokens_test.go |
transfer/ | 转账 | batch_transfer_test.go |
测试框架:Go testing + stretchr/testify(tests/go.mod:7)。cbdc-biz 单测另用 alicebob/miniredis/v2 与 DATA-DOG/go-sqlmock(cbdc-biz/go.mod:8,46)。
docs/
详见 02-architecture · docs/ 与 plans/。
open-docs/
来源:open-docs/(VitePress 内容在 open-docs/docs/)。
| 路径 | 用途 |
|---|---|
docs/.vitepress/ | VitePress 配置(config.ts / theme / components) |
docs/index.md | 首页 |
docs/guide/ | 15 个用户指南 .md |
docs/architecture/overview.md | 架构概览 |
docs/changelog.md | 变更日志 |
docs/api-reference.md | API 参考(占位,57 字节) |
Dockerfile | 文档站点镜像 |
scripts/
来源:README.md:138-160、scripts/。
| 脚本 | 用途 |
|---|---|
start-kms-system.sh | 一键 KMS 系统启动(支持 --local-kms / --quick / --skip-build) |
check-auditor-key.sh | 审计节点密钥检查 |
看代码推荐路径
README.md→ 顶层布局、三层架构、启动顺序。cbdc-biz/app/endorser/cmd/endorser/main.go:56→ 单应用启动模板。cbdc-biz/pkg/common/nodesdk/→ FSC 节点启动 SDK。cbdc-biz/pkg/utxo_management/、pkg/token_selector/、pkg/auditor/→ 核心业务原语。cbdc-network/Makefile+configs/test-full-kms.yaml→ 网络部署机制。tests/e2e/、tests/transfer/→ 端到端用例。cbdc-biz/conf/<role>/core.yaml→ 各应用真实运行配置(含端口、bizhub_addr、p2p、token、fabric)。