From d5d99651c00bd40eadec4a525f1dc42b075a9540 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 8 Dec 2020 14:17:36 -0500 Subject: [PATCH] [FAB-17039] Skip retrieving pvtdata from transient store when txid is missing (#2183) (#2201) Check if txid is available before retrieving private data from the transient store Signed-off-by: Wenjian Qiao (cherry picked from commit 72d5cc818487fc0b38fa0a08df7e016275bf1068) Co-authored-by: Wenjian Qiao --- gossip/privdata/dataretriever.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/gossip/privdata/dataretriever.go b/gossip/privdata/dataretriever.go index ac6cbe76bc8..afe2552dd8f 100644 --- a/gossip/privdata/dataretriever.go +++ b/gossip/privdata/dataretriever.go @@ -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, @@ -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 }