Restoring Hyperledger Fabric Network After It Is Off - hyperledger-fabric

I am working on a project using hyperledger fabric.
Currently, I use the test-network in the hyperledger fabric document to develop it fabric document.
But what I'm worried about is if my computer turns off and the hyperledger fabric network turns off, will I be able to restore the previous network values again?
What should I do if I can?
In the current practice example, if you enter the test-network ./network.sh down command, you can see that the generated msp(?) files and authentication-related files. Should I modify this network.sh file so that the generated authentication-related files are not deleted when the server goes down, and if the file exists when the server is turned on again, should I modify it so that the network can be configured?

If you want to retain your current network, even in a stopped state, run the following command in the docker folder.
docker-compose -f docker-compose-couch.yaml -f docker-compose-ca.yaml -f docker-compose-test-net.yaml stop
This command stops the current containers from running. When you want to start the same network again, use the same command and use start instead of stop, as shown next.
docker-compose -f docker-compose-couch.yaml -f docker-compose-ca.yaml -f docker-compose-test-net.yaml start
Using ./network down command removes all traces of the network, other than the files that were there from the beginning.

But what I'm worried about is if my computer turns off and the hyperledger fabric network turns off, will I be able to restore the previous network values again?
If the containers are in Exited(not due to errors) state you can bring those containers Up again.
Normally we maintain persistence DB to store data.
In Test network we are not bothered about restarting the network and generating new certs repeatedly. If it is a prod env we just execute the script(network.js) only once.
You can also make changes(micro-scripts) to the existing scripts based on your use-case/requirements.

Related

Hyperledger starting project for my own use case

As of now I have used fabric-samples repo and used network.sh to start network . They already have connection-org.yaml file which has necessary information.
When I need to use fabric for my app , I know I need to start fabric network right ? Then I need to also create channel and user into it . How do I do it ? Should I just copy and paste that network.sh from fabric-samples ? What about connection-org.yaml? I think all of them is hardcoded right ? What should I do about it ?
Every tutorial has prebuilt these things never explaining what they are. Any help would be heavily appreciated
As you have mentioned that you have used Fabric Repo, I am expecting you to to be familiar with the Hyperledger Fabric Blockchain Framework.
Following factors related to the network should be decided first.
Channel name.
How many and Which are the Organizations are participating in the Consortium,
How many peers per Organization?
Ordering Network would RAFT based, But how many orderer nodes ?
Whether state database would use Couch DB or LevelDB
How the MSP Crypto would be generated ( Is Fabric CA going to be used[ If yes, then own root certificate/rootCA ?] or Cryptogen Tool)
Once the above has been laid out, then the next step is to start coding the network script.
The images should be already loaded into the local docker repository, and the Fabric binaries should be available in a location accessible to the script. If the docker images are not loaded, then the machine should have connectivity to internet and then to docker-hub.
It would be good to start with a docker based network setup.
The network and persistent data stores ( docker network, ports and volumes) should be planned.
Once that is sorted out, the coding of the docker compose files could start. Following are the points to be noted during this step.
Create a single compose with all the organizations Or create individual compose files for each organizations. Take a look at the docker compose yaml files present along with the network.sh to get an idea.
Decide on the docker subnet ( network reference)
Provide the same network reference against each service / each
individual compose files.
Provide the env variables for the below items.
Map the MSP folders.
Decide on the SSL as applicable
Provide CouchDB ports(if applicable), Peer Ports, Gossip ports,
Orderer ports etc.
If planning to use cryptogen, then create the config files as per the Org structure. If its CA, then write commands as per the org structure.
Now again refer to the network.sh script and try to figure out how the crypto is generated ( as applicable to your choice). Also refer to the cleanup part from network.sh to understand how it is being done, what is being removed, and what is being retained.
Every time the script bombs, make sure that you cleanup and then start. ie, all the docker containers and volumes to be removed. You could retain your MSP cryptos if you want to.
Locate the command to create the channel, and adding peers to the channel.
The content from env.sh is a good example on how to set the environment variables needed within your script.
Once all the members have joined the channel, the setup the anchor peers per organizations.
Write a version of the script after referring to the example.
By the end of proper execution of the steps above, the script should be able to get a Hyperledger Fabric network up and running.

Block chain data will lose in Hyperleger composer network

I Just create a hyper ledger composer network in production level. There are many data(Participant and asset) is existing in my composer blockchain( That is on CouchDB). My main problem is I need to set up a hyper ledger explorer for my existing network. I already use https://github.com/hyperledger/blockchain-explorer. But the issue is my network orderer port is not synced with explorer( I already post a question regarding this issue Hyperledger explorer starting problem- orderer port communication issue. Unfortunately no replay).
At this moment I decided to stop the running hyper ledger composer network and start again it without any data(participant and asset data) lose. Actually restart the network without data loss is possible...???
Have any other suggestion is available to resolve my issue..???
Any suggestion is much appreciated..
Thank you.
OS: Ubuntu 16.04
Composer: 0.19.16
Fabric: 1.1.0
When you stop your business network using stopFaric.sh under fabric-dev-servers (or fabric-tools). It will stop fabric Containers and after that run startFabric.sh it will recreate new Containers from the Docker Images. Impact of this is that you lose all data(assets, participant, transaction etc) of your business network.
So if you want to stop and start your fabric without loss of existing data. Then follow below commands :
Need to change the directory where the docker-compose.yml(/home/<user>/fabric-dev-servers/fabric-scripts/hlfv11/composer) file is, and
Run docker-compose stop to stop the Fabric then
Run docker-compose start to restart Fabric it will start your network with existing data. Make sure you are in the correct folder.
Hope, it will help you :)

Get HLF blockchain info

here's my problem.
I have set a development env for HLF using Vagrant, made some changes to HLF source and built new docker images.
Then I deployed a network with 3 peers and 1 orderer, starting from custom HLF images and installed the basic chaincode that uses 'a' and 'b' variable as assets, making some operation (chaincode_example02).
Now I would like to see blockchain info such as blocks hash, ledger height and so on. How can access this info? Is there a way without using any app made with SDKs? For instance, some command executed by CLI.
If not, what's the fastest way to get this info? Thanks.
Ok, solved the problem.
This does what i needed:
docker exec -it cli bash peer channel getinfo -c <channel-name>

Hyperledger data persistence between fabric restarts

I have tried to search and research on this topic, but could not find any solution so far.
Has anyone tried this scenario? Start the fabric, create a business network, create a sample app to post transactions to this network. So far so good. Shut down the fabric now and restart it. Has anyone seen that the transactions are lost? So how does one go about making the ledger survive restarts?
You need to mount a volume for the directory /var/hyperledger/production in the orderer and peer containers in docker. This is where all the persistent data is being held containing channel information, transactions and blocks.
If you are spinning up your containers through docker-compose you can add:
volumes:
- <some local dir>:/var/hyperledger/production
If you are spinning up your containers through docker run add the argument:
-v <some local dir>:/var/hyperledger/production
Haven't used composer much myself so not quite sure how composer builds the containers, if you are using that.
You will also need to make sure each node goes to its own directory so it doesn't conflict.

Hyperledger composer got stuck when upgrading the network

Here are the steps that I went through:
Stop and tear down fabric
Start fabric
Create a Business network using yo hyperledger-composer
Create .bna archive and install it
Start network with version 0.0.1
Import card to the playground
All these steps work fine, but when I start playground and try to upgrade business network with my changes, in a browser it gets stuck on
Please Wait: Your new business network is being upgraded
Upgrading business network using PeerAdmin#hlfv1 (2/2)
and never responds
Here what I see in logs of composer--playground:
info: [Hyperledger-Composer] :ConnectionProfileManager :getConnectionManagerByTyp Looking up a connection manager for type 0=hlfv1
Maybe someone has already faced this kind of issue and knows how solve it? Or in the local environment, I should upgrade it manually?
P.S I am new to Composer, so all these steps I found in the
Developer tutorial
The composer network upgrade command and its equivalent action in the Composer Playground generate a new docker "chaincode image" and "chaincode container". Creating the image and starting the container is what takes the time. You will see that you now have redundant docker containers and images of previous versions of the Business Network. This is intended behaviour of Hyperledger Fabric (and Composer) but you may want to do some housekeeping to remove the old versions.
If you are in early versions of development and experimentation - generating lots of versions of Networks, you can use the 'Web Profile' in the Playground which simulates a Fabric in the LocalStorage of the Browser - it is much faster but if you use it be sure to periodically export to a BNA otherwise you might lose work if there is a browser issue or upgrade.
Updated following Comment
The command docker ps can be used to see all running containers (docker ps -a will also show stopped containers.) docker stop is used to stop a container and docker rm to remove the container.
Docker containers are running (or stopped) instances of docker images so you will also want to remove the redundant images. You list the images with docker images and remove them with docker rmi.
The docker web site has a full list of commands.
Interestingly, but the process of upgrading the network took more time than I thought, so the solution will be simple:
Wait 3-4 minutes until the process finishes and do not click anywhere
in the browser (by mistake I tried to reconnect to the card, and in
that case, the process of upgrading fails).
Additionally, important to mention, in the manual process of upgrading of the card(using CLI), it takes the same amount of time

Resources