Skip to content

Commit 629e26e

Browse files
committed
[FAB-7641] Fix panic when iterating over private data
The gossip pull delegates fetching data from the data retriever which is a bridge between gossip and the transient store. The data retriever quries the ledger and iterates over an iterator until Next() returns nil (or error). However, Next() can also return an object that has its inner fields be nil which represent that this current data element has no data in it, and iteration must continue on. This change set makes the code skip if the inner element is nil, and adds a unit test for this. Change-Id: Ica249e3b3a5081b1fc7357baa45bf9d0bc209e11 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 7af5264 commit 629e26e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

gossip/privdata/dataretriever.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func (dr *dataRetriever) CollectionRWSet(dig *gossip2.PvtDataDigest) []util.Priv
9090
return pRWsets
9191
}
9292
rws := res.PvtSimulationResults
93+
if rws == nil {
94+
logger.Debug("Skipping empty PvtSimulationResults received at block height", res.ReceivedAtBlockHeight)
95+
continue
96+
}
9397
pRWsets = append(pRWsets, dr.extractPvtRWsets(rws.NsPvtRwset, dig.Namespace, dig.Collection)...)
9498
}
9599
} else { // Since ledger height is above block sequence number private data is available in the ledger

gossip/privdata/dataretriever_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ func TestNewDataRetriever_GetDataFromTransientStore(t *testing.T) {
6969
namespace := "testChaincodeName1"
7070
collectionName := "testCollectionName"
7171

72-
rwSetScanner.
73-
On("Next").Return(&transientstore.EndorserPvtSimulationResults{
72+
rwSetScanner.On("Next").Return(&transientstore.EndorserPvtSimulationResults{
73+
ReceivedAtBlockHeight: 2,
74+
PvtSimulationResults: nil,
75+
}, nil).Once().On("Next").Return(&transientstore.EndorserPvtSimulationResults{
7476
ReceivedAtBlockHeight: 2,
7577
PvtSimulationResults: &rwset.TxPvtReadWriteSet{
7678
DataModel: rwset.TxReadWriteSet_KV,

0 commit comments

Comments
 (0)