@@ -44,42 +44,43 @@ type RWSetScanner interface {
44
44
Close ()
45
45
}
46
46
47
- // Store manages the storage of private read- write sets for a ledgerId.
47
+ // Store manages the storage of private write sets for a ledgerId.
48
48
// Ideally, a ledger can remove the data from this storage when it is committed to
49
49
// the permanent storage or the pruning of some data items is enforced by the policy
50
50
type Store interface {
51
- // Persist stores the private read-write set of a transaction in the transient store
52
- Persist (txid string , endorsementBlkHt uint64 , privateSimulationResults * rwset.TxPvtReadWriteSet ) error
51
+ // Persist stores the private write set of a transaction in the transient store
52
+ // based on txid and the block height the private data was received at
53
+ Persist (txid string , blockHeight uint64 , privateSimulationResults * rwset.TxPvtReadWriteSet ) error
53
54
// GetTxPvtRWSetByTxid returns an iterator due to the fact that the txid may have multiple private
54
- // RWSets persisted from different endorsers (via Gossip)
55
+ // write sets persisted from different endorsers (via Gossip)
55
56
GetTxPvtRWSetByTxid (txid string , filter ledger.PvtNsCollFilter ) (RWSetScanner , error )
56
- // PurgeByTxids removes private read- write set of a given set of transactions from the
57
+ // PurgeByTxids removes private write sets of a given set of transactions from the
57
58
// transient store
58
59
PurgeByTxids (txids []string ) error
59
- // PurgeByHeight removes private read-writes set generated by endorsers at block height lesser than
60
- // a given maxBlockNumToRetain. In other words, Purge only retains private read- write sets
61
- // that were generated at block height of maxBlockNumToRetain or higher. Though the private
62
- // read- write sets stored in transient store is removed by coordinator using PurgebyTxids()
60
+ // PurgeByHeight removes private write sets at block height lesser than
61
+ // a given maxBlockNumToRetain. In other words, Purge only retains private write sets
62
+ // that were persisted at block height of maxBlockNumToRetain or higher. Though the private
63
+ // write sets stored in transient store is removed by coordinator using PurgebyTxids()
63
64
// after successful block commit, PurgeByHeight() is still required to remove orphan entries (as
64
65
// transaction that gets endorsed may not be submitted by the client for commit)
65
66
PurgeByHeight (maxBlockNumToRetain uint64 ) error
66
- // GetMinEndorsementBlkHt returns the lowest retained endorsement block height
67
- GetMinEndorsementBlkHt () (uint64 , error )
67
+ // GetMinTransientBlkHt returns the lowest block height remaining in transient store
68
+ GetMinTransientBlkHt () (uint64 , error )
68
69
Shutdown ()
69
70
}
70
71
71
- // EndorserPvtSimulationResults captures the deatils of the simulation results specific to an endorser
72
+ // EndorserPvtSimulationResults captures the details of the simulation results specific to an endorser
72
73
type EndorserPvtSimulationResults struct {
73
- EndorsementBlockHeight uint64
74
- PvtSimulationResults * rwset.TxPvtReadWriteSet
74
+ ReceivedAtBlockHeight uint64
75
+ PvtSimulationResults * rwset.TxPvtReadWriteSet
75
76
}
76
77
77
78
//////////////////////////////////////////////
78
79
// Implementation
79
80
/////////////////////////////////////////////
80
81
81
82
// storeProvider encapsulates a leveldb provider which is used to store
82
- // private read- write set of simulated transactions, and implements TransientStoreProvider
83
+ // private write sets of simulated transactions, and implements TransientStoreProvider
83
84
// interface.
84
85
type storeProvider struct {
85
86
dbProvider * leveldbhelper.Provider
@@ -114,16 +115,17 @@ func (provider *storeProvider) Close() {
114
115
provider .dbProvider .Close ()
115
116
}
116
117
117
- // Persist stores the private read-write set of a transaction in the transient store
118
- func (s * store ) Persist (txid string , endorsementBlkHt uint64 ,
118
+ // Persist stores the private write set of a transaction in the transient store
119
+ // based on txid and the block height the private data was received at
120
+ func (s * store ) Persist (txid string , blockHeight uint64 ,
119
121
privateSimulationResults * rwset.TxPvtReadWriteSet ) error {
120
122
dbBatch := leveldbhelper .NewUpdateBatch ()
121
123
122
- // Create compositeKey with appropriate prefix, txid, uuid and endorsementBlkHt
123
- // Due to the fact that the txid may have multiple private RWSets persisted from different
124
+ // Create compositeKey with appropriate prefix, txid, uuid and blockHeight
125
+ // Due to the fact that the txid may have multiple private write sets persisted from different
124
126
// endorsers (via Gossip), we postfix an uuid with the txid to avoid collision.
125
127
uuid := util .GenerateUUID ()
126
- compositeKeyPvtRWSet := createCompositeKeyForPvtRWSet (txid , uuid , endorsementBlkHt )
128
+ compositeKeyPvtRWSet := createCompositeKeyForPvtRWSet (txid , uuid , blockHeight )
127
129
privateSimulationResultsBytes , err := proto .Marshal (privateSimulationResults )
128
130
if err != nil {
129
131
return err
@@ -132,16 +134,16 @@ func (s *store) Persist(txid string, endorsementBlkHt uint64,
132
134
133
135
// Create two index: (i) by txid, and (ii) by height
134
136
135
- // Create compositeKey for purge index by height with appropriate prefix, endorsementBlkHt ,
137
+ // Create compositeKey for purge index by height with appropriate prefix, blockHeight ,
136
138
// txid, uuid and store the compositeKey (purge index) with a null byte as value. Note that
137
139
// the purge index is used to remove orphan entries in the transient store (which are not removed
138
140
// by PurgeTxids()) using BTL policy by PurgeByHeight(). Note that orphan entries are due to transaction
139
141
// that gets endorsed but not submitted by the client for commit)
140
- compositeKeyPurgeIndexByHeight := createCompositeKeyForPurgeIndexByHeight (endorsementBlkHt , txid , uuid )
142
+ compositeKeyPurgeIndexByHeight := createCompositeKeyForPurgeIndexByHeight (blockHeight , txid , uuid )
141
143
dbBatch .Put (compositeKeyPurgeIndexByHeight , emptyValue )
142
144
143
145
// Create compositeKey for purge index by txid with appropriate prefix, txid, uuid,
144
- // endorsementBlkHt and store the compositeKey (purge index) with a null byte as value.
146
+ // blockHeight and store the compositeKey (purge index) with a null byte as value.
145
147
// Though compositeKeyPvtRWSet itself can be used to purge private write set by txid,
146
148
// we create a separate composite key with a null byte as value. The reason is that
147
149
// if we use compositeKeyPvtRWSet, we unnecessarily read (potentially large) private write
@@ -150,14 +152,14 @@ func (s *store) Persist(txid string, endorsementBlkHt uint64,
150
152
// Note: We can create compositeKeyPurgeIndexByTxid by just replacing the prefix of compositeKeyPvtRWSet
151
153
// with purgeIndexByTxidPrefix. For code readability and to be expressive, we use a
152
154
// createCompositeKeyForPurgeIndexByTxid() instead.
153
- compositeKeyPurgeIndexByTxid := createCompositeKeyForPurgeIndexByTxid (txid , uuid , endorsementBlkHt )
155
+ compositeKeyPurgeIndexByTxid := createCompositeKeyForPurgeIndexByTxid (txid , uuid , blockHeight )
154
156
dbBatch .Put (compositeKeyPurgeIndexByTxid , emptyValue )
155
157
156
158
return s .db .WriteBatch (dbBatch , true )
157
159
}
158
160
159
161
// GetTxPvtRWSetByTxid returns an iterator due to the fact that the txid may have multiple private
160
- // RWSets persisted from different endorsers.
162
+ // write sets persisted from different endorsers.
161
163
func (s * store ) GetTxPvtRWSetByTxid (txid string , filter ledger.PvtNsCollFilter ) (RWSetScanner , error ) {
162
164
// Construct startKey and endKey to do an range query
163
165
startKey := createTxidRangeStartKey (txid )
@@ -167,7 +169,7 @@ func (s *store) GetTxPvtRWSetByTxid(txid string, filter ledger.PvtNsCollFilter)
167
169
return & RwsetScanner {txid , iter , filter }, nil
168
170
}
169
171
170
- // PurgeByTxids removes private read- write set of a given set of transactions from the
172
+ // PurgeByTxids removes private write sets of a given set of transactions from the
171
173
// transient store. PurgeByTxids() is expected to be called by coordinator after
172
174
// committing a block to ledger.
173
175
func (s * store ) PurgeByTxids (txids []string ) error {
@@ -181,20 +183,20 @@ func (s *store) PurgeByTxids(txids []string) error {
181
183
iter := s .db .GetIterator (startKey , endKey )
182
184
183
185
// Get all txid and uuid from above result and remove it from transient store (both
184
- // read/ write set and the corresponding indexes.
186
+ // write set and the corresponding indexes.
185
187
for iter .Next () {
186
188
// For each entry, remove the private read-write set and correponding indexes
187
189
188
- // Remove private read- write set
190
+ // Remove private write set
189
191
compositeKeyPurgeIndexByTxid := iter .Key ()
190
192
// Note: We can create compositeKeyPvtRWSet by just replacing the prefix of compositeKeyPurgeIndexByTxid
191
193
// with prwsetPrefix. For code readability and to be expressive, we split and create again.
192
- uuid , endorsementBlkHt := splitCompositeKeyOfPurgeIndexByTxid (compositeKeyPurgeIndexByTxid )
193
- compositeKeyPvtRWSet := createCompositeKeyForPvtRWSet (txid , uuid , endorsementBlkHt )
194
+ uuid , blockHeight := splitCompositeKeyOfPurgeIndexByTxid (compositeKeyPurgeIndexByTxid )
195
+ compositeKeyPvtRWSet := createCompositeKeyForPvtRWSet (txid , uuid , blockHeight )
194
196
dbBatch .Delete (compositeKeyPvtRWSet )
195
197
196
198
// Remove purge index -- purgeIndexByHeight
197
- compositeKeyPurgeIndexByHeight := createCompositeKeyForPurgeIndexByHeight (endorsementBlkHt , txid , uuid )
199
+ compositeKeyPurgeIndexByHeight := createCompositeKeyForPurgeIndexByHeight (blockHeight , txid , uuid )
198
200
dbBatch .Delete (compositeKeyPurgeIndexByHeight )
199
201
200
202
// Remove purge index -- purgeIndexByTxid
@@ -207,10 +209,10 @@ func (s *store) PurgeByTxids(txids []string) error {
207
209
return s .db .WriteBatch (dbBatch , true )
208
210
}
209
211
210
- // PurgeByHeight removes private read-writes set generated by endorsers at block height lesser than
211
- // a given maxBlockNumToRetain. In other words, PurgeByHeight only retains private read- write sets
212
- // that were generated at block height of maxBlockNumToRetain or higher. Though the private
213
- // read- write sets stored in transient store is removed by coordinator using PurgebyTxids()
212
+ // PurgeByHeight removes private write sets at block height lesser than
213
+ // a given maxBlockNumToRetain. In other words, Purge only retains private write sets
214
+ // that were persisted at block height of maxBlockNumToRetain or higher. Though the private
215
+ // write sets stored in transient store is removed by coordinator using PurgebyTxids()
214
216
// after successful block commit, PurgeByHeight() is still required to remove orphan entries (as
215
217
// transaction that gets endorsed may not be submitted by the client for commit)
216
218
func (s * store ) PurgeByHeight (maxBlockNumToRetain uint64 ) error {
@@ -222,18 +224,18 @@ func (s *store) PurgeByHeight(maxBlockNumToRetain uint64) error {
222
224
dbBatch := leveldbhelper .NewUpdateBatch ()
223
225
224
226
// Get all txid and uuid from above result and remove it from transient store (both
225
- // read/ write set and the corresponding index.
227
+ // write set and the corresponding index.
226
228
for iter .Next () {
227
229
// For each entry, remove the private read-write set and correponding indexes
228
230
229
- // Remove private read- write set
231
+ // Remove private write set
230
232
compositeKeyPurgeIndexByHeight := iter .Key ()
231
- txid , uuid , endorsementBlkHt := splitCompositeKeyOfPurgeIndexByHeight (compositeKeyPurgeIndexByHeight )
232
- compositeKeyPvtRWSet := createCompositeKeyForPvtRWSet (txid , uuid , endorsementBlkHt )
233
+ txid , uuid , blockHeight := splitCompositeKeyOfPurgeIndexByHeight (compositeKeyPurgeIndexByHeight )
234
+ compositeKeyPvtRWSet := createCompositeKeyForPvtRWSet (txid , uuid , blockHeight )
233
235
dbBatch .Delete (compositeKeyPvtRWSet )
234
236
235
237
// Remove purge index -- purgeIndexByTxid
236
- compositeKeyPurgeIndexByTxid := createCompositeKeyForPurgeIndexByTxid (txid , uuid , endorsementBlkHt )
238
+ compositeKeyPurgeIndexByTxid := createCompositeKeyForPurgeIndexByTxid (txid , uuid , blockHeight )
237
239
dbBatch .Delete (compositeKeyPurgeIndexByTxid )
238
240
239
241
// Remove purge index -- purgeIndexByHeight
@@ -244,19 +246,19 @@ func (s *store) PurgeByHeight(maxBlockNumToRetain uint64) error {
244
246
return s .db .WriteBatch (dbBatch , true )
245
247
}
246
248
247
- // GetMinEndorsementBlkHt returns the lowest retained endorsement block height
248
- func (s * store ) GetMinEndorsementBlkHt () (uint64 , error ) {
249
+ // GetMinTransientBlkHt returns the lowest block height remaining in transient store
250
+ func (s * store ) GetMinTransientBlkHt () (uint64 , error ) {
249
251
// Current approach performs a range query on purgeIndex with startKey
250
- // as 0 (i.e., endorsementBlkHt ) and returns the first key which denotes
251
- // the lowest retained endorsement block height. An alternative approach
252
- // is to explicitly store the minEndorsementBlkHt in the transientStore.
252
+ // as 0 (i.e., blockHeight ) and returns the first key which denotes
253
+ // the lowest block height remaining in transient store . An alternative approach
254
+ // is to explicitly store the minBlockHeight in the transientStore.
253
255
startKey := createPurgeIndexByHeightRangeStartKey (0 )
254
256
iter := s .db .GetIterator (startKey , nil )
255
- // Fetch the minimum endorsement block height
257
+ // Fetch the minimum transient block height
256
258
if iter .Next () {
257
259
dbKey := iter .Key ()
258
- _ , _ , endorsementBlkHt := splitCompositeKeyOfPurgeIndexByHeight (dbKey )
259
- return endorsementBlkHt , nil
260
+ _ , _ , blockHeight := splitCompositeKeyOfPurgeIndexByHeight (dbKey )
261
+ return blockHeight , nil
260
262
}
261
263
iter .Release ()
262
264
// Returning an error may not be the right thing to do here. May be
@@ -277,7 +279,7 @@ func (scanner *RwsetScanner) Next() (*EndorserPvtSimulationResults, error) {
277
279
}
278
280
dbKey := scanner .dbItr .Key ()
279
281
dbVal := scanner .dbItr .Value ()
280
- _ , endorsementBlkHt := splitCompositeKeyOfPvtRWSet (dbKey )
282
+ _ , blockHeight := splitCompositeKeyOfPvtRWSet (dbKey )
281
283
282
284
txPvtRWSet := & rwset.TxPvtReadWriteSet {}
283
285
if err := proto .Unmarshal (dbVal , txPvtRWSet ); err != nil {
@@ -286,8 +288,8 @@ func (scanner *RwsetScanner) Next() (*EndorserPvtSimulationResults, error) {
286
288
filteredTxPvtRWSet := pvtdatastorage .TrimPvtWSet (txPvtRWSet , scanner .filter )
287
289
288
290
return & EndorserPvtSimulationResults {
289
- EndorsementBlockHeight : endorsementBlkHt ,
290
- PvtSimulationResults : filteredTxPvtRWSet ,
291
+ ReceivedAtBlockHeight : blockHeight ,
292
+ PvtSimulationResults : filteredTxPvtRWSet ,
291
293
}, nil
292
294
}
293
295
0 commit comments