@@ -10,6 +10,7 @@ import (
10
10
"fmt"
11
11
12
12
"github.com/hyperledger/fabric/common/channelconfig"
13
+ "github.com/hyperledger/fabric/common/crypto"
13
14
"github.com/hyperledger/fabric/common/flogging"
14
15
"github.com/hyperledger/fabric/common/util"
15
16
"github.com/hyperledger/fabric/core/chaincode"
@@ -34,6 +35,7 @@ type privateDataDistributor func(channel string, txID string, privateData *rwset
34
35
35
36
// Support contains functions that the endorser requires to execute its tasks
36
37
type Support interface {
38
+ crypto.SignerSupport
37
39
// IsSysCCAndNotInvokableExternal returns true if the supplied chaincode is
38
40
// ia system chaincode and it NOT invokable
39
41
IsSysCCAndNotInvokableExternal (name string ) bool
@@ -60,7 +62,7 @@ type Support interface {
60
62
// GetChaincodeDefinition returns ccprovider.ChaincodeDefinition for the chaincode with the supplied name
61
63
GetChaincodeDefinition (ctx context.Context , chainID string , txid string , signedProp * pb.SignedProposal , prop * pb.Proposal , chaincodeID string , txsim ledger.TxSimulator ) (ccprovider.ChaincodeDefinition , error )
62
64
63
- //CheckACL checks the ACL for the resource for the channel using the
65
+ //CheckACL checks the ACL for the resource for the Channel using the
64
66
//SignedProposal from which an id can be extracted for testing against a policy
65
67
CheckACL (signedProp * pb.SignedProposal , chdr * common.ChannelHeader , shdr * common.SignatureHeader , hdrext * pb.ChaincodeHeaderExtension ) error
66
68
@@ -72,9 +74,15 @@ type Support interface {
72
74
// ChaincodeDefinition differs from the instantiation policy stored on the ledger
73
75
CheckInstantiationPolicy (name , version string , cd ccprovider.ChaincodeDefinition ) error
74
76
75
- // GetApplicationConfig returns the configtxapplication.SharedConfig for the channel
77
+ // GetApplicationConfig returns the configtxapplication.SharedConfig for the Channel
76
78
// and whether the Application config exists
77
79
GetApplicationConfig (cid string ) (channelconfig.Application , bool )
80
+
81
+ // NewQueryCreator creates a new QueryCreator
82
+ NewQueryCreator (channel string ) (QueryCreator , error )
83
+
84
+ // EndorseWithPlugin endorses the response with a plugin
85
+ EndorseWithPlugin (ctx Context ) (* pb.ProposalResponse , error )
78
86
}
79
87
80
88
// Endorser provides the Endorser service ProcessProposal
@@ -93,7 +101,7 @@ type validateResult struct {
93
101
}
94
102
95
103
// NewEndorserServer creates and returns a new Endorser server instance.
96
- func NewEndorserServer (privDist privateDataDistributor , s Support ) pb. EndorserServer {
104
+ func NewEndorserServer (privDist privateDataDistributor , s Support ) * Endorser {
97
105
e := & Endorser {
98
106
distributePrivateData : privDist ,
99
107
s : s ,
@@ -103,8 +111,8 @@ func NewEndorserServer(privDist privateDataDistributor, s Support) pb.EndorserSe
103
111
104
112
//call specified chaincode (system or user)
105
113
func (e * Endorser ) callChaincode (ctxt context.Context , chainID string , version string , txid string , signedProp * pb.SignedProposal , prop * pb.Proposal , cis * pb.ChaincodeInvocationSpec , cid * pb.ChaincodeID , txsim ledger.TxSimulator ) (* pb.Response , * pb.ChaincodeEvent , error ) {
106
- endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s version: %s" , chainID , shorttxid ( txid ) , cid , version )
107
- defer endorserLogger .Debugf ("[%s][%s] Exit" , chainID , shorttxid ( txid ) )
114
+ endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s version: %s" , chainID , txid , cid , version )
115
+ defer endorserLogger .Debugf ("[%s][%s] Exit" , chainID , txid )
108
116
var err error
109
117
var res * pb.Response
110
118
var ccevent * pb.ChaincodeEvent
@@ -160,7 +168,7 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s
160
168
161
169
//TO BE REMOVED WHEN JAVA CC IS ENABLED
162
170
//disableJavaCCInst if trying to install, instantiate or upgrade Java CC
163
- func (e * Endorser ) disableJavaCCInst (cid * pb.ChaincodeID , cis * pb.ChaincodeInvocationSpec ) error {
171
+ func (e * Endorser ) DisableJavaCCInst (cid * pb.ChaincodeID , cis * pb.ChaincodeInvocationSpec ) error {
164
172
//if not lscc we don't care
165
173
if cid .Name != "lscc" {
166
174
return nil
@@ -191,7 +199,7 @@ func (e *Endorser) disableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc
191
199
return errors .Errorf ("too few arguments passed. expected %d" , argNo )
192
200
}
193
201
194
- if javaEnabled () {
202
+ if JavaEnabled () {
195
203
endorserLogger .Debug ("java chaincode enabled" )
196
204
} else {
197
205
endorserLogger .Debug ("java chaincode disabled" )
@@ -209,8 +217,8 @@ func (e *Endorser) disableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc
209
217
return nil
210
218
}
211
219
212
- //simulate the proposal by calling the chaincode
213
- func (e * Endorser ) simulateProposal (ctx context.Context , chainID string , txid string , signedProp * pb.SignedProposal , prop * pb.Proposal , cid * pb.ChaincodeID , txsim ledger.TxSimulator ) (ccprovider.ChaincodeDefinition , * pb.Response , []byte , * pb.ChaincodeEvent , error ) {
220
+ //SimulateProposal simulates the proposal by calling the chaincode
221
+ func (e * Endorser ) SimulateProposal (ctx context.Context , chainID string , txid string , signedProp * pb.SignedProposal , prop * pb.Proposal , cid * pb.ChaincodeID , txsim ledger.TxSimulator ) (ccprovider.ChaincodeDefinition , * pb.Response , []byte , * pb.ChaincodeEvent , error ) {
214
222
endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s" , chainID , shorttxid (txid ), cid )
215
223
defer endorserLogger .Debugf ("[%s][%s] Exit" , chainID , shorttxid (txid ))
216
224
//we do expect the payload to be a ChaincodeInvocationSpec
@@ -222,7 +230,7 @@ func (e *Endorser) simulateProposal(ctx context.Context, chainID string, txid st
222
230
}
223
231
224
232
//disable Java install,instantiate,upgrade for now
225
- if err = e .disableJavaCCInst (cid , cis ); err != nil {
233
+ if err = e .DisableJavaCCInst (cid , cis ); err != nil {
226
234
return nil , nil , nil , nil , err
227
235
}
228
236
@@ -281,7 +289,7 @@ func (e *Endorser) simulateProposal(ctx context.Context, chainID string, txid st
281
289
}
282
290
283
291
//endorse the proposal by calling the ESCC
284
- func (e * Endorser ) endorseProposal (ctx context.Context , chainID string , txid string , signedProp * pb.SignedProposal , proposal * pb.Proposal , response * pb.Response , simRes []byte , event * pb.ChaincodeEvent , visibility []byte , ccid * pb.ChaincodeID , txsim ledger.TxSimulator , cd ccprovider.ChaincodeDefinition ) (* pb.ProposalResponse , error ) {
292
+ func (e * Endorser ) endorseProposal (_ context.Context , chainID string , txid string , signedProp * pb.SignedProposal , proposal * pb.Proposal , response * pb.Response , simRes []byte , event * pb.ChaincodeEvent , visibility []byte , ccid * pb.ChaincodeID , txsim ledger.TxSimulator , cd ccprovider.ChaincodeDefinition ) (* pb.ProposalResponse , error ) {
285
293
endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s" , chainID , shorttxid (txid ), ccid )
286
294
defer endorserLogger .Debugf ("[%s][%s] Exit" , chainID , shorttxid (txid ))
287
295
@@ -307,11 +315,6 @@ func (e *Endorser) endorseProposal(ctx context.Context, chainID string, txid str
307
315
}
308
316
}
309
317
310
- resBytes , err := putils .GetBytesResponse (response )
311
- if err != nil {
312
- return nil , errors .Wrap (err , "failed to marshal response bytes" )
313
- }
314
-
315
318
// set version of executing chaincode
316
319
if isSysCC {
317
320
// if we want to allow mixed fabric levels we should
@@ -321,50 +324,19 @@ func (e *Endorser) endorseProposal(ctx context.Context, chainID string, txid str
321
324
ccid .Version = cd .CCVersion ()
322
325
}
323
326
324
- ccidBytes , err := putils .Marshal (ccid )
325
- if err != nil {
326
- return nil , errors .Wrap (err , "failed to marshal ChaincodeID" )
327
- }
328
-
329
- // 3) call the ESCC we've identified
330
- // arguments:
331
- // args[0] - function name (not used now)
332
- // args[1] - serialized Header object
333
- // args[2] - serialized ChaincodeProposalPayload object
334
- // args[3] - ChaincodeID of executing chaincode
335
- // args[4] - result of executing chaincode
336
- // args[5] - binary blob of simulation results
337
- // args[6] - serialized events
338
- // args[7] - payloadVisibility
339
- args := [][]byte {[]byte ("" ), proposal .Header , proposal .Payload , ccidBytes , resBytes , simRes , eventBytes , visibility }
340
- version := util .GetSysCCVersion ()
341
- ecccis := & pb.ChaincodeInvocationSpec {ChaincodeSpec : & pb.ChaincodeSpec {Type : pb .ChaincodeSpec_GOLANG , ChaincodeId : & pb.ChaincodeID {Name : escc }, Input : & pb.ChaincodeInput {Args : args }}}
342
- res , _ , err := e .callChaincode (ctx , chainID , version , txid , signedProp , proposal , ecccis , & pb.ChaincodeID {Name : escc }, txsim )
343
- if err != nil {
344
- return nil , err
327
+ ctx := Context {
328
+ PluginName : escc ,
329
+ Channel : chainID ,
330
+ SignedProposal : signedProp ,
331
+ ChaincodeID : ccid ,
332
+ Event : eventBytes ,
333
+ SimRes : simRes ,
334
+ Response : response ,
335
+ Visibility : visibility ,
336
+ Proposal : proposal ,
337
+ TxID : txid ,
345
338
}
346
-
347
- if res .Status >= shim .ERRORTHRESHOLD {
348
- return & pb.ProposalResponse {Response : res }, nil
349
- }
350
-
351
- prBytes := res .Payload
352
- // Note that we do not extract any simulation results from
353
- // the call to ESCC. This is intentional becuse ESCC is meant
354
- // to endorse (i.e. sign) the simulation results of a chaincode,
355
- // but it can't obviously sign its own. Furthermore, ESCC runs
356
- // on private input (its own signing key) and so if it were to
357
- // produce simulationr results, they are likely to be different
358
- // from other ESCCs, which would stand in the way of the
359
- // endorsement process.
360
-
361
- //3 -- respond
362
- pResp , err := putils .GetProposalResponse (prBytes )
363
- if err != nil {
364
- return nil , err
365
- }
366
-
367
- return pResp , nil
339
+ return e .s .EndorseWithPlugin (ctx )
368
340
}
369
341
370
342
//preProcess checks the tx proposal headers, uniqueness and ACL
@@ -422,7 +394,7 @@ func (e *Endorser) preProcess(signedProp *pb.SignedProposal) (*validateResult, e
422
394
// check ACL only for application chaincodes; ACLs
423
395
// for system chaincodes are checked elsewhere
424
396
if ! e .s .IsSysCC (hdrExt .ChaincodeId .Name ) {
425
- // check that the proposal complies with the channel 's writers
397
+ // check that the proposal complies with the Channel 's writers
426
398
if err = e .s .CheckACL (signedProp , chdr , shdr , hdrExt ); err != nil {
427
399
vr .resp = & pb.ProposalResponse {Response : & pb.Response {Status : 500 , Message : err .Error ()}}
428
400
return vr , err
@@ -488,7 +460,7 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
488
460
// to validate the supplied action before endorsing it
489
461
490
462
//1 -- simulate
491
- cd , res , simulationResult , ccevent , err := e .simulateProposal (ctx , chainID , txid , signedProp , prop , hdrExt .ChaincodeId , txsim )
463
+ cd , res , simulationResult , ccevent , err := e .SimulateProposal (ctx , chainID , txid , signedProp , prop , hdrExt .ChaincodeId , txsim )
492
464
if err != nil {
493
465
return & pb.ProposalResponse {Response : & pb.Response {Status : 500 , Message : err .Error ()}}, nil
494
466
}
0 commit comments