Distributed Ledger Data Representation
In Hyperledger Fabric, 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 the chaincode. The world state can change frequently, as states can be created, updated and deleted.
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 the 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 because once written, it cannot be modified; it is immutable.
Chaincode mostly interacts with the world state: e.g., it is more likely you need information about the current account balance instead of the account transactions history. Nevertheless, it is possible to trace every asset origin by auditing the blockchain.
From the chaincode perspective, the world state consists of key-value pairs, where the key is a non-empty string and the value is an arbitrary byte array. There are no restrictions on how keys or values should be stored: you can use any appropriate format, though sometimes it is a lot more convenient to use standard encodings (such as JSON or protobuf) for values representation.
All chaincode interaction with the ledger is handled via ChaincodeStub interface and will be covered further in this course.
Last updated
Was this helpful?