@@ -7,15 +7,13 @@ SPDX-License-Identifier: Apache-2.0
7
7
package privdata
8
8
9
9
import (
10
- "errors"
11
- "fmt"
12
-
13
10
"github.com/hyperledger/fabric/core/ledger"
14
11
"github.com/hyperledger/fabric/core/transientstore"
15
12
"github.com/hyperledger/fabric/gossip/privdata/common"
16
13
"github.com/hyperledger/fabric/gossip/util"
17
14
gossip2 "github.com/hyperledger/fabric/protos/gossip"
18
15
"github.com/hyperledger/fabric/protos/ledger/rwset"
16
+ "github.com/pkg/errors"
19
17
)
20
18
21
19
// StorageDataRetriever defines an API to retrieve private date from the storage
@@ -64,7 +62,7 @@ func (dr *dataRetriever) CollectionRWSet(digests []*gossip2.PvtDataDigest, block
64
62
height , err := dr .store .LedgerHeight ()
65
63
if err != nil {
66
64
// if there is an error getting info from the ledger, we need to try to read from transient store
67
- return nil , false , fmt . Errorf ( "wasn't able to read ledger height, due to %s" , err )
65
+ return nil , false , errors . Wrap ( err , "wasn't able to read ledger height" )
68
66
}
69
67
if height <= blockNum {
70
68
logger .Debug ("Current ledger height " , height , "is below requested block sequence number" ,
@@ -112,7 +110,7 @@ func (dr *dataRetriever) fromLedger(digests []*gossip2.PvtDataDigest, blockNum u
112
110
113
111
pvtData , err := dr .store .GetPvtDataByNum (blockNum , filter )
114
112
if err != nil {
115
- return nil , errors .New ( fmt . Sprint ( "wasn't able to obtain private data, block sequence number" , blockNum , " due to" , err ) )
113
+ return nil , errors .Errorf ( "wasn't able to obtain private data, block sequence number %d, due to %s " , blockNum , err )
116
114
}
117
115
118
116
results := make (Dig2PvtRWSetWithConfig )
@@ -137,24 +135,24 @@ func (dr *dataRetriever) fromLedger(digests []*gossip2.PvtDataDigest, blockNum u
137
135
138
136
confHistoryRetriever , err := dr .store .GetConfigHistoryRetriever ()
139
137
if err != nil {
140
- return nil , errors .New ( fmt . Sprint ( "cannot obtain configuration history retriever, for collection, " , dig . Collection ,
141
- " txID " , dig . TxId , " block sequence number " , dig .BlockSeq , " due to" , err ) )
138
+ return nil , errors .Errorf ( "cannot obtain configuration history retriever, for collection <%s>" +
139
+ " txID <%s> block sequence number <%d> due to <%s> " , dig .Collection , dig . TxId , dig . BlockSeq , err )
142
140
}
143
141
144
142
configInfo , err := confHistoryRetriever .MostRecentCollectionConfigBelow (dig .BlockSeq , dig .Namespace )
145
143
if err != nil {
146
- return nil , errors .New ( fmt . Sprint ( "cannot find recent collection config update below block sequence = " , dig . BlockSeq ,
147
- " collection name = " , dig .Collection , " for chaincode " , dig .Namespace ) )
144
+ return nil , errors .Errorf ( "cannot find recent collection config update below block sequence = %d," +
145
+ " collection name = <%s> for chaincode <%s> " , dig .BlockSeq , dig . Collection , dig .Namespace )
148
146
}
149
147
150
148
if configInfo == nil {
151
- return nil , errors .New ( fmt . Sprint ( "no collection config update below block sequence = " , dig . BlockSeq ,
152
- " collection name = " , dig . Collection , " for chaincode " , dig .Namespace , " is available " ) )
149
+ return nil , errors .Errorf ( "no collection config update below block sequence = <%d>" +
150
+ " collection name = <%s> for chaincode <%s> is available " , dig .BlockSeq , dig . Collection , dig . Namespace )
153
151
}
154
152
configs := extractCollectionConfig (configInfo .CollectionConfig , dig .Collection )
155
153
if configs == nil {
156
- return nil , errors .New ( fmt . Sprint ( "no collection config was found for collection " , dig . Collection ,
157
- " namespace " , dig .Namespace , " txID " , dig .TxId ) )
154
+ return nil , errors .Errorf ( "no collection config was found for collection <%s>" +
155
+ " namespace <%s> txID <%s> " , dig .Collection , dig . Namespace , dig .TxId )
158
156
}
159
157
pvtRWSetWithConfig .CollectionConfig = configs
160
158
results [common.DigKey {
@@ -173,17 +171,17 @@ func (dr *dataRetriever) fromTransientStore(dig *gossip2.PvtDataDigest, filter m
173
171
results := & util.PrivateRWSetWithConfig {}
174
172
it , err := dr .store .GetTxPvtRWSetByTxid (dig .TxId , filter )
175
173
if err != nil {
176
- return nil , errors .New ( fmt . Sprint ( "was not able to retrieve private data from transient store, namespace" , dig . Namespace ,
177
- ", collection name" , dig . Collection , ", txID " , dig .TxId , ", due to" , err ) )
174
+ return nil , errors .Errorf ( "was not able to retrieve private data from transient store, namespace <%s>" +
175
+ ", collection name %s, txID <%s>, due to <%s> " , dig .Namespace , dig . Collection , dig . TxId , err )
178
176
}
179
177
defer it .Close ()
180
178
181
179
maxEndorsedAt := uint64 (0 )
182
180
for {
183
181
res , err := it .NextWithConfig ()
184
182
if err != nil {
185
- return nil , errors .New ( fmt . Sprint ( "error getting next element out of private data iterator, namespace" , dig . Namespace ,
186
- ", collection name" , dig . Collection , ", txID " , dig .TxId , ", due to" , err ) )
183
+ return nil , errors .Errorf ( "error getting next element out of private data iterator, namespace <%s>" +
184
+ ", collection name <%s>, txID <%s>, due to <%s> " , dig .Namespace , dig . Collection , dig . TxId , err )
187
185
}
188
186
if res == nil {
189
187
return results , nil
@@ -229,13 +227,13 @@ func (dr *dataRetriever) extractPvtRWsets(pvtRWSets []*rwset.NsPvtReadWriteSet,
229
227
for _ , nsws := range pvtRWSets {
230
228
// and in each namespace - iterate over all collections
231
229
if nsws .Namespace != namespace {
232
- logger .Warning ("Received private data namespace " , nsws .Namespace , " instead of " , namespace , " skipping..." )
230
+ logger .Debug ("Received private data namespace " , nsws .Namespace , " instead of " , namespace , " skipping..." )
233
231
continue
234
232
}
235
233
for _ , col := range nsws .CollectionPvtRwset {
236
234
// This isn't the collection we're looking for
237
235
if col .CollectionName != collectionName {
238
- logger .Warning ("Received private data collection " , col .CollectionName , " instead of " , collectionName , " skipping..." )
236
+ logger .Debug ("Received private data collection " , col .CollectionName , " instead of " , collectionName , " skipping..." )
239
237
continue
240
238
}
241
239
// Add the collection pRWset to the accumulated set
0 commit comments