6

I have started learning hyperledger. Became familiarised with it by creating a sample app using the composer playground. My doubt is regarding the decentralized storage using hyperledger. I have read some few docs which mentions about :

  • Saving the hash of the data within the blockchain to ensure the immutability.

  • Saving the image within the blockchain(as an asset) through the base64 string.

Some of the things were clear but a large portion still remains uncertain. They are :

  • Where is the data stored within the blockchain? Is it in couchdb ?
  • Suppose the data is stored within the couchdb and via multipeer a new peer gets added to the channel, then does it mean that all the couchdb's of the peers get synced ?

Any resources/tutorials that mention about data storage with the blockchain, decentralized storage etc. would be very helpful.

Thanks!

Sooraj
  • 514
  • 4
  • 20

3 Answers3

7

the blockchain data, aka the ledger, is stored as a physical file. it contains linked blocks, each block consisting of a set of transactions. Each state change is stored there.

By contrast, the world state only contains the current state of every asset as that's what applications need.

The world state is implemented as a database, couchdb being a good option, there is a simpler one available but that one offers much less in terms of querying capability.

Of course what this means is that the world state can be easily recreated from the ledger at any point in time.

when a new peer gets added to a channel, its own world state is created from the ledger.

a good read describing all this is here: https://hyperledger-fabric.readthedocs.io/en/release-1.3/ledger/ledger.html

Andrei Dragotoniu
  • 6,155
  • 3
  • 18
  • 32
  • 1
    One doubt. I have been reading about file storing within the blockchain. Finally came to a point that ethreum or hyperledger based blockchain have to be connected to IPFS for file storage and just the returning hash to be stored back into the hyperledger/ etherum. But IPFS is a blockchain too how was it able to store data? – Sooraj Nov 05 '18 at 11:48
  • 1
    Blockchain is not intended to store large amount of data, also it would be very expensive on ethereum. IPFS is not a blockchain, it is a versioned peer to peer file sharing system (uses BitTorrent technology), you can see it as a distributed file system as files are stored on users file systems across the network. More blockchain-oriented solutions would be projects like [Sia](https://sia.tech/) or [filecoin](https://filecoin.io/) (uses IPFS) but again data is not stored on the blockchain itself. – Yann39 Nov 05 '18 at 12:48
3

To clarify further, a ledger does not literally store business objects but it stores important information/facts about those objects -so history of these important facts is in ledger and current value of this important fact is in world state.So the actual object (the one about which facts are stored in ledger and world state) lives in an external datastore - could be called sort of 'off-chain' data. But the information we store in the ledger allows us to know facts about it and locate it as well. Hope this helps.

Rahul Jain
  • 31
  • 2
  • Good, you answer hit the core of the proposed question. What are best choice to save off-chain data? If we have Hyperledger that works handling many (business) file hashes, how we can store these data? Could IPFS be a good choice? Take in mind that we may have many channels and we won't share some files with the peers of other channels. – shogitai Jun 19 '19 at 07:28
  • 1
    At present IPFS is the only option that comes to my mind but not without its complexities because every participant will have to install blockchain node, IPFS and a middleware i guess. This would make peer-to-peer complex and middleware has to be constantly up. Never tried this but this is what comes to my mind. Regarding sharing of files with channels - you can store the data in encrypted format and give the key only to the participant of the channel. this probably should solve the problem. Let me know how you finally solved your problem – Rahul Jain Jul 19 '19 at 14:05
1
  1. The data is stored in the ledger which is the blockchain. Couchdb only holds states, which can be refreshed from the ledger. Couchdb helps in faster querying the blockchain data.
  2. Yes, all the peer's will have same blocks via gossiping. Couchdb just reads the data from ledger and create a state for itself.
  • 1
    What about the large business files that have to be stored "off-chain"? What are the best choice to do it? – shogitai Jun 19 '19 at 07:26