Skip to content

Commit

Permalink
[FAB-8343] Remove metadata from block comparison
Browse files Browse the repository at this point in the history
Change-Id: I4722a9186e26b9323f2782d8da36560a178da0d7
Signed-off-by: Divyank Katira <[email protected]>
  • Loading branch information
d1vyank committed Feb 16, 2018
1 parent ff9b6bf commit a1037f5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
31 changes: 16 additions & 15 deletions pkg/fabric-client/channel/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package channel

import (
"bytes"
"net/http"
"strconv"

Expand Down Expand Up @@ -242,28 +241,30 @@ func (c *Ledger) QueryConfigBlock(targets []fab.ProposalProcessor, minResponses
Fcn: "GetConfigBlock",
Args: [][]byte{[]byte(c.chName)},
}
tpr, err := queryChaincode(c.ctx, c.chName, request, targets)
if err != nil && len(tpr) == 0 {
tprs, err := queryChaincode(c.ctx, c.chName, request, targets)
if err != nil && len(tprs) == 0 {
return nil, errors.WithMessage(err, "queryChaincode failed")
}

responses := collectProposalResponses(tpr)
if len(tprs) < minResponses {
return nil, errors.Errorf("Required minimum %d endorsments got %d", minResponses, len(tprs))
}

if len(responses) < minResponses {
return nil, errors.Errorf("Required minimum %d endorsments got %d", minResponses, len(responses))
block, err := createCommonBlock(tprs[0])
if err != nil {
return nil, err
}

r := responses[0]
for _, p := range responses {
if bytes.Compare(r, p) != 0 {
return nil, errors.New("Payloads for config block do not match")
// Compare block data from remaining responses
for _, tpr := range tprs[1:] {
b, err := createCommonBlock(tpr)
if err != nil {
return nil, err
}
}

block := &common.Block{}
err = proto.Unmarshal(responses[0], block)
if err != nil {
return nil, errors.Wrap(err, "unmarshal block failed")
if !proto.Equal(block.Data, b.Data) {
return nil, errors.New("Payloads for config block do not match")
}
}

if block.Data == nil || block.Data.Data == nil {
Expand Down
34 changes: 34 additions & 0 deletions pkg/fabric-client/channel/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient"
"github.com/hyperledger/fabric-sdk-go/pkg/errors/multi"
"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/mocks"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -177,6 +178,39 @@ func TestQueryConfig(t *testing.T) {

}

func TestQueryConfigBlockDifferentMetadata(t *testing.T) {
channel, _ := setupTestLedger()
builder := &mocks.MockConfigBlockBuilder{
MockConfigGroupBuilder: mocks.MockConfigGroupBuilder{
ModPolicy: "Admins",
MSPNames: []string{
"Org1MSP",
"Org2MSP",
},
OrdererAddress: "localhost:7054",
RootCA: validRootCA,
},
Index: 0,
LastConfigIndex: 0,
}

b := builder.Build()
b.Metadata = &common.BlockMetadata{Metadata: [][]byte{[]byte("test1")}}

payload1, err := proto.Marshal(b)
assert.Nil(t, err, "Failed to marshal mock block")

b.Metadata = &common.BlockMetadata{Metadata: [][]byte{[]byte("test2")}}
payload2, err := proto.Marshal(b)
assert.Nil(t, err, "Failed to marshal mock block")

peer1 := mocks.MockPeer{MockName: "Peer1", MockURL: "http://peer1.com", MockRoles: []string{}, MockCert: nil, Payload: payload1, Status: 200}
peer2 := mocks.MockPeer{MockName: "Peer2", MockURL: "http://peer2.com", MockRoles: []string{}, MockCert: nil, Payload: payload2, Status: 200}

_, err = channel.QueryConfigBlock([]fab.ProposalProcessor{&peer1, &peer2}, 2)
assert.Nil(t, err, "Expected success querying blocks with identical block data payloads")
}

func TestFilterResponses(t *testing.T) {
tprs := []*fab.TransactionProposalResponse{}
err := fmt.Errorf("test")
Expand Down

0 comments on commit a1037f5

Please sign in to comment.