Skip to content

Commit f93f863

Browse files
committed
[FAB-1355] Make gossip JoinChannel use block utils
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 <[email protected]>
1 parent 0eadb03 commit f93f863

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

gossip/service/gossip_service.go

+5-19
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ package service
1818

1919
import (
2020
"sync"
21-
"fmt"
2221

23-
pb "github.com/golang/protobuf/proto"
2422
"github.com/hyperledger/fabric/core/committer"
2523
"github.com/hyperledger/fabric/gossip/comm"
2624
gossipCommon "github.com/hyperledger/fabric/gossip/common"
@@ -30,6 +28,7 @@ import (
3028
"github.com/hyperledger/fabric/gossip/proto"
3129
"github.com/hyperledger/fabric/gossip/state"
3230
"github.com/hyperledger/fabric/protos/common"
31+
"github.com/hyperledger/fabric/protos/utils"
3332
"google.golang.org/grpc"
3433
)
3534

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

82-
if block.Data == nil || block.Data.Data == nil || len(block.Data.Data) == 0 {
83-
return fmt.Errorf("Cannot join channel, configuration block is empty")
84-
}
85-
86-
envelope := &common.Envelope{}
87-
if err := pb.Unmarshal(block.Data.Data[0], envelope); err != nil {
88-
return err
89-
}
90-
91-
payload := &common.Payload{}
92-
if err := pb.Unmarshal(envelope.Payload, payload); err != nil {
81+
if chainID, err := utils.GetChainIDFromBlock(block); err != nil {
9382
return err
83+
} else {
84+
// Initialize new state provider for given committer
85+
g.chains[chainID] = state.NewGossipStateProvider(g.gossip, g.comm, commiter)
9486
}
9587

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

0 commit comments

Comments
 (0)