Skip to content

Commit e0fd885

Browse files
committed
[FAB-9653] Cleanup endorser ProcessProposal log msg
This CR cleans up an endorser log message that printed as "Exit: request from%!(EXTRA string=172.22.0.14:59776)" It also adds a space before any comments in the code that lacked them and fixes go vet issues in the tests. Change-Id: Ie8bc64134392e99eea046e139840cacb13e8c8d7 Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
1 parent d72c7a4 commit e0fd885

File tree

2 files changed

+150
-66
lines changed

2 files changed

+150
-66
lines changed

core/endorser/endorser.go

+43-43
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ type Support interface {
5252
// GetTransactionByID retrieves a transaction by id
5353
GetTransactionByID(chid, txID string) (*pb.ProcessedTransaction, error)
5454

55-
//IsSysCC returns true if the name matches a system chaincode's
56-
//system chaincode names are system, chain wide
55+
// IsSysCC returns true if the name matches a system chaincode's
56+
// system chaincode names are system, chain wide
5757
IsSysCC(name string) bool
5858

5959
//Execute - execute proposal, return original response of chaincode
@@ -62,8 +62,8 @@ type Support interface {
6262
// GetChaincodeDefinition returns ccprovider.ChaincodeDefinition for the chaincode with the supplied name
6363
GetChaincodeDefinition(ctx context.Context, chainID string, txid string, signedProp *pb.SignedProposal, prop *pb.Proposal, chaincodeID string, txsim ledger.TxSimulator) (ccprovider.ChaincodeDefinition, error)
6464

65-
//CheckACL checks the ACL for the resource for the Channel using the
66-
//SignedProposal from which an id can be extracted for testing against a policy
65+
// CheckACL checks the ACL for the resource for the channel using the
66+
// SignedProposal from which an id can be extracted for testing against a policy
6767
CheckACL(signedProp *pb.SignedProposal, chdr *common.ChannelHeader, shdr *common.SignatureHeader, hdrext *pb.ChaincodeHeaderExtension) error
6868

6969
// IsJavaCC returns true if the CDS package bytes describe a chaincode
@@ -111,7 +111,7 @@ func NewEndorserServer(privDist privateDataDistributor, s Support) *Endorser {
111111
return e
112112
}
113113

114-
//call specified chaincode (system or user)
114+
// call specified chaincode (system or user)
115115
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) {
116116
endorserLogger.Debugf("[%s][%s] Entry chaincode: %s version: %s", chainID, txid, cid, version)
117117
defer endorserLogger.Debugf("[%s][%s] Exit", chainID, txid)
@@ -123,37 +123,37 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s
123123
ctxt = context.WithValue(ctxt, chaincode.TXSimulatorKey, txsim)
124124
}
125125

126-
//is this a system chaincode
126+
// is this a system chaincode
127127
scc := e.s.IsSysCC(cid.Name)
128128

129129
res, ccevent, err = e.s.Execute(ctxt, chainID, cid.Name, version, txid, scc, signedProp, prop, cis)
130130
if err != nil {
131131
return nil, nil, err
132132
}
133133

134-
//per doc anything < 400 can be sent as TX.
135-
//fabric errors will always be >= 400 (ie, unambiguous errors )
136-
//"lscc" will respond with status 200 or 500 (ie, unambiguous OK or ERROR)
134+
// per doc anything < 400 can be sent as TX.
135+
// fabric errors will always be >= 400 (ie, unambiguous errors )
136+
// "lscc" will respond with status 200 or 500 (ie, unambiguous OK or ERROR)
137137
if res.Status >= shim.ERRORTHRESHOLD {
138138
return res, nil, nil
139139
}
140140

141-
//----- BEGIN - SECTION THAT MAY NEED TO BE DONE IN LSCC ------
142-
//if this a call to deploy a chaincode, We need a mechanism
143-
//to pass TxSimulator into LSCC. Till that is worked out this
144-
//special code does the actual deploy, upgrade here so as to collect
145-
//all state under one TxSimulator
141+
// ----- BEGIN - SECTION THAT MAY NEED TO BE DONE IN LSCC ------
142+
// if this a call to deploy a chaincode, We need a mechanism
143+
// to pass TxSimulator into LSCC. Till that is worked out this
144+
// special code does the actual deploy, upgrade here so as to collect
145+
// all state under one TxSimulator
146146
//
147-
//NOTE that if there's an error all simulation, including the chaincode
148-
//table changes in lscc will be thrown away
147+
// NOTE that if there's an error all simulation, including the chaincode
148+
// table changes in lscc will be thrown away
149149
if cid.Name == "lscc" && len(cis.ChaincodeSpec.Input.Args) >= 3 && (string(cis.ChaincodeSpec.Input.Args[0]) == "deploy" || string(cis.ChaincodeSpec.Input.Args[0]) == "upgrade") {
150150
var cds *pb.ChaincodeDeploymentSpec
151151
cds, err = putils.GetChaincodeDeploymentSpec(cis.ChaincodeSpec.Input.Args[2])
152152
if err != nil {
153153
return nil, nil, err
154154
}
155155

156-
//this should not be a system chaincode
156+
// this should not be a system chaincode
157157
if e.s.IsSysCC(cds.ChaincodeSpec.ChaincodeId.Name) {
158158
return nil, nil, errors.Errorf("attempting to deploy a system chaincode %s/%s", cds.ChaincodeSpec.ChaincodeId.Name, chainID)
159159
}
@@ -163,25 +163,25 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s
163163
return nil, nil, err
164164
}
165165
}
166-
//----- END -------
166+
// ----- END -------
167167

168168
return res, ccevent, err
169169
}
170170

171-
//TO BE REMOVED WHEN JAVA CC IS ENABLED
172-
//disableJavaCCInst if trying to install, instantiate or upgrade Java CC
171+
// TO BE REMOVED WHEN JAVA CC IS ENABLED
172+
// disableJavaCCInst if trying to install, instantiate or upgrade Java CC
173173
func (e *Endorser) DisableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvocationSpec) error {
174-
//if not lscc we don't care
174+
// if not lscc we don't care
175175
if cid.Name != "lscc" {
176176
return nil
177177
}
178178

179-
//non-nil spec ? leave it to callers to handle error if this is an error
179+
// non-nil spec ? leave it to callers to handle error if this is an error
180180
if cis.ChaincodeSpec == nil || cis.ChaincodeSpec.Input == nil {
181181
return nil
182182
}
183183

184-
//should at least have a command arg, leave it to callers if this is an error
184+
// should at least have a command arg, leave it to callers if this is an error
185185
if len(cis.ChaincodeSpec.Input.Args) < 1 {
186186
return nil
187187
}
@@ -193,7 +193,7 @@ func (e *Endorser) DisableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc
193193
case "deploy", "upgrade":
194194
argNo = 2
195195
default:
196-
//what else can it be ? leave it caller to handle it if error
196+
// what else can it be ? leave it caller to handle it if error
197197
return nil
198198
}
199199

@@ -205,7 +205,7 @@ func (e *Endorser) DisableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc
205205
endorserLogger.Debug("java chaincode enabled")
206206
} else {
207207
endorserLogger.Debug("java chaincode disabled")
208-
//finally, if JAVA not enabled error out
208+
// finally, if JAVA not enabled error out
209209
isjava, err := e.s.IsJavaCC(cis.ChaincodeSpec.Input.Args[argNo])
210210
if err != nil {
211211
return err
@@ -215,23 +215,23 @@ func (e *Endorser) DisableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc
215215
}
216216
}
217217

218-
//not a java install, instantiate or upgrade op
218+
// not a java install, instantiate or upgrade op
219219
return nil
220220
}
221221

222-
//SimulateProposal simulates the proposal by calling the chaincode
222+
// SimulateProposal simulates the proposal by calling the chaincode
223223
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) {
224224
endorserLogger.Debugf("[%s][%s] Entry chaincode: %s", chainID, shorttxid(txid), cid)
225225
defer endorserLogger.Debugf("[%s][%s] Exit", chainID, shorttxid(txid))
226-
//we do expect the payload to be a ChaincodeInvocationSpec
227-
//if we are supporting other payloads in future, this be glaringly point
228-
//as something that should change
226+
// we do expect the payload to be a ChaincodeInvocationSpec
227+
// if we are supporting other payloads in future, this be glaringly point
228+
// as something that should change
229229
cis, err := putils.GetChaincodeInvocationSpec(prop)
230230
if err != nil {
231231
return nil, nil, nil, nil, err
232232
}
233233

234-
//disable Java install,instantiate,upgrade for now
234+
// disable Java install,instantiate,upgrade for now
235235
if err = e.DisableJavaCCInst(cid, cis); err != nil {
236236
return nil, nil, nil, nil, err
237237
}
@@ -254,7 +254,7 @@ func (e *Endorser) SimulateProposal(ctx context.Context, chainID string, txid st
254254
version = util.GetSysCCVersion()
255255
}
256256

257-
//---3. execute the proposal and get simulation results
257+
// ---3. execute the proposal and get simulation results
258258
var simResult *ledger.TxSimulationResults
259259
var pubSimResBytes []byte
260260
var res *pb.Response
@@ -298,15 +298,15 @@ func (e *Endorser) SimulateProposal(ctx context.Context, chainID string, txid st
298298
return cdLedger, res, pubSimResBytes, ccevent, nil
299299
}
300300

301-
//endorse the proposal by calling the ESCC
301+
// endorse the proposal by calling the ESCC
302302
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) {
303303
endorserLogger.Debugf("[%s][%s] Entry chaincode: %s", chainID, shorttxid(txid), ccid)
304304
defer endorserLogger.Debugf("[%s][%s] Exit", chainID, shorttxid(txid))
305305

306306
isSysCC := cd == nil
307307
// 1) extract the name of the escc that is requested to endorse this chaincode
308308
var escc string
309-
//ie, "lscc" or system chaincodes
309+
// ie, "lscc" or system chaincodes
310310
if isSysCC {
311311
escc = "escc"
312312
} else {
@@ -349,7 +349,7 @@ func (e *Endorser) endorseProposal(_ context.Context, chainID string, txid strin
349349
return e.s.EndorseWithPlugin(ctx)
350350
}
351351

352-
//preProcess checks the tx proposal headers, uniqueness and ACL
352+
// preProcess checks the tx proposal headers, uniqueness and ACL
353353
func (e *Endorser) preProcess(signedProp *pb.SignedProposal) (*validateResult, error) {
354354
vr := &validateResult{}
355355
// at first, we check whether the message is valid
@@ -424,10 +424,10 @@ func (e *Endorser) preProcess(signedProp *pb.SignedProposal) (*validateResult, e
424424
// ProcessProposal process the Proposal
425425
func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedProposal) (*pb.ProposalResponse, error) {
426426
addr := util.ExtractRemoteAddress(ctx)
427-
endorserLogger.Debug("Entering: Got request from", addr)
428-
defer endorserLogger.Debugf("Exit: request from", addr)
427+
endorserLogger.Debug("Entering: request from", addr)
428+
defer endorserLogger.Debug("Exit: request from", addr)
429429

430-
//0 -- check and validate
430+
// 0 -- check and validate
431431
vr, err := e.preProcess(signedProp)
432432
if err != nil {
433433
resp := vr.resp
@@ -462,14 +462,14 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
462462
// around separately, since eventually it gets added to context anyways
463463
ctx = context.WithValue(ctx, chaincode.HistoryQueryExecutorKey, historyQueryExecutor)
464464
}
465-
//this could be a request to a chainless SysCC
465+
// this could be a request to a chainless SysCC
466466

467467
// TODO: if the proposal has an extension, it will be of type ChaincodeAction;
468468
// if it's present it means that no simulation is to be performed because
469469
// we're trying to emulate a submitting peer. On the other hand, we need
470470
// to validate the supplied action before endorsing it
471471

472-
//1 -- simulate
472+
// 1 -- simulate
473473
cd, res, simulationResult, ccevent, err := e.SimulateProposal(ctx, chainID, txid, signedProp, prop, hdrExt.ChaincodeId, txsim)
474474
if err != nil {
475475
return &pb.ProposalResponse{Response: &pb.Response{Status: 500, Message: err.Error()}}, nil
@@ -493,11 +493,11 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
493493
}
494494
}
495495

496-
//2 -- endorse and get a marshalled ProposalResponse message
496+
// 2 -- endorse and get a marshalled ProposalResponse message
497497
var pResp *pb.ProposalResponse
498498

499-
//TODO till we implement global ESCC, CSCC for system chaincodes
500-
//chainless proposals (such as CSCC) don't have to be endorsed
499+
// TODO till we implement global ESCC, CSCC for system chaincodes
500+
// chainless proposals (such as CSCC) don't have to be endorsed
501501
if chainID == "" {
502502
pResp = &pb.ProposalResponse{Response: res}
503503
} else {

0 commit comments

Comments
 (0)