@@ -10,6 +10,7 @@ import (
1010 "fmt"
1111
1212 "github.com/hyperledger/fabric/common/channelconfig"
13+ "github.com/hyperledger/fabric/common/crypto"
1314 "github.com/hyperledger/fabric/common/flogging"
1415 "github.com/hyperledger/fabric/common/util"
1516 "github.com/hyperledger/fabric/core/chaincode"
@@ -34,6 +35,7 @@ type privateDataDistributor func(channel string, txID string, privateData *rwset
3435
3536// Support contains functions that the endorser requires to execute its tasks
3637type Support interface {
38+ crypto.SignerSupport
3739 // IsSysCCAndNotInvokableExternal returns true if the supplied chaincode is
3840 // ia system chaincode and it NOT invokable
3941 IsSysCCAndNotInvokableExternal (name string ) bool
@@ -60,7 +62,7 @@ type Support interface {
6062 // GetChaincodeDefinition returns ccprovider.ChaincodeDefinition for the chaincode with the supplied name
6163 GetChaincodeDefinition (ctx context.Context , chainID string , txid string , signedProp * pb.SignedProposal , prop * pb.Proposal , chaincodeID string , txsim ledger.TxSimulator ) (ccprovider.ChaincodeDefinition , error )
6264
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
6466 //SignedProposal from which an id can be extracted for testing against a policy
6567 CheckACL (signedProp * pb.SignedProposal , chdr * common.ChannelHeader , shdr * common.SignatureHeader , hdrext * pb.ChaincodeHeaderExtension ) error
6668
@@ -72,9 +74,15 @@ type Support interface {
7274 // ChaincodeDefinition differs from the instantiation policy stored on the ledger
7375 CheckInstantiationPolicy (name , version string , cd ccprovider.ChaincodeDefinition ) error
7476
75- // GetApplicationConfig returns the configtxapplication.SharedConfig for the channel
77+ // GetApplicationConfig returns the configtxapplication.SharedConfig for the Channel
7678 // and whether the Application config exists
7779 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 )
7886}
7987
8088// Endorser provides the Endorser service ProcessProposal
@@ -93,7 +101,7 @@ type validateResult struct {
93101}
94102
95103// 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 {
97105 e := & Endorser {
98106 distributePrivateData : privDist ,
99107 s : s ,
@@ -103,8 +111,8 @@ func NewEndorserServer(privDist privateDataDistributor, s Support) pb.EndorserSe
103111
104112//call specified chaincode (system or user)
105113func (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 )
108116 var err error
109117 var res * pb.Response
110118 var ccevent * pb.ChaincodeEvent
@@ -160,7 +168,7 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s
160168
161169//TO BE REMOVED WHEN JAVA CC IS ENABLED
162170//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 {
164172 //if not lscc we don't care
165173 if cid .Name != "lscc" {
166174 return nil
@@ -191,7 +199,7 @@ func (e *Endorser) disableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc
191199 return errors .Errorf ("too few arguments passed. expected %d" , argNo )
192200 }
193201
194- if javaEnabled () {
202+ if JavaEnabled () {
195203 endorserLogger .Debug ("java chaincode enabled" )
196204 } else {
197205 endorserLogger .Debug ("java chaincode disabled" )
@@ -209,8 +217,8 @@ func (e *Endorser) disableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc
209217 return nil
210218}
211219
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 ) {
214222 endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s" , chainID , shorttxid (txid ), cid )
215223 defer endorserLogger .Debugf ("[%s][%s] Exit" , chainID , shorttxid (txid ))
216224 //we do expect the payload to be a ChaincodeInvocationSpec
@@ -222,7 +230,7 @@ func (e *Endorser) simulateProposal(ctx context.Context, chainID string, txid st
222230 }
223231
224232 //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 {
226234 return nil , nil , nil , nil , err
227235 }
228236
@@ -281,7 +289,7 @@ func (e *Endorser) simulateProposal(ctx context.Context, chainID string, txid st
281289}
282290
283291//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 ) {
285293 endorserLogger .Debugf ("[%s][%s] Entry chaincode: %s" , chainID , shorttxid (txid ), ccid )
286294 defer endorserLogger .Debugf ("[%s][%s] Exit" , chainID , shorttxid (txid ))
287295
@@ -307,11 +315,6 @@ func (e *Endorser) endorseProposal(ctx context.Context, chainID string, txid str
307315 }
308316 }
309317
310- resBytes , err := putils .GetBytesResponse (response )
311- if err != nil {
312- return nil , errors .Wrap (err , "failed to marshal response bytes" )
313- }
314-
315318 // set version of executing chaincode
316319 if isSysCC {
317320 // 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
321324 ccid .Version = cd .CCVersion ()
322325 }
323326
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 ,
345338 }
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 )
368340}
369341
370342//preProcess checks the tx proposal headers, uniqueness and ACL
@@ -422,7 +394,7 @@ func (e *Endorser) preProcess(signedProp *pb.SignedProposal) (*validateResult, e
422394 // check ACL only for application chaincodes; ACLs
423395 // for system chaincodes are checked elsewhere
424396 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
426398 if err = e .s .CheckACL (signedProp , chdr , shdr , hdrExt ); err != nil {
427399 vr .resp = & pb.ProposalResponse {Response : & pb.Response {Status : 500 , Message : err .Error ()}}
428400 return vr , err
@@ -488,7 +460,7 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
488460 // to validate the supplied action before endorsing it
489461
490462 //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 )
492464 if err != nil {
493465 return & pb.ProposalResponse {Response : & pb.Response {Status : 500 , Message : err .Error ()}}, nil
494466 }
0 commit comments