Skip to content

Commit

Permalink
[FAB-1796] cleanup linter errors
Browse files Browse the repository at this point in the history
modified:   gossip/service/channel.go
modified:   gossip/service/channel_test.go
modified:   gossip/service/gossip_service.go

Change-Id: Ie645641d99a40de662bc24f02609dff41b589f5c
Signed-off-by: Luis Sanchez <sanchezl@us.ibm.com>
  • Loading branch information
Luis Sanchez committed Jan 21, 2017
1 parent f78b4b8 commit c198a72
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
8 changes: 4 additions & 4 deletions gossip/service/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ package service
import (
"fmt"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/gossip/api"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/protos/utils"
)

// unMarshal is used to un-marshall proto-buffer types.
// In tests, I override this variable with a function
var unMarshal func (buf []byte, pb proto.Message) error
var unMarshal func(buf []byte, pb proto.Message) error

func init() {
unMarshal = proto.Unmarshal
Expand All @@ -37,7 +37,7 @@ func init() {
// This is an implementation of api.JoinChannelMessage.
// This object is created from a *common.Block
type joinChannelMessage struct {
seqNum uint64
seqNum uint64
anchorPeers []api.AnchorPeer
}

Expand Down Expand Up @@ -91,7 +91,7 @@ func parseBlock(block *common.Block) (*peer.AnchorPeers, error) {
found = true
anchorPeerConfig = confItem
}
if ! found {
if !found {
return nil, fmt.Errorf("Didn't find AnchorPeer definition in configuration block")
}
rawAnchorPeersBytes := anchorPeerConfig.Value
Expand Down
14 changes: 5 additions & 9 deletions gossip/service/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ import (
"testing"
"time"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/configtx"
"github.com/hyperledger/fabric/common/genesis"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/peer"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/hyperledger/fabric/common/configtx"
"github.com/hyperledger/fabric/protos/utils"
"github.com/stretchr/testify/assert"
)

type blockInvalidator func(*common.Block) *common.Block


// unMarshaller is a mock for proto.Unmarshal
// that fails on an Nth attempt
type unMarshaller struct {
Expand All @@ -47,7 +46,7 @@ func (um *unMarshaller) unMarshal(buf []byte, pb proto.Message) error {
return proto.Unmarshal(buf, pb)
}

func failUnmarshallAtAttempt(attempts int) func (buf []byte, pb proto.Message) error {
func failUnmarshallAtAttempt(attempts int) func(buf []byte, pb proto.Message) error {
um := &unMarshaller{attemptsLeft: attempts}
return um.unMarshal
}
Expand Down Expand Up @@ -104,7 +103,6 @@ func TestInvalidJoinChannelBlock(t *testing.T) {
}
testJoinChannelFails(t, multipleAnchorPeers, nil)


noAnchorPeers := func(_ *common.Block) *common.Block {
anchorPeers := &peer.AnchorPeers{
AnchorPees: []*peer.AnchorPeer{},
Expand Down Expand Up @@ -137,7 +135,6 @@ func TestValidJoinChannelBlock(t *testing.T) {
assert.Equal(t, []byte("cert"), []byte(jcm.AnchorPeers()[0].Cert))
}


func testJoinChannelFails(t *testing.T, invalidator blockInvalidator, unMarshallFunc func(buf []byte, pb proto.Message) error) {
if unMarshallFunc != nil {
unMarshal = unMarshallFunc
Expand All @@ -155,7 +152,6 @@ func testJoinChannelFails(t *testing.T, invalidator blockInvalidator, unMarshall
unMarshal = proto.Unmarshal
}


func createValidJoinChanMessage(t *testing.T, seqNum int, host string, port int, cert []byte) *common.Block {
anchorPeers := &peer.AnchorPeers{
AnchorPees: []*peer.AnchorPeer{{Cert: cert, Host: host, Port: int32(port)}},
Expand All @@ -181,4 +177,4 @@ func createAnchorPeerConfItem(t *testing.T, anchorPeers *peer.AnchorPeers, key s
Type: common.ConfigurationItem_Peer,
Value: serializedAnchorPeers,
}
}
}
13 changes: 7 additions & 6 deletions gossip/service/gossip_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,17 @@ func (g *gossipServiceImpl) JoinChannel(commiter committer.Committer, block *com
g.lock.Lock()
defer g.lock.Unlock()

if chainID, err := utils.GetChainIDFromBlock(block); err != nil {
chainID, err := utils.GetChainIDFromBlock(block)
if err != nil {
return err
} else {
// Initialize new state provider for given committer
logger.Debug("Creating state provider for chainID", chainID)
g.JoinChan(joinChannelMessage, gossipCommon.ChainID(chainID))
g.chains[chainID] = state.NewGossipStateProvider(chainID, g, commiter)
}

// Initialize new state provider for given committer
logger.Debug("Creating state provider for chainID", chainID)
g.JoinChan(joinChannelMessage, gossipCommon.ChainID(chainID))
g.chains[chainID] = state.NewGossipStateProvider(chainID, g, commiter)
return nil

}

// GetBlock returns block for given chain
Expand Down

0 comments on commit c198a72

Please sign in to comment.