Where does world state store physically - hyperledger-fabric

Ok, we have a commiting peers - running containers. As i assume, there is an LevelDB or CouchDB database server in containers, that stores world state. As far as i know, data must be available only from blockchain. Why can't I just connect to that database throught container and see the data or change it? If it protected, tell me, please, how protection is creating.

By default, the CouchDB container cannot be accessed from the outside--only the attached peer is allowed to access it. Also, it can be set up with name/password login.
LevelDB does not have its own container.

Related

How to view the data stored on transaction log?

I'm using hyperledger fabric 2.0. I have successfully ran chaincodes on the fabric network and my data is storing on the couch db. I'm viewing the data stored on the couch DB using
But I want to prove to my faculty that the data is being stored on the transaction log too. Is there any way to view the data that is stored on the transaction log?
If I understand it correctly you basically want to retrieve the ledger data while you're already able to access the world state (couch-db).
One way could be, depending upon what SDK you're using, you can use an instance of 'Channel' and run queries against the ledger data.
Following are the methods available in NodeSDK which could help you to run queries against your ledger:
queryBlock
queryBlockByHash
queryBlockByTxID
queryTransaction

How to prevent access to the state database outside the chaincode process

I am building a system that will hold sensitive user data.
which means that I need to prevent any access to the state database outside the chaincode process.
also if I am publishing the database as a docker image, how do I make sure that the peer uses that specific database image, and not a tampered one.
How to prevent access to the state database outside the chaincode
process
You need to ensure 2 things:
Data that the chaincode reads cannot be used outside of the chaincode
Data that the chaincode reads cannot be altered, and if it's altered then it can be detected.
The first problem can be mitigated by encrypting the data, and the second problem can be mitigated by having the chaincode attach a MAC (Message Authentication Code) tag to every item it writes, and also validate the MAC tag of any item it reads, and if the tag is invalid then return an error.
Worth to mention that you should MAC the ciphertext and not encrypt the MAC (first encrypt, then MAC).
also if I am publishing the database as a docker image, how do I make
sure that the peer uses that specific database image, and not a
tampered one.
If the chaincode has the MAC key embedded inside of it, then the database image you publish will contain records that the chaincode did not produce (hence, did not attach appropritate MAC tags to it) then it will be detected.
The problem is that a malicious administrator could also provide the peer with a valid database container but from the past.
There is another option you can investigate which is Fabric Private Chaincode which uses the Intel SGX TEE(Trusted Execution Environment) feature.

How can a peer node retrieve old data after it crashes in Hyperledger Fabric?

I am pretty new to Hyperledger Fabric. I read a bit about gossip protocol but did not get a clear idea. Please help me with these questions.
How could a node recover old data from a channel after a crash?
What if the channel had only a single peer node and this node crashed?
A peer can get old data from a channel from other peers when it recovers. Another way, if you are pointing to a volume were it is storing the ledger information and all its credentials when it recovers can read it from there, thats why it is recomended to use a persistance storage.
Thats bad practice as you are not going to offer High availability, so without peers you are going to stop giving service and your ledger is not going to be available. But, as you can read from the documentation, you can recover from the orderer.
All ledger, blocks etc stores in below particular location in the peer container
/var/hyperledger/production
All you have todo is create a backup volume and map it
Sample snippet below
Create Volume:
volumes:
backup_peer1:
Add Volume to container:
- backup_peer1:/var/hyperledger/production

State Sync in for Hyperledger Fabric using LEVELDB?

Reading the docs ,I understand that there are two options to maintain the world state LEVELDB and COUCHDB .
In case of LevelDB ,"LevelDB is the default state database embedded in the peer node" I am assuming it is local to a peer . As in every peer has a copy of LevelDB running .
In case of CouchDB there is a separate container to run it ,and all the peers can use it to execute transactions (all the peers see the same data )
In the first case for LevelDB ,how is the version of the data synced across all the peers?
Is this a plug and play feature , Can I for
example use an ETCD cluster ,instead of CouchDB ?
It's actually the same for both LevelDB and CouchDB. The database is basically used as a persistent last know value store. It can be rebuilt at any time for the ledger (the block chain) which is actually what is replicated across all peers via the ordering service
EDIT To clarify, peers receive blocks from the orderer. Each peer than validates the transactions in each block and for each valid transaction it will update the state in the database. In the case of LevelDB, it's an embedded call and in the case of CouchDB the peer communicates with CouchDB via the CouchDB HTTP API. Of course it also writes the blocks to the ledger files on disk as well.
It's not plug and play ... only LevelDB and CouchDB are currently supported. The codebase itself supports adding additional databases, but someone would need to implement the support in the actual codebase.

Hyperledger fabric couchdb persistent

background:
I am developing Hyperledger Fabric Network(v1.1) and are using couchdb.
For continuing operation. It is necessary to persist data go each component(peer, orderer etc..).
Issue:
I don't know what I should persist couchdb's data for continuing operation in production environment.
Question:
(1)Should I persist these data in the below? And, if there is insufficient, please tell me that what I should persist data.
/opt/couchdb/data
/opt/couchdb/etc
(2)If I don't persist these couchdb's data. what will happen? (For example,
querying error,clush the data and difference from block's data).Please tell me.
sincerely.
If you don't persist the CouchDB data, then if you delete or upgrade the container you will lose the data. The good news is that if you have persisted the ledger from your peer, it will rebuild the data in CouchDB on startup but of course this will delay how long it takes for the peer to be able to serve any type of request.
The CouchDB image uses /opt/couchdb/data as the volume where it stores the data so you'll want to mount an external volume there.

Resources