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.
Related
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.
I am saving files inside my ledger with fabric 1.1 and leveldb. As expected, this makes the peers' docker containers to fastly run out of space. I thought that changing to couchdb was going to fix the problem (it transfers the problem to the couchdb container, but I can handle that), but to my surprise, I've checked that using couchdb in fact saves data to the couchdb containers, but it also saves data inside the peers!. For example, uploading a 1,3MB file to my app, configured to use couchdb, also creates a "blockfile" in /var/hyperledger/production/ledgersData/chains/chains/mychannel of 1.3MB inside the involved peers. How can this be? Is it possible to disable this behaviour and save data only in couch containers? (or mounted volumes for this containers), is this a bug fixed in newer fabric versions?. If not possible, how can I configure bigger peers?.
I know I can change the solution to hash attachments, save only references to this hashes inside my ledger and store data in an external data store, but I'm working on a project with this requirement and changing the approach is not a possibility.
Thanks.
The peer has both a file-based ledger (the "blockchain") as well as a state database which holds / caches the last know value for any given key.
State can be stored in either goleveldb or in CouchDB. The ledger is always stored on the peer filesystem. (Note that goleveldb data files are also stored on the peer filesystem).
The location is set via peer.fileSystemPath in core.yaml and the default value is /var/hyperledger/production. You can mount an external volume for this as well if you want to store the files on the host and not inside the container filesystem.
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.
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.
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