@@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
7
7
package resmgmt
8
8
9
9
import (
10
- "bytes"
11
10
reqContext "context"
12
11
"fmt"
13
12
"strings"
@@ -192,7 +191,12 @@ func (p *lifecycleProcessor) checkCommitReadiness(reqCtx reqContext.Context, cha
192
191
return LifecycleCheckCCCommitReadinessResponse {}, errors .WithMessage (err , "sending approve transaction proposal failed to verify signature" )
193
192
}
194
193
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
+ )
196
200
if err != nil {
197
201
return LifecycleCheckCCCommitReadinessResponse {}, err
198
202
}
@@ -275,7 +279,11 @@ func (p *lifecycleProcessor) queryCommitted(reqCtx reqContext.Context, channelID
275
279
return nil , errors .WithMessage (err , "sending query committed transaction proposal failed to verify signature" )
276
280
}
277
281
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
+ )
279
287
if err != nil {
280
288
return nil , err
281
289
}
@@ -526,22 +534,42 @@ func (p *lifecycleProcessor) unmarshalChaincodeDefinitions(payload []byte) ([]Li
526
534
return results , nil
527
535
}
528
536
537
+ type unmarshaller func (payload []byte ) (proto.Message , error )
538
+
529
539
// 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
+
532
544
for _ , r := range responses {
545
+ m , err := unmarshal (r .Response .Payload )
546
+ if err != nil {
547
+ return err
548
+ }
549
+
533
550
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 )
536
553
}
537
554
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 )
540
557
}
541
558
}
542
559
543
- lastResponse = r
560
+ lastResponse = m
561
+ lastStatus = r .Response .Status
544
562
}
545
563
546
564
return nil
547
565
}
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