Ledger
In Hyperledger Fabric, a ledger is a sequenced, tamper-resistant record of all state transitions. State transitions are a result of chaincode invocations (“transactions”) submitted by participating parties. Each transaction results in a set of key-value pairs that are committed to a ledger, creating, updating, or deleting states.
There is one ledger per channel, and each peer maintains a copy of a ledger for a channel it is a member of. A ledger consists of two distinct, though related, parts—a world state and a blockchain.
A world state is a database that holds a cache of the current values of a set of ledger states. Ledger states are, by default, expressed as key-value pairs, and accessible from a chaincode. The world state can change frequently, as states can be created, updated, and deleted.
Chaincode invocations execute transactions against a world state. To make these chaincode interactions extremely efficient, the latest values of all keys are stored in a state database. A state database is simply an indexed view into the blockchain’s transaction log. It can therefore be regenerated from the chain at any time. The state database will automatically get recovered (or generated if needed) upon peer startup, before transactions are accepted.
State database options include LevelDB and CouchDB. LevelDB is a default state database embedded in the peer process. LevelDB stores chaincode data as key-value pairs. CouchDB is an optional alternative external state database that provides rich query support if your data is modeled as JSON.
A blockchain is a transaction log that records all the changes that have resulted in the current world state. Transactions are collected inside blocks that are appended to a blockchain, enabling you to understand the history of changes that have resulted in the current world state. The blockchain data structure is very different to the world state’s because once written, it cannot be modified—it is immutable.
Blocks in the blockchain are hash-linked. A block header includes a hash of the block’s transactions, as well as a hash of the previous block. In this way, all the transactions in a ledger are sequenced and cryptographically linked together, making it impossible to tamper the ledger data without breaking the hash links. Therefore, it is easy to check that a peer is trusted and consistent using only the latest block.
A blockchain is stored on a peer filesystem (either local or attached storage), efficiently supporting the append-only nature of the blockchain workload.
Last updated
Was this helpful?