fabric-gateway 在 Node.js 上需要 4 分钟来完成成功或失败。

huangapple go评论84阅读模式
英文:

fabric-gateway on node.js takes 4 minutes to complete fail or success

问题

I'm trying to migrate from fabric-network to fabric-gateway, in largely due to experiencing an issue with fabric-network where hundreds of connections are left open and eventually clog the server. I've read this is not that uncommon and that a solution would be to use fabric-gateway. However, the fabric-gateway implementation is somewhat different. My current implementation is taking 4 minutes (I measure the time) to complete, whether it's a success or failure. By that time, the API call (via Postman) triggered the SDK times out, but I eventually I get a response in the console.

This is the main code, pretty straightforward:

// IDENTITY
const credentials = fs.readFileSync(CERT_PATH);
console.log({ credentials });
const identity = { mspId: "Org1MSP", credentials };

// SIGNER
const privateKeyPem = fs.readFileSync(PK_PATH);
const privateKey = crypto.createPrivateKey(privateKeyPem);
console.log({ privateKey });
const signer = signers.newPrivateKeySigner(privateKey);

// CLIENT
const rootCERT = await fs.readFileSync(ROOT_PATH);
const tlsCredentials = await grpc.credentials.createSsl(rootCERT);
console.log({ tlsCredentials });
const client = new grpc.Client("localhost:7051", tlsCredentials, {
"grpc.ssl_target_name_override": "peer0.org1.example.com",
"grpc.default_authority": "localhost:7054",
});
console.log({ client });
const gateway = connect({ identity, signer, client });
try {
const network = gateway.getNetwork("mychannel");
const contract = network.getContract("transaction");
const stringQuery = {"selector": { "transactionId": {"$ne":"0"} } };
const res = await contract.evaluateTransaction(
"QueryTransaction",
stringQuery
);
console.log("RESULT:", decoder.decode(res));
} finally {
gateway.close();
client.close();
}

I've tested the code above in my local environment, and it works just fine. But when I have it run on the TEST environment, it takes 4 minutes to resolve.

A couple of differences among environments:

  • My local implementation uses Root CA, and the TEST network implements Intermediate CA. So for the latter, I use a chain certificate.
  • My local implementation is running both peer and ordered nodes at 2.4.0, while the Test network has peer at 2.4.0 and ordered at 2.4.5.

I've also found this issue https://github.com/hyperledger/fabric/issues/3224 which talks a bit about a similar problem, but with the GO SDK, and If I understood correctly, It should be fixed.

It's worth mentioning that it takes (almost) exactly 4 minutes each time. Almost as if it were configured to last 360 seconds...

英文:

I'm trying to migrate from fabric-network to fabric-gateway, in largely due to experiencing an issue with fabric-network where hundreds of connections are left open and eventually clog the server. I've read this is not that uncommon and that a solution would be to use fabric-gateway. However, the fabric-gateway implementation is somewhat different. My current implementation is taking 4 minutes (I measure the time) to complete, whether it's a success or failure. By that time, the API call (via Postman) triggered the SDK times out, but I eventually I get a response in the console.

This is the main code, pretty straightforward:

  // IDENTITY
  const credentials = fs.readFileSync(CERT_PATH);
  console.log({ credentials });
  const identity = { mspId: "Org1MSP", credentials };

  // SIGNER
  const privateKeyPem = fs.readFileSync(PK_PATH);
  const privateKey = crypto.createPrivateKey(privateKeyPem);
  console.log({ privateKey });
  const signer = signers.newPrivateKeySigner(privateKey);

  // CLIENT
  const rootCERT = await fs.readFileSync(ROOT_PATH);
  const tlsCredentials = await grpc.credentials.createSsl(rootCERT);
  console.log({ tlsCredentials });
  const client = new grpc.Client("localhost:7051", tlsCredentials, {
    "grpc.ssl_target_name_override": "peer0.org1.example.com",
    "grpc.default_authority": "localhost:7054",
  });
  console.log({ client });
  const gateway = connect({ identity, signer, client });
  try {
    const network = gateway.getNetwork("mychannel");
    const contract = network.getContract("transaction");
    const stringQuery = `{"selector": { "transactionId": {"$ne":"0"} } }`;
    const res = await contract.evaluateTransaction(
      "QueryTransaction",
      stringQuery
    );
    console.log("RESULT:", decoder.decode(res));
  } finally {
    gateway.close();
    client.close();
  }

I've tested the code above in my local environment, and it works just fine. But when I have it run on the TEST environment, it takes 4 minutes to resolve.

A couple of differences among environments:

  • My local implementation uses Root CA, and the TEST network implements Intermediate CA. So for the latter, I use a chain certificate.
  • My local implementation is running both peer and ordered nodes at 2.4.0, while the Test network has peer at 2.4.0 and ordered at 2.4.5.

I've also found this issue https://github.com/hyperledger/fabric/issues/3224 which talks a bit about a similar problem, but with the GO SDK, and If I understood correctly, It should be fixed.

It's worth mentioning that it takes (almost) exactly 4 minutes each time. Almost as if it were configured to last 360 seconds...

答案1

得分: 0

如果您遇到了这个问题,请查找以下内容:

  • 如果您使用的是2.4版本及以上的Hyperledger Fabric,请使用fabric-gateway而不是fabric-network
  • 请检查您的链码逻辑,避免嵌套链码调用以及在没有索引的情况下使用逻辑运算符和/或进行CouchDB查询。请始终使用索引。
英文:

If you've been experiencing this problem, look for the following items:

  • Use fabric-gateway instead of fabric-network if you have fabric 2.4v and up.
  • Review your chaincode logic, avoid nested chaincode invocations and CouchDB queries using logical operators and/or without indexes. Always use indexes.

huangapple
  • 本文由 发表于 2023年3月8日 17:33:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671362.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定