Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between chain and state database in Hyperledger fabric?

What are the main difference between chain and state database in Hyperledger fabric. I'm confusing whether they both are same.

like image 264
Moulali Avatar asked Nov 27 '17 06:11

Moulali


People also ask

What is state database in Hyperledger Fabric?

The state database in Hyperledger Fabric peer nodes on Managed Blockchain networks created using Hyperledger Fabric 1.4 and later supports two types of peer state databases: CouchDB is a state database in Managed Blockchain that models ledger data as JSON.

Why is state database used in Hyperledger Fabric?

The state database holds the last known committed value for any given key. It is populated when each peers validates and commits a transaction. The state database can always be rebuilt from re-processing the ledger. There are currently two options for the state database: an embedded LevelDB or an external CouchDB.

What is the database used with Hyperledger Fabric?

The LevelDB database is a fast database that allows you to store key-value pairs. The LevelDB database was written at Google by Sanjay Ghemawat and Jeff Dean, and is currently the only database used by Hyperledger Fabric for storing transaction logs.


2 Answers

There are two place which "store" data in Hyperledger Fabric:

  • the ledger
  • the state database

The ledger is the actual "blockchain". It is a file-based ledger which stores serialized blocks. Each block has one or more transactions. Each transaction contains a read-write set which modifies one or more key/value pairs. The ledger is the definitive source of data and is immutable.

The state database holds the last known committed value for any given key. It is populated when each peers validates and commits a transaction. The state database can always be rebuilt from re-processing the ledger. There are currently two options for the state database: an embedded LevelDB or an external CouchDB.

As an aside, if you are familiar with Hyperledger Fabric channels, there is a separate ledger for each channel as well.

like image 161
Gari Singh Avatar answered Sep 20 '22 20:09

Gari Singh


The chain is a transaction log, structured as hash-linked blocks, where each block contains a sequence of N transactions. The block header includes a hash of the block’s transactions, as well as a hash of the prior block’s header. In this way, all transactions on the ledger are sequenced and cryptographically linked together.

The state database is simply an indexed view into the chain’s transaction log, it can therefore be regenerated from the chain at any time.

Source: http://hyperledger-fabric.readthedocs.io/en/release/ledger.html

like image 44
kots Avatar answered Sep 23 '22 20:09

kots