【问题标题】:Failed to submit transaction: Error: no suitable peers available to initialize from提交交易失败:错误:没有合适的节点可用于初始化
【发布时间】:2020-08-21 05:28:57
【问题描述】:

我正在运行我的区块链项目,该项目是使用区块链的选举系统,使用超级账本结构和 IBM 区块链平台 VSCode 扩展(在本地运行我的网络)。我成功运行连接到本地结构,并且我的网关运行成功(附图片)。此外,peer、orderer、certificate authority 的所有 docker 容器都在运行(附图片)。

connected to local fabric and gateway

all docker containers running successfuly

我面临的问题是(在连接到本地结构和网关之后)我使用命令“node invoke.js”运行invoke.js 文件时遇到上述错误。以下图片链接显示了我如何运行 invoke.js

trying to run invoke.js but facing error

以下是我的 config.json 文件代码

    {
  "connection_file": "fabric_connection.json",
  "appAdmin": "admin",
  "appAdminSecret": "adminpw",
  "orgMSPID": "org1MSP",
  "caName": "ca",
  "userName": "V1",
  "gatewayDiscovery": { "enabled": true, "asLocalhost": true }
}

以下是我的 fabric-connection.json 文件代码

{
    "certificateAuthorities": {
        "ca.org1.example.com": {
            "caName": "ca",
            "url": "http://localhost:17090"
        }
    },
    "client": {
        "connection": {
            "timeout": {
                "orderer": "300",
                "peer": {
                    "endorser": "300"
                }
            }
        },
        "organization": "Org1MSP"
    },
    "name": "ca.org1.example.com",
    "organizations": {
        "Org1MSP": {
            "certificateAuthorities": [
                "ca.org1.example.com"
            ],
            "mspid": "Org1MSP",
            "peers": [
                "Org1Peer1"
            ]
        }
    },
    "peers": {
        "Org1Peer1": {
            "url": "grpc://localhost:17091"
        }
    },
    "version": "1.0.0"
}

以下是我的invoke.js文件完整代码

//Import Hyperledger Fabric 1.4 programming model - fabric-network
'use strict';

const { FileSystemWallet, Gateway } = require('fabric-network');
const path = require('path');
const fs = require('fs');

//connect to the config file
const configPath = path.join(process.cwd(), './config.json');
const configJSON = fs.readFileSync(configPath, 'utf8');
const config = JSON.parse(configJSON);

// connect to the connection file
const ccpPath = path.join(process.cwd(), './ibpConnection.json');
const ccpJSON = fs.readFileSync(ccpPath, 'utf8');
const connectionProfile = JSON.parse(ccpJSON);

// A wallet stores a collection of identities for use
const walletPath = path.join(process.cwd(), './wallet');
const wallet = new FileSystemWallet(walletPath);
console.log(`Wallet path: ${walletPath}`);

const peerIdentity = 'admin';

async function queryAll() {
  
  try {

    let response;

    // Check to see if we've already enrolled the user.
    const userExists = await wallet.exists(peerIdentity);
    if (!userExists) {
      console.log('An identity for the user ' + peerIdentity + ' does not exist in the wallet');
      console.log('Run the registerUser.js application before retrying');
      response.error = 'An identity for the user ' + peerIdentity + ' does not exist in the wallet. Register ' + peerIdentity + ' first';
      return response;
    }

    //connect to Fabric Network, but starting a new gateway
    const gateway = new Gateway();

    //use our config file, our peerIdentity, and our discovery options to connect to Fabric network.
    await gateway.connect(connectionProfile, { wallet, identity: peerIdentity, discovery: config.gatewayDiscovery });

    //connect to our channel that has been created on IBM Blockchain Platform
    const network = await gateway.getNetwork('mychannel');

    //connect to our insurance contract that has been installed / instantiated on IBM Blockchain Platform
    const contract = await network.getContract('voteChainDemo'); 
    //submit transaction to the smart contract that is installed / instnatiated on the peers
    console.log('calling contract.evaluateTransaction, with args');
    response = await contract.submitTransaction('queryAll');
    response = JSON.parse(response.toString());
    console.log(`response from evaluateTransaction: ${(response)}`)
   

    console.log('Transaction has been submitted');

    // Disconnect from the gateway.
    await gateway.disconnect();

  } catch (error) {
    console.error(`Failed to submit transaction: ${error}`);
  }
}
// let args = ["V1"]
// args = args.toString();
queryAll();

当我查看 peer0.org1.example.com 的 docker 容器日志时,我看到了以下日志

enter image description here

以下是ibpconnection.json文件的代码

{
  "name": "mychannel",
  "description": "Network on IBP v2",
  "version": "1.0.0",
  "client": {
      "organization": "org1MSP"
  },
  "organizations": {
      "org1MSP": {
          "mspid": "org1MSP",
          "peers": [
              "173.193.112.109:17091"
          ],
          "certificateAuthorities": [
              "173.193.112.109:7054"
          ]
      }
  },
  "orderers": {
      "173.193.112.109:7050": {
          "url": "grpcs://173.193.112.109:17097",
          "tlsCACerts": {
              "pem": "-----BEGIN CERTIFICATE-----\nMIICJzCCAc6gAwIBAgIUCZxOyrvnwM/IG/3zQ9opnOE/gBEwCgYIKoZIzj0EAwIw\nZTELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK\nEwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRYwFAYDVQQDEw1PcmRlcmVy\nQ0EtdGxzMB4XDTE5MDYxNDIwNDcwMFoXDTM0MDYxMDIwNDcwMFowZTELMAkGA1UE\nBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQKEwtIeXBlcmxl\nZGdlcjEPMA0GA1UECxMGRmFicmljMRYwFAYDVQQDEw1PcmRlcmVyQ0EtdGxzMFkw\nEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEOXI7XkoPBn7a9Q1x2S8SpmilQBalhorq\nCo96GChxQU0HJX/1qRPNN72CKx2YS/ksl+eOaHe/+pH32S5VWZLxaKNcMFowDgYD\nVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQEwHQYDVR0OBBYEFIdV28CJ\nPozrl6hpxVkKpNdmAO7vMBUGA1UdEQQOMAyHBK3BcG2HBApM2GAwCgYIKoZIzj0E\nAwIDRwAwRAIgTOPmbGXzIL8SriNT/x8XdBLoTbpEVd/HIpv9nf0bWysCIBvOppOp\nvINgCydCwV1FTbP5tuqYxuShVTAba1h9ZZmm\n-----END CERTIFICATE-----\n"
          }
      }
  },
  "peers": {
      "173.193.112.109:17091": {
          "url": "grpcs://173.193.112.109:17093",
          "tlsCACerts": {
              "pem": "-----BEGIN CERTIFICATE-----\nMIICIzCCAcqgAwIBAgIUbY5U1xnvvSqJ61CgeMp9/qu448owCgYIKoZIzj0EAwIw\nYzELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK\nEwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRQwEgYDVQQDEwtWb3RlckNB\nLXRsczAeFw0xOTA2MTQyMDQwMDBaFw0zNDA2MTAyMDQwMDBaMGMxCzAJBgNVBAYT\nAlVTMRcwFQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEUMBIGA1UEChMLSHlwZXJsZWRn\nZXIxDzANBgNVBAsTBkZhYnJpYzEUMBIGA1UEAxMLVm90ZXJDQS10bHMwWTATBgcq\nhkjOPQIBBggqhkjOPQMBBwNCAASFv8sUAUfTvn8AJ/fiqrk0wdoMaKlG38nU6HZB\nkdUgFWZH9vnlTTBT77+GYRXuv78lg7ttus6DEAJE0X1xDd27o1wwWjAOBgNVHQ8B\nAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQUHuwEDf9d4vrv\nZM+qveoS9PV8/5cwFQYDVR0RBA4wDIcErcFwbYcECkzYYDAKBggqhkjOPQQDAgNH\nADBEAiBjynyKK+Bo4WX3wQII1nk2BU8OaYAuBvpTS/pPROdX+QIgSsLzKWuR7dFN\n50KrbM4ayRuaFBOFL88FflKxaRjQels=\n-----END CERTIFICATE-----\n"
          },
          "grpcOptions": {
              "ssl-target-name-override": "173.193.112.109"
          }
      }
  },
  "certificateAuthorities": {
      "173.193.112.109:7054": {
          "url": "https://173.193.112.109:17090",
          "caName": "ca",
          "tlsCACerts": {
              "pem": "-----BEGIN CERTIFICATE-----\r\nMIICezCCAeSgAwIBAgIJNQli68LG70HNMA0GCSqGSIb3DQEBBQUAMHUxGDAWBgNV\r\nBAMTDzE3My4xOTMuMTEyLjEwOTELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRo\r\nIENhcm9saW5hMRAwDgYDVQQHEwdSYWxlaWdoMQwwCgYDVQQKEwNJQk0xEzARBgNV\r\nBAsTCkJsb2NrY2hhaW4wHhcNMTkwNjE0MjA0NDM2WhcNMjAwNjEzMjA0NDM2WjB1\r\nMRgwFgYDVQQDEw8xNzMuMTkzLjExMi4xMDkxCzAJBgNVBAYTAlVTMRcwFQYDVQQI\r\nEw5Ob3J0aCBDYXJvbGluYTEQMA4GA1UEBxMHUmFsZWlnaDEMMAoGA1UEChMDSUJN\r\nMRMwEQYDVQQLEwpCbG9ja2NoYWluMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\r\ngQCXKBfHLyQfavboQU0y/3S4jlqh6vQgXZKeAMliXfigf6aLG/3Oc4pxuQxBccB6\r\nAiYTFZdShTy2Usx5GsDf5PWxfD4vJ8FWzAGlIYmVqseKXXjsQvwMlCMyS9K2NaDo\r\n9tXwvHz8Sgncq7KccseVYwX4FFpSQWZsIV27Y2xkMZ9bVQIDAQABoxMwETAPBgNV\r\nHREECDAGhwStwXBtMA0GCSqGSIb3DQEBBQUAA4GBAG1+VZNSQdm0DX9CbZzx9zbx\r\nnTEHyrhVTgZs5YuUvZX8BErYfJFxuPBsXhOpQan/L9y+a7C/Caac4WJ/l/l34e5M\r\nG1Hn603wkHpR0UFuGCikdctm+6iHUVro5CMfQlEPIqaJSTFb7Ju5aeeerHnkvQx8\r\nBShP1pNsvsyOctmFhQCQ\r\n-----END CERTIFICATE-----\r\n"
          }
      }
  }
}

【问题讨论】:

  • 你能告诉你连接配置和引发异常的invoke.js的相关部分吗?另外,你能在对等容器的日志中看到任何反应吗?
  • 当然,我已经修改了问题并提供了config.json、local-fabric.json和invoke.js代码
  • 还添加了 peer0.org1.example.com 的容器日志
  • 为什么peer连接不到orderer?订购者日志中有任何提示吗?
  • 想不通。我认为问题出在我现在在问题中添加的 ibpconnection.json 文件中。

标签: visual-studio-code hyperledger-fabric ibm-blockchain


【解决方案1】:

在我的项目中,几乎和你一样,我没有在我的连接配置文件中指定orderers。我不确定您的场景是否需要它。

此外,我认为问题是由您在ibpconnection.jsonfile 中指定的不正确的网址引起的。

orderers 应该有"url": "grpcs://173.193.112.109:7050"

peers 应该有"url": "grpcs://173.193.112.109:17091"

希望这将修复错误。祝你好运!!!!

【讨论】:

  • 另外,也许改变:"ssl-target-name-override": "173.193.112.109""ssl-target-name-override": "peer0.org1.example.com"
猜你喜欢
  • 2015-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-06
  • 1970-01-01
  • 1970-01-01
  • 2021-05-11
  • 2014-04-09
相关资源
最近更新 更多