Blockchain Hyperledger Fabric — 问题和解决方案

外网看到了一个关于fabric网络搭建遇到问题的好文,搬运过来
Blockchain Hyperledger Fabric — Errors & Solutions
Hello, In this article I wanted to share some of the errors you might face & the possible solutions.
please note that, I have faced “n” number of errors while I was working in Blockchain project, I have spent countless hours reading out articles, reaching out experts to fix the same. This article is to just help the people who are beginners & struggling to solve the errors that are quite often pop up during your development stage. If you have any errors that are not listed here, please feel free to comments, will get it added .
Error No 1:
Error: Error trying to ping. Error: 2 UNKNOWN: make sure the chaincode test-registry has been successfully instantiated and try again: could not find chaincode with name ‘test-registry’
Solutions: Make sure that you have installed the network before you start. Use below commands to start the network

  • composer network install — card PeerAdmin@hlfv1 — archiveFile network-name@0.0.1.bna
  • composer network start — networkName networkname — networkVersion 0.0.1 — networkAdmin admin — networkAdminEnrollSecret adminpw — card PeerAdmin@hlfv1 — file networkadmin.card
    Error No 2:
    Error:
    docker: Error response from daemon: Conflict. The container name “/composer-playground” is already in use by container “9f224b04663a4fa65f50843e5f7e28f7e7df662507a9b42ae5dfc72fd3433405”. You have to remove (or rename) that container to be able to reuse that name.
    See ‘docker run — help’.
    Solutions: Kill the dockers by running following command & re-execute the composer-playground command (“docker run — name composer-playground — publish 8080:8080 hyperledger/composer-playground”)
    docker rm -f $(docker ps -a -q)
    docker kill $(docker ps -q)
    docker rm $(docker ps -aq)
    docker rmi $(docker images dq-* -q)
    Error No 3:
    Error: Chaincode already exists error
    Solutions: Kill docker images, stop fabric & start fabric again. Once it runs fine, then start deploying the business network card again.
    ./stopFabric.sh
    ./startFabric.sh
    Error No 4:
    Error: NG Serve Error
    Solutions: Use npm instead of ng serve.
    npm start
    Error No 5:
    Error: Authorisation error REST-API
    Solutions: Setup COMPOSER_PROVIDERS in environment variable, and restart the composer-rest-server
    Follow this link https://github.com/hyperledger/composer/blob/master/packages/composer-website/jekylldocs/integrating/enabling-rest-authentication.md
    Error No 6:
    Discovering types from business network definition …
    Connection fails: Error: Error trying to ping. Error: 2 UNKNOWN: make sure the chaincode ‘network-name’ has been successfully instantiated and try again: could not find chaincode with name ‘network-name’
    Solutions: Make sure to install & start the business network before you run composer-rest-server command.
    1)composer network install — card PeerAdmin@hlfv1 — archiveFile network-name@0.0.1.bna
    2)composer network start — networkName ‘network-name’ — networkVersion 0.0.1 — networkAdmin admin — networkAdminEnrollSecret adminpw — card PeerAdmin@hlfv1 — file networkadmin.card
    ERROR No 7:
    ERROR: for couchdb Cannot create container for service couchdb: Conflict. The container name “/couchdb” is already in use by container “de8ceaf8f21b53bb4c9883eb618448f6f07c7690bea8ab122ef3b689e846eab4”. You have to remove (or rename) that Creating orderer.example.com … error
    Solutions: Kill the dockers by running following command
    docker rm -f $(docker ps -aq)
    Error No : 8
    Error: Cannot find module ‘fabric-client’
    Solution: Perform npm update, this will install necessary plug-in’s & modules.
    npm update
    Error No : 9
    Error: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install?
    Solution: perform npm install, this will install necessary node_modules.
    npm install
    Error No: 10
    Error: Angular2 app generated by “yo fabric-composer” does not have UI for Transactions
    Solutions: We have issue open in Github — please follow the issue for more updates
    Solution Update :
    Go to .component.html file in src/app/ folder and check for line
    <button type=”button” class=”btn btn-primary invokeTransactionBtn” data-toggle=”modal”>Invoke
    Just add data-target attribute to it as below:
    <button type=”button” class=”btn btn-primary invokeTransactionBtn” data-toggle=”modal” data-target=”#addTransactionModal”>Invoke
    #addTransactionModal is the id for the modal which has the form.
    LInk : https://github.com/hyperledger/composer/issues/4121
    Error No: 11
    Error: Connection fails: Error: Error trying to ping. Error: Composer runtime (0.19.8) is not compatible with client (0.19.5)
    It will be retried for the next request.
    Solutions:
    ./stopFabric.sh
    npm install -g composer-playground@0.19.8
    composer-rest-server
    Error No 12:
    ERROR: curl: (7) Failed to connect to localhost port 49160: Connection refused
    Solution: docker run — rm -i -t -p 49160:8080 /node-app
    Note: This kind of error will only shoot up, when you build your own docker container & trying to execute it.
    Error No 13:
    ERROR: network composer_default id b1067bdec4ca1800510fc9cc1f5d3500736e48920693b03831df0d8d8472ffac has active endpoints
    You might hit this error, when you trying to execute new fabric-server(but the old one still in running state)
    Solutions : Stop the already running fabric server, using .stopFabric.sh or .stop.sh(whatever the script you has in your network), then apply the following command to remove the running docker containers, and re-execute the fabric
    docker rm -f $(docker ps -a -q)
    Error No 14:
    Error: Node.JS Error: ENOSPC
    Solution : https://stackoverflow.com/questions/22475849/node-js-error-enospc .
    Error NO 15:
    Error: failed to create deliver client: orderer client failed to connect to orderer.example.com:7050: failed to create new connection: context deadline exceeded
    Solution : You need to review the Orderer logs first to ensure what’s happening under the hood.
    Step 1: docker logs orderer.example.com
    Step 2: go to configtx.yaml file and check the capabilities
    ensure you have right versions downloaded
    Error No 16:
    Error: Failed to import the business network card
    Failed to import the business network card
    keyword: required
    dataPath: .peers[‘peer0.org1.example.com’]
    schemaPath: #/required
    params:
    missingProperty: eventUrl
    message: should have required property ‘eventUrl’
    Error: Errors found in the connection profile in the card
    Command failed
    Solution: You are trying to run fabric v1.1, but it pulls out fabric v1.2 createpeeradmin.sh
    Error No : 17
    Error: container is marked for removal and cannot be started
    Sometimes, when you kill / remove containers, it would sit up in “Removal Queue” or in “Dead Status”, that would be mounted forever and will not allow you to run your next steps… So you have to remove the containers using below command. this kills all the containers that are marked in DEAD state.
    Solution: docker rm $(docker ps — all -q -f status=dead)
    Error No : 18
    Error: sendPeersProposal — Promise is rejected: Error: chaincode with name ‘chain-code-name’ already exists
    Situtation — Occurred while instantiating chaincode
    Solutions: This error mostly would occur due to the fact that, chaincode would have already instantiated on peers. So get rid of this, remove the node_modules & do npm install once it finishes fine, restart the “install chaincode” and then “instantitaet chaincode”.
    Or
    Use different chain_node id
    Error No : 19
    CRIT 008 Error on outputBlock: Error writing genesis block: open ./channel-artifacts/genesis.block: no such file or directory
    Solution : Create channel-artifacts folder before you run the command
    ./configtxgen -profile FourOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
    Error No : 20
    Error: readBlock -> DEBU 00a Got status: &{FORBIDDEN} Error: can’t read the block: &{FORBIDDEN}
    Solution : Make sure, before you start your network no other containers are running behind. This error occurs due to permission issues, that containers are in conflict with existing containers. Goahead, kill the containers using docker rm -f $(docker ps -a -q) command & restart your network.
    Error No : 21
    grpc: addrConn.createTransport failed to connect to {peer0.org1.example.com:7051 0 }. Err :connection error: desc = “transport: Error while dialing dial tcp: lookup peer0.org1.example.com on 127.0.0.11:53: no such host”. Reconnecting…
    Solution: … to be identified…
    Error No : 22
    Error: Network Not found issue
    Solution : Go to ./peer-base.yaml and change CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE to the corresponding network name. Clean the docker containers and then rebuild
    Error No : 23
    Error: Sending the Instantiate Proposal …
    error: [Peer.js]: sendProposal — timed out after:45000
    Solution: …
    Note: After some time, it ran fine. but I will keep it updated when I face it again.
    Error No : 24
    Error: could not assemble transaction: ProposalResponsePayloads do not match — proposal response: version:1 response:<status:200 >
    Solution: Make sure, yo have installed Chaincode in the peers you are trying to invoke the transactions. Set the environment variables for the peers. For instance :
    CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp CORE_PEER_ADDRESS=peer0.org2.example.com:7051 CORE_PEER_LOCALMSPID=”Org2MSP” CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
    Error No :25
    Error: Calling enrollment endpoint failed with error [Error: connect ECONNREFUSED 127.0.0.1:7054]
    Solution: Regenerate Crypto Files, then point the secretKey in docker-composer-yaml file for ca-fabric (if 7054 is pointeed to CA-fabric)
    Error No : 26 instantiate-chaincode-Instantiate proposal was bad
    This error would mostly occur when you try to instantiate the Chaincode.
    Solution: you should understand the basic flow how it works first?, when you install Chaincode on peers, it would mostly be successfull, but after you install and instantiate the chaincode it would perform lot of actions such as
    Scanning for Chaincode Syntax, Logical issues, etc.,
    Bundling the code together
    Trying to create a container with chaincodename-chaincode version
    So what happen is that, the “Chaincode” instantitation mostly would fail in “Syntax checking & logical issues in your chaincode”… To identify the same, run the following command in separate terminal
    docker logs -f peer0.org1.example.com
    Here, peer should be the one where you are trying to instantiate. this will give you clear logs behind , what’s happening and where the errors are being thrown, fix the errors & re install , instantitate… YOU SHOULD BE GOOD TO GO
    Error 27: instantiate-chaincode — Error: ChannelEventHub has been shutdown
    Solution: Mostly this occurs in “instantiate-chaincode” section, eventhub will get disconnect when it finds more than one chaincode version (when you upgraded with multiple version of same chaincode). Just kill all the containers, just keep the one that’s the latest version then try install & instantitate the chaincode
    Error 28: instantiate-chaincode — Error: ChannelEventHub has been shutdown
    Solution: Mostly this occurs in “instantiate-chaincode” section, eventhub will get disconnect when it finds more than one chaincode version (when you upgraded with multiple version of same chaincode). Just kill all the containers, just keep the one that’s the latest version then try install & instantitate the chaincode
    Error 29: Cannot use encKey (type string) as type []byte in argument to entities.NewAES256EncrypterEntity
    Error 30: instantiate Proposal was bad — Chaincode
    Solution: When you find this error,
    i) Check if you have right fabric-client & fabric-ca-client by using below command
    npm ls fabric-client
    npm ls fabric-ca-client
    Ensure, you have right compatible docker images with respect to fabric-client version.
    ERROR 31: docker: Got permission denied while trying to connect to the Docker daemon socket at unix
    Solution: sudo usermod -a -G docker $USER
    Perform this operation in your terminal, close it and re-open the terminal. if issue still persists, then re-boot your system.
    ERROR 32: [Remote.js]: Error: Failed to connect before the deadline URL:grpcs://localhost:7051
    ERROR 33: response ::{“status”:”BAD_REQUEST”,”info”:”error authorizing update: error validating ReadSet: readset expected key [Group] /Channel/Application at version 0, but got version 1"}
    SOLUTION : Mostly you will get this error when you trying to create a channel where channel would have already got created. So you can ignore this message and proceed with “JOIN Channel”
    ERROR 34: response ::{“status”:”FORBIDDEN”,”info”:”Failed to reach implicit threshold of 1 sub-policies, required 1 remaining: permission denied”}
    ERROR 35 : affiliation validation: Failed getting affiliation ‘org3.department1
    Solutions: the issue is that the fabric-ca being used in the sample does not know about the new affiliation. By default, fabric-ca only has the following affiliations:
    org1.department1 org1.department2 org2.department1
    go to app/helper.js and update the logic like below, replace getRegisteredUser function with below logic.
    var getRegisteredUser = async function(username, userOrg, isJson) {
    try {
    var client = await getClientForOrg(userOrg);
    logger.debug(‘Successfully initialized the credential stores’);
    // client can now act as an agent for organization Org1
    // first check to see if the user is already enrolled
    var user = await client.getUserContext(username, true);
    if (user && user.isEnrolled()) {
    logger.info(‘Successfully loaded member from persistence’);
    var response = {
    success: false,
    };
    return response;
    } else {
    // user was not enrolled, so we will need an admin user object to register
    logger.info(‘User %s was not enrolled, so we will need an admin user object to register’,username);
    var admins = hfc.getConfigSetting(‘admins’);
    let adminUserObj = await client.setUserContext({username: admins[0].username, password: admins[0].secret});
    //newly added
    if(adminUserObj.getAffiliation() != userOrg.toLowerCase()){
    logger.info(‘Admin affiliation not registered. Registering now.’);
    adminUserObj.setAffiliation(userOrg.toLowerCase());
    adminUserObj.setRoles([‘peer’,’orderer’,’client’,’user’]);
    adminUserObj = await client.setUserContext(adminUserObj);
    }
    logger.info(‘Admin User: %s’, adminUserObj);
    let affiliation = userOrg.toLowerCase() + ‘.department1’;
    let caClient = client.getCertificateAuthority();
    //check if org exists
    const affiliationService = caClient.newAffiliationService();
    const registeredAffiliations = await affiliationService.getAll(adminUserObj);
    if(!registeredAffiliations.result.affiliations.some(x => x.name == userOrg.toLowerCase())){
    logger.info(‘Register the new affiliation: %s ‘, affiliation);
    await affiliationService.create({name: affiliation, force: true}, adminUserObj);
    }
    let secret = await caClient.register({
    enrollmentID: username,
    affiliation: affiliation
    }, adminUserObj);
    logger.debug(‘Successfully got the secret for user %s — %s’,username);

user = await client.setUserContext({username:username, password:secret});
logger.debug(‘Successfully enrolled username %s and setUserContext on the client object’, username);

}
if(user && user.isEnrolled) {
if (isJson && isJson === true) {
var response = {
success: true,
secret: user._enrollmentSecret,
message: username + ‘ enrolled Successfully’,
};
return response;
}
} else {
throw new Error(‘User was not enrolled ‘);
}
} catch(error) {
let message = ‘Failed to register the username ‘ + username + ‘ for organization ‘ + userOrg + ‘ with error: ‘ + error.toString();
logger.error(message);
var response = {
success: false,
message: message,
};
return response;
}
};
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -
Note: Like this article?, give Logeswaran a thumbs-up(Claps) & follow him on Linkedin / Twitter
Do you have an error which is not listed here? pls go ahead and add that in the comment section below.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 答:要使Hyperledger Fabric与Python链接,您可以使用Hyperledger Fabric SDK for Python或Hyperledger Fabric Node SDK for Python,它们都可以帮助您与Hyperledger Fabric网络交互。 ### 回答2: 要将Hyperledger Fabric与Python连接起来,可以使用Fabric提供的Python SDK来实现。 首先,需要在Python环境中安装Fabric的Python SDK。可以使用pip命令来安装,如下所示: ```shell pip install fabric-sdk-py ``` 安装完成后,可以在Python脚本中导入SDK相关的包,如: ```python from hfc.fabric import Client ``` 然后,需要创建一个Client实例,该实例将用于连接和与Fabric网络进行交互。在创建实例时,需要指定Fabric网络的配置文件路径,如: ```python client = Client(net_profile="path_to_network_config.yaml") ``` 接下来,需要根据实际情况设置与Fabric网络连接的相关参数。可以使用client对象的一些方法来设置,如: ```python client.set_peer_tls_certs("peer_name", "path_to_cert") client.set_orderer_tls_certs("orderer_name", "path_to_cert") ``` 然后,可以使用client对象提供的各种方法来与Fabric网络进行交互,如创建通道、加入组织、查询链码等操作。例如,查询链码可以使用以下代码: ```python response = client.query_instantiated_chaincodes(channel_name="mychannel", peers=["peer_name"]) print(response) ``` 最后,可以使用client对象的方法来与Fabric网络断开连接,并释放资源,如: ```python client.close() ``` 以上是一个简单的示例,演示了如何将Hyperledger Fabric与Python连接起来,并进行一些基本的操作。具体的使用方法还可以根据实际需求和业务场景进行进一步的深入学习和应用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值