Skip to content

Commit

Permalink
[FAB-1355] Make gossip JoinChannel use block utils
Browse files Browse the repository at this point in the history
As mention in comment to CR 3175, get chain id out
of the block should be abstracted out to the utility
package. This commit takes care to replace chain id
code from gossip join channel functionality by common
utility function.

Change-Id: I62708190c41e8a5174bfd41546e751604f80659e
Signed-off-by: Artem Barger <bartem@il.ibm.com>
  • Loading branch information
C0rWin committed Dec 15, 2016
1 parent 0eadb03 commit f93f863
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions gossip/service/gossip_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package service

import (
"sync"
"fmt"

pb "github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/committer"
"github.com/hyperledger/fabric/gossip/comm"
gossipCommon "github.com/hyperledger/fabric/gossip/common"
Expand All @@ -30,6 +28,7 @@ import (
"github.com/hyperledger/fabric/gossip/proto"
"github.com/hyperledger/fabric/gossip/state"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -79,26 +78,13 @@ func (g *gossipServiceImpl) JoinChannel(commiter committer.Committer, block *com
g.lock.Lock()
defer g.lock.Unlock()

if block.Data == nil || block.Data.Data == nil || len(block.Data.Data) == 0 {
return fmt.Errorf("Cannot join channel, configuration block is empty")
}

envelope := &common.Envelope{}
if err := pb.Unmarshal(block.Data.Data[0], envelope); err != nil {
return err
}

payload := &common.Payload{}
if err := pb.Unmarshal(envelope.Payload, payload); err != nil {
if chainID, err := utils.GetChainIDFromBlock(block); err != nil {
return err
} else {
// Initialize new state provider for given committer
g.chains[chainID] = state.NewGossipStateProvider(g.gossip, g.comm, commiter)
}

chainID := payload.Header.ChainHeader.ChainID
if len(chainID) == 0 {
return fmt.Errorf("Cannot join channel, with empty chainID")
}
// Initialize new state provider for given committer
g.chains[chainID] = state.NewGossipStateProvider(g.gossip, g.comm, commiter)
return nil
}

Expand Down

0 comments on commit f93f863

Please sign in to comment.