主题
fabric-x-sdk · 模块详解
本仓库 submodule:fabric-x-sdk/。路径相对该 submodule 根。
顶层 Go 文件
| 文件 | 内容 | 行号 |
|---|---|---|
types.go | Endorsement struct(13-18)、Signer interface(20-23) | 13-23 |
logging.go | Logger interface(18-23)、NoOpLogger、StdLogger、TestLogger | 18-89 |
blocks/(10 个 Go 文件)
| 关键符号 | 文件 | 行号 |
|---|---|---|
ReadWriteSet | types.go | 13-16 |
Version | types.go | 29-32 |
WriteRecord | types.go | 35-44 |
Block | types.go | 51-60 |
Transaction | types.go | 62-70 |
BlockParser interface | processor.go | 23-25 |
BlockHandler interface | processor.go | 26-28 |
Processor struct | processor.go | 30-33 |
Processor.ProcessBlock | processor.go | 37-49 |
MVCCValidator struct | mvcc.go | 33-43 |
NewMVCCValidator | mvcc.go | 15-25 |
RecordGetter interface(Get) | mvcc.go | 28-30 |
(*MVCCValidator).Validate | mvcc.go | 49 |
子包:
blocks/fabric/—— Fabric block parser(parser.go/mvcc.go)blocks/fabricx/—— Fabric-X block parser
endorsement/(5 个 Go 文件)
| 关键符号 | 文件 | 行号 |
|---|---|---|
Builder interface | proposal.go | 27-30 |
Invocation struct | proposal.go | 32-43 |
ExecutionResult struct | proposal.go | 45-57 |
Parse(SignedProposal) | proposal.go | 104-196 |
proposal.go:89-103 安全警告:签名验证未实现,仅用于可信环境。
子包:
endorsement/fabric/——EndorsementBuilder(实现endorsement.Builder;builder.go:27-29struct、Endorse自:32),用ledger/rwset/kvrwsetendorsement/fabricx/——EndorsementBuilder(实现endorsement.Builder;builder.go:32-34struct、Endorse自:38),定义常量EventKey="_event_"/InputKey="_input_"(builder.go:23-26)
identity/(1 个 Go 文件)
来源:identity/msp.go。
| 项 | 行号 |
|---|---|
Signer struct(priv_sk / signcert / mspID) | 26-30 |
SignerFromMSP | 33-65 |
(*Signer).Sign | 67-69 |
sign(内部,ECDSA SHA-256,ToLowS + MarshalECDSASignature) | 71-84 |
(*Signer).Serialize(msp.SerializedIdentity proto) | 86-88 |
parsePrivateKey(PEM PKCS#8 ECDSA) | 90-105 |
network/(10 个 Go 文件)
| 关键符号 | 文件 | 行号 |
|---|---|---|
Peer struct | peer.go | 32-35 |
NewPeer(TLS / gRPC backoff / hostname override) | peer.go | 37-72 |
(*Peer).ProcessProposal | peer.go | 78-87 |
BlockProcessor interface | peer.go | 91-93 |
(*Peer).SubscribeBlocks(开 peer Deliver 流,按 SeekInfo 流式拉块) | peer.go | 97-100+ |
PeerConf struct(Address / TLS) | peer.go | 148-151 |
Orderer struct | orderer.go | 143-147 |
NewOrderer | orderer.go | 39-68 |
(*Orderer).Broadcast | orderer.go | 150-169 |
TxPackager interface(PackageTx) | orderer.go | 29-31 |
OrdererConf struct(Address / TLS) | orderer.go | 34-37 |
FabricSubmitter struct / NewSubmitter | orderer.go | 71-99 |
子包:
network/fabric/—— Fabric packager +NewSynchronizer(peer.go:56)network/fabricx/—— Fabric-X packager +NewSynchronizer(peer.go:47)network/fixtures/—— 测试 fixtures
顶层 network/synchronizer.go:Synchronizer struct(:63)、NewSynchronizer(:89)、tls.go 的 TLSConfig。
state/(6 个 Go 文件)
| 关键符号 | 文件 | 行号 |
|---|---|---|
NewReadDB(SQLite 只读,WAL,多连接) | db.go | 25-35 |
NewWriteDB(SQLite 读写,单连接,自动建表) | db.go | 39-54 |
VersionedDB struct | db.go | 57-60 |
SimulationStore struct | sim.go | 26-34 |
ReadStore interface(Get + BlockNumber) | sim.go | 37-40 |
NewSimulationStore | sim.go | 46 |
Log struct(Address / Topics / Data) | sim.go | 17-21 |
子包:
state/sqlite/—— SQLite backend(sqlite.go,依赖modernc.org/sqlite)
fabrictest/(4 个 Go 文件)
| 关键符号 | 文件 | 行号 |
|---|---|---|
Network struct(PeerPort / OrdererPort / oSrv / pSrv / orderer / ledger) | network.go | 35-42 |
TxParser interface | network.go | 47-49 |
实现 orderer Broadcast API 与 peer Deliver endpoint(README.md:14)。
local/(2 个 Go 文件)
| 关键符号 | 文件 | 行号 |
|---|---|---|
VersionedDB interface(BlockNumber / Handle / Get) | submit.go | 21-25 |
LocalSubmitter struct | submit.go | 30-37 |
TxPackager interface | submit.go | 40-42 |
TxParser interface(ParseTx) | submit.go | 44-47 |
NewLocalSubmitter | submit.go | 49-50+ |
integration/(2 个 Go 文件)
文件:integration_test.go、cases_test.go。
Makefile:45-46 中的 test-x 跑 TestFabricXCommitter;Makefile:61-62 中的 test-fablo 跑 TestFablo。
example/endorser/
来源:example/endorser/README.md:196-207、example/endorser/cmd/endorser/main.go。
结构:
example/endorser/
├── cmd/
│ ├── endorser/ 背书服务入口
│ └── client/ 开发 CLI
├── config/ 服务配置 struct
├── sampleconfig/ 服务配置文件
├── service/ 服务实现 + 集成测试
├── go.mod
└── README.md功能(example/endorser/README.md:4-22):
- Fabric 或 Fabric-X 背书服务
- 暴露 Fabric
ProcessProposalAPI - 与 committing peer 同步 world state
- 生成并签名 R/W set
- mTLS 认证
- 客户端 CLI
入口 main.go:
| 项 | 行号 |
|---|---|
| cobra 命令 | 28-36 |
-c/--config(必填)、--log-level flag | 38-40 |
| YAML 配置加载(viperutil) | 49-61 |
| 服务创建(多 namespace + executor) | 82-95 |
connection.StartService(fabric-x-committer) | 104 |
Executor 接口(example/endorser/README.md:73-91):可访问 invocation、通过 SimulationStore 读 world state、返回 endorsement.Success(...)。
TLS 三种模式(example/endorser/README.md:180-194):none / tls / mtls。env 前缀 ENDORSER_。
看代码推荐路径
README.md→ 8 子包的一行职责。types.go+logging.go→ 顶层基础类型。blocks/processor.go:23-49→ 块处理流水线。endorsement/proposal.go:27-43+identity/msp.go:33-69→ 背书 + 签名。network/peer.go:32-100+network/orderer.go:39-68→ 客户端实现。state/db.go:25-54+state/sim.go:26-50→ SQLite 与 simulation。example/endorser/cmd/endorser/main.go:28-104→ 端到端示例。