@@ -7,6 +7,9 @@ SPDX-License-Identifier: Apache-2.0
7
7
package privdata
8
8
9
9
import (
10
+ "errors"
11
+ "fmt"
12
+
10
13
"github.com/hyperledger/fabric/core/ledger"
11
14
"github.com/hyperledger/fabric/core/transientstore"
12
15
"github.com/hyperledger/fabric/gossip/util"
@@ -19,7 +22,7 @@ import (
19
22
type StorageDataRetriever interface {
20
23
// CollectionRWSet retrieves for give digest relevant private data if
21
24
// available otherwise returns nil
22
- CollectionRWSet (dig * gossip2.PvtDataDigest ) * util.PrivateRWSetWithConfig
25
+ CollectionRWSet (dig * gossip2.PvtDataDigest ) ( * util.PrivateRWSetWithConfig , error )
23
26
}
24
27
25
28
// DataStore defines set of APIs need to get private data
@@ -53,7 +56,7 @@ func NewDataRetriever(store DataStore) StorageDataRetriever {
53
56
54
57
// CollectionRWSet retrieves for give digest relevant private data if
55
58
// available otherwise returns nil
56
- func (dr * dataRetriever ) CollectionRWSet (dig * gossip2.PvtDataDigest ) * util.PrivateRWSetWithConfig {
59
+ func (dr * dataRetriever ) CollectionRWSet (dig * gossip2.PvtDataDigest ) ( * util.PrivateRWSetWithConfig , error ) {
57
60
filter := map [string ]ledger.PvtCollFilter {
58
61
dig .Namespace : map [string ]bool {
59
62
dig .Collection : true ,
@@ -63,9 +66,8 @@ func (dr *dataRetriever) CollectionRWSet(dig *gossip2.PvtDataDigest) *util.Priva
63
66
height , err := dr .store .LedgerHeight ()
64
67
if err != nil {
65
68
// if there is an error getting info from the ledger, we need to try to read from transient store
66
- logger .Error ("Wasn't able to read ledger height, due to" , err , "trying to lookup " +
67
- "private data from transient store, namespace" , dig .Namespace , "collection name" , dig .Collection , "txID" , dig .TxId )
68
- return nil
69
+ return nil , errors .New (fmt .Sprint ("Wasn't able to read ledger height, due to" , err , "trying to lookup " +
70
+ "private data from transient store, namespace" , dig .Namespace , "collection name" , dig .Collection , "txID" , dig .TxId ))
69
71
}
70
72
if height <= dig .BlockSeq {
71
73
logger .Debug ("Current ledger height " , height , "is below requested block sequence number" ,
@@ -79,13 +81,12 @@ func (dr *dataRetriever) CollectionRWSet(dig *gossip2.PvtDataDigest) *util.Priva
79
81
return dr .fromLedger (dig , filter )
80
82
}
81
83
82
- func (dr * dataRetriever ) fromLedger (dig * gossip2.PvtDataDigest , filter map [string ]ledger.PvtCollFilter ) * util.PrivateRWSetWithConfig {
84
+ func (dr * dataRetriever ) fromLedger (dig * gossip2.PvtDataDigest , filter map [string ]ledger.PvtCollFilter ) ( * util.PrivateRWSetWithConfig , error ) {
83
85
results := & util.PrivateRWSetWithConfig {}
84
86
pvtData , err := dr .store .GetPvtDataByNum (dig .BlockSeq , filter )
85
87
if err != nil {
86
- logger .Error ("Wasn't able to obtain private data for collection" , dig .Collection ,
87
- "txID" , dig .TxId , "block sequence number" , dig .BlockSeq , "due to" , err )
88
- return nil
88
+ return nil , errors .New (fmt .Sprint ("wasn't able to obtain private data for collection" , dig .Collection ,
89
+ "txID" , dig .TxId , "block sequence number" , dig .BlockSeq , "due to" , err ))
89
90
}
90
91
91
92
for _ , data := range pvtData {
@@ -99,53 +100,47 @@ func (dr *dataRetriever) fromLedger(dig *gossip2.PvtDataDigest, filter map[strin
99
100
100
101
confHistoryRetriever , err := dr .store .GetConfigHistoryRetriever ()
101
102
if err != nil {
102
- logger .Error ("Cannot obtain configuration history retriever, for collection," , dig .Collection ,
103
- "txID" , dig .TxId , "block sequence number" , dig .BlockSeq , "due to" , err )
104
- return nil
103
+ return nil , errors .New (fmt .Sprint ("cannot obtain configuration history retriever, for collection," , dig .Collection ,
104
+ "txID" , dig .TxId , "block sequence number" , dig .BlockSeq , "due to" , err ))
105
105
}
106
106
107
107
configInfo , err := confHistoryRetriever .MostRecentCollectionConfigBelow (dig .BlockSeq , dig .Namespace )
108
108
if err != nil {
109
- logger .Error ("Cannot find recent collection config update below block sequence = " , dig .BlockSeq ,
110
- "collection name =" , dig .Collection , "for chaincode" , dig .Namespace )
111
- return nil
109
+ return nil , errors .New (fmt .Sprint ("cannot find recent collection config update below block sequence = " , dig .BlockSeq ,
110
+ "collection name =" , dig .Collection , "for chaincode" , dig .Namespace ))
112
111
}
113
112
114
113
if configInfo == nil {
115
- logger .Error ("No collection config update below block sequence = " , dig .BlockSeq ,
116
- "collection name =" , dig .Collection , "for chaincode" , dig .Namespace , "is available" )
117
- return nil
114
+ return nil , errors .New (fmt .Sprint ("no collection config update below block sequence = " , dig .BlockSeq ,
115
+ "collection name =" , dig .Collection , "for chaincode" , dig .Namespace , "is available" ))
118
116
}
119
117
configs := dr .extractCollectionConfigs (configInfo .CollectionConfig , dig )
120
118
if configs == nil {
121
- logger .Error ("No collection config was found for collection" , dig .Collection ,
122
- "namespace" , dig .Namespace , "txID" , dig .TxId )
123
- return nil
119
+ return nil , errors .New (fmt .Sprint ("no collection config was found for collection" , dig .Collection ,
120
+ "namespace" , dig .Namespace , "txID" , dig .TxId ))
124
121
}
125
122
results .CollectionConfig = configs
126
- return results
123
+ return results , nil
127
124
}
128
125
129
- func (dr * dataRetriever ) fromTransientStore (dig * gossip2.PvtDataDigest , filter map [string ]ledger.PvtCollFilter ) * util.PrivateRWSetWithConfig {
126
+ func (dr * dataRetriever ) fromTransientStore (dig * gossip2.PvtDataDigest , filter map [string ]ledger.PvtCollFilter ) ( * util.PrivateRWSetWithConfig , error ) {
130
127
results := & util.PrivateRWSetWithConfig {}
131
128
it , err := dr .store .GetTxPvtRWSetByTxid (dig .TxId , filter )
132
129
if err != nil {
133
- logger .Error ("Was not able to retrieve private data from transient store, namespace" , dig .Namespace ,
134
- ", collection name" , dig .Collection , ", txID" , dig .TxId , ", due to" , err )
135
- return nil
130
+ return nil , errors .New (fmt .Sprint ("was not able to retrieve private data from transient store, namespace" , dig .Namespace ,
131
+ ", collection name" , dig .Collection , ", txID" , dig .TxId , ", due to" , err ))
136
132
}
137
133
defer it .Close ()
138
134
139
135
maxEndorsedAt := uint64 (0 )
140
136
for {
141
137
res , err := it .NextWithConfig ()
142
138
if err != nil {
143
- logger .Error ("Error getting next element out of private data iterator, namespace" , dig .Namespace ,
144
- ", collection name" , dig .Collection , ", txID" , dig .TxId , ", due to" , err )
145
- return nil
139
+ return nil , errors .New (fmt .Sprint ("error getting next element out of private data iterator, namespace" , dig .Namespace ,
140
+ ", collection name" , dig .Collection , ", txID" , dig .TxId , ", due to" , err ))
146
141
}
147
142
if res == nil {
148
- return results
143
+ return results , nil
149
144
}
150
145
rws := res .PvtSimulationResultsWithConfig
151
146
if rws == nil {
0 commit comments