Skip to content

fabric-x-sdk · 模块详解

本仓库 submodule:fabric-x-sdk/。路径相对该 submodule 根。

顶层 Go 文件

文件内容行号
types.goEndorsement struct(13-18)、Signer interface(20-23)13-23
logging.goLogger interface(18-23)、NoOpLoggerStdLoggerTestLogger18-89

blocks/(10 个 Go 文件)

关键符号文件行号
ReadWriteSettypes.go13-16
Versiontypes.go29-32
WriteRecordtypes.go35-44
Blocktypes.go51-60
Transactiontypes.go62-70
BlockParser interfaceprocessor.go23-25
BlockHandler interfaceprocessor.go26-28
Processor structprocessor.go30-33
Processor.ProcessBlockprocessor.go37-49
MVCCValidator structmvcc.go33-43
NewMVCCValidatormvcc.go15-25
RecordGetter interface(Getmvcc.go28-30
(*MVCCValidator).Validatemvcc.go49

子包:

  • blocks/fabric/ —— Fabric block parser(parser.go / mvcc.go
  • blocks/fabricx/ —— Fabric-X block parser

endorsement/(5 个 Go 文件)

关键符号文件行号
Builder interfaceproposal.go27-30
Invocation structproposal.go32-43
ExecutionResult structproposal.go45-57
Parse(SignedProposal)proposal.go104-196

proposal.go:89-103 安全警告:签名验证未实现,仅用于可信环境。

子包:

  • endorsement/fabric/ —— EndorsementBuilder(实现 endorsement.Builderbuilder.go:27-29 struct、Endorse:32),用 ledger/rwset/kvrwset
  • endorsement/fabricx/ —— EndorsementBuilder(实现 endorsement.Builderbuilder.go:32-34 struct、Endorse:38),定义常量 EventKey="_event_" / InputKey="_input_"builder.go:23-26

identity/(1 个 Go 文件)

来源:identity/msp.go

行号
Signer struct(priv_sk / signcert / mspID26-30
SignerFromMSP33-65
(*Signer).Sign67-69
sign(内部,ECDSA SHA-256,ToLowS + MarshalECDSASignature71-84
(*Signer).Serialize(msp.SerializedIdentity proto)86-88
parsePrivateKey(PEM PKCS#8 ECDSA)90-105

network/(10 个 Go 文件)

关键符号文件行号
Peer structpeer.go32-35
NewPeer(TLS / gRPC backoff / hostname override)peer.go37-72
(*Peer).ProcessProposalpeer.go78-87
BlockProcessor interfacepeer.go91-93
(*Peer).SubscribeBlocks(开 peer Deliver 流,按 SeekInfo 流式拉块)peer.go97-100+
PeerConf struct(Address / TLSpeer.go148-151
Orderer structorderer.go143-147
NewOrdererorderer.go39-68
(*Orderer).Broadcastorderer.go150-169
TxPackager interface(PackageTxorderer.go29-31
OrdererConf struct(Address / TLSorderer.go34-37
FabricSubmitter struct / NewSubmitterorderer.go71-99

子包:

  • network/fabric/ —— Fabric packager + NewSynchronizerpeer.go:56
  • network/fabricx/ —— Fabric-X packager + NewSynchronizerpeer.go:47
  • network/fixtures/ —— 测试 fixtures

顶层 network/synchronizer.goSynchronizer struct(:63)、NewSynchronizer:89)、tls.goTLSConfig

state/(6 个 Go 文件)

关键符号文件行号
NewReadDB(SQLite 只读,WAL,多连接)db.go25-35
NewWriteDB(SQLite 读写,单连接,自动建表)db.go39-54
VersionedDB structdb.go57-60
SimulationStore structsim.go26-34
ReadStore interface(Get + BlockNumbersim.go37-40
NewSimulationStoresim.go46
Log struct(Address / Topics / Datasim.go17-21

子包:

  • state/sqlite/ —— SQLite backend(sqlite.go,依赖 modernc.org/sqlite

fabrictest/(4 个 Go 文件)

关键符号文件行号
Network struct(PeerPort / OrdererPort / oSrv / pSrv / orderer / ledgernetwork.go35-42
TxParser interfacenetwork.go47-49

实现 orderer Broadcast API 与 peer Deliver endpoint(README.md:14)。

local/(2 个 Go 文件)

关键符号文件行号
VersionedDB interface(BlockNumber / Handle / Getsubmit.go21-25
LocalSubmitter structsubmit.go30-37
TxPackager interfacesubmit.go40-42
TxParser interface(ParseTxsubmit.go44-47
NewLocalSubmittersubmit.go49-50+

integration/(2 个 Go 文件)

文件:integration_test.gocases_test.go

Makefile:45-46 中的 test-xTestFabricXCommitterMakefile:61-62 中的 test-fabloTestFablo

example/endorser/

来源:example/endorser/README.md:196-207example/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 ProcessProposal API
  • 与 committing peer 同步 world state
  • 生成并签名 R/W set
  • mTLS 认证
  • 客户端 CLI

入口 main.go

行号
cobra 命令28-36
-c/--config(必填)、--log-level flag38-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_

看代码推荐路径

  1. README.md → 8 子包的一行职责。
  2. types.go + logging.go → 顶层基础类型。
  3. blocks/processor.go:23-49 → 块处理流水线。
  4. endorsement/proposal.go:27-43 + identity/msp.go:33-69 → 背书 + 签名。
  5. network/peer.go:32-100 + network/orderer.go:39-68 → 客户端实现。
  6. state/db.go:25-54 + state/sim.go:26-50 → SQLite 与 simulation。
  7. example/endorser/cmd/endorser/main.go:28-104 → 端到端示例。