Skip to content

Commit

Permalink
Revert "rm old proto related code from transient store (#1464)" (#1467)
Browse files Browse the repository at this point in the history
This reverts commit c712090.

Signed-off-by: senthil <[email protected]>
  • Loading branch information
cendhu authored Jun 26, 2020
1 parent c712090 commit 68f68ca
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 14 deletions.
42 changes: 28 additions & 14 deletions core/transientstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"errors"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/ledger/rwset"
"github.com/hyperledger/fabric-protos-go/transientstore"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
Expand All @@ -24,7 +25,7 @@ var (
emptyValue = []byte{}
nilByte = byte('\x00')
// ErrStoreEmpty is used to indicate that there are no entries in transient store
ErrStoreEmpty = errors.New("transient store is empty")
ErrStoreEmpty = errors.New("Transient store is empty")
)

//////////////////////////////////////////////
Expand Down Expand Up @@ -64,7 +65,7 @@ type storeProvider struct {
dbProvider *leveldbhelper.Provider
}

// Store holds an instance of a levelDB.
// store holds an instance of a levelDB.
type Store struct {
db *leveldbhelper.DBHandle
ledgerID string
Expand Down Expand Up @@ -293,22 +294,35 @@ func (scanner *RwsetScanner) Next() (*EndorserPvtSimulationResults, error) {
return nil, err
}

rwsetWithConf := &transientstore.TxPvtReadWriteSetWithConfigInfo{}
if err := proto.Unmarshal(dbVal[1:], rwsetWithConf); err != nil {
return nil, err
}
rwsetWithConf.PvtRwset = trimPvtWSet(rwsetWithConf.PvtRwset, scanner.filter)
rwsetWithConf.CollectionConfigs, err = trimPvtCollectionConfigs(
rwsetWithConf.CollectionConfigs,
scanner.filter,
)
if err != nil {
return nil, err
txPvtRWSet := &rwset.TxPvtReadWriteSet{}
txPvtRWSetWithConfig := &transientstore.TxPvtReadWriteSetWithConfigInfo{}

var filteredTxPvtRWSet *rwset.TxPvtReadWriteSet
if dbVal[0] == nilByte {
// new proto, i.e., TxPvtReadWriteSetWithConfigInfo
if err := proto.Unmarshal(dbVal[1:], txPvtRWSetWithConfig); err != nil {
return nil, err
}

filteredTxPvtRWSet = trimPvtWSet(txPvtRWSetWithConfig.GetPvtRwset(), scanner.filter)
configs, err := trimPvtCollectionConfigs(txPvtRWSetWithConfig.CollectionConfigs, scanner.filter)
if err != nil {
return nil, err
}
txPvtRWSetWithConfig.CollectionConfigs = configs
} else {
// old proto, i.e., TxPvtReadWriteSet
if err := proto.Unmarshal(dbVal, txPvtRWSet); err != nil {
return nil, err
}
filteredTxPvtRWSet = trimPvtWSet(txPvtRWSet, scanner.filter)
}

txPvtRWSetWithConfig.PvtRwset = filteredTxPvtRWSet

return &EndorserPvtSimulationResults{
ReceivedAtBlockHeight: blockHeight,
PvtSimulationResultsWithConfig: rwsetWithConf,
PvtSimulationResultsWithConfig: txPvtRWSetWithConfig,
}, nil
}

Expand Down
56 changes: 56 additions & 0 deletions core/transientstore/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,62 @@ func TestTransientStorePersistAndRetrieve(t *testing.T) {
assert.Equal(endorsersResults, actualEndorsersResults)
}

func TestTransientStorePersistAndRetrieveBothOldAndNewProto(t *testing.T) {
testStore, cleanup := testStore(t)
defer cleanup()
assert := assert.New(t)
txid := "txid-1"
var receivedAtBlockHeight uint64 = 10
var err error

// Create and persist private simulation results with old proto for txid-1
samplePvtRWSet := samplePvtData(t)
err = testStore.persistOldProto(txid, receivedAtBlockHeight, samplePvtRWSet)
assert.NoError(err)

// Create and persist private simulation results with new proto for txid-1
samplePvtRWSetWithConfig := samplePvtDataWithConfigInfo(t)
err = testStore.Persist(txid, receivedAtBlockHeight, samplePvtRWSetWithConfig)
assert.NoError(err)

// Construct the expected results
var expectedEndorsersResults []*EndorserPvtSimulationResults

pvtRWSetWithConfigInfo := &transientstore.TxPvtReadWriteSetWithConfigInfo{
PvtRwset: samplePvtRWSet,
}

endorser0SimulationResults := &EndorserPvtSimulationResults{
ReceivedAtBlockHeight: receivedAtBlockHeight,
PvtSimulationResultsWithConfig: pvtRWSetWithConfigInfo,
}
expectedEndorsersResults = append(expectedEndorsersResults, endorser0SimulationResults)

endorser1SimulationResults := &EndorserPvtSimulationResults{
ReceivedAtBlockHeight: receivedAtBlockHeight,
PvtSimulationResultsWithConfig: samplePvtRWSetWithConfig,
}
expectedEndorsersResults = append(expectedEndorsersResults, endorser1SimulationResults)

// Retrieve simulation results of txid-1 from store
iter, err := testStore.GetTxPvtRWSetByTxid(txid, nil)
assert.NoError(err)

var actualEndorsersResults []*EndorserPvtSimulationResults
for {
result, err := iter.Next()
assert.NoError(err)
if result == nil {
break
}
actualEndorsersResults = append(actualEndorsersResults, result)
}
iter.Close()
sortResults(expectedEndorsersResults)
sortResults(actualEndorsersResults)
assert.Equal(expectedEndorsersResults, actualEndorsersResults)
}

func TestTransientStorePurgeByTxids(t *testing.T) {
testStore, cleanup := testStore(t)
defer cleanup()
Expand Down

0 comments on commit 68f68ca

Please sign in to comment.