为什么peer chaincode实例化成功执行多次

问题描述 投票:1回答:4

我可以成功执行peer chaincode instantiate多次,它应该返回它存在,但没有。为什么?

logs after instantiate command

logs the docker returns

脚步:

来自my github project chaincode-docker-devmode,我复制msp(peer和orderer一起使用),genesis.block,helloch.tx,docker-compose-with-couch.yaml等形成其他地方,应该没问题。当我执行:

docker-compose -f docker-compose-with-couch.yaml up

peer,orderer,couchdb0,cli start然后cli执行script.sh

#script.sh content
peer channel create -c helloch -f helloch.tx -o orderer:7050
peer channel join -b helloch.block

然后我在chaincode-docker-devmode当前路径使用终端模拟cli环境,方法如下:

#cli simulation, $pwd  is the chaincode-docker-devmode path
export CORE_VM_ENDPOINT=unix:///var/run/run/docker.sock
export CORE_LOGGING_LEVEL=DEBUG
export CORE_PEER_ID=cli
export CORE_PEER_ADDRESS=127.0.0.1:7051
export CORE_PEER_LOCALMSPID=DEFAULT
export CORE_PEER_MSPCONFIGPATH=$pwd/msp
bash

当我执行peer channel list它可以显示我加入了helloch

渠道。然后我执行:

peer chaincode install -n hello -v 1.0 -l java -p chaincode/hsl-hsl-user-guide-examples-v14/mytest
peer chaincode instantiate -o 127.0.0.1:7050 -C helloch  -n hello -v 1.0 -l java -c "{\"Args\":[\"init\",\"a\", \"100\", \"b\",\"100\"]}"

但是我可以多次实例化并且日志不会返回错误as same as above instantiate logs,实际上它没有成功实例化,为什么?

hyperledger-fabric
4个回答
4
投票

链代码的实例化本质上是一个事务,因此它必须得到认可,排序和承诺才能生效。现在,在您的情况下,peer cli instantiate命令成功,因为事务提议已成功签署并签署提交给订购服务的提案。同时基于以下日志输出:

peer        | 2017-09-05 01:09:23.650 UTC [ConnProducer] NewConnection -> ERRO 6da Failed connecting to 127.0.0.1:7050 , error: context deadline exceeded
peer        | 2017-09-05 01:09:23.650 UTC [deliveryClient] connect -> ERRO 6db Failed obtaining connection: Could not connect to any of the endpoints: [127.0.0.1:7050]

Peer无法连接到订购服务端点,在您的情况下配置为127.0.0.1:7050,因此最终实例化事务未提交。因此,您可以再次执行instantiate命令,因为先前尝试的对等分类帐中不存在实例化事务记录。

您需要将订购服务端点从127.0.0.1:7050更改为orderer:7050并重试您的实验。此值在configtx.yaml文件中配置,例如:

Orderer: &OrdererDefaults

    # Orderer Type: The orderer implementation to start
    # Available types are "solo" and "kafka"
    OrdererType: solo

    Addresses:
        - orderer:7050

2
投票

在我的情况下,这给了我麻烦,因为我没有在调用调用/查询事务之前给实例化过程足够的时间。

尝试在实例化和调用/查询事务之间添加sleep命令:

peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n fabcar -l "$LANGUAGE" -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"

# Sleeping to allow time for chaincode to instantiate on peers
sleep 30

peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n fabcar -c '{"function":"initLedger","Args":[""]}'

这仅适用于您在某种CLI容器中运行“启动”脚本的情况。在我的情况下,我有script.sh,当我第一次启动网络时运行。


0
投票

您只能将具有相同名称的链代码实例化一次。


0
投票
peer channel create -c helloch -f helloch.tx -o 127.0.0.1:7050

在上面之后,你可以通过命令看到helloch.block详细信息

configtxgen --inspectBlock helloch.block

表明

"OrdererAddresses": {
                "Version": "0",
                "ModPolicy": "/Channel/Orderer/Admins",
                "Value": {
                    "addresses": [
                        "127.0.0.1:7050"
                    ]
                }
            },

似乎helloch.block(通道配置)中连接的orderer地址来自genesis.block(从configtx.yaml生成)

© www.soinside.com 2019 - 2024. All rights reserved.