@@ -29,10 +29,13 @@ import (
29
29
ledgerUtil "github.com/hyperledger/fabric/core/ledger/util"
30
30
"github.com/hyperledger/fabric/msp"
31
31
32
+ "github.com/hyperledger/fabric/common/policies"
32
33
"github.com/hyperledger/fabric/protos/common"
33
34
"github.com/hyperledger/fabric/protos/peer"
34
35
"github.com/hyperledger/fabric/protos/utils"
35
36
"github.com/op/go-logging"
37
+
38
+ "github.com/hyperledger/fabric/common/cauthdsl"
36
39
)
37
40
38
41
// Support provides all of the needed to evaluate the VSCC
@@ -45,6 +48,13 @@ type Support interface {
45
48
46
49
// Apply attempts to apply a configtx to become the new config
47
50
Apply (configtx * common.ConfigEnvelope ) error
51
+
52
+ // PolicyManager returns the policies.Manager for the channel
53
+ PolicyManager () policies.Manager
54
+
55
+ // GetMSPIDs returns the IDs for the application MSPs
56
+ // that have been defined in the channel
57
+ GetMSPIDs (cid string ) []string
48
58
}
49
59
50
60
//Validator interface which defines API to validate block transactions
@@ -58,7 +68,7 @@ type Validator interface {
58
68
// and vscc execution, in order to increase
59
69
// testability of txValidator
60
70
type vsccValidator interface {
61
- VSCCValidateTx (payload * common.Payload , envBytes []byte ) error
71
+ VSCCValidateTx (payload * common.Payload , envBytes []byte , env * common. Envelope ) error
62
72
}
63
73
64
74
// vsccValidator implementation which used to call
@@ -148,7 +158,7 @@ func (v *txValidator) Validate(block *common.Block) error {
148
158
149
159
//the payload is used to get headers
150
160
logger .Debug ("Validating transaction vscc tx validate" )
151
- if err = v .vscc .VSCCValidateTx (payload , d ); err != nil {
161
+ if err = v .vscc .VSCCValidateTx (payload , d , env ); err != nil {
152
162
txID := txID
153
163
logger .Errorf ("VSCCValidateTx for transaction txId = %s returned error %s" , txID , err )
154
164
txsfltr .SetFlag (tIdx , peer .TxValidationCode_ENDORSEMENT_POLICY_FAILURE )
@@ -191,7 +201,8 @@ func (v *txValidator) Validate(block *common.Block) error {
191
201
return nil
192
202
}
193
203
194
- func (v * vsccValidatorImpl ) VSCCValidateTx (payload * common.Payload , envBytes []byte ) error {
204
+ func (v * vsccValidatorImpl ) VSCCValidateTx (payload * common.Payload , envBytes []byte , env * common.Envelope ) error {
205
+ // get channel header
195
206
chdr , err := utils .UnmarshalChannelHeader (payload .Header .ChannelHeader )
196
207
if err != nil {
197
208
return err
@@ -226,22 +237,25 @@ func (v *vsccValidatorImpl) VSCCValidateTx(payload *common.Payload, envBytes []b
226
237
return err
227
238
}
228
239
229
- // LSCC should not undergo standard VSCC type of
230
- // validation. It should instead go through system
231
- // policy validation to determine whether the issuer
232
- // is entitled to deploy a chaincode on our chain
233
- // VSCCValidateTx should
234
- if hdrExt .ChaincodeId .Name == "lscc" {
235
- // TODO: until FAB-1934 is in, we need to stop here
236
- logger .Debugf ("Invocation of LSCC detected, no further VSCC validation necessary" )
237
- return nil
238
- }
239
-
240
- // obtain name of the VSCC and the policy from LSCC
241
- vscc , policy , err := v .ccprovider .GetCCValidationInfoFromLSCC (ctxt , txid , nil , nil , chainID , hdrExt .ChaincodeId .Name )
242
- if err != nil {
243
- logger .Errorf ("Unable to get chaincode data from LSCC for txid %s, due to %s" , txid , err )
244
- return err
240
+ var vscc string
241
+ var policy []byte
242
+ if hdrExt .ChaincodeId .Name != "lscc" {
243
+ // when we are validating any chaincode other than
244
+ // LSCC, we need to ask LSCC to give us the name
245
+ // of VSCC and of the policy that should be used
246
+
247
+ // obtain name of the VSCC and the policy from LSCC
248
+ vscc , policy , err = v .ccprovider .GetCCValidationInfoFromLSCC (ctxt , txid , nil , nil , chainID , hdrExt .ChaincodeId .Name )
249
+ if err != nil {
250
+ logger .Errorf ("Unable to get chaincode data from LSCC for txid %s, due to %s" , txid , err )
251
+ return err
252
+ }
253
+ } else {
254
+ // when we are validating LSCC, we use the default
255
+ // VSCC and a default policy that requires one signature
256
+ // from any of the members of the channel
257
+ vscc = "vscc"
258
+ policy = cauthdsl .SignedByAnyMember (v .support .GetMSPIDs (chainID ))
245
259
}
246
260
247
261
// build arguments for VSCC invocation
0 commit comments