Skip to content

Commit 891e965

Browse files
committed
[FAB-10747] Fix endorsedAt block in transientstore
Transient store uses simulation block height to determine purging schedule for orphaned (uncommitted) private data in transient store. There was a problem where endorser was not passing the simulation block height to transient store persist function, causing 0 to be used as the simulation height. The impact was that all private data was getting purged from transient store at each purge cycle, including private data for recent in-flight transactions. This commit passes the simulation height to the transient store, and removes SimulationBlkHt from TxSimulationResults, as it was never set or used as initially intended. Change-Id: I28523d503c1233f2c0221fb8efcc9890f89fae3a Signed-off-by: David Enyeart <enyeart@us.ibm.com>
1 parent a508871 commit 891e965

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

core/endorser/endorser.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,11 @@ func (e *Endorser) SimulateProposal(ctx context.Context, chainID string, txid st
316316
}
317317
// Add ledger height at which transaction was endorsed,
318318
// `endorsedAt` is obtained from the block storage and at times this could be 'endorsement Height + 1'.
319-
// However, since we use this height only to select the configuration, this works for now.
319+
// However, since we use this height only to select the configuration (3rd parameter in distributePrivateData) and
320+
// manage transient store purge for orphaned private writesets (4th parameter in distributePrivateData), this works for now.
320321
// Ideally, ledger should add support in the simulator as a first class function `GetHeight()`.
321322
pvtDataWithConfig.EndorsedAt = endorsedAt
322-
if err := e.distributePrivateData(chainID, txid, pvtDataWithConfig, simResult.SimulationBlkHt); err != nil {
323+
if err := e.distributePrivateData(chainID, txid, pvtDataWithConfig, endorsedAt); err != nil {
323324
return nil, nil, nil, nil, err
324325
}
325326
}

core/ledger/ledger_interface.go

-3
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,9 @@ func (filter PvtNsCollFilter) Has(ns string, coll string) bool {
245245
}
246246

247247
// TxSimulationResults captures the details of the simulation results
248-
// the field 'SimulationBlkHt' captures the approximate height of the blockchain on which
249-
// the transaction is simulated - this is used to decide when to expire the 'PvtDataSimulationResults' from transient storage
250248
type TxSimulationResults struct {
251249
PubSimulationResults *rwset.TxReadWriteSet
252250
PvtSimulationResults *rwset.TxPvtReadWriteSet
253-
SimulationBlkHt uint64
254251
}
255252

256253
// GetPubSimulationBytes returns the serialized bytes of public readwrite set

core/transientstore/store.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (provider *storeProvider) Close() {
142142
func (s *store) Persist(txid string, blockHeight uint64,
143143
privateSimulationResults *rwset.TxPvtReadWriteSet) error {
144144

145-
logger.Debugf("Persisting private data to transient store for txid = %s", txid)
145+
logger.Debugf("Persisting private data to transient store for txid [%s] at block height [%d]", txid, blockHeight)
146146

147147
dbBatch := leveldbhelper.NewUpdateBatch()
148148

@@ -190,7 +190,7 @@ func (s *store) Persist(txid string, blockHeight uint64,
190190
func (s *store) PersistWithConfig(txid string, blockHeight uint64,
191191
privateSimulationResultsWithConfig *transientstore.TxPvtReadWriteSetWithConfigInfo) error {
192192

193-
logger.Debugf("Persisting private data to transient store for txid = %s", txid)
193+
logger.Debugf("Persisting private data to transient store for txid [%s] at block height [%d]", txid, blockHeight)
194194

195195
dbBatch := leveldbhelper.NewUpdateBatch()
196196

@@ -320,6 +320,8 @@ func (s *store) PurgeByHeight(maxBlockNumToRetain uint64) error {
320320
// Remove private write set
321321
compositeKeyPurgeIndexByHeight := iter.Key()
322322
txid, uuid, blockHeight := splitCompositeKeyOfPurgeIndexByHeight(compositeKeyPurgeIndexByHeight)
323+
logger.Debugf("Purging from transient store private data simulated at block [%d]: txid [%s] uuid [%s]", blockHeight, txid, uuid)
324+
323325
compositeKeyPvtRWSet := createCompositeKeyForPvtRWSet(txid, uuid, blockHeight)
324326
dbBatch.Delete(compositeKeyPvtRWSet)
325327

0 commit comments

Comments
 (0)