How to maintain the asset/ledger data post restarting Blockchain Network? - hyperledger-fabric

We are using Composer to connect Blockchain Network (Hyperledger Fabric).
We have created one POC using above technology stack. But when we restart blockchain network all asset data stored on ledger is lost.
How to retrieve that ledger data after restarting the blockchain network?
Thanks in advance.

You can persist the data on the disk.
Mount a directory in the docker-host into a relevant directory in the container. For example, you may add the following two lines in the peer container specification in the docker-compose-base.yaml file:
volumes:
- /var/hyperledger/peer0:/var/hyperledger/production
For the CouchDB container, you may add the following two lines in the CouchDB container specification:
volumes:
- /var/hyperledger/couchdb0:/opt/couchdb/data
Ref: http://hyperledger-fabric.readthedocs.io/en/release/build_network.html#a-note-on-data-persistence

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.

Hyperledger fabric where the blockchain state are saved

I using the hyperledger fabric network with 2 organisation. Now my question, where does the fabric store the blockchain state. Because i am facing the issue, when i turn down the organisation using the docker, All state of blockchain are vanished/delete. How i can keep the track of or save blockchain state, so i don't want to start the blockchain all the time from state zero. Please suggest me.
even for the fabric blockchain explorer also.
You will need to use persistent volumes to ensure that the data is not stored on the container filesystem else it will be destroyed when the container(s) are destroyed.
For peers, the two key attributes in core.yaml are:
peer.fileSystemPath - this defaults to /var/hyperledger/production and is where the ledger, installed chaincodes, etc are kept. The corresponding environment variable is CORE_PEER_FILESYSTEMPATH.
peer.mspConfigPath - where the local MSP info is stored. The corresponding environment variable is CORE_PEER_MSPCONFIGPATH.
For orderers, the two key attributes in orderer.yaml are:
FileLedger.Location - this defaults to /var/hyperledger/production/orderer and is where the channel ledgers are stored. The corresponding environment variable is ORDERER_FILELEDGER_LOCATION.
General.LocalMSPDir - where the local MSP info is stored. The corresponding environment variable is ORDERER_GENERAL_LOCALMSPDIR.
Easily, you can map the content of the docker outside the docker and save it.
In example, for orderer, all its content is inside /var/hyperledger/production/orderer.
You can map this folder outside in a local folder.
In this way you will see the content of the docker folder even without logging the docker bash.
Now you can copy this content in another folder, let's say backup.
When you re-create the docker, you can map the backup folder so that it will start with the previous content you had inside.

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 :)

Where are the channel MSP (cred files) stored locally on a Hyperledger Fabric node?

I've read through the Hyperledger Fabric docs and have played around with setting up my own network using some of the examples. However I still am having trouble understanding where the nodes access their channel MSP information.
If I understand correctly, in the default MSP implementation the Channel MSP is replicated across each node in the channel. http://hyperledger-fabric.readthedocs.io/en/release-1.1/membership/membership.html#local-and-channel-msps However, when I boot up a running network initialized with a channel, while I can see the files that constitute a node's local MSP, I do not see the files that constitute the node's channel MSP. Where are these actually stored in the node and how do they access them during validation?
Look into the docker composer yaml file ,which Up's your docker containers. You will have the volume mappings(physical location) defined for all contianers.

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.

Resources