Hyperledger fabric 无法使用Hyperledger结构节点SDK让对等方加入通道

Hyperledger fabric 无法使用Hyperledger结构节点SDK让对等方加入通道,hyperledger-fabric,hyperledger,Hyperledger Fabric,Hyperledger,我一直在尝试按照这里的说明创建一个新通道(基于现有通道),并让现有的对等方加入该通道 我遇到的错误是在newChannel.joinChannel(j_请求)上。提升[JoinChain][CompositeChannel2]:[在使用策略[Admins]的无通道检查策略期间验证提案的创建者是否满足本地MSP主体时失败:[此标识不是管理员]] 但我不知道如何确保当前用户是管理员 我的网络基于fabric samples目录中的基本网络。我使用fabcar示例中的脚本注册管理员。见下文。然后我尝试

我一直在尝试按照这里的说明创建一个新通道(基于现有通道),并让现有的对等方加入该通道

我遇到的错误是在
newChannel.joinChannel(j_请求)
上。提升
[JoinChain][CompositeChannel2]:[在使用策略[Admins]的无通道检查策略期间验证提案的创建者是否满足本地MSP主体时失败:[此标识不是管理员]]

但我不知道如何确保当前用户是管理员

我的网络基于fabric samples目录中的基本网络。我使用fabcar示例中的脚本注册管理员。见下文。然后我尝试确保管理员用户是提交加入频道请求的当前用户,如下所示:

const setAdminAsUser = async () => {
  try {
    const admin = await fabric_client.getUserContext('admin', true)
    return fabric_client.setUserContext(admin, true)
  } catch(error) {
    console.log('Error setting admin as user', error)
  }
}
然后,我邀请同龄人加入频道的功能如下所示(注意只有一个组织和一个同龄人):

注册管理员的功能,基于fabcar示例:

const enrollAdmin = () => {
  // create the key value store as defined in the fabric-client/config/default.json 'key-value-store' setting
  return Fabric_Client.newDefaultKeyValueStore({ path: store_path}).then((state_store) => {
    // assign the store to the fabric client
    fabric_client.setStateStore(state_store);
    var crypto_suite = Fabric_Client.newCryptoSuite();
    // use the same location for the state store (where the users' certificate are kept)
    // and the crypto store (where the users' keys are kept)
    var crypto_store = Fabric_Client.newCryptoKeyStore({path: store_path});
    crypto_suite.setCryptoKeyStore(crypto_store);
    fabric_client.setCryptoSuite(crypto_suite);
    var tlsOptions = {
      trustedRoots: [],
      verify: false
    };
    // be sure to change the http to https when the CA is running TLS enabled
    fabric_ca_client = new Fabric_CA_Client('http://localhost:7054', tlsOptions , 'ca.org1.example.com', crypto_suite);
    // first check to see if the admin is already enrolled
    return fabric_client.getUserContext('admin', true);
  }).then((user_from_store) => {
    if (user_from_store && user_from_store.isEnrolled()) {
      console.log('Successfully loaded admin from persistence');
      admin_user = user_from_store;
      return null;
    } else {
      // need to enroll it with CA server
      return fabric_ca_client.enroll({
        enrollmentID: 'admin',
        enrollmentSecret: 'adminpw'
      }).then((enrollment) => {
        console.log('Successfully enrolled admin user "admin"');
        return fabric_client.createUser(
            {username: 'admin',
              mspid: 'Org1MSP',
              cryptoContent: { privateKeyPEM: enrollment.key.toBytes(), signedCertPEM: enrollment.certificate }
            });
      }).then((user) => {
        admin_user = user;
        return fabric_client.setUserContext(admin_user);
      }).catch((err) => {
        console.error('Failed to enroll and persist admin. Error: ' + err.stack ? err.stack : err);
        throw new Error('Failed to enroll admin');
      });
    }
  }).then(() => {
      console.log('Assigned the admin user to the fabric client ::' + admin_user.toString());
  }).catch((err) => {
      console.error('Failed to enroll admin: ' + err);
  });
}
用教程文档敲打砖墙,所以任何帮助都会非常棒

编辑:

下面是我当前如何生成配置更新,然后对其进行签名。这是基于SDK教程的

// This takes a config file that includes the organisations that will be added to the channel
const encodeChannelConfig = () => {
  return new Promise((resolve, reject) => {
    console.log('encoding channel config')

    var config_json = fs.readFileSync("./newChannel.json");
    config_json = JSON.stringify(JSON.parse(config_json))

    superagent.post('http://127.0.0.1:7059/protolator/encode/common.ConfigUpdate',
      config_json)
      .buffer()
      .end((err, res) => {
        if(err) {
          return;
        }
        resolve(res.body);
      });
  })
}

const signChannelConfig = (encodedChannelConfig) => {
  return new Promise((resolve, reject) => {
    console.log('signing channel config')

    var signature = fabric_client.signChannelConfig(encodedChannelConfig);
    signatures.push(signature);
    resolve(signatures);
  })
}

如果尚未在fabric\u客户端上执行setAdminSigningIdentity,请尝试

这将允许在使用true选项执行newTransactionID时使用管理员凭据

注意:此管理员与CA中的管理员用户不同,私钥和证书由cryptogen生成,并且可能位于类似的目录中

加密配置/peerOrganizations/org1/users/Admin@org1/msp/密钥库


加密配置/peerOrganizations/org1/users/Admin@org1/msp/签名证书

谢谢Eric。我想,setAdminSigningIdentity克服了我所犯的错误。但是
newChannel.joinChannel(j_请求)
仍然失败,现在出现了以下错误:
[{错误:2未知:拒绝访问:channel[]creator org[Org1MSP]
。该通道数组看起来不是空的,但我真的不知道会发生什么。您是否执行了client.createChannel(请求)在执行joinChannel之前的某个时刻?此步骤也需要管理员凭据。是的,但当我在createChannel之前执行setAdminSigningIdentity时,提交响应如下所示:
{状态:'禁止',信息:'未能达到1个子策略的隐式阈值,需要剩余1个:权限被拒绝'}
检查createChannel请求中包含的签名。通过在请求对象中不包含任何签名,我可以重新创建相同的错误消息。再次感谢。我已更新了问题,以显示我如何生成配置更新并对其签名。在这些步骤之前,我将调用setAdminSigningIdentity,因此我相信配置应该由组织管理员签名。是否有其他方法检查签名,你知道吗?
// This takes a config file that includes the organisations that will be added to the channel
const encodeChannelConfig = () => {
  return new Promise((resolve, reject) => {
    console.log('encoding channel config')

    var config_json = fs.readFileSync("./newChannel.json");
    config_json = JSON.stringify(JSON.parse(config_json))

    superagent.post('http://127.0.0.1:7059/protolator/encode/common.ConfigUpdate',
      config_json)
      .buffer()
      .end((err, res) => {
        if(err) {
          return;
        }
        resolve(res.body);
      });
  })
}

const signChannelConfig = (encodedChannelConfig) => {
  return new Promise((resolve, reject) => {
    console.log('signing channel config')

    var signature = fabric_client.signChannelConfig(encodedChannelConfig);
    signatures.push(signature);
    resolve(signatures);
  })
}