@@ -13,6 +13,7 @@ import (
13
13
"github.com/hyperledger/fabric/protos/ledger/rwset"
14
14
15
15
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
16
+ "github.com/hyperledger/fabric/common/util"
16
17
"github.com/hyperledger/fabric/core/ledger"
17
18
"github.com/hyperledger/fabric/core/ledger/pvtdatastorage"
18
19
"github.com/syndtr/goleveldb/leveldb/iterator"
@@ -38,13 +39,10 @@ type StoreProvider interface {
38
39
// the permanent storage or the pruning of some data items is enforced by the policy
39
40
type Store interface {
40
41
// Persist stores the private read-write set of a transaction in the transient store
41
- Persist (txid string , endorserid string , endorsementBlkHt uint64 , privateSimulationResults * rwset.TxPvtReadWriteSet ) error
42
+ Persist (txid string , endorsementBlkHt uint64 , privateSimulationResults * rwset.TxPvtReadWriteSet ) error
42
43
// GetTxPvtRWSetByTxid returns an iterator due to the fact that the txid may have multiple private
43
44
// RWSets persisted from different endorsers (via Gossip)
44
- GetTxPvtRWSetByTxid (txid string , filter ledger.PvtNsCollFilter ) (* rwsetScanner , error )
45
- // GetSelfSimulatedTxPvtRWSetByTxid returns the private read-write set generated from the simulation
46
- // performed by the peer itself
47
- GetSelfSimulatedTxPvtRWSetByTxid (txid string ) (* EndorserPvtSimulationResults , error )
45
+ GetTxPvtRWSetByTxid (txid string , filter ledger.PvtNsCollFilter ) (* RwsetScanner , error )
48
46
// Purge removes private read-writes set generated by endorsers at block height lesser than
49
47
// a given maxBlockNumToRetain. In other words, Purge only retains private read-write sets
50
48
// that were generated at block height of maxBlockNumToRetain or higher.
@@ -56,7 +54,6 @@ type Store interface {
56
54
57
55
// EndorserPvtSimulationResults captures the deatils of the simulation results specific to an endorser
58
56
type EndorserPvtSimulationResults struct {
59
- EndorserID string
60
57
EndorsementBlockHeight uint64
61
58
PvtSimulationResults * rwset.TxPvtReadWriteSet
62
59
}
@@ -78,7 +75,7 @@ type store struct {
78
75
ledgerID string
79
76
}
80
77
81
- type rwsetScanner struct {
78
+ type RwsetScanner struct {
82
79
txid string
83
80
dbItr iterator.Iterator
84
81
filter ledger.PvtNsCollFilter
@@ -102,56 +99,38 @@ func (provider *storeProvider) Close() {
102
99
}
103
100
104
101
// Persist stores the private read-write set of a transaction in the transient store
105
- func (s * store ) Persist (txid string , endorserid string ,
106
- endorsementBlkHt uint64 , privateSimulationResults * rwset.TxPvtReadWriteSet ) error {
102
+ func (s * store ) Persist (txid string , endorsementBlkHt uint64 ,
103
+ privateSimulationResults * rwset.TxPvtReadWriteSet ) error {
107
104
dbBatch := leveldbhelper .NewUpdateBatch ()
108
105
109
- // Create compositeKey with appropriate prefix, txid, endorserid and endorsementBlkHt
110
- compositeKey := createCompositeKeyForPvtRWSet (txid , endorserid , endorsementBlkHt )
106
+ // Create compositeKey with appropriate prefix, txid, uuid and endorsementBlkHt
107
+ // Due to the fact that the txid may have multiple private RWSets persisted from different
108
+ // endorsers (via Gossip), we postfix an uuid with the txid to avoid collision.
109
+ uuid := util .GenerateUUID ()
110
+ compositeKey := createCompositeKeyForPvtRWSet (txid , uuid , endorsementBlkHt )
111
111
privateSimulationResultsBytes , err := proto .Marshal (privateSimulationResults )
112
112
if err != nil {
113
113
return err
114
114
}
115
115
dbBatch .Put (compositeKey , privateSimulationResultsBytes )
116
116
117
- // Create compositeKey with appropriate prefix, endorsementBlkHt, txid, endorserid & Store
117
+ // Create compositeKey with appropriate prefix, endorsementBlkHt, txid, uuid & Store
118
118
// the compositeKey (purge index) a null byte as value.
119
- compositeKey = createCompositeKeyForPurgeIndex (endorsementBlkHt , txid , endorserid )
119
+ compositeKey = createCompositeKeyForPurgeIndex (endorsementBlkHt , txid , uuid )
120
120
dbBatch .Put (compositeKey , emptyValue )
121
121
122
122
return s .db .WriteBatch (dbBatch , true )
123
123
}
124
124
125
125
// GetTxPvtRWSetByTxid returns an iterator due to the fact that the txid may have multiple private
126
- // RWSets persisted from different endorserids. Eventually, we may pass a set of collections name
127
- // (filters) along with txid.
128
- func (s * store ) GetTxPvtRWSetByTxid (txid string , filter ledger.PvtNsCollFilter ) (* rwsetScanner , error ) {
126
+ // RWSets persisted from different endorsers.
127
+ func (s * store ) GetTxPvtRWSetByTxid (txid string , filter ledger.PvtNsCollFilter ) (* RwsetScanner , error ) {
129
128
// Construct startKey and endKey to do an range query
130
129
startKey := createTxidRangeStartKey (txid )
131
130
endKey := createTxidRangeEndKey (txid )
132
131
133
132
iter := s .db .GetIterator (startKey , endKey )
134
- return & rwsetScanner {txid , iter , filter }, nil
135
- }
136
-
137
- // GetSelfSimulatedTxPvtRWSetByTxid returns the private write set generated from the simulation performed
138
- // by the peer itself. Eventually, we may pass a set of collections name (filters) along with txid.
139
- func (s * store ) GetSelfSimulatedTxPvtRWSetByTxid (txid string ) (* EndorserPvtSimulationResults , error ) {
140
- var err error
141
- var itr * rwsetScanner
142
- if itr , err = s .GetTxPvtRWSetByTxid (txid , nil ); err != nil {
143
- return nil , err
144
- }
145
- defer itr .Close ()
146
- var res * EndorserPvtSimulationResults
147
- for {
148
- if res , err = itr .Next (); res == nil || err != nil {
149
- return nil , err
150
- }
151
- if selfSimulated (res ) {
152
- return res , nil
153
- }
154
- }
133
+ return & RwsetScanner {txid , iter , filter }, nil
155
134
}
156
135
157
136
// Purge removes private read-writes set generated by endorsers at block height lesser than
@@ -165,12 +144,12 @@ func (s *store) Purge(maxBlockNumToRetain uint64) error {
165
144
166
145
dbBatch := leveldbhelper .NewUpdateBatch ()
167
146
168
- // Get all txid and endorserid from above result and remove it from transient store (both
147
+ // Get all txid and uuid from above result and remove it from transient store (both
169
148
// read/write set and the corresponding index.
170
149
for iter .Next () {
171
150
dbKey := iter .Key ()
172
- txid , endorserid , endorsementBlkHt := splitCompositeKeyOfPurgeIndex (dbKey )
173
- compositeKey := createCompositeKeyForPvtRWSet (txid , endorserid , endorsementBlkHt )
151
+ txid , uuid , endorsementBlkHt := splitCompositeKeyOfPurgeIndex (dbKey )
152
+ compositeKey := createCompositeKeyForPvtRWSet (txid , uuid , endorsementBlkHt )
174
153
dbBatch .Delete (compositeKey )
175
154
dbBatch .Delete (dbKey )
176
155
}
@@ -203,13 +182,13 @@ func (s *store) Shutdown() {
203
182
204
183
// Next moves the iterator to the next key/value pair.
205
184
// It returns whether the iterator is exhausted.
206
- func (scanner * rwsetScanner ) Next () (* EndorserPvtSimulationResults , error ) {
185
+ func (scanner * RwsetScanner ) Next () (* EndorserPvtSimulationResults , error ) {
207
186
if ! scanner .dbItr .Next () {
208
187
return nil , nil
209
188
}
210
189
dbKey := scanner .dbItr .Key ()
211
190
dbVal := scanner .dbItr .Value ()
212
- endorserid , endorsementBlkHt := splitCompositeKeyOfPvtRWSet (dbKey )
191
+ _ , endorsementBlkHt := splitCompositeKeyOfPvtRWSet (dbKey )
213
192
214
193
txPvtRWSet := & rwset.TxPvtReadWriteSet {}
215
194
if err := proto .Unmarshal (dbVal , txPvtRWSet ); err != nil {
@@ -218,17 +197,12 @@ func (scanner *rwsetScanner) Next() (*EndorserPvtSimulationResults, error) {
218
197
filteredTxPvtRWSet := pvtdatastorage .TrimPvtWSet (txPvtRWSet , scanner .filter )
219
198
220
199
return & EndorserPvtSimulationResults {
221
- EndorserID : endorserid ,
222
200
EndorsementBlockHeight : endorsementBlkHt ,
223
201
PvtSimulationResults : filteredTxPvtRWSet ,
224
202
}, nil
225
203
}
226
204
227
205
// Close releases resource held by the iterator
228
- func (scanner * rwsetScanner ) Close () {
206
+ func (scanner * RwsetScanner ) Close () {
229
207
scanner .dbItr .Release ()
230
208
}
231
-
232
- func selfSimulated (pvtSimRes * EndorserPvtSimulationResults ) bool {
233
- return pvtSimRes .EndorserID == ""
234
- }
0 commit comments