Skip to content

Commit

Permalink
[FAB-7641] Fix panic when iterating over private data
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
yacovm committed Jan 7, 2018
1 parent 7af5264 commit 629e26e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions gossip/privdata/dataretriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func (dr *dataRetriever) CollectionRWSet(dig *gossip2.PvtDataDigest) []util.Priv
return pRWsets
}
rws := res.PvtSimulationResults
if rws == nil {
logger.Debug("Skipping empty PvtSimulationResults received at block height", res.ReceivedAtBlockHeight)
continue
}
pRWsets = append(pRWsets, dr.extractPvtRWsets(rws.NsPvtRwset, dig.Namespace, dig.Collection)...)
}
} else { // Since ledger height is above block sequence number private data is available in the ledger
Expand Down
6 changes: 4 additions & 2 deletions gossip/privdata/dataretriever_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ func TestNewDataRetriever_GetDataFromTransientStore(t *testing.T) {
namespace := "testChaincodeName1"
collectionName := "testCollectionName"

rwSetScanner.
On("Next").Return(&transientstore.EndorserPvtSimulationResults{
rwSetScanner.On("Next").Return(&transientstore.EndorserPvtSimulationResults{
ReceivedAtBlockHeight: 2,
PvtSimulationResults: nil,
}, nil).Once().On("Next").Return(&transientstore.EndorserPvtSimulationResults{
ReceivedAtBlockHeight: 2,
PvtSimulationResults: &rwset.TxPvtReadWriteSet{
DataModel: rwset.TxReadWriteSet_KV,
Expand Down

0 comments on commit 629e26e

Please sign in to comment.