@@ -24,7 +24,7 @@ import (
24
24
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
25
25
"github.com/hyperledger/fabric/core/ledger/util/leveldbhelper"
26
26
"github.com/hyperledger/fabric/protos/common"
27
- "github.com/hyperledger/fabric/protos/utils"
27
+ putils "github.com/hyperledger/fabric/protos/utils"
28
28
logging "github.com/op/go-logging"
29
29
)
30
30
@@ -97,41 +97,57 @@ func (historyDB *historyDB) Commit(block *common.Block) error {
97
97
//TODO add check for invalid trans in bit array
98
98
for _ , envBytes := range block .Data .Data {
99
99
tranNo ++
100
- logger .Debugf ("Updating history for tranNo: %v" , tranNo )
101
100
102
- // extract actions from the envelope message
103
- respPayload , err := utils .GetActionFromEnvelope (envBytes )
101
+ env , err := putils .GetEnvelopeFromBlock (envBytes )
104
102
if err != nil {
105
103
return err
106
104
}
107
105
108
- //preparation for extracting RWSet from transaction
109
- txRWSet := & rwset.TxReadWriteSet {}
110
-
111
- // Get the Result from the Action and then Unmarshal
112
- // it into a TxReadWriteSet using custom unmarshalling
113
- if err = txRWSet .Unmarshal (respPayload .Results ); err != nil {
106
+ payload , err := putils .GetPayload (env )
107
+ if err != nil {
114
108
return err
115
109
}
116
110
117
- // for each transaction, loop through the namespaces and writesets
118
- // and add a history record for each write
119
- for _ , nsRWSet := range txRWSet .NsRWs {
120
- ns := nsRWSet .NameSpace
111
+ if common .HeaderType (payload .Header .ChainHeader .Type ) == common .HeaderType_ENDORSER_TRANSACTION {
121
112
122
- for _ , kvWrite := range nsRWSet .Writes {
123
- writeKey := kvWrite .Key
113
+ logger .Debugf ("Updating history for tranNo: %d" , tranNo )
114
+ // extract actions from the envelope message
115
+ respPayload , err := putils .GetActionFromEnvelope (envBytes )
116
+ if err != nil {
117
+ return err
118
+ }
124
119
125
- logger .Debugf ("Writing history record for: ns=%s, key=%s, blockNo=%d tranNo=%d" ,
126
- ns , writeKey , blockNo , tranNo )
120
+ //preparation for extracting RWSet from transaction
121
+ txRWSet := & rwset.TxReadWriteSet {}
122
+
123
+ // Get the Result from the Action and then Unmarshal
124
+ // it into a TxReadWriteSet using custom unmarshalling
125
+ if err = txRWSet .Unmarshal (respPayload .Results ); err != nil {
126
+ return err
127
+ }
128
+ // for each transaction, loop through the namespaces and writesets
129
+ // and add a history record for each write
130
+ for _ , nsRWSet := range txRWSet .NsRWs {
131
+ ns := nsRWSet .NameSpace
127
132
128
- //composite key for history records is in the form ns~key~blockNo~tranNo
129
- compositeHistoryKey := historydb . ConstructCompositeHistoryKey ( ns , writeKey , blockNo , tranNo )
133
+ for _ , kvWrite := range nsRWSet . Writes {
134
+ writeKey := kvWrite . Key
130
135
131
- // No value is required, write an empty byte array (emptyValue) since Put() of nil is not allowed
132
- dbBatch .Put (compositeHistoryKey , emptyValue )
136
+ logger .Debugf ("Writing history record for: ns=%s, key=%s, blockNo=%d tranNo=%d" ,
137
+ ns , writeKey , blockNo , tranNo )
138
+
139
+ //composite key for history records is in the form ns~key~blockNo~tranNo
140
+ compositeHistoryKey := historydb .ConstructCompositeHistoryKey (ns , writeKey , blockNo , tranNo )
141
+
142
+ // No value is required, write an empty byte array (emptyValue) since Put() of nil is not allowed
143
+ dbBatch .Put (compositeHistoryKey , emptyValue )
144
+ }
133
145
}
146
+
147
+ } else {
148
+ logger .Debugf ("Skipping transaction %d since it is not an endorsement transaction\n " , tranNo )
134
149
}
150
+
135
151
}
136
152
137
153
// add savepoint for recovery purpose
0 commit comments