Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does delState work in Fabric?

I'm new to IBM Hyperledger Fabric.

While trying to go over documents, I see there are couple states getState, putState, delState., etc

https://github.com/hyperledger/fabric/blob/master/core/chaincode/shim/chaincode.go

I'm wondering if ledger is 'immutable and chained', how can we 'delete' the state?

Given that it is a ledger which is chained by each transaction or transactions, wouldn't it be impossible to delete state or at least corrupt the chains of hash?

Thank you!

like image 702
alwayscurious Avatar asked Dec 24 '22 18:12

alwayscurious


1 Answers

There is a state database that stores keys and their values. This is different from the sequence of blocks that make up the blockchain. A key and its associated value can be removed from the state database using the DelState function. However, this does not mean that there is an alteration of blocks on the blockchain. The removal of a key and value would be stored as a transaction on the blockchain just as the prior addition and any modifications were stored as transactions on the blockchain.

Concerning different hashes, it is possible that block hashes could diverge if there is non-deterministic chaincode. Creating chaincode that is non-deterministic should be avoided. Here is a documentation topic that discusses non-deterministic chaincode.

The history of a key can be retrieved after the key is deleted. There is a GetHistoryForKey() API that retrieves the history and part of its response is an IsDeleted flag that indicates if the key was deleted. It would be possible to create a key, delete the key, and then create the key again; the GetHistoryForKey() API would track such a case.

The state database stores the current state, so the key and its value are deleted from the state database. The GetHistoryForKey() API reviews the chain history and not the state database to find prior key values.

There is an example that illustrates use of the GetHistoryForKey() API. See the getHistoryForMarble function.

like image 70
Andrew Tharp Avatar answered Feb 27 '23 03:02

Andrew Tharp