Skip to content

Commit db12773

Browse files
author
Jason Yellick
committed
FAB-16353 Pass chaincode input from unpack
The endorser.go path is currently doubly unmarshaling the chaincode input. This CR simply uses the one preserved/parsed during the unpacking process instead. Change-Id: I81c06977eac801bea4418981f1c737e7cbb4852c Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent eb09155 commit db12773

File tree

2 files changed

+3
-28
lines changed

2 files changed

+3
-28
lines changed

core/endorser/endorser.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,12 @@ func (e *Endorser) callChaincode(txParams *ccprovider.TransactionParams, input *
160160
}
161161

162162
// SimulateProposal simulates the proposal by calling the chaincode
163-
func (e *Endorser) SimulateProposal(txParams *ccprovider.TransactionParams, chaincodeName string) (*pb.Response, []byte, *pb.ChaincodeEvent, error) {
163+
func (e *Endorser) SimulateProposal(txParams *ccprovider.TransactionParams, chaincodeName string, chaincodeInput *pb.ChaincodeInput) (*pb.Response, []byte, *pb.ChaincodeEvent, error) {
164164
endorserLogger.Debugf("[%s][%s] Entry chaincode: %s", txParams.ChannelID, shorttxid(txParams.TxID), chaincodeName)
165165
defer endorserLogger.Debugf("[%s][%s] Exit", txParams.ChannelID, shorttxid(txParams.TxID))
166-
// we do expect the payload to be a ChaincodeInvocationSpec
167-
// if we are supporting other payloads in future, this be glaringly point
168-
// as something that should change
169-
cis, err := protoutil.GetChaincodeInvocationSpec(txParams.Proposal)
170-
if err != nil {
171-
return nil, nil, nil, err
172-
}
173166

174167
// ---3. execute the proposal and get simulation results
175-
res, ccevent, err := e.callChaincode(txParams, cis.ChaincodeSpec.Input, chaincodeName)
168+
res, ccevent, err := e.callChaincode(txParams, chaincodeInput, chaincodeName)
176169
if err != nil {
177170
endorserLogger.Errorf("[%s][%s] failed to invoke chaincode %s, error: %+v", txParams.ChannelID, shorttxid(txParams.TxID), chaincodeName, err)
178171
return nil, nil, nil, err
@@ -403,7 +396,7 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
403396
}
404397

405398
// 1 -- simulate
406-
res, simulationResult, ccevent, err := e.SimulateProposal(txParams, up.ChaincodeName)
399+
res, simulationResult, ccevent, err := e.SimulateProposal(txParams, up.ChaincodeName, up.Input)
407400
if err != nil {
408401
return &pb.ProposalResponse{Response: &pb.Response{Status: 500, Message: err.Error()}}, nil
409402
}

core/endorser/endorser_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -631,24 +631,6 @@ func TestEndorseEndorsementFailureDueToCCError(t *testing.T) {
631631
testEndorsementCompletedMetric(t, fakeMetrics, 1, util.GetTestChainID(), "ccid", "false")
632632
}
633633

634-
func TestSimulateProposal(t *testing.T) {
635-
es := endorser.NewEndorserServer(pvtEmptyDistributor, &mocks.MockSupport{
636-
GetApplicationConfigBoolRv: true,
637-
GetApplicationConfigRv: &mc.MockApplication{CapabilitiesRv: &mc.MockApplicationCapabilities{}},
638-
GetTransactionByIDErr: errors.New(""),
639-
ChaincodeDefinitionRv: &ccprovider.ChaincodeData{Escc: "ESCC"},
640-
ExecuteResp: &pb.Response{Status: 200, Payload: protoutil.MarshalOrPanic(&pb.ProposalResponse{Response: &pb.Response{}})},
641-
GetTxSimulatorRv: &mocks.MockTxSim{
642-
GetTxSimulationResultsRv: &ledger.TxSimulationResults{
643-
PubSimulationResults: &rwset.TxReadWriteSet{},
644-
},
645-
},
646-
}, &disabled.Provider{})
647-
648-
_, _, _, err := es.SimulateProposal(&ccprovider.TransactionParams{}, "")
649-
assert.Error(t, err)
650-
}
651-
652634
func TestEndorserAcquireTxSimulator(t *testing.T) {
653635
tc := []struct {
654636
name string

0 commit comments

Comments
 (0)