Why we need validated ledger in a peer in hyperledger fabric? - hyperledger-fabric

Before going to my question please refer what is validated ledger in hyperledger fabric here.
Here my questions are:
1) It is mentioned in the doc that "if a new peer joins the network, other peers could not transfer the discarded blocks (pertaining to PeerLedger) to the joining peer, nor convince the joining peer of the validity of their vBlocks".
So while adding a new peer why another peers are sending only validated ledger and why they are not sending peer ledger which consists of both valid and invalid transactions?
2) Validated ledger consists of these following things :
1) The hash of the previous vBlock.
2) vBlock number.
3) An ordered list of all valid transactions committed by the peers since the last vBlock was computed (i.e., list of valid transactions in a corresponding block).
4) The hash of the corresponding block (in PeerLedger) from which the current vBlock is derived.
Why it is maintaining hash of the corresponding block (in PeerLedger) from which the current vBlock is derived?

Related

Hyperledger Fabric - Detection of Modification to StateDB in Peer

This is a question about StateDB automatic fix after tampering.
We're wondering if manipulation to StateDB (CouchDB) could be detected and fixed automatically by peer.
The following documents states there is a a state reconciliation process synchronizing world state in Peer.
https://hyperledger-fabric.readthedocs.io/ja/latest/gossip.html#gossip-messaging
In addition to the automatic forwarding of received messages, a state
reconciliation process synchronizes world state across peers on each
channel. Each peer continually pulls blocks from other peers on the
channel, in order to repair its own state if discrepancies are
identified.
But when we test it as follows:
Step 4: modify value of key a in StateDB
Step 10: Wait for 15 minutes
Step 11: Create a new block
Step 12: Check value of a through chaincode and confirm it in StateDB directly
The tampered value is not fixed automatically by peer.
Can you help clarify the meaning of "state reconciliation process" in the above document and if peer would fix the tampering to StateDB.
Thank you.
Gossip protocol is to sync up legit data among peers, not tampered data in my view. What is legit data? Data whose computed hash at anypoint of time matches with the orignally computed hash, which will not be the case for the tampered data, and so I'd not expect Gossip protocol to sync such 'dirty data'. This defeats the purpose of Blockchain altogether as a technology, and hence this is a wrong test to be performed in my view.
Now, then what is Gossip protocol? Refer https://hyperledger-fabric.readthedocs.io/ja/latest/gossip.html#gossip-protocol
"Peers affected by delays, network partitions, or other causes
resulting in missed blocks will eventually be synced up to the current
ledger state by contacting peers in possession of these missing
blocks."
So, in cases where the peer should have comitted a block to ledger and would have missed due to some reasons like the ones said above, 'Gossip' is only a fall back strategy for the HLF to reconcile the ledger among the peers.
Now in your test case, I see you are using 'query', now query does not go via the orderer to all the peers, it just goes to one peer and returns the value, you need to do a 'getStringState' as a 'transaction', for the 'enderosement' to run, and that is when would the endorsement fail citing the mismatch between the values for the same key among the peers is what I'd expect.
# Gossip state transfer related configuration
state:
# indicates whenever state transfer is enabled or not
# default value is true, i.e. state transfer is active
# and takes care to sync up missing blocks allowing
# lagging peer to catch up to speed with rest network
enabled: false
.......................................................................................................
# the process of reconciliation is done in an endless loop, while in each iteration reconciler tries to
# pull from the other peers the most recent missing blocks with a maximum batch size limitation.
# reconcileBatchSize determines the maximum batch size of missing private data that will be reconciled in a
# single iteration.
reconcileBatchSize: 10
# reconcileSleepInterval determines the time reconciler sleeps from end of an iteration until the beginning
# of the next reconciliation iteration.
reconcileSleepInterval: 1m
# reconciliationEnabled is a flag that indicates whether private data reconciliation is enable or not.
reconciliationEnabled: true
Link: https://github.com/hyperledger/fabric/blob/master/sampleconfig/core.yaml
In addition to the automatic forwarding of received messages, a state reconciliation process synchronizes world state across peers on each channel. Each peer continually pulls blocks from other peers on the channel, in order to repair its own state if discrepancies are identified. Because fixed connectivity is not required to maintain gossip-based data dissemination, the process reliably provides data consistency and integrity to the shared ledger, including tolerance for node crashes.

What factors influence the ordering of transactions in a block in HLF 1.4.4?

In the documentation for the transaction flow of hyperledger fabric it is mentioned that
"The ordering service does not need to inspect the entire content of a transaction in order to perform its operation, it simply receives transactions from all channels in the network, orders them chronologically by channel, and creates blocks of transactions per channel."
I have a couple of questions here
What does "chronological ordering" mean?. Does it mean that the transactions for a channel are ordered depending on the time they are received at the Ordering service node (Leader) ?
If two client applications are submitting an update transaction for the same key on the ledger almost at the same time [Let us call them tx1 (updating key x to value p) , tx2 (updating key x to value q)], all the endorsing peers will simulate the update transaction proposal and return the write set in the transaction proposal response. When the clients send these endorsement proposal requests to ordering service nodes , in which order will these update transactions be ordered in a block ?.
The order of transactions in the block can be tx1,tx2 OR tx2,tx1 , assuming the update transaction has only the write set and no read set , both the transactions in either orders are valid. What will be the final value of the key on the ledger [p or q] ?
I am trying to understand if the final value of x is deterministic , and what factors would influence it.
What does "chronological ordering" mean?. Does it mean that the transactions for a channel are ordered depending on the time they are received at the Ordering service node (Leader)?
In general, the orderer makes no guarantees about the order in which messages will be delivered just that messages will be delivered in the same order to all peer nodes.
In practice, the following generally holds true for the current orderer implementations:
Solo - messages should be delivered in the order in which they were received
Kafka - messages should be delivered in the order in which they were received by each orderer node and generally even in the order they are received across multiple ordering nodes.
This holds true for the latest fabric version as well.
If two client applications are submitting an update transaction for the same key on the ledger almost at the same time [Let us call them tx1 (updating key x to value p) , tx2 (updating key x to value q)], all the endorsing peers will simulate the update transaction proposal and return the write set in the transaction proposal response. When the clients send these endorsement proposal requests to ordering service nodes, in which order will these update transactions be ordered in a block ?.
When you submit a transaction, the peer generates a read and write set. This read/write set is then used when the transaction is committed to the ledger. It contains the name of the variables to be read/written and their version when they were read. If, during the time between set creation and committing, a different transaction was committed and changed the version of the variable, the original transaction will be rejected during committal because the version when read is not the current version.
To address this, you will have to create data and transaction structures that avoid concurrently editing the same key, other you might get MVCC_READ_CONFLICT error.

What kind of transactions we can find in Hyperledger Fabric blocks?

In Bitcoin blockchain, transactions are only of the type "transferring some amount from X to Y", so we always have an actual change the blockchain.
In Hyperledger Fabric transaction are like:
Instatiate some chaincode in a channel
Invoke some chaincode (that may be just a query to show a certain
asset in the ledger / world state)
I'm sure that instantiating chaincode in some channel or running something that changes the world state are transaction that qualify to fit in a block.
What I don't understand is exactly which transactions can enter in the next block. If some chaincode does not write or update the world state (in RW sets, the Read set is the same of the Write one) can still be included in the next block? Or can be safely "discarded"?
All endorsing peer must have instantiated chaincode so that they can simulate transactions and create Read/Write(RW) set. Installing and instantiating chaincode are different transaction than regular invoke.
Invoking some transaction meansa it can be one of
Query
Adding Asset, Updating Asset, Deleting Asset
HF maintains versioning of each unique key and it increases chronologically when we update same asset. This versioning (MVCC - Multiversion concurrency control) avoid double-spending problem as well.
HF dont care about whatever value we puts for key(Value could be anything).
Lets assume we have to add car asset with key car1 and value is {"name":"Audi", "owner":"ABC"}.
When we send the transaction to all endorsing peer, they create RW set as below
Read Set: NA
Write set: Key-car1, version-1, value-{"name":"Audi", "owner":"ABC"}
When the tx gets committed to blockchain, one of the block will have this transaction and the current state database (Couch db or level db) will heve this latest value for that key : Key-car1, version-1, value-{ "name": "Audi", "owner": "ABC"}
Let's assume if we updating this same asset(car1)
car1 - { "name": "Audi", "owner": "PQR"}
Here we are changing owner from ABC to PQR
This time Endorsing peer create the following RW set
Read Set: Key-car1, version-1
Write set: Key-car1, version-2, value-{"name":"Audi", "owner":"PQR"}
Once the tx gets committed to the blockchain. again this transaction gets added into one block and most importantly, the current state database will get updated with this latest value and old value will be updated and the version also get changed to 2.

Definition of ledger

I was reading the documentation of hyperledger fabric. In the transaction flow page I found this line
The chaincode (containing a set of key value pairs representing
the initial state of the radish market) is installed on the peers and
instantiated on the channel.
This line confused me. I think it is the definition of ledger .But here it is written as chaincode.
Is my perception correct ?
Can anyone explain me ?
Chaincode (or the more commonly-known term smart-contract) defines a set of business models, transaction definitions and logics which the application (SDK) could utilize to create transactions.
For the sentence you show above, this does not refer to the definition of the chaincode. I believe it merely conveys the idea that a list of radishes (in key and value pair) has been defined in the chaincode already, so once it is instantiated (or a initRadish function, if it exists in the chaincode is being called), that list of radishes will become part of the world state in the ledger.
How ledger and chaincode relate in Fabric?
Ledger consists of two components, namely world state and blockchain. World state stores the latest values of the key, whereas the blockchain stores all the transaction log that leads to the world state.
As I said above, chaincode defines the transaction logics in terms of functions such that the application could call to create transaction, which triggers state transition or state retrieval.
For example, you have a function called buyRadish(radishID, newOwner) defined in the chaincode. Suppose there is a radish with key R1001 with value {"owner": FarmerA, "status": OnSale}. This is the key-value pair before any transaction occurs. Once the function in the chaincode is invoked with the argument radishID = R1001, newOwner = Ken, a transaction is created and the state of radish with key R1001 will become {"owner": Ken, "status": Sold}. Note that this latest state of the radish will be seen at the world state.
With the example above, you can think in this way:
The ledger stores the latest key-value pairs (or to be precise latest value of the key). The chaincode may have some key-value pairs for initialization purpose; however, the point is that we are passing a new set of key-value pairs (radishID = R1001, newOwner = Ken) as argument to the function in chaincode, so as to update the values of the same key (radishID = R1001) in the world state of the ledger.
Hope it helps.
A chaincode is programmatic code deployed on the network, where it is executed and validated by chain validators together during the consensus process. Developers can use chaincodes to develop business contracts, asset definitions, and collectively-managed decentralized applications.
more about chaincode click here
How ledger and chaincode relate in Fabric?
Chaincode is a program (smart contract) that is written to read and update the ledger state.

Where is the 'real' ledger and How is it maintained?

In a Hyperledger Fabric network, ledgers which all peers(endorsing peers and committing peers) have are replicated ledgers.
It seems to imply there is a unique 'real/original/genuine' ledger per channel.
I'd like to ask these:
Is there a real ledger? If so, where is it(or where is it defined?) and who owns it?
Those replicated ledgers are updated by each peer, after VSCC, MVCC validation. Then who updates the 'real' ledger?
Does 'World State' only refers to the 'real' ledger?
I'd really appreciate if you answer my questions.
Please tell me if these questions are clarified to you. Thank you!
I don't understand what exactly you mean by 'real' ledger. There is one & only ledger per channel, replicated across all participants per channel. When I say participants, I mean all peers (both endorsing & committing) of an organization's MSP belonging to a given channel.
State DB (a.k.a World state) refers to the database that maintains the current value of a given key. Let me give you an example. You know that a blockchain is a liked list on steroids (with added security, immutability, etc). Say, you have a key A with value 100 in Block 1. You transact in the following manner.
Block 2 -- A := A-10
Block 15 -- A := A-12
.
.
.
Block 10,000 -- A := A-3
So, after Block 10,000, if you need the current value of key A, you have to calculate the value from Block 1. So to manage this efficiently, Fabric folks implemented a state database that updates the value of a key in the state after every transaction. It's sole responsibility is to improve efficiency. If your state gets corrupted, Fabric will automatically rebuild it from Block 0.

Resources