简体   繁体   English

HyperLedger结构链代码未更新

[英]HyperLedger fabric chaincode not updated

I am trying to follow along this sample Hyperledger Fabric code: https://github.com/hyperledger/education/tree/master/LFS171x/fabric-material 我正在尝试遵循此示例Hyperledger Fabric代码: https : //github.com/hyperledger/education/tree/master/LFS171x/fabric-material

Initially I replaced chaincode/tuna-app/tuna-chaincode.go with my go file chaincode/tuna-app/test.go. 最初,我用go文件chaincode / tuna-app / test.go替换了chaincode / tuna-app / tuna-chaincode.go。 test.go had changes just in what we initialize in the ledger through its initLedger function call. test.go的更改仅在于我们通过其initLedger函数调用在分类帐中初始化的内容。 It worked fine, with no changes required in tuna-app/.startFabric.sh. 它运行良好,不需要在tuna-app / .startFabric.sh中进行任何更改。

Now when I again try to change the ledger through its initLedger function call, its not happening. 现在,当我再次尝试通过其initLedger函数调用更改分类帐时,它没有发生。 Even if I comment the function itself, it still shows the old content of the ledger. 即使我评论了函数本身,它仍然显示分类帐的旧内容。

How do I update my chaincode with visible changes? 如何使用可见的更改更新链码?

startFabric.sh contains the following code: startFabric.sh包含以下代码:

set -e

# don't rewrite paths for Windows Git Bash users
export MSYS_NO_PATHCONV=1

starttime=$(date +%s)

if [ ! -d ~/.hfc-key-store/ ]; then
    mkdir ~/.hfc-key-store/
fi

# launch network; create channel and join peer to channel
cd ../basic-network
./start.sh

# Now launch the CLI container in order to install, instantiate chaincode
# and prime the ledger with our 10 tuna catches
docker-compose -f ./docker-compose.yml up -d cli

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode install -n tuna-app -v 1.0 -p github.com/test-app
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n tuna-app -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
sleep 10
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n tuna-app -c '{"function":"initLedger","Args":[""]}'

printf "\nTotal execution time : $(($(date +%s) - starttime)) secs ...\n\n"
printf "\nStart with the registerAdmin.js, then registerUser.js, then server.js\n\n"

I tried by adding the following line after peer chaincode instantiate : 我尝试在对等链码实例化之后添加以下行:

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n tuna-app -c '{"function":"initLedger","Args":[""]}'

But it gives the following error: 但是它给出了以下错误:

Error: Chaincode version is not provided for upgrade

When I change upgrade statement to: 当我将升级声明更改为:

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n tuna-app -v 1.0 -c '{"function":"initLedger","Args":[""]}'

Error changes to: 错误更改为:

Error: Error endorsing chaincode: rpc error: code = Unknown desc = chaincode error (status: 500, message: version already exists for chaincode with name 'tuna-app')

To make the changes in the chaincode made reflect, following steps were taken: 1. Stop all the containers 为了反映链码中的更改,采取了以下步骤:1.停止所有容器

docker stop $(docker ps -aq)
  1. Delete all the containers 删除所有容器

docker rm -f $(docker ps -aq)

  1. Find the following image when you run docker images One of the output will be this among the other hyperledger binary images. 当您运行发现下面的图像docker images的一个输出的将是其他hyperledger二进制图像中。

REPOSITORY TAG, IMAGE ID, CREATED, SIZE: dev-peer0.org1.example.com-tuna-app-1.0-b58eb592ed6ced10f52cc063bda0c303a4272089a3f9a99000d921f94b9bae9b, latest, 0919d7c15f0a, 3 minutes ago, 172MB

Delete it using the following command: 使用以下命令将其删除:

docker rmi 0919d7c15f0a

Run the fabric again using ./startFabric.sh, npm install, node registerAdmin.js, node registerUser.js and node server.js. 使用./startFabric.sh、npm install,node registerAdmin.js,node registerUser.js和node server.js再次运行结构。 It should work 它应该工作

I would guess you alrwady have version 1.0 installed, thats why its complaining that it already exists. 我猜您alrwady已经安装了1.0版,这就是为什么它抱怨它已经存在。 Try it with 1.1 or 2.0 by using -v 2.0 instead of -v 1.0 . 通过使用-v 2.0而不是-v 1.0与1.1或2.0一起尝试。

It's pretty tricky once you miss the sequence. 一旦错过序列,这将非常棘手。 As per my knowledge, deployment of a chaincode in HLF is a two step process. 据我所知,在HLF中部署链码是一个两步过程。

Step 1. Transfer the source code into the peer ( each chaincode gets a chaincode id which approximately is a function of their name, path and version). 步骤1.将源代码转移到同位体中(每个链码都获得一个链码ID,该ID大约是其名称,路径和版本的函数)。 This gets signed by your keys and transferred to the all the peers you have chosen as target. 这将由您的密钥签名并转移到您已选择作为目标的所有对等方。 ( This step by the way, is called installation. ) (这个步骤称为安装。)

Step 2. The source code is compiled, with all the vendor libs ( I'm talking about the GoLang chaincode version here, hoping that it would be same for the other ones too.). 步骤2。使用所有供应商库编译源代码(我在这里谈论的是GoLang链码版本,希望其他版本也一样。) A docker image is built and a container gets formed with that binary. 构建了一个docker映像,并使用该二进制文件形成了一个容器。 ( This is the part which is known as instantiation - which also becomes an Upgrade if it's already done earlier. ) (这是称为实例化的部分-如果之前已经完成,则也将成为升级。)

In this process, the step 1 would want the chaincode to be unique. 在此过程中,步骤1将希望链码是唯一的。 If you have installed once, then if you want to send it again, then make sure you have changed the version number to say abc-1.0 to abc-2.0. 如果已安装一次,则要再次发送,请确保已将版本号更改为abc-1.0到abc-2.0。 This will save you at Installation step. 这将在安装步骤中节省您的时间。

Once your installation is successful, then it's the matter of when to call for an upgrade and when not. 一旦安装成功,那么什么时候需要升级就可以了,什么时候不要求升级。 If you have run this container earlier, then right step is to upgrade. 如果您以前运行过此容器,则正确的步骤是升级。

Or the other way around is to do what you did. 或者另一种方法是做您所做的事情。 Clean up and start fresh - which works ok for development, but not for production - as your data goes "poof" with that clean up. 清理并重新开始-这对于开发是可行的,但不适用于生产-因为数据随清理而变得“糟糕”。

when developing chaincode on hyperledger fabric. 在超级账本结构上开发chaincode时。

1: we have to remove chaincode docker image for testing each change. 1:我们必须删除chaincode docker映像以测试每个更改。 For Example: name of install chaincode is mycc 例如:安装链码的名称是mycc

#remove container
docker rm -f $(docker ps -aq)
#remove images
docker rmi mycc-0-container id or name

2: you can install chaincode just by changing its name like mycc is currently running then you have to change mycc1 and now you need to use mycc1 and perform your transactions. 2:您可以仅通过更改其名称来安装chaincode,就像当前正在运行mycc,然后必须更改mycc1,现在需要使用mycc1并执行事务。 For Example: 例如:

#Already install chaincode has named mycc
#following command will install same chaincode(updated) with chaincodeName
#mycc1
docker exec cli peer chaincode install -n mycc1 -v 0 -p github.com/sacc

Note: now you need to instantiate , invoke and query chaincode with name mycc1. 注意:现在您需要实例化,调用和查询名称为mycc1的链码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM