Understanding the Read, Write Set in Hyperledger Fabric

0
17

During simulation of a transaction at an Endorser, a read-write set is prepared for the transaction. The read set contains a list of unique keys and their committed versions that the transaction reads during simulation. The write set contains a list of unique keys (though there can be overlap with the keys present in the read set) and their new values that the transaction writes. Example :
Invoke transaction function is performed by the client for changing ownership of the car from Owner Alice to Bob. Once transaction reached to endorsing peer, resultant read-write sets are

Read Write set

Note: the version number is based on incremental order which basically derived from the height of committing transactions.

RW Set during Validation Phase

The client sends RW(Read-Write) set received from endorsing peer to the Orderer. Now Orderer creates a block and sends to Leader peers of each organization which basically gossip to all committing peers.

A committer uses the read set portion of the read-write set for checking the validity of a transaction and the write set portion of the read-write set for updating the versions and the values of the affected keys.

In the validation phase, a transaction is considered valid if the version of each key present in the read set of the transaction matches the version for the same key in the world state. This validation is done for stopping Double spending. Example: Alice created two transactions, one Selling the same car to Bob and another selling to Charlie.

Resultant RW set by endorsing Peer

Now, Tx 1 reached to validation phase and committing peer checked the version number present in read set of RW set and the current version in world state of that particular key.

Comparing version of key 123904 in Read set of RW Set and World State db

Since version number is same, committing peer will include this transaction in its ledger and hence version number of key will be incremented.

Now, Tx 2 reached to validation phase and committing peer checked the version number present in read set of RW set and the current version in world state of that particular key.

Version number mismatch because Tx 1 got committed into ledger and version number got change

Due to the mismatch in the version number of particular key 123904, Tx 2 will get decline and thus double spending will be avoided.

Write Set stored in World State DB

once key is modified due to write operation , World State DB does not override the previous value but it keeps the version history of entire data. New record will be inserted while keeping old version of data. This approach help us to find complete history of particular key.

version history stroed in World State DB

Conclusion:

Read Write set is a process for validation and thus resulting in avoiding double spending in the Hyperledger Fabric.

Get Best Software Deals Directly In Your Inbox

Understanding the Read, Write Set in Hyperledger Fabric was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.