如何在 Hyperledger Fabric 中实施和部署可插拔的 ESCC 或 VSCC 策略?

How to implement and deploy pluggable ESCC or VSCC policies in Hyperledger Fabric?

我想在现有的 VSCC 和 ESCC 中分别添加一些额外的验证和背书逻辑。是否有关于如何编辑自定义 VSCC 和 ESCC 并将其部署到 Hyperledger Fabric 的文档?

VSCC和ESCC是系统链码,接口和链码一模一样,看链码文档或者去VSCC source code。您可以添加自己的验证系统链码并将其与您的链码相关联。

系统链代码是用对等可执行文件构建的,不经过事务性 install/instantiate 过程。它在对等点启动时加载,因此需要在 core/scc/importsysccs.go 中进行一些注册。查看 systemChaincodes 变量,您可以看到其他人是如何注册的。

所有系统链代码,特别是 VSCC 和 ESCC,应该实现 Chaincode 接口:

// Chaincode interface must be implemented by all chaincodes. The fabric runs
// the transactions by calling these functions as specified.
type Chaincode interface {
    // Init is called during Instantiate transaction after the chaincode container
    // has been established for the first time, allowing the chaincode to
    // initialize its internal data
    Init(stub ChaincodeStubInterface) pb.Response

    // Invoke is called to update or query the ledger in a proposal transaction.
    // Updated state variables are not committed to the ledger until the
    // transaction is committed.
    Invoke(stub ChaincodeStubInterface) pb.Response
}

目前所有系统链代码都静态编译成对等代码并列在链代码部分的 importsysccs.go file. Additionally they have to be enabled at core.yaml 文件中,例如:

chaincode:

    # system chaincodes whitelist. To add system chaincode "myscc" to the
    # whitelist, add "myscc: enable" to the list below, and register in
    # chaincode/importsysccs.go
    system:
        cscc: enable
        lscc: enable
        escc: enable
        vscc: enable
        qscc: enable

接下来,您将实例化您的链代码,并希望提供自定义 VSCC 和 ESCC,您需要将它们的名称提供给 LSCC。例如,如果您将使用 peer cli,您可以按以下方式进行操作:

peer chaincode instantiate -o localhost:7050 -n myCC -v 1.0 -C mychannel -c '{"Args": ["init"]}' --vscc myVSCC --escc myESCC