Skip to content

Commit

Permalink
[FAB-17039] Skip retrieving pvtdata from transient store when txid is…
Browse files Browse the repository at this point in the history
… missing (#2183) (#2201)

Check if txid is available before retrieving private data from the transient store

Signed-off-by: Wenjian Qiao <wenjianq@gmail.com>
(cherry picked from commit 72d5cc8)

Co-authored-by: Wenjian Qiao <wenjianq@gmail.com>
  • Loading branch information
mergify[bot] and wenjianqiao committed Dec 8, 2020
1 parent 3496dfc commit d5d9965
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions gossip/privdata/dataretriever.go
Expand Up @@ -55,14 +55,27 @@ func (dr *dataRetriever) CollectionRWSet(digests []*protosgossip.PvtDataDigest,
// if there is an error getting info from the ledger, we need to try to read from transient store
return nil, false, errors.Wrap(err, "wasn't able to read ledger height")
}
if height <= blockNum {

// The condition may be true for either commit or reconciliation case when another peer sends a request to retrieve private data.
// For the commit case, get the private data from the transient store because the block has not been committed.
// For the reconciliation case, this peer is further behind the ledger height than the peer that requested for the private data.
// In this case, the ledger does not have the requested private data. Also, the data cannot be queried in the transient store,
// as the txID in the digest will be missing.
if height <= blockNum { // Check whenever current ledger height is equal or below block sequence num.
dr.logger.Debug("Current ledger height ", height, "is below requested block sequence number",
blockNum, "retrieving private data from transient store")
}

if height <= blockNum { // Check whenever current ledger height is equal or below block sequence num.
results := make(Dig2PvtRWSetWithConfig)
for _, dig := range digests {
// skip retrieving from transient store if txid is not available
if dig.TxId == "" {
dr.logger.Infof("Skip querying transient store for chaincode %s, collection name %s, block number %d, sequence in block %d, "+
"as the txid is missing, perhaps because it is a reconciliation request",
dig.Namespace, dig.Collection, blockNum, dig.SeqInBlock)

continue
}

filter := map[string]ledger.PvtCollFilter{
dig.Namespace: map[string]bool{
dig.Collection: true,
Expand Down Expand Up @@ -191,7 +204,7 @@ func (dr *dataRetriever) fromTransientStore(dig *protosgossip.PvtDataDigest, fil
colConfigs, found := rws.CollectionConfigs[dig.Namespace]
if !found {
dr.logger.Error("No collection config was found for chaincode", dig.Namespace, "collection name",
dig.Namespace, "txID", dig.TxId)
dig.Collection, "txID", dig.TxId)
continue
}

Expand Down

0 comments on commit d5d9965

Please sign in to comment.