Difference between chain and state database in Hyp

2019-04-09 12:11发布

问题:

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

回答1:

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.



回答2:

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