@@ -17,15 +17,14 @@ limitations under the License.
17
17
package txvalidator
18
18
19
19
import (
20
- "context"
21
20
"fmt"
22
21
23
22
"github.com/golang/protobuf/proto"
24
23
coreUtil "github.com/hyperledger/fabric/common/util"
25
- "github.com/hyperledger/fabric/core/chaincode"
24
+ "github.com/hyperledger/fabric/core/common/ccprovider"
25
+ "github.com/hyperledger/fabric/core/common/validation"
26
26
"github.com/hyperledger/fabric/core/ledger"
27
27
ledgerUtil "github.com/hyperledger/fabric/core/ledger/util"
28
- "github.com/hyperledger/fabric/core/peer"
29
28
"github.com/hyperledger/fabric/protos/common"
30
29
"github.com/hyperledger/fabric/protos/utils"
31
30
"github.com/op/go-logging"
@@ -48,7 +47,8 @@ type vsccValidator interface {
48
47
// vsccValidator implementation which used to call
49
48
// vscc chaincode and validate block transactions
50
49
type vsccValidatorImpl struct {
51
- ledger ledger.ValidatedLedger
50
+ ledger ledger.ValidatedLedger
51
+ ccprovider ccprovider.ChaincodeProvider
52
52
}
53
53
54
54
// implementation of Validator interface, keeps
@@ -69,7 +69,12 @@ func init() {
69
69
// NewTxValidator creates new transactions validator
70
70
func NewTxValidator (ledger ledger.ValidatedLedger ) Validator {
71
71
// Encapsulates interface implementation
72
- return & txValidator {ledger , & vsccValidatorImpl {ledger }}
72
+ return & txValidator {ledger , & vsccValidatorImpl {ledger : ledger , ccprovider : ccprovider .GetChaincodeProvider ()}}
73
+ }
74
+
75
+ func (v * txValidator ) chainExists (chain string ) bool {
76
+ // TODO: implement this function!
77
+ return true
73
78
}
74
79
75
80
func (v * txValidator ) Validate (block * common.Block ) {
@@ -92,11 +97,19 @@ func (v *txValidator) Validate(block *common.Block) {
92
97
logger .Debug ("Validating transaction peer.ValidateTransaction()" )
93
98
var payload * common.Payload
94
99
var err error
95
- if payload , _ , err = peer .ValidateTransaction (env ); err != nil {
100
+ if payload , err = validation .ValidateTransaction (env ); err != nil {
96
101
logger .Errorf ("Invalid transaction with index %d, error %s" , tIdx , err )
97
102
continue
98
103
}
99
104
105
+ chain := payload .Header .ChainHeader .ChainID
106
+ logger .Debug ("Transaction is for chain %s" , chain )
107
+
108
+ if ! v .chainExists (chain ) {
109
+ logger .Errorf ("Dropping transaction for non-existent chain %s" , chain )
110
+ continue
111
+ }
112
+
100
113
if common .HeaderType (payload .Header .ChainHeader .Type ) == common .HeaderType_ENDORSER_TRANSACTION {
101
114
// Check duplicate transactions
102
115
txID := payload .Header .ChainHeader .TxID
@@ -113,7 +126,13 @@ func (v *txValidator) Validate(block *common.Block) {
113
126
continue
114
127
}
115
128
} else if common .HeaderType (payload .Header .ChainHeader .Type ) == common .HeaderType_CONFIGURATION_TRANSACTION {
116
- logger .Warningf ("Validation for common.HeaderType_CONFIGURATION_TRANSACTION %d pending JIRA-1639" , tIdx )
129
+ // TODO: here we should call CSCC and pass it the config tx
130
+ // note that there is quite a bit more validation necessary
131
+ // on this tx, namely, validation that each config item has
132
+ // signature matching the policy required for the item from
133
+ // the existing configuration; this is taken care of nicely
134
+ // by configtx.Manager (see fabric/common/configtx).
135
+ logger .Debug ("config transaction received for chain %s" , chain )
117
136
}
118
137
119
138
if _ , err := proto .Marshal (env ); err != nil {
@@ -157,15 +176,12 @@ func (v *vsccValidatorImpl) VSCCValidateTx(payload *common.Payload, envBytes []b
157
176
// args[1] - serialized Envelope
158
177
args := [][]byte {[]byte ("" ), envBytes }
159
178
160
- // get context for the chaincode execution
161
- lgr := v .ledger
162
- txsim , err := lgr .NewTxSimulator ()
179
+ ctxt , err := v .ccprovider .GetContext (v .ledger )
163
180
if err != nil {
164
- logger .Errorf ("Cannot obtain tx simulator txid=%s, err %s" , txid , err )
181
+ logger .Errorf ("Cannot obtain context for txid=%s, err %s" , txid , err )
165
182
return err
166
183
}
167
- defer txsim .Done ()
168
- ctxt := context .WithValue (context .Background (), chaincode .TXSimulatorKey , txsim )
184
+ defer v .ccprovider .ReleaseContext ()
169
185
170
186
// get header extensions so we have the visibility field
171
187
hdrExt , err := utils .GetChaincodeHeaderExtension (payload .Header )
@@ -177,31 +193,24 @@ func (v *vsccValidatorImpl) VSCCValidateTx(payload *common.Payload, envBytes []b
177
193
// Explanation: we actually deploying chaincode transaction,
178
194
// hence no lccc yet to query for the data, therefore currently
179
195
// introducing a workaround to skip obtaining LCCC data.
180
- var data * chaincode. ChaincodeData
196
+ vscc := "vscc"
181
197
if hdrExt .ChaincodeID .Name != "lccc" {
182
198
// Extracting vscc from lccc
183
- logger .Info ("Extracting chaincode data from LCCC txid = " , txid , "chainID" , chainID , "chaincode name" , hdrExt .ChaincodeID .Name )
184
- data , err = chaincode .GetChaincodeDataFromLCCC (ctxt , txid , nil , chainID , hdrExt .ChaincodeID .Name )
199
+ vscc , err = v .ccprovider .GetVSCCFromLCCC (ctxt , txid , nil , chainID , hdrExt .ChaincodeID .Name )
185
200
if err != nil {
186
201
logger .Errorf ("Unable to get chaincode data from LCCC for txid %s, due to %s" , txid , err )
187
202
return err
188
203
}
189
204
}
190
205
191
- vscc := "vscc"
192
- // Check whenever VSCC defined for chaincode data
193
- if data != nil && data .Vscc != "" {
194
- vscc = data .Vscc
195
- }
196
-
197
206
vscctxid := coreUtil .GenerateUUID ()
198
207
// Get chaincode version
199
208
version := coreUtil .GetSysCCVersion ()
200
- cccid := chaincode . NewCCContext (chainID , vscc , version , vscctxid , true , nil )
209
+ cccid := v . ccprovider . GetCCContext (chainID , vscc , version , vscctxid , true , nil )
201
210
202
211
// invoke VSCC
203
212
logger .Info ("Invoking VSCC txid" , txid , "chaindID" , chainID )
204
- _ , _ , err = chaincode .ExecuteChaincode (ctxt , cccid , args )
213
+ _ , _ , err = v . ccprovider .ExecuteChaincode (ctxt , cccid , args )
205
214
if err != nil {
206
215
logger .Errorf ("VSCC check failed for transaction txid=%s, error %s" , txid , err )
207
216
return err
0 commit comments