ReadSet and WriteSet

On receipt of a transaction invocation message from a client, the endorsing peer executes a transaction. The execution invokes the chaincode in the context of the peer's Worldstate and records all reads and writes of its data on the ledger into a ReadSet and WriteSet.

The transaction's WriteSet contains a list of key and value pairs that were modified during the execution by the chaincode. When the value of a key is modified (that is, a new key and value are recorded or an existing key is updated with a new value), the WriteSet will contain the updated key and value pair.

When a key is deleted, the WriteSet will contain the key with an attribute marking the key as deleted. If a single key is modified multiple times during chaincode execution, the WriteSet will contain the latest modified value.

The transaction's ReadSet contains a list of keys and their versions that were accessed during execution by the chaincode. The version number of a key is derived from a combination of the block number and the transaction number within the block. This design enables the efficient searching and processing of data. Another section of the transaction contains information about range queries and their outcome. Remember that when a chaincode reads the value of a key, the latest committed value in the ledger is returned.

If modifications introduced during chaincode execution are stored in the WriteSet, when a chaincode is reading a key modified during execution, the committed—not modified—value will be returned. Therefore, if a modified value is needed later during the same execution, the chaincode must be implemented such that it retains and uses the correct values.

An example of a transaction's ReadSet and WriteSet is as follows:

{
"rwset": {
"reads": [
{
"key": "key1",
"version": {
"block_num": {
"low": 9546,
"high": 0,
"unsigned": true
},
"tx_num": {
"low": 0,
"high": 0,
"unsigned": true
}
}
}
],
"range_queries_info": [],
"writes": [
{
"key": "key1",
"is_delete": false,
"value": "value1"
},
{
"key": "key2",
"is_delete": true
}
]
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.144.100