@@ -20,18 +20,17 @@ import (
20
20
"fmt"
21
21
22
22
"github.com/golang/protobuf/proto"
23
- "github.com/hyperledger/fabric/common/cauthdsl"
24
23
coreUtil "github.com/hyperledger/fabric/common/util"
25
24
"github.com/hyperledger/fabric/core/chaincode/shim"
26
25
"github.com/hyperledger/fabric/core/common/ccprovider"
27
26
"github.com/hyperledger/fabric/core/common/validation"
28
27
"github.com/hyperledger/fabric/core/ledger"
29
28
ledgerUtil "github.com/hyperledger/fabric/core/ledger/util"
30
29
"github.com/hyperledger/fabric/msp"
30
+
31
31
"github.com/hyperledger/fabric/protos/common"
32
32
"github.com/hyperledger/fabric/protos/utils"
33
33
"github.com/op/go-logging"
34
- "github.com/syndtr/goleveldb/leveldb/errors"
35
34
)
36
35
37
36
// Support provides all of the needed to evaluate the VSCC
@@ -177,41 +176,6 @@ func (v *txValidator) Validate(block *common.Block) error {
177
176
return nil
178
177
}
179
178
180
- // getSemiHardcodedPolicy returns a policy that requests
181
- // one valid signature from the first MSP in this
182
- // chain's MSP manager
183
- // FIXME: this needs to be removed as soon as we extract the policy from LCCC
184
- func getSemiHardcodedPolicy (chainID string , mspMgr msp.MSPManager ) ([]byte , error ) {
185
- // 1) determine the MSP identifier for the first MSP in this chain
186
- var msp msp.MSP
187
- msps , err := mspMgr .GetMSPs ()
188
- if err != nil {
189
- return nil , fmt .Errorf ("Could not retrieve the MSPs for the chain manager, err %s" , err )
190
- }
191
- if len (msps ) == 0 {
192
- return nil , errors .New ("At least one MSP was expected" )
193
- }
194
- for _ , m := range msps {
195
- msp = m
196
- break
197
- }
198
- mspid , err := msp .GetIdentifier ()
199
- if err != nil {
200
- return nil , fmt .Errorf ("Failure getting the msp identifier, err %s" , err )
201
- }
202
-
203
- // 2) get the policy
204
- p := cauthdsl .SignedByMspMember (mspid )
205
-
206
- // 3) marshal it and return it
207
- b , err := proto .Marshal (p )
208
- if err != nil {
209
- return nil , fmt .Errorf ("Could not marshal policy, err %s" , err )
210
- }
211
-
212
- return b , err
213
- }
214
-
215
179
func (v * vsccValidatorImpl ) VSCCValidateTx (payload * common.Payload , envBytes []byte ) error {
216
180
// Chain ID
217
181
chainID := payload .Header .ChainHeader .ChainID
@@ -230,21 +194,6 @@ func (v *vsccValidatorImpl) VSCCValidateTx(payload *common.Payload, envBytes []b
230
194
return err
231
195
}
232
196
233
- // TODO: temporary workaround until the policy is specified
234
- // by the deployer and can be retrieved via LCCC: we create
235
- // a policy that requests 1 valid signature from this chain's
236
- // MSP
237
- policy , err := getSemiHardcodedPolicy (chainID , v .support .MSPManager ())
238
- if err != nil {
239
- return err
240
- }
241
-
242
- // build arguments for VSCC invocation
243
- // args[0] - function name (not used now)
244
- // args[1] - serialized Envelope
245
- // args[2] - serialized policy
246
- args := [][]byte {[]byte ("" ), envBytes , policy }
247
-
248
197
ctxt , err := v .ccprovider .GetContext (v .support .Ledger ())
249
198
if err != nil {
250
199
logger .Errorf ("Cannot obtain context for txid=%s, err %s" , txid , err )
@@ -258,22 +207,32 @@ func (v *vsccValidatorImpl) VSCCValidateTx(payload *common.Payload, envBytes []b
258
207
return err
259
208
}
260
209
261
- // TODO: Temporary solution until FAB-1422 get resolved
262
- // Explanation: we actually deploying chaincode transaction,
263
- // hence no lccc yet to query for the data, therefore currently
264
- // introducing a workaround to skip obtaining LCCC data.
265
- vscc := "vscc"
266
- if hdrExt .ChaincodeID .Name != "lccc" {
267
- // Extracting vscc from lccc
268
- // TODO: extract policy as well when available; it's the second argument returned by GetCCValidationInfoFromLCCC
269
- vscc , _ , err = v .ccprovider .GetCCValidationInfoFromLCCC (ctxt , txid , nil , chainID , hdrExt .ChaincodeID .Name )
270
- if err != nil {
271
- logger .Errorf ("Unable to get chaincode data from LCCC for txid %s, due to %s" , txid , err )
272
- return err
273
- }
210
+ // LCCC should not undergo standard VSCC type of
211
+ // validation. It should instead go through system
212
+ // policy validation to determine whether the issuer
213
+ // is entitled to deploy a chaincode on our chain
214
+ // VSCCValidateTx should
215
+ if hdrExt .ChaincodeID .Name == "lccc" {
216
+ // TODO: until FAB-1934 is in, we need to stop here
217
+ logger .Infof ("Invocation of LCCC detected, no further VSCC validation necessary" )
218
+ return nil
219
+ }
220
+
221
+ // obtain name of the VSCC and the policy from LCCC
222
+ vscc , policy , err := v .ccprovider .GetCCValidationInfoFromLCCC (ctxt , txid , nil , chainID , hdrExt .ChaincodeID .Name )
223
+ if err != nil {
224
+ logger .Errorf ("Unable to get chaincode data from LCCC for txid %s, due to %s" , txid , err )
225
+ return err
274
226
}
275
227
228
+ // build arguments for VSCC invocation
229
+ // args[0] - function name (not used now)
230
+ // args[1] - serialized Envelope
231
+ // args[2] - serialized policy
232
+ args := [][]byte {[]byte ("" ), envBytes , policy }
233
+
276
234
vscctxid := coreUtil .GenerateUUID ()
235
+
277
236
// Get chaincode version
278
237
version := coreUtil .GetSysCCVersion ()
279
238
cccid := v .ccprovider .GetCCContext (chainID , vscc , version , vscctxid , true , nil )
0 commit comments