通过链代码从结构中获取状态总是 return 空值
GetState from fabric via chaincode always return empty value
我在chaincode dev mode
基于官方chaincode example搭建了一个区块链网络,三个组织,六个peer。我直接将链代码示例部署到区块链网络上。像peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
这样的方式调用chaincode是没有问题的。但是每次我通过 GetState (key)
实现查询的链码查询分类帐时,它总是 return empty value
,即使我可以通过调用 [=] 获得 key/value 对16=] 其中 return 是所有 key/value 对。我检查了安装链代码的对等方的日志。日志如下所示。
2018-01-17 09:01:26.670 UTC [chaincode] processStream -> DEBU 961 [43697748]Received message GET_STATE from shim
2018-01-17 09:01:26.670 UTC [chaincode] handleMessage -> DEBU 962 [43697748]Fabric side Handling ChaincodeMessage of type: GET_STATE in state rea
2018-01-17 09:01:26.670 UTC [chaincode] afterGetState -> DEBU 963 [43697748]Received GET_STATE, invoking get state from ledger
2018-01-17 09:01:26.670 UTC [chaincode] filterError -> DEBU 964 Ignoring NoTransitionError: no transition
2018-01-17 09:01:26.670 UTC [chaincode] func1 -> DEBU 965 [43697748] getting state for chaincode test, key , channel chainplaza
2018-01-17 09:01:26.671 UTC [stateleveldb] GetState -> DEBU 966 GetState(). ns=test, key=
2018-01-17 09:01:26.671 UTC [chaincode] func1 -> DEBU 967 [43697748]No state associated with key: a. Sending RESPONSE with an empty payload
2018-01-17 09:01:26.671 UTC [chaincode] 1 -> DEBU 968 [43697748]handleGetState serial send RESPONSE
2018-01-17 09:01:26.671 UTC [chaincode] processStream -> DEBU 969 [43697748]Received message COMPLETED from shim
2018-01-17 09:01:26.671 UTC [chaincode] handleMessage -> DEBU 96a [43697748]Fabric side Handling ChaincodeMessage of type: COMPLETED in state rea
2018-01-17 09:01:26.671 UTC [chaincode] handleMessage -> DEBU 96b [43697748e1ea4c6f0f6af336f6c413583716c8ec1d59c10118ecfd49bf581509]HandleMessage
2018-01-17 09:01:26.671 UTC [chaincode] notify -> DEBU 96c notifying Txid:43697748e1ea4c6f0f6af336f6c413583716c8ec1d59c10118ecfd49bf581509
2018-01-17 09:01:26.671 UTC [chaincode] Execute -> DEBU 96d Exit
奇怪的是[stateleveldb] GetState -> DEBU 966 GetState(). ns=test, key=
,key
部分是空的。在正常运行的区块链中,key
的值应该是GetState(key)
的参数。
那么什么样的错误会导致这种奇怪的情况呢?
我使用的链码可以在 here.
中找到
我自己找到了原因。这是因为 fabric
在实例化链代码时使用 ccenv
图像来构建链代码。此图像在其 GOPATH
中具有指定版本的结构源代码以构建链码。我猜图像中的面料源代码版本应该与用于build/compile面料的源代码相同(包括peer/order等)。并且图片中fabric源码的vendor中有一个依赖工程(github.com/miekg/pkcs11
)。这个项目负责加密的东西。在我的链代码项目中,我还在其他链代码中提供了 github.com/miekg/pkcs11
,但使用了不同的提交版本。似乎会引起冲突。但我不确切知道它是如何引起冲突的。在我删除了我自己销售的 pkcs11
之后。所有的问题都消失了。
我在chaincode dev mode
基于官方chaincode example搭建了一个区块链网络,三个组织,六个peer。我直接将链代码示例部署到区块链网络上。像peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
这样的方式调用chaincode是没有问题的。但是每次我通过 GetState (key)
实现查询的链码查询分类帐时,它总是 return empty value
,即使我可以通过调用 [=] 获得 key/value 对16=] 其中 return 是所有 key/value 对。我检查了安装链代码的对等方的日志。日志如下所示。
2018-01-17 09:01:26.670 UTC [chaincode] processStream -> DEBU 961 [43697748]Received message GET_STATE from shim
2018-01-17 09:01:26.670 UTC [chaincode] handleMessage -> DEBU 962 [43697748]Fabric side Handling ChaincodeMessage of type: GET_STATE in state rea
2018-01-17 09:01:26.670 UTC [chaincode] afterGetState -> DEBU 963 [43697748]Received GET_STATE, invoking get state from ledger
2018-01-17 09:01:26.670 UTC [chaincode] filterError -> DEBU 964 Ignoring NoTransitionError: no transition
2018-01-17 09:01:26.670 UTC [chaincode] func1 -> DEBU 965 [43697748] getting state for chaincode test, key , channel chainplaza
2018-01-17 09:01:26.671 UTC [stateleveldb] GetState -> DEBU 966 GetState(). ns=test, key=
2018-01-17 09:01:26.671 UTC [chaincode] func1 -> DEBU 967 [43697748]No state associated with key: a. Sending RESPONSE with an empty payload
2018-01-17 09:01:26.671 UTC [chaincode] 1 -> DEBU 968 [43697748]handleGetState serial send RESPONSE
2018-01-17 09:01:26.671 UTC [chaincode] processStream -> DEBU 969 [43697748]Received message COMPLETED from shim
2018-01-17 09:01:26.671 UTC [chaincode] handleMessage -> DEBU 96a [43697748]Fabric side Handling ChaincodeMessage of type: COMPLETED in state rea
2018-01-17 09:01:26.671 UTC [chaincode] handleMessage -> DEBU 96b [43697748e1ea4c6f0f6af336f6c413583716c8ec1d59c10118ecfd49bf581509]HandleMessage
2018-01-17 09:01:26.671 UTC [chaincode] notify -> DEBU 96c notifying Txid:43697748e1ea4c6f0f6af336f6c413583716c8ec1d59c10118ecfd49bf581509
2018-01-17 09:01:26.671 UTC [chaincode] Execute -> DEBU 96d Exit
奇怪的是[stateleveldb] GetState -> DEBU 966 GetState(). ns=test, key=
,key
部分是空的。在正常运行的区块链中,key
的值应该是GetState(key)
的参数。
那么什么样的错误会导致这种奇怪的情况呢? 我使用的链码可以在 here.
中找到我自己找到了原因。这是因为 fabric
在实例化链代码时使用 ccenv
图像来构建链代码。此图像在其 GOPATH
中具有指定版本的结构源代码以构建链码。我猜图像中的面料源代码版本应该与用于build/compile面料的源代码相同(包括peer/order等)。并且图片中fabric源码的vendor中有一个依赖工程(github.com/miekg/pkcs11
)。这个项目负责加密的东西。在我的链代码项目中,我还在其他链代码中提供了 github.com/miekg/pkcs11
,但使用了不同的提交版本。似乎会引起冲突。但我不确切知道它是如何引起冲突的。在我删除了我自己销售的 pkcs11
之后。所有的问题都消失了。