hyperledger-composer nodejs sdk ping fails - node.js

Using the hyperledger-composer NodeJS SDK at latest levels. Attempting to ping network using the provided example code in composer-admin ping
var fs = require('fs');
var path = require('path');
var composer = require('composer-admin');
var composerClient = require('composer-client');
var composerCommon = require('composer-common');
var adminConnection = new composer.AdminConnection();
adminConnection.connect(config.composer.connectionProfile, config.composer.adminID, config.composer.adminPW)
.then(function(){
adminConnection.ping()
.then(function(result){
console.log("network ping successful: ",result);
res.send({ping: result});
})
.catch(function(error){
var _error = error;
console.log("network ping failed: "+_error);
res.send({ping: _error.toString()});
});
});
When executing this command, get the following response:
Error: error trying to ping.
Error: error trying to query chaincode.
Error: Missing "chaincodeId" parameter in the proposal request
However, the ping command takes no parameters. Help, please?
Inspecting the composer-admin code, shows that the security context is evaluated prior to a ping. When I look at the security context object returned by the new composer.AdminConnection() request, the network identifier object is empty - undefined. If I update that field with my network identifier using the following code
adminConnection.securityContext.connection.businessNetworkIdentifier = "zerotoblockchain-network#0.1.6";
the error messages change to:
Error: error trying to ping.
Error: error trying to query chaincode.
Error: could not find chaincode with name 'zerotoblockchain-network#0.1.6' - make sure the chaincode zerotoblockchain-network#0.1.6 has been successfully instantiated and try again
Using the admin interface to list networks returns this network as deployed. Don't understand why the message is about chaincode when the update was to the network identifier as created by the composer archive and deployed via the composer deploy services.

Whether or not this was a bug, it's been resolved in the latest version of composer (v0.12). Highly recommend removing version numbers from package.json file for all composer node modules as these are updated VERY frequently and version mismatches are generating many spurious erros.

Related

Timeout when communicating with Web3 Provider

Background
I am trying to investigate and solve problems with a containerized NodeJS web service app that communicates with Avalanche Test Network (https://api.avax-test.network/ext/bc/C/rpc) in order to Mint NFTs.
//...
provider = new HDWalletProvider({
privateKeys: [walletPrivateKey],
providerOrUrl: "https://api.avax-test.network/ext/bc/C/rpc",
pollingInterval: 4000,
});
const myContract = Contract(Contract_NFT);
myContract.setProvider(provider);
const _instance = await myContract.at(process.env.CONTRACT_NFT_ADDRESS);
_instance.mint(provider.getAddress(), mintURL, { from: provider.getAddress() })
//...
Note: I am not the developer of app.
Issue
After starting the container, first request completes successfully. However subsequent requests fail with code: -32603 message: 'ETIMEDOUT' error
at new NodeError (node:internal/errors:387:5)
at Web3ProviderEngine.emit (node:events:502:17)
at /app/node_modules/web3-provider-engine/index.js:54:14
at afterRequest (/app/node_modules/web3-provider-engine/index.js:148:21)
at /app/node_modules/web3-provider-engine/index.js:174:21
at /app/node_modules/web3-provider-engine/index.js:232:9
at /app/node_modules/async/internal/once.js:12:16
at replenish (/app/node_modules/async/internal/eachOfLimit.js:61:25)
at /app/node_modules/async/internal/eachOfLimit.js:71:9
at eachLimit (/app/node_modules/async/eachLimit.js:43:36)
at /app/node_modules/async/internal/doLimit.js:9:16
at end (/app/node_modules/web3-provider-engine/index.js:211:5)
at Request._callback (/app/node_modules/web3-provider-engine/subproviders/rpc.js:36:21)
at self.callback (/app/node_modules/request/request.js:185:22)
at Request.emit (node:events:513:28)
at Timeout.<anonymous> (/app/node_modules/request/request.js:851:16)
Error: PollingBlockTracker - encountered an error while attempting to update latest block:
undefined
at PollingBlockTracker._performSync (/app/node_modules/eth-block-tracker/src/polling.js:51:24)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
When the app is used outside a container and directly on server OS, all requests successfully complete.
What I have tried
I tried searching the internet forums and boards. Similar issue is mentioned in some posts but suggested solution is to tweak Timeout/Interval values which did not help with my issue and still got the error.
I tried using the same NodeJS and NPM versions installed on server OS. Also tried using different versions of NodeJS( 14.XX, 16.XX). Still got the same error.
Also I have tried changing and configuring Docker network( different type of network driver, different IPAM config, passing extra hosts etc.). Still got the same error.
I have confirmed that mentioned URL is accessible from inside container using ping, nc and dig tools. Also have confirmed that successful HTTPS connection is being established.
Questions
What is causing this behavior?
What I can do to reliably use this app inside container?
Have I missed something?

Timeout while deploying nodejs based chaincode

I am getting the below error while trying to deploy any nodejs based chaincode on hyperledger 1.4 network :
Error: could not assemble transaction, err proposal response was not
successful, error code 500, msg timeout expired while starting
chaincode
I have even tried the base example chaincode_example02, that is also giving the same error.
Please help.

sendPeersProposal - Promise is rejected: Error: Failed to connect before the deadline

Hell everyone, I am trying to setup a multi-org hyperledger fabric network and I run it already successfully. But when I tried to connect using Node SDK to fabric network to get some data. I am facing below error, I suspect that it is because of the tls cert file but I dont exactly know whats the problem. Hope someone can help me on this. See below details:
Error:
var peer = fabric_client.newPeer(
'grpcs://localhost:7051', {
'pem': 'somepath/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem'
});
channel.addPeer(peer);

Data size limit. Error: Received message larger than max

I am running a node script which connects to the business network and adds assets to the network.
I get the below error.
Error: Error trying invoke business network. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: Received message larger than max (5153800 vs. 4194304)
at _initializeChannel.then.then.then.then.catch (/home/sneha/node-app-v1/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:916:34)
at <anonymous>
I followed this solved issue: https://jira.hyperledger.org/browse/FAB-3301
and changed remote.js file in respective node modules [ composer-playground,composer-client,composer-admin,composer-common etc.. ]
Even after the changes, I can't add the asset through the node script. It throws the same error.
If I add the asset through composer playground it successfully adds the asset but then I can't access the network [ in composer playground ] it throws this error
Error: No connection found with ID 2db7d182-8856-44d5-a9d8-5f7178726423
How can I solve both errors?
How can I set the limit to infinite?
I am using:
Node version: v8.9.4
Composer version: v0.16.5
To change grpc message limits requires you to create/update your connection profile. See https://hyperledger.github.io/composer/reference/connectionprofile
for information about connection profiles.
A no connection profile with id found usually implies you have restarted playground, but not restarted your interaction with playground. Would suggest closing the playground tab and creating new tab to use playground in.

hyperledger composer V 0.12 deploy fails

Working with Hyperledger Composer V0.12 invoking the deploy function using the following code, which returns a 'successful' result:
/**
* Deploys a new BusinessNetworkDefinition to the Hyperledger Fabric. The connection must be connected for this method to succeed.
* #param {express.req} req - the inbound request object from the client
* req.body.myArchive: _string - string name of object
* req.body.deployOptions: _object - string name of object
* #param {express.res} res - the outbound response object for communicating back to client
* #param {express.next} next - an express service to enable post processing prior to responding to the client
* returns composerAdmin.connection - either an error or a connection object
* #function
*/
exports.deploy = function(req, res, next) {
let newFile = path.join(path.dirname(require.main.filename),'network/dist',req.body.myArchive);
let archiveFile = fs.readFileSync(newFile);
let adminConnection = new composerAdmin.AdminConnection();
return BusinessNetworkDefinition.fromArchive(archiveFile)
.then(function(archive) {
adminConnection.connect(config.composer.connectionProfile, config.composer.adminID, config.composer.adminPW)
.then(function(){
adminConnection.deploy(archive)
.then(function(){
console.log('business network '+req.body.myArchive+' deployed successful: ');
res.send({deploy: req.body.myArchive+' deploy succeeded'});
})
.catch(function(error){
console.log('business network '+req.body.myArchive+' deploy failed: ',error);
res.send({deploy: error});
});
});
});
};
However when I go through the following process:
start docker images, deploy network using cli
ping
undeploy
ping
deploy
ping
I get the following results:
[2] at: 08:10:36.058 Url is: /composer/admin/ping
network ping successful: { version: '0.12.0', participant: null }
[3] at: 08:11:05.503 Url is: /composer/admin/undeploy
zerotoblockchain-network network undeploy successful
[4] at: 08:11:25.186 Url is: /composer/admin/ping
(node:18241) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Error trying to ping. Error: Error trying to query chaincode. Error: chaincode error (status: 500, message: Error: The business network has been undeployed)
[5] at: 08:11:34.393 Url is: /composer/admin/deploy
business network zerotoblockchain-network.bna deployed successful:
[6] at: 08:11:44.211 Url is: /composer/admin/ping
(node:18241) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Error trying to ping. Error: Error trying to query chaincode. Error: chaincode error (status: 500, message: Error: The business network has been undeployed)
This indicates that the composer deploy function is not actually deploying the network, even though I appear to receive a successful completion message from the deploy service. Help, please?
When you undeploy a business network, all it does is mark the business network as unreachable. It remains deployed and still running. The reason for this is that currently Hyperledger fabric provides no mechanism for shutting down instantiated chaincode. So all we can do is mark it as unusable.
The deploy API and command are the old way to get a business network up and running. The new way is the install/start combination. The reason that deploy reports successful is that it has to make decisions about errors reported back by both the install and start commands in order to continue to work in an expected manner in the Hyperledger Fabric way of doing things. So although it reports a success for deploying, it's really doing nothing because it is already deployed.

Resources