【问题标题】:IBM Blockchain Platform Nodejs client app can't submit transaction: No peers defined for MSP 'org1Admin' to discover fromIBM Blockchain Platform Nodejs 客户端应用程序无法提交事务:没有为要从中发现的 MSP 'org1Admin' 定义对等方
【发布时间】:2020-06-04 18:45:34
【问题描述】:

我在 IBM Blockchain Platform 云中部署了一个非常基本的 IBM Blockchain 网络:只有一个对等组织和一个订购者组织。我已经安装并实例化了一个非常基本的合约(只是 CRUD 操作),现在我正在尝试使用模板 Nodejs 客户端应用程序为我的资产提交创建交易;这是我的代码:

'use strict';

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

async function main() {
  try {

    // Parse the connection profile. This would be the path to the file downloaded
    // from the IBM Blockchain Platform operational console.
    const ccpPath = path.resolve(__dirname, 'connection.json');
    const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));

    // Configure a wallet. This wallet must already be primed with an identity that
    // the application can use to interact with the peer node.
    const walletPath = path.resolve(__dirname, 'wallet');
    const wallet = new FileSystemWallet(walletPath);

    // Create a new gateway, and connect to the gateway peer node(s). The identity
    // specified must already exist in the specified wallet.
    const gateway = new Gateway();

    await gateway.connect(ccp, { wallet: wallet, identity: 'orgAdmin' , discovery: {"enabled": true, "asLocalhost":false }});

    // Get the network channel that the smart contract is deployed to.
    const network = await gateway.getNetwork('erschannel');

    // Get the smart contract from the network channel.
    const contract = network.getContract('ers_contract');

    // Submit the 'createCar' transaction to the smart contract, and wait for it
    // to be committed to the ledger.
    await contract.submitTransaction('createErsGenHash', 'ersGenHashId_1', 'ersGenHashId_1_value');
    console.log('Transaction has been submitted');

    await gateway.disconnect();

    } catch (error) {
      console.error(`Failed to submit transaction: ${error}`);
      process.exit(1);
    }
  }
main();

我已成功注册身份 orgAdmin 并将其下载到我的本地钱包中(至少我做对了!!)。执行上述操作时,出现以下错误:

C:\work\hlf>node invoke.js
2020-06-04T18:34:28.213Z - error: [Network]: _initializeInternalChannel: No peers defined for MSP 'orgAdmin' to discover from
Failed to submit transaction: Error: No peers defined for MSP 'orgAdmin' to discover from

这是我的 connection.json 配置文件(我从 IBM Blockchain Platform 控制台下载的);奇怪的是没有orderer信息:

{
    "name": "ORG1MSPprofile",
    "description": "Network on IBP v2",
    "version": "1.0.0",
    "client": {
        "organization": "ORG1MSP"
    },
    "organizations": {
        "ORG1MSP": {
            "mspid": "ORG1MSP",
            "certificateAuthorities": [
                "184.172.233.238:31951"
            ],
            "peers": [
                "184.172.233.238:30604"
            ]
        }
    },
    "peers": {
        "184.172.233.238:30604": {
            "url": "grpcs://184.172.233.238:30604",
            "tlsCACerts": {
                "pem": "-----BEGIN CERTIFICATE-----\nxxxxxxxxxxx\n-----END CERTIFICATE-----\n"
            },
            "grpcOptions": {
                "ssl-target-name-override": "184.172.233.238"
            }
        }
    },
    "certificateAuthorities": {
        "184.172.233.238:31951": {
            "url": "https://184.172.233.238:31951",
            "caName": "ca",
            "tlsCACerts": {
                "pem": "-----BEGIN CERTIFICATE-----\nxxxxxxxxxxx\n-----END CERTIFICATE-----\n"
            }
        }
    }
}

我怀疑问题在于我如何配置 IBM 云区块链网络。我按照here 的关于构建网络的官方教程进行操作。

【问题讨论】:

    标签: hyperledger-fabric ibm-blockchain


    【解决方案1】:

    你的问题的关键是这个错误信息

    Error: No peers defined for MSP 'orgAdmin' to discover from
    

    您已在钱包中注册您的身份,mspid 为orgAdmin。在您的连接配置文件中,定义的 mspid 是 ORG1MSP

        "organizations": {
            "ORG1MSP": {
                "mspid": "ORG1MSP"
    

    因此,当客户端尝试查找与您选择的身份一起使用的对等方时,它会尝试查找属于组织一部分的对等方,其 mspid orgAdmin 在您的连接配置文件中不是已知的 mspid,因此导致您看到的错误消息。解决方案是删除并重新导入您的身份(或从新钱包开始)并使用正确的 mspid 再次导入身份。

    此外,完全预计连接配置文件中没有订购者列表。这称为动态连接配置文件,包含交互所需的最少信息。其余所需信息(例如其他对等方和订购者)是来自客户端 sdk 的对等方的discovered。正如您在代码中看到的那样,您已指定启用发现。

    【讨论】:

    • 非常感谢;正如您所说,问题在于将身份导入钱包时;以前我用X509WalletMixin.createIdentity("orgAdmin", enrollment.certificate, enrollment.key.toBytes()); 导入它现在我用X509WalletMixin.createIdentity("ORG1MSP", enrollment.certificate, enrollment.key.toBytes()); 替换它并且它可以工作;我想这是有道理的:身份是由部分(用户)与更大的整体(组织)的组合给出的。
    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-29
    相关资源
    最近更新 更多