Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit bdbc9bd

Browse files
authored
[FABG-1006] Fix for query committed "responses do not match" (#129)
Compare the protos in the responses instead of the bytes. Signed-off-by: Bob Stasyszyn <[email protected]>
1 parent 470fd07 commit bdbc9bd

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

pkg/client/resmgmt/lifecycleclient_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,8 @@ func TestClient_LifecycleCheckCCCommitReadiness(t *testing.T) {
662662
ctx.SetCustomChannelProvider(cp)
663663

664664
resp, err := rc.LifecycleCheckCCCommitReadiness(channel1, req, WithTargets(peer1))
665-
require.EqualError(t, err, "responses from endorsers do not match")
665+
require.Error(t, err)
666+
require.Contains(t, err.Error(), "responses from endorsers do not match")
666667
require.Empty(t, resp)
667668
})
668669
}
@@ -1109,7 +1110,8 @@ func TestClient_LifecycleQueryCommittedCC(t *testing.T) {
11091110
ctx.SetCustomChannelProvider(cp)
11101111

11111112
resp, err := rc.LifecycleQueryCommittedCC(channel1, LifecycleQueryCommittedCCRequest{}, WithTargets(&fcmocks.MockPeer{}))
1112-
require.EqualError(t, err, "responses from endorsers do not match")
1113+
require.Error(t, err)
1114+
require.Contains(t, err.Error(), "responses from endorsers do not match")
11131115
require.Empty(t, resp)
11141116
})
11151117
}

pkg/client/resmgmt/lifecycleprocessor.go

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
77
package resmgmt
88

99
import (
10-
"bytes"
1110
reqContext "context"
1211
"fmt"
1312
"strings"
@@ -192,7 +191,12 @@ func (p *lifecycleProcessor) checkCommitReadiness(reqCtx reqContext.Context, cha
192191
return LifecycleCheckCCCommitReadinessResponse{}, errors.WithMessage(err, "sending approve transaction proposal failed to verify signature")
193192
}
194193

195-
err = p.verifyResponsesMatch(txProposalResponse)
194+
err = p.verifyResponsesMatch(txProposalResponse,
195+
func(payload []byte) (proto.Message, error) {
196+
result := &lb.CheckCommitReadinessResult{}
197+
return result, proto.Unmarshal(payload, result)
198+
},
199+
)
196200
if err != nil {
197201
return LifecycleCheckCCCommitReadinessResponse{}, err
198202
}
@@ -275,7 +279,11 @@ func (p *lifecycleProcessor) queryCommitted(reqCtx reqContext.Context, channelID
275279
return nil, errors.WithMessage(err, "sending query committed transaction proposal failed to verify signature")
276280
}
277281

278-
err = p.verifyResponsesMatch(txProposalResponse)
282+
err = p.verifyResponsesMatch(txProposalResponse,
283+
func(payload []byte) (proto.Message, error) {
284+
return unmarshalCCDefResults(req.Name, payload)
285+
},
286+
)
279287
if err != nil {
280288
return nil, err
281289
}
@@ -526,22 +534,42 @@ func (p *lifecycleProcessor) unmarshalChaincodeDefinitions(payload []byte) ([]Li
526534
return results, nil
527535
}
528536

537+
type unmarshaller func(payload []byte) (proto.Message, error)
538+
529539
// verifyResponsesMatch ensures that the payload in all of the responses are the same
530-
func (p *lifecycleProcessor) verifyResponsesMatch(responses []*fab.TransactionProposalResponse) error {
531-
var lastResponse *fab.TransactionProposalResponse
540+
func (p *lifecycleProcessor) verifyResponsesMatch(responses []*fab.TransactionProposalResponse, unmarshal unmarshaller) error {
541+
var lastStatus int32
542+
var lastResponse proto.Message
543+
532544
for _, r := range responses {
545+
m, err := unmarshal(r.Response.Payload)
546+
if err != nil {
547+
return err
548+
}
549+
533550
if lastResponse != nil {
534-
if lastResponse.Response.Status != r.Response.Status {
535-
return errors.New("status in responses from endorsers do not match")
551+
if lastStatus != r.Response.Status {
552+
return errors.Errorf("status in responses from endorsers do not match: [%d] and [%d]", lastStatus, r.Response.Status)
536553
}
537554

538-
if !bytes.Equal(lastResponse.Response.Payload, r.Response.Payload) {
539-
return errors.New("responses from endorsers do not match")
555+
if !proto.Equal(lastResponse, m) {
556+
return errors.Errorf("responses from endorsers do not match: [%+v] and [%+v]", lastResponse, m)
540557
}
541558
}
542559

543-
lastResponse = r
560+
lastResponse = m
561+
lastStatus = r.Response.Status
544562
}
545563

546564
return nil
547565
}
566+
567+
func unmarshalCCDefResults(name string, payload []byte) (proto.Message, error) {
568+
if name != "" {
569+
result := &lb.QueryChaincodeDefinitionResult{}
570+
return result, proto.Unmarshal(payload, result)
571+
}
572+
573+
result := &lb.QueryChaincodeDefinitionsResult{}
574+
return result, proto.Unmarshal(payload, result)
575+
}

0 commit comments

Comments
 (0)