Skip to content

Commit

Permalink
Merge "Implementing VerifyBlock for Gossip"
Browse files Browse the repository at this point in the history
  • Loading branch information
yacovm authored and Gerrit Code Review committed Mar 2, 2017
2 parents 715ddcf + 8257b3d commit 565a758
Show file tree
Hide file tree
Showing 14 changed files with 499 additions and 127 deletions.
20 changes: 1 addition & 19 deletions common/mocks/policies/policies.go
Expand Up @@ -76,22 +76,4 @@ func (m *Manager) GetPolicy(id string) (policies.Policy, bool) {
}
}
return m.Policy, m.Policy != nil
}

type PolicyManagerMgmt struct{}

func (m *PolicyManagerMgmt) GetPolicy(id string) (policies.Policy, bool) {
panic("implement me")
}

func (m *PolicyManagerMgmt) Manager(path []string) (policies.Manager, bool) {
return &Manager{Policy: &Policy{Err: nil}}, false
}

func (m *PolicyManagerMgmt) BasePath() string {
panic("implement me")
}

func (m *PolicyManagerMgmt) PolicyNames() []string {
panic("implement me")
}
}
8 changes: 8 additions & 0 deletions common/policies/policy.go
Expand Up @@ -98,6 +98,14 @@ type Provider interface {
NewPolicy(data []byte) (Policy, error)
}

// ChannelPolicyManagerGetter is a support interface
// to get access to the policy manager of a given channel
type ChannelPolicyManagerGetter interface {
// Returns the policy manager associated to the passed channel
// and true if it was the manager requested, or false if it is the default manager
Manager(channelID string) (Manager, bool)
}

type policyConfig struct {
policies map[string]Policy
managers map[string]*ManagerImpl
Expand Down
38 changes: 6 additions & 32 deletions core/peer/peer.go
Expand Up @@ -363,40 +363,14 @@ func GetChannelsInfo() []*pb.ChannelInfo {
return channelInfoArray
}

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

type policyManagerMgmt struct{}
type channelPolicyManagerGetter struct{}

func (c *policyManagerMgmt) GetPolicy(id string) (policies.Policy, bool) {
panic("implement me")
}

// Manager returns the policy manager associated to a channel
// specified by a path of length 1 that has the name of the channel as the only
// coordinate available.
// If the path has length different from 1, then the method returns (nil, false).
// If the channel does not exists, then the method returns (nil, false)
// Nothing is created.
func (c *policyManagerMgmt) Manager(path []string) (policies.Manager, bool) {
if len(path) != 1 {
return nil, false
}

policyManager := GetPolicyManager(path[0])
func (c *channelPolicyManagerGetter) Manager(channelID string) (policies.Manager, bool) {
policyManager := GetPolicyManager(channelID)
return policyManager, policyManager != nil
}

func (c *policyManagerMgmt) BasePath() string {
panic("implement me")
}

func (c *policyManagerMgmt) PolicyNames() []string {
panic("implement me")
}
4 changes: 2 additions & 2 deletions core/peer/peer_test.go
Expand Up @@ -23,7 +23,7 @@ import (
"testing"

configtxtest "github.com/hyperledger/fabric/common/configtx/test"
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
"github.com/hyperledger/fabric/common/localmsp"
ccp "github.com/hyperledger/fabric/core/common/ccprovider"
"github.com/hyperledger/fabric/core/deliverservice"
"github.com/hyperledger/fabric/core/deliverservice/blocksprovider"
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestCreateChainFromBlock(t *testing.T) {
msptesttools.LoadMSPSetupForTesting("../../msp/sampleconfig")

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

err = CreateChainFromBlock(block)
Expand Down
4 changes: 2 additions & 2 deletions core/scc/cscc/configure_test.go
Expand Up @@ -24,7 +24,7 @@ import (

"github.com/golang/protobuf/proto"
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
"github.com/hyperledger/fabric/common/localmsp"
"github.com/hyperledger/fabric/core/chaincode"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/deliverservice"
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {

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

// Successful path for JoinChain
Expand Down
5 changes: 3 additions & 2 deletions gossip/service/gossip_service_test.go
Expand Up @@ -25,7 +25,7 @@ import (
"bytes"
"time"

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

wg.Done()
}()
Expand Down
55 changes: 55 additions & 0 deletions msp/mgmt/deserializer.go
@@ -0,0 +1,55 @@
/*
Copyright IBM Corp. 2017 All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package mgmt

import (
"github.com/hyperledger/fabric/msp"
)

// DeserializersManager is a support interface to
// access the local and channel deserializers
type DeserializersManager interface {

// GetLocalMSPIdentifier returns the local MSP identifier
GetLocalMSPIdentifier() string

// GetLocalDeserializer returns the local identity deserializer
GetLocalDeserializer() msp.IdentityDeserializer

// GetChannelDeserializers returns a map of the channel deserializers
GetChannelDeserializers() map[string]msp.IdentityDeserializer
}

// DeserializersManager returns a new instance of DeserializersManager
func NewDeserializersManager() DeserializersManager {
return &mspDeserializersManager{}
}

type mspDeserializersManager struct{}

func (m *mspDeserializersManager) GetLocalMSPIdentifier() string {
id, _ := GetLocalMSP().GetIdentifier()
return id
}

func (m *mspDeserializersManager) GetLocalDeserializer() msp.IdentityDeserializer {
return GetLocalMSP()
}

func (m *mspDeserializersManager) GetChannelDeserializers() map[string]msp.IdentityDeserializer {
return GetDeserializers()
}
4 changes: 2 additions & 2 deletions msp/mgmt/mgmt.go
Expand Up @@ -69,11 +69,11 @@ func GetManagerForChain(chainID string) msp.MSPManager {
}

// GetManagers returns all the managers registered
func GetManagers() map[string]msp.MSPManager {
func GetDeserializers() map[string]msp.IdentityDeserializer {
m.Lock()
defer m.Unlock()

clone := make(map[string]msp.MSPManager)
clone := make(map[string]msp.IdentityDeserializer)

for key, mspManager := range mspMap {
clone[key] = mspManager
Expand Down

0 comments on commit 565a758

Please sign in to comment.