@@ -25,15 +25,19 @@ import (
25
25
"github.com/hyperledger/fabric/common/ledger/blkstorage"
26
26
"github.com/hyperledger/fabric/common/ledger/util"
27
27
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
28
+ ledgerUtil "github.com/hyperledger/fabric/core/ledger/util"
29
+ "github.com/hyperledger/fabric/protos/common"
30
+ "github.com/hyperledger/fabric/protos/peer"
28
31
)
29
32
30
33
const (
31
- blockNumIdxKeyPrefix = 'n'
32
- blockHashIdxKeyPrefix = 'h'
33
- txIDIdxKeyPrefix = 't'
34
- blockNumTranNumIdxKeyPrefix = 'a'
35
- blockTxIDIdxKeyPrefix = 'b'
36
- indexCheckpointKeyStr = "indexCheckpointKey"
34
+ blockNumIdxKeyPrefix = 'n'
35
+ blockHashIdxKeyPrefix = 'h'
36
+ txIDIdxKeyPrefix = 't'
37
+ blockNumTranNumIdxKeyPrefix = 'a'
38
+ blockTxIDIdxKeyPrefix = 'b'
39
+ txValidationResultIdxKeyPrefix = 'v'
40
+ indexCheckpointKeyStr = "indexCheckpointKey"
37
41
)
38
42
39
43
var indexCheckpointKey = []byte (indexCheckpointKeyStr )
@@ -47,13 +51,15 @@ type index interface {
47
51
getTxLoc (txID string ) (* fileLocPointer , error )
48
52
getTXLocByBlockNumTranNum (blockNum uint64 , tranNum uint64 ) (* fileLocPointer , error )
49
53
getBlockLocByTxID (txID string ) (* fileLocPointer , error )
54
+ getTxValidationCodeByTxID (txID string ) (peer.TxValidationCode , error )
50
55
}
51
56
52
57
type blockIdxInfo struct {
53
58
blockNum uint64
54
59
blockHash []byte
55
60
flp * fileLocPointer
56
61
txOffsets []* txindexInfo
62
+ metadata * common.BlockMetadata
57
63
}
58
64
59
65
type blockIndex struct {
@@ -92,6 +98,7 @@ func (index *blockIndex) indexBlock(blockIdxInfo *blockIdxInfo) error {
92
98
logger .Debugf ("Indexing block [%s]" , blockIdxInfo )
93
99
flp := blockIdxInfo .flp
94
100
txOffsets := blockIdxInfo .txOffsets
101
+ txsfltr := ledgerUtil .TxValidationFlags (blockIdxInfo .metadata .Metadata [common .BlockMetadataIndex_TRANSACTIONS_FILTER ])
95
102
batch := leveldbhelper .NewUpdateBatch ()
96
103
flpBytes , err := flp .marshal ()
97
104
if err != nil {
@@ -141,6 +148,13 @@ func (index *blockIndex) indexBlock(blockIdxInfo *blockIdxInfo) error {
141
148
}
142
149
}
143
150
151
+ // Index6 - Store transaction validation result by transaction id
152
+ if _ , ok := index .indexItemsMap [blkstorage .IndexableAttrTxValidationCode ]; ok {
153
+ for idx , txoffset := range txOffsets {
154
+ batch .Put (constructTxValidationCodeIDKey (txoffset .txID ), []byte {byte (txsfltr .Flag (idx ))})
155
+ }
156
+ }
157
+
144
158
batch .Put (indexCheckpointKey , encodeBlockNum (blockIdxInfo .blockNum ))
145
159
if err := index .db .WriteBatch (batch , false ); err != nil {
146
160
return err
@@ -228,6 +242,26 @@ func (index *blockIndex) getTXLocByBlockNumTranNum(blockNum uint64, tranNum uint
228
242
return txFLP , nil
229
243
}
230
244
245
+ func (index * blockIndex ) getTxValidationCodeByTxID (txID string ) (peer.TxValidationCode , error ) {
246
+ if _ , ok := index .indexItemsMap [blkstorage .IndexableAttrTxValidationCode ]; ! ok {
247
+ return peer .TxValidationCode (- 1 ), blkstorage .ErrAttrNotIndexed
248
+ }
249
+
250
+ raw , err := index .db .Get (constructTxValidationCodeIDKey (txID ))
251
+
252
+ if err != nil {
253
+ return peer .TxValidationCode (- 1 ), err
254
+ } else if raw == nil {
255
+ return peer .TxValidationCode (- 1 ), blkstorage .ErrAttrNotIndexed
256
+ } else if len (raw ) != 1 {
257
+ return peer .TxValidationCode (- 1 ), errors .New ("Invalid value in indexItems" )
258
+ }
259
+
260
+ result := peer .TxValidationCode (int32 (raw [0 ]))
261
+
262
+ return result , nil
263
+ }
264
+
231
265
func constructBlockNumKey (blockNum uint64 ) []byte {
232
266
blkNumBytes := util .EncodeOrderPreservingVarUint64 (blockNum )
233
267
return append ([]byte {blockNumIdxKeyPrefix }, blkNumBytes ... )
@@ -245,6 +279,10 @@ func constructBlockTxIDKey(txID string) []byte {
245
279
return append ([]byte {blockTxIDIdxKeyPrefix }, []byte (txID )... )
246
280
}
247
281
282
+ func constructTxValidationCodeIDKey (txID string ) []byte {
283
+ return append ([]byte {txValidationResultIdxKeyPrefix }, []byte (txID )... )
284
+ }
285
+
248
286
func constructBlockNumTranNumKey (blockNum uint64 , txNum uint64 ) []byte {
249
287
blkNumBytes := util .EncodeOrderPreservingVarUint64 (blockNum )
250
288
tranNumBytes := util .EncodeOrderPreservingVarUint64 (txNum )
0 commit comments