Skip to content

Commit 8257b3d

Browse files
committed
Implementing VerifyBlock for Gossip
This change-set does the following: 1. Refactors the mcs package to simplify mocking; 2. Implements the method VerifyBlock of the MessageCryptoService interface. 3. Tests This change-set should be merged together with https://gerrit.hyperledger.org/r/#/c/6321/ Change-Id: Ia4a1d92ee5ede55caaffe9a9b53afb2552308e2d Signed-off-by: Angelo De Caro <[email protected]>
1 parent f7935c1 commit 8257b3d

File tree

14 files changed

+499
-127
lines changed

14 files changed

+499
-127
lines changed

common/mocks/policies/policies.go

+1-19
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,4 @@ func (m *Manager) GetPolicy(id string) (policies.Policy, bool) {
7676
}
7777
}
7878
return m.Policy, m.Policy != nil
79-
}
80-
81-
type PolicyManagerMgmt struct{}
82-
83-
func (m *PolicyManagerMgmt) GetPolicy(id string) (policies.Policy, bool) {
84-
panic("implement me")
85-
}
86-
87-
func (m *PolicyManagerMgmt) Manager(path []string) (policies.Manager, bool) {
88-
return &Manager{Policy: &Policy{Err: nil}}, false
89-
}
90-
91-
func (m *PolicyManagerMgmt) BasePath() string {
92-
panic("implement me")
93-
}
94-
95-
func (m *PolicyManagerMgmt) PolicyNames() []string {
96-
panic("implement me")
97-
}
79+
}

common/policies/policy.go

+8
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ type Provider interface {
9898
NewPolicy(data []byte) (Policy, error)
9999
}
100100

101+
// ChannelPolicyManagerGetter is a support interface
102+
// to get access to the policy manager of a given channel
103+
type ChannelPolicyManagerGetter interface {
104+
// Returns the policy manager associated to the passed channel
105+
// and true if it was the manager requested, or false if it is the default manager
106+
Manager(channelID string) (Manager, bool)
107+
}
108+
101109
type policyConfig struct {
102110
policies map[string]Policy
103111
managers map[string]*ManagerImpl

core/peer/peer.go

+6-32
Original file line numberDiff line numberDiff line change
@@ -363,40 +363,14 @@ func GetChannelsInfo() []*pb.ChannelInfo {
363363
return channelInfoArray
364364
}
365365

366-
// GetPolicyManagerMgmt returns a special PolicyManager whose
367-
// only function is to give access to the policy manager of
368-
// a given channel. If the channel does not exists then,
369-
// it returns nil.
370-
// The only method implemented is therefore 'Manager'.
371-
func GetPolicyManagerMgmt() policies.Manager {
372-
return &policyManagerMgmt{}
366+
// NewChannelPolicyManagerGetter returns a new instance of ChannelPolicyManagerGetter
367+
func NewChannelPolicyManagerGetter() policies.ChannelPolicyManagerGetter {
368+
return &channelPolicyManagerGetter{}
373369
}
374370

375-
type policyManagerMgmt struct{}
371+
type channelPolicyManagerGetter struct{}
376372

377-
func (c *policyManagerMgmt) GetPolicy(id string) (policies.Policy, bool) {
378-
panic("implement me")
379-
}
380-
381-
// Manager returns the policy manager associated to a channel
382-
// specified by a path of length 1 that has the name of the channel as the only
383-
// coordinate available.
384-
// If the path has length different from 1, then the method returns (nil, false).
385-
// If the channel does not exists, then the method returns (nil, false)
386-
// Nothing is created.
387-
func (c *policyManagerMgmt) Manager(path []string) (policies.Manager, bool) {
388-
if len(path) != 1 {
389-
return nil, false
390-
}
391-
392-
policyManager := GetPolicyManager(path[0])
373+
func (c *channelPolicyManagerGetter) Manager(channelID string) (policies.Manager, bool) {
374+
policyManager := GetPolicyManager(channelID)
393375
return policyManager, policyManager != nil
394376
}
395-
396-
func (c *policyManagerMgmt) BasePath() string {
397-
panic("implement me")
398-
}
399-
400-
func (c *policyManagerMgmt) PolicyNames() []string {
401-
panic("implement me")
402-
}

core/peer/peer_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"testing"
2424

2525
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
26-
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
26+
"github.com/hyperledger/fabric/common/localmsp"
2727
ccp "github.com/hyperledger/fabric/core/common/ccprovider"
2828
"github.com/hyperledger/fabric/core/deliverservice"
2929
"github.com/hyperledger/fabric/core/deliverservice/blocksprovider"
@@ -93,7 +93,7 @@ func TestCreateChainFromBlock(t *testing.T) {
9393
msptesttools.LoadMSPSetupForTesting("../../msp/sampleconfig")
9494

9595
identity, _ := mgmt.GetLocalSigningIdentityOrPanic().Serialize()
96-
messageCryptoService := mcs.New(&mockpolicies.PolicyManagerMgmt{})
96+
messageCryptoService := mcs.New(&mcs.MockChannelPolicyManagerGetter{}, localmsp.NewSigner(), mgmt.NewDeserializersManager())
9797
service.InitGossipServiceCustomDeliveryFactory(identity, "localhost:13611", grpcServer, &mockDeliveryClientFactory{}, messageCryptoService)
9898

9999
err = CreateChainFromBlock(block)

core/scc/cscc/configure_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
"github.com/golang/protobuf/proto"
2626
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
27-
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
27+
"github.com/hyperledger/fabric/common/localmsp"
2828
"github.com/hyperledger/fabric/core/chaincode"
2929
"github.com/hyperledger/fabric/core/chaincode/shim"
3030
"github.com/hyperledger/fabric/core/deliverservice"
@@ -152,7 +152,7 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {
152152

153153
msptesttools.LoadMSPSetupForTesting("../../../msp/sampleconfig")
154154
identity, _ := mgmt.GetLocalSigningIdentityOrPanic().Serialize()
155-
messageCryptoService := mcs.New(&mockpolicies.PolicyManagerMgmt{})
155+
messageCryptoService := mcs.New(&mcs.MockChannelPolicyManagerGetter{}, localmsp.NewSigner(), mgmt.NewDeserializersManager())
156156
service.InitGossipServiceCustomDeliveryFactory(identity, "localhost:13611", grpcServer, &mockDeliveryClientFactory{}, messageCryptoService)
157157

158158
// Successful path for JoinChain

gossip/service/gossip_service_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"bytes"
2626
"time"
2727

28-
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
28+
"github.com/hyperledger/fabric/common/localmsp"
2929
"github.com/hyperledger/fabric/core/deliverservice"
3030
"github.com/hyperledger/fabric/core/deliverservice/blocksprovider"
3131
"github.com/hyperledger/fabric/gossip/api"
@@ -60,7 +60,8 @@ func TestInitGossipService(t *testing.T) {
6060
wg.Add(10)
6161
for i := 0; i < 10; i++ {
6262
go func() {
63-
InitGossipService(identity, "localhost:5611", grpcServer, mcs.New(&mockpolicies.PolicyManagerMgmt{}))
63+
messageCryptoService := mcs.New(&mcs.MockChannelPolicyManagerGetter{}, localmsp.NewSigner(), mgmt.NewDeserializersManager())
64+
InitGossipService(identity, "localhost:5611", grpcServer, messageCryptoService)
6465

6566
wg.Done()
6667
}()

msp/mgmt/deserializer.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright IBM Corp. 2017 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package mgmt
18+
19+
import (
20+
"github.com/hyperledger/fabric/msp"
21+
)
22+
23+
// DeserializersManager is a support interface to
24+
// access the local and channel deserializers
25+
type DeserializersManager interface {
26+
27+
// GetLocalMSPIdentifier returns the local MSP identifier
28+
GetLocalMSPIdentifier() string
29+
30+
// GetLocalDeserializer returns the local identity deserializer
31+
GetLocalDeserializer() msp.IdentityDeserializer
32+
33+
// GetChannelDeserializers returns a map of the channel deserializers
34+
GetChannelDeserializers() map[string]msp.IdentityDeserializer
35+
}
36+
37+
// DeserializersManager returns a new instance of DeserializersManager
38+
func NewDeserializersManager() DeserializersManager {
39+
return &mspDeserializersManager{}
40+
}
41+
42+
type mspDeserializersManager struct{}
43+
44+
func (m *mspDeserializersManager) GetLocalMSPIdentifier() string {
45+
id, _ := GetLocalMSP().GetIdentifier()
46+
return id
47+
}
48+
49+
func (m *mspDeserializersManager) GetLocalDeserializer() msp.IdentityDeserializer {
50+
return GetLocalMSP()
51+
}
52+
53+
func (m *mspDeserializersManager) GetChannelDeserializers() map[string]msp.IdentityDeserializer {
54+
return GetDeserializers()
55+
}

msp/mgmt/mgmt.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ func GetManagerForChain(chainID string) msp.MSPManager {
6969
}
7070

7171
// GetManagers returns all the managers registered
72-
func GetManagers() map[string]msp.MSPManager {
72+
func GetDeserializers() map[string]msp.IdentityDeserializer {
7373
m.Lock()
7474
defer m.Unlock()
7575

76-
clone := make(map[string]msp.MSPManager)
76+
clone := make(map[string]msp.IdentityDeserializer)
7777

7878
for key, mspManager := range mspMap {
7979
clone[key] = mspManager

0 commit comments

Comments
 (0)