From d0c97c0026701fb1f227aefb61455372fc70d9ec Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Wed, 9 Aug 2017 14:56:18 -0400 Subject: [PATCH] [FAB-5649] Invert configtx resource encapsulation The configtx manager current retains a reference to the channel config, but to support other config types, this actually needs to be inverted so that the channel config retains a reference to the configtx manager. This CR performs this inversion and fixes the embedding packages of the configtx.Manager to instead embed the channelconfig.Resources. [FAB-5650] Move channel creation from configtx One of the last big offenders for putting channel config specific code into the configtx package is the templating code, which provides mechanisms to create new channel configurations. The generic templating is fine to remain there, but the channel specifics must be moved ot the channel config folder. Note: These two sub-tasks were squashed into one because of otherwise difficult to break import cycles. Change-Id: Ib8bf829216e19fbbbd8841c9a3551356ed1676b6 Signed-off-by: Jason Yellick --- common/config/channel/api.go | 48 +++++--- common/config/channel/initializer.go | 41 ++++++- common/config/channel/template.go | 113 ++++++++++++++++++ common/config/channel/template_test.go | 98 +++++++++++++++ common/configtx/api/api.go | 39 +----- common/configtx/manager.go | 6 +- common/configtx/manager_test.go | 12 +- common/configtx/template.go | 96 +-------------- common/configtx/template_test.go | 83 ------------- common/configtx/update.go | 2 +- common/configtx/update_test.go | 6 +- common/mocks/config/resources.go | 71 +++++++++++ common/mocks/config/resources_test.go | 17 +++ common/mocks/configtx/configtx.go | 61 ++-------- common/mocks/configtx/configtx_test.go | 8 +- common/policies/policy.go | 1 + common/tools/configtxgen/main.go | 41 ++++--- .../configtxlator/sanitycheck/sanitycheck.go | 3 +- core/chaincode/chaincode_support_test.go | 2 +- core/common/validation/config_test.go | 4 +- core/peer/peer.go | 50 ++++---- .../common/msgprocessor/standardchannel.go | 4 +- orderer/common/msgprocessor/systemchannel.go | 54 ++++----- .../common/msgprocessor/systemchannel_test.go | 31 +++-- .../msgprocessor/systemchannelfilter.go | 8 +- .../msgprocessor/systemchannelfilter_test.go | 28 ++--- orderer/common/multichannel/chainsupport.go | 5 +- orderer/common/multichannel/registrar.go | 18 ++- orderer/common/multichannel/registrar_test.go | 4 +- orderer/common/performance/utils.go | 4 +- .../broadcast_config/newchain.go | 4 +- peer/channel/create.go | 3 +- peer/common/common.go | 8 +- 33 files changed, 523 insertions(+), 450 deletions(-) create mode 100644 common/config/channel/template.go create mode 100644 common/config/channel/template_test.go create mode 100644 common/mocks/config/resources.go create mode 100644 common/mocks/config/resources_test.go diff --git a/common/config/channel/api.go b/common/config/channel/api.go index 667f9083879..161a42f1de5 100644 --- a/common/config/channel/api.go +++ b/common/config/channel/api.go @@ -1,26 +1,17 @@ /* -Copyright IBM Corp. 2017 All Rights Reserved. +Copyright IBM Corp. 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. +SPDX-License-Identifier: Apache-2.0 */ -// Note, the directory is still configvalues, but this is stuttery and config -// is a more accurate and better name, TODO, update directory package config import ( "time" + configtxapi "github.com/hyperledger/fabric/common/configtx/api" + "github.com/hyperledger/fabric/common/policies" + "github.com/hyperledger/fabric/msp" cb "github.com/hyperledger/fabric/protos/common" ab "github.com/hyperledger/fabric/protos/orderer" pb "github.com/hyperledger/fabric/protos/peer" @@ -97,3 +88,32 @@ type Orderer interface { // Organizations returns the organizations for the ordering service Organizations() map[string]Org } + +// Resources is the common set of config resources for all channels +// Depending on whether chain is used at the orderer or at the peer, other +// config resources may be available +type Resources interface { + // ConfigtxManager returns the configtx.Manager for the channel + ConfigtxManager() configtxapi.Manager + + // PolicyManager returns the policies.Manager for the channel + PolicyManager() policies.Manager + + // ChannelConfig returns the config.Channel for the chain + ChannelConfig() Channel + + // OrdererConfig returns the config.Orderer for the channel + // and whether the Orderer config exists + OrdererConfig() (Orderer, bool) + + // ConsortiumsConfig() returns the config.Consortiums for the channel + // and whether the consortiums config exists + ConsortiumsConfig() (Consortiums, bool) + + // ApplicationConfig returns the configtxapplication.SharedConfig for the channel + // and whether the Application config exists + ApplicationConfig() (Application, bool) + + // MSPManager returns the msp.MSPManager for the chain + MSPManager() msp.MSPManager +} diff --git a/common/config/channel/initializer.go b/common/config/channel/initializer.go index 673ab60cc5b..1daf0939970 100644 --- a/common/config/channel/initializer.go +++ b/common/config/channel/initializer.go @@ -22,6 +22,8 @@ import ( "github.com/hyperledger/fabric/common/cauthdsl" "github.com/hyperledger/fabric/common/config" configtxmsp "github.com/hyperledger/fabric/common/config/channel/msp" + "github.com/hyperledger/fabric/common/configtx" + configtxapi "github.com/hyperledger/fabric/common/configtx/api" "github.com/hyperledger/fabric/common/policies" "github.com/hyperledger/fabric/msp" cb "github.com/hyperledger/fabric/protos/common" @@ -35,6 +37,7 @@ type resources struct { policyManager *policies.ManagerImpl configRoot *Root mspConfigHandler *configtxmsp.MSPConfigHandler + configtxManager configtxapi.Manager } // PolicyManager returns the policies.Manager for the chain @@ -42,6 +45,11 @@ func (r *resources) PolicyManager() policies.Manager { return r.policyManager } +// ConfigtxManager returns the configtxapi.Manager for the chain +func (r *resources) ConfigtxManager() configtxapi.Manager { + return r.configtxManager +} + // ChannelConfig returns the api.ChannelConfig for the chain func (r *resources) ChannelConfig() Channel { return r.configRoot.Channel() @@ -133,18 +141,45 @@ func (i *policyProposerRoot) CommitProposals(tx interface{}) {} type Initializer struct { *resources + configtxapi.Manager ppr *policyProposerRoot } -// NewInitializer creates a chain Initializer for the basic set of common chain resources -func NewInitializer() *Initializer { +// New creates a new channel config, complete with backing configtx manager +// TODO move configtx.Manager to resources, make func on Resources type +func New(envConfig *cb.Envelope, callOnUpdate []func(*Initializer)) (*Initializer, error) { resources := newResources() - return &Initializer{ + i := &Initializer{ resources: resources, ppr: &policyProposerRoot{ policyManager: resources.policyManager, }, } + var err error + initialized := false + i.Manager, err = configtx.NewManagerImpl(envConfig, i, []func(cm configtxapi.Manager){ + func(cm configtxapi.Manager) { + // This gets invoked once at instantiation before we are ready for it + // we manually do this right after + if !initialized { + return + } + logger.Criticalf("Making callback normally") + for _, callback := range callOnUpdate { + callback(i) + } + }, + }) + if err != nil { + return nil, err + } + initialized = true + i.resources.configtxManager = i.Manager + logger.Criticalf("Making callback manually") + for _, callback := range callOnUpdate { + callback(i) + } + return i, err } func (i *Initializer) RootGroupKey() string { diff --git a/common/config/channel/template.go b/common/config/channel/template.go new file mode 100644 index 00000000000..0ffaf4562f3 --- /dev/null +++ b/common/config/channel/template.go @@ -0,0 +1,113 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package config + +import ( + "fmt" + + configmsp "github.com/hyperledger/fabric/common/config/channel/msp" + "github.com/hyperledger/fabric/common/configtx" + "github.com/hyperledger/fabric/common/policies" + "github.com/hyperledger/fabric/common/util" + "github.com/hyperledger/fabric/msp" + cb "github.com/hyperledger/fabric/protos/common" + "github.com/hyperledger/fabric/protos/utils" +) + +const ( + msgVersion = int32(0) + epoch = 0 +) + +type channelCreationTemplate struct { + consortiumName string + orgs []string +} + +// NewChainCreationTemplate takes a consortium name and a Template to produce a +// Template which outputs an appropriately constructed list of ConfigUpdateEnvelopes. +func NewChainCreationTemplate(consortiumName string, orgs []string) configtx.Template { + return &channelCreationTemplate{ + consortiumName: consortiumName, + orgs: orgs, + } +} + +func (cct *channelCreationTemplate) Envelope(channelID string) (*cb.ConfigUpdateEnvelope, error) { + rSet := TemplateConsortium(cct.consortiumName) + wSet := TemplateConsortium(cct.consortiumName) + + rSet.Groups[ApplicationGroupKey] = cb.NewConfigGroup() + wSet.Groups[ApplicationGroupKey] = cb.NewConfigGroup() + + for _, org := range cct.orgs { + rSet.Groups[ApplicationGroupKey].Groups[org] = cb.NewConfigGroup() + wSet.Groups[ApplicationGroupKey].Groups[org] = cb.NewConfigGroup() + } + + wSet.Groups[ApplicationGroupKey].ModPolicy = configmsp.AdminsPolicyKey + wSet.Groups[ApplicationGroupKey].Policies[configmsp.AdminsPolicyKey] = policies.ImplicitMetaPolicyWithSubPolicy(configmsp.AdminsPolicyKey, cb.ImplicitMetaPolicy_MAJORITY) + wSet.Groups[ApplicationGroupKey].Policies[configmsp.AdminsPolicyKey].ModPolicy = configmsp.AdminsPolicyKey + wSet.Groups[ApplicationGroupKey].Policies[configmsp.WritersPolicyKey] = policies.ImplicitMetaPolicyWithSubPolicy(configmsp.WritersPolicyKey, cb.ImplicitMetaPolicy_ANY) + wSet.Groups[ApplicationGroupKey].Policies[configmsp.WritersPolicyKey].ModPolicy = configmsp.AdminsPolicyKey + wSet.Groups[ApplicationGroupKey].Policies[configmsp.ReadersPolicyKey] = policies.ImplicitMetaPolicyWithSubPolicy(configmsp.ReadersPolicyKey, cb.ImplicitMetaPolicy_ANY) + wSet.Groups[ApplicationGroupKey].Policies[configmsp.ReadersPolicyKey].ModPolicy = configmsp.AdminsPolicyKey + wSet.Groups[ApplicationGroupKey].Version = 1 + + return &cb.ConfigUpdateEnvelope{ + ConfigUpdate: utils.MarshalOrPanic(&cb.ConfigUpdate{ + ChannelId: channelID, + ReadSet: rSet, + WriteSet: wSet, + }), + }, nil +} + +// MakeChainCreationTransaction is a handy utility function for creating new chain transactions using the underlying Template framework +func MakeChainCreationTransaction(channelID string, consortium string, signer msp.SigningIdentity, orgs ...string) (*cb.Envelope, error) { + newChainTemplate := NewChainCreationTemplate(consortium, orgs) + newConfigUpdateEnv, err := newChainTemplate.Envelope(channelID) + if err != nil { + return nil, err + } + + payloadSignatureHeader := &cb.SignatureHeader{} + if signer != nil { + sSigner, err := signer.Serialize() + if err != nil { + return nil, fmt.Errorf("Serialization of identity failed, err %s", err) + } + + newConfigUpdateEnv.Signatures = []*cb.ConfigSignature{&cb.ConfigSignature{ + SignatureHeader: utils.MarshalOrPanic(utils.MakeSignatureHeader(sSigner, utils.CreateNonceOrPanic())), + }} + + newConfigUpdateEnv.Signatures[0].Signature, err = signer.Sign(util.ConcatenateBytes(newConfigUpdateEnv.Signatures[0].SignatureHeader, newConfigUpdateEnv.ConfigUpdate)) + if err != nil { + return nil, err + } + + payloadSignatureHeader = utils.MakeSignatureHeader(sSigner, utils.CreateNonceOrPanic()) + } + + payloadChannelHeader := utils.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, msgVersion, channelID, epoch) + utils.SetTxID(payloadChannelHeader, payloadSignatureHeader) + payloadHeader := utils.MakePayloadHeader(payloadChannelHeader, payloadSignatureHeader) + payload := &cb.Payload{Header: payloadHeader, Data: utils.MarshalOrPanic(newConfigUpdateEnv)} + paylBytes := utils.MarshalOrPanic(payload) + + var sig []byte + if signer != nil { + // sign the payload + sig, err = signer.Sign(paylBytes) + if err != nil { + return nil, err + } + } + + return &cb.Envelope{Payload: paylBytes, Signature: sig}, nil +} diff --git a/common/config/channel/template_test.go b/common/config/channel/template_test.go new file mode 100644 index 00000000000..21af81c6ba7 --- /dev/null +++ b/common/config/channel/template_test.go @@ -0,0 +1,98 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package config + +import ( + "testing" + + configmsp "github.com/hyperledger/fabric/common/config/channel/msp" + "github.com/hyperledger/fabric/common/configtx" + mmsp "github.com/hyperledger/fabric/common/mocks/msp" + cb "github.com/hyperledger/fabric/protos/common" + "github.com/hyperledger/fabric/protos/utils" + + "github.com/golang/protobuf/proto" + "github.com/stretchr/testify/assert" +) + +func TestNewChainTemplate(t *testing.T) { + consortiumName := "Test" + orgs := []string{"org1", "org2", "org3"} + nct := NewChainCreationTemplate(consortiumName, orgs) + + newChainID := "foo" + configEnv, err := nct.Envelope(newChainID) + if err != nil { + t.Fatalf("Error creation a chain creation config") + } + + configUpdate, err := configtx.UnmarshalConfigUpdate(configEnv.ConfigUpdate) + if err != nil { + t.Fatalf("Should not have errored: %s", err) + } + + consortiumProto := &cb.Consortium{} + err = proto.Unmarshal(configUpdate.WriteSet.Values[ConsortiumKey].Value, consortiumProto) + assert.NoError(t, err) + assert.Equal(t, consortiumName, consortiumProto.Name, "Should have set correct consortium name") + + assert.Equal(t, configUpdate.WriteSet.Groups[ApplicationGroupKey].Version, uint64(1)) + + assert.Len(t, configUpdate.WriteSet.Groups[ApplicationGroupKey].Groups, len(orgs)) + + for _, org := range orgs { + group, ok := configUpdate.WriteSet.Groups[ApplicationGroupKey].Groups[org] + assert.True(t, ok, "Expected to find %s but did not", org) + for _, policy := range group.Policies { + assert.Equal(t, configmsp.AdminsPolicyKey, policy.ModPolicy) + } + } +} + +func TestMakeChainCreationTransactionWithSigner(t *testing.T) { + channelID := "foo" + + signer, err := mmsp.NewNoopMsp().GetDefaultSigningIdentity() + assert.NoError(t, err, "Creating noop MSP") + + cct, err := MakeChainCreationTransaction(channelID, "test", signer) + assert.NoError(t, err, "Making chain creation tx") + + assert.NotEmpty(t, cct.Signature, "Should have signature") + + payload, err := utils.UnmarshalPayload(cct.Payload) + assert.NoError(t, err, "Unmarshaling payload") + + configUpdateEnv, err := configtx.UnmarshalConfigUpdateEnvelope(payload.Data) + assert.NoError(t, err, "Unmarshaling ConfigUpdateEnvelope") + + assert.NotEmpty(t, configUpdateEnv.Signatures, "Should have config env sigs") + + sigHeader, err := utils.GetSignatureHeader(payload.Header.SignatureHeader) + assert.NoError(t, err, "Unmarshaling SignatureHeader") + assert.NotEmpty(t, sigHeader.Creator, "Creator specified") +} + +func TestMakeChainCreationTransactionNoSigner(t *testing.T) { + channelID := "foo" + cct, err := MakeChainCreationTransaction(channelID, "test", nil) + assert.NoError(t, err, "Making chain creation tx") + + assert.Empty(t, cct.Signature, "Should have empty signature") + + payload, err := utils.UnmarshalPayload(cct.Payload) + assert.NoError(t, err, "Unmarshaling payload") + + configUpdateEnv, err := configtx.UnmarshalConfigUpdateEnvelope(payload.Data) + assert.NoError(t, err, "Unmarshaling ConfigUpdateEnvelope") + + assert.Empty(t, configUpdateEnv.Signatures, "Should have no config env sigs") + + sigHeader, err := utils.GetSignatureHeader(payload.Header.SignatureHeader) + assert.NoError(t, err, "Unmarshaling SignatureHeader") + assert.Empty(t, sigHeader.Creator, "No creator specified") +} diff --git a/common/configtx/api/api.go b/common/configtx/api/api.go index 83a9ee4fc9c..0628f34b328 100644 --- a/common/configtx/api/api.go +++ b/common/configtx/api/api.go @@ -18,9 +18,7 @@ package api import ( "github.com/hyperledger/fabric/common/config" - channelconfig "github.com/hyperledger/fabric/common/config/channel" "github.com/hyperledger/fabric/common/policies" - "github.com/hyperledger/fabric/msp" cb "github.com/hyperledger/fabric/protos/common" "github.com/golang/protobuf/proto" @@ -28,8 +26,6 @@ import ( // Manager provides a mechanism to query and update config type Manager interface { - Resources - // Apply attempts to apply a configtx to become the new config Apply(configEnv *cb.ConfigEnvelope) error @@ -49,32 +45,6 @@ type Manager interface { Sequence() uint64 } -// Resources is the common set of config resources for all channels -// Depending on whether chain is used at the orderer or at the peer, other -// config resources may be available -type Resources interface { - // PolicyManager returns the policies.Manager for the channel - PolicyManager() policies.Manager - - // ChannelConfig returns the config.Channel for the chain - ChannelConfig() channelconfig.Channel - - // OrdererConfig returns the config.Orderer for the channel - // and whether the Orderer config exists - OrdererConfig() (channelconfig.Orderer, bool) - - // ConsortiumsConfig() returns the config.Consortiums for the channel - // and whether the consortiums config exists - ConsortiumsConfig() (channelconfig.Consortiums, bool) - - // ApplicationConfig returns the configtxapplication.SharedConfig for the channel - // and whether the Application config exists - ApplicationConfig() (channelconfig.Application, bool) - - // MSPManager returns the msp.MSPManager for the chain - MSPManager() msp.MSPManager -} - // Transactional is an interface which allows for an update to be proposed and rolled back type Transactional interface { // RollbackConfig called when a config proposal is abandoned @@ -107,12 +77,7 @@ type Proposer interface { // RootGroupKey is the string to use to namespace the root group RootGroupKey() string -} - -// Initializer is used as indirection between Manager and Handler to allow -// for single Handlers to handle multiple paths -type Initializer interface { - Proposer - Resources + // PolicyManager() returns the policy manager for considering config changes + PolicyManager() policies.Manager } diff --git a/common/configtx/manager.go b/common/configtx/manager.go index ae40abb948a..cac41497142 100644 --- a/common/configtx/manager.go +++ b/common/configtx/manager.go @@ -49,9 +49,8 @@ type configSet struct { } type configManager struct { - api.Resources callOnUpdate []func(api.Manager) - initializer api.Initializer + initializer api.Proposer current *configSet } @@ -111,7 +110,7 @@ func validateChannelID(channelID string) error { return nil } -func NewManagerImpl(envConfig *cb.Envelope, initializer api.Initializer, callOnUpdate []func(api.Manager)) (api.Manager, error) { +func NewManagerImpl(envConfig *cb.Envelope, initializer api.Proposer, callOnUpdate []func(api.Manager)) (api.Manager, error) { if envConfig == nil { return nil, fmt.Errorf("Nil envelope") } @@ -140,7 +139,6 @@ func NewManagerImpl(envConfig *cb.Envelope, initializer api.Initializer, callOnU } cm := &configManager{ - Resources: initializer, initializer: initializer, current: &configSet{ sequence: configEnv.Config.Sequence, diff --git a/common/configtx/manager_test.go b/common/configtx/manager_test.go index db6f5d9ebaa..2b277835672 100644 --- a/common/configtx/manager_test.go +++ b/common/configtx/manager_test.go @@ -34,10 +34,8 @@ var defaultChain = "default.chain.id" func defaultInitializer() *mockconfigtx.Initializer { return &mockconfigtx.Initializer{ - Resources: mockconfigtx.Resources{ - PolicyManagerVal: &mockpolicies.Manager{ - Policy: &mockpolicies.Policy{}, - }, + PolicyManagerVal: &mockpolicies.Manager{ + Policy: &mockpolicies.Policy{}, }, PolicyProposerVal: &mockconfigtx.PolicyProposer{ Transactional: mockconfigtx.Transactional{}, @@ -350,7 +348,7 @@ func TestConfigChangeViolatesPolicy(t *testing.T) { t.Fatalf("Error constructing config manager: %s", err) } // Set the mock policy to error - initializer.Resources.PolicyManagerVal.Policy.Err = fmt.Errorf("err") + initializer.PolicyManagerVal.Policy.Err = fmt.Errorf("err") newConfig := makeConfigUpdateEnvelope(defaultChain, makeConfigSet(), makeConfigSet(makeConfigPair("foo", "foo", 1, []byte("foo")))) @@ -373,8 +371,8 @@ func TestUnchangedConfigViolatesPolicy(t *testing.T) { } // Set the mock policy to error - initializer.Resources.PolicyManagerVal.PolicyMap = make(map[string]policies.Policy) - initializer.Resources.PolicyManagerVal.PolicyMap["foo"] = &mockpolicies.Policy{Err: fmt.Errorf("err")} + initializer.PolicyManagerVal.PolicyMap = make(map[string]policies.Policy) + initializer.PolicyManagerVal.PolicyMap["foo"] = &mockpolicies.Policy{Err: fmt.Errorf("err")} newConfig := makeConfigUpdateEnvelope( defaultChain, diff --git a/common/configtx/template.go b/common/configtx/template.go index 68112aa14bc..fe56ef53bf3 100644 --- a/common/configtx/template.go +++ b/common/configtx/template.go @@ -19,11 +19,6 @@ package configtx import ( "fmt" - "github.com/hyperledger/fabric/common/config/channel" - configmsp "github.com/hyperledger/fabric/common/config/channel/msp" - "github.com/hyperledger/fabric/common/policies" - "github.com/hyperledger/fabric/common/util" - "github.com/hyperledger/fabric/msp" cb "github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric/protos/utils" @@ -31,11 +26,8 @@ import ( ) const ( - // CreationPolicyKey defines the config key used in the channel - // config, under which the creation policy is defined. - CreationPolicyKey = "CreationPolicy" - msgVersion = int32(0) - epoch = 0 + msgVersion = int32(0) + epoch = 0 ) // Template can be used to facilitate creation of config transactions @@ -205,87 +197,3 @@ type channelCreationTemplate struct { consortiumName string orgs []string } - -// NewChainCreationTemplate takes a consortium name and a Template to produce a -// Template which outputs an appropriately constructed list of ConfigUpdateEnvelopes. -func NewChainCreationTemplate(consortiumName string, orgs []string) Template { - return &channelCreationTemplate{ - consortiumName: consortiumName, - orgs: orgs, - } -} - -func (cct *channelCreationTemplate) Envelope(channelID string) (*cb.ConfigUpdateEnvelope, error) { - rSet := config.TemplateConsortium(cct.consortiumName) - wSet := config.TemplateConsortium(cct.consortiumName) - - rSet.Groups[config.ApplicationGroupKey] = cb.NewConfigGroup() - wSet.Groups[config.ApplicationGroupKey] = cb.NewConfigGroup() - - for _, org := range cct.orgs { - rSet.Groups[config.ApplicationGroupKey].Groups[org] = cb.NewConfigGroup() - wSet.Groups[config.ApplicationGroupKey].Groups[org] = cb.NewConfigGroup() - } - - wSet.Groups[config.ApplicationGroupKey].ModPolicy = configmsp.AdminsPolicyKey - wSet.Groups[config.ApplicationGroupKey].Policies[configmsp.AdminsPolicyKey] = policies.ImplicitMetaPolicyWithSubPolicy(configmsp.AdminsPolicyKey, cb.ImplicitMetaPolicy_MAJORITY) - wSet.Groups[config.ApplicationGroupKey].Policies[configmsp.AdminsPolicyKey].ModPolicy = configmsp.AdminsPolicyKey - wSet.Groups[config.ApplicationGroupKey].Policies[configmsp.WritersPolicyKey] = policies.ImplicitMetaPolicyWithSubPolicy(configmsp.WritersPolicyKey, cb.ImplicitMetaPolicy_ANY) - wSet.Groups[config.ApplicationGroupKey].Policies[configmsp.WritersPolicyKey].ModPolicy = configmsp.AdminsPolicyKey - wSet.Groups[config.ApplicationGroupKey].Policies[configmsp.ReadersPolicyKey] = policies.ImplicitMetaPolicyWithSubPolicy(configmsp.ReadersPolicyKey, cb.ImplicitMetaPolicy_ANY) - wSet.Groups[config.ApplicationGroupKey].Policies[configmsp.ReadersPolicyKey].ModPolicy = configmsp.AdminsPolicyKey - wSet.Groups[config.ApplicationGroupKey].Version = 1 - - return &cb.ConfigUpdateEnvelope{ - ConfigUpdate: utils.MarshalOrPanic(&cb.ConfigUpdate{ - ChannelId: channelID, - ReadSet: rSet, - WriteSet: wSet, - }), - }, nil -} - -// MakeChainCreationTransaction is a handy utility function for creating new chain transactions using the underlying Template framework -func MakeChainCreationTransaction(channelID string, consortium string, signer msp.SigningIdentity, orgs ...string) (*cb.Envelope, error) { - newChainTemplate := NewChainCreationTemplate(consortium, orgs) - newConfigUpdateEnv, err := newChainTemplate.Envelope(channelID) - if err != nil { - return nil, err - } - - payloadSignatureHeader := &cb.SignatureHeader{} - if signer != nil { - sSigner, err := signer.Serialize() - if err != nil { - return nil, fmt.Errorf("Serialization of identity failed, err %s", err) - } - - newConfigUpdateEnv.Signatures = []*cb.ConfigSignature{&cb.ConfigSignature{ - SignatureHeader: utils.MarshalOrPanic(utils.MakeSignatureHeader(sSigner, utils.CreateNonceOrPanic())), - }} - - newConfigUpdateEnv.Signatures[0].Signature, err = signer.Sign(util.ConcatenateBytes(newConfigUpdateEnv.Signatures[0].SignatureHeader, newConfigUpdateEnv.ConfigUpdate)) - if err != nil { - return nil, err - } - - payloadSignatureHeader = utils.MakeSignatureHeader(sSigner, utils.CreateNonceOrPanic()) - } - - payloadChannelHeader := utils.MakeChannelHeader(cb.HeaderType_CONFIG_UPDATE, msgVersion, channelID, epoch) - utils.SetTxID(payloadChannelHeader, payloadSignatureHeader) - payloadHeader := utils.MakePayloadHeader(payloadChannelHeader, payloadSignatureHeader) - payload := &cb.Payload{Header: payloadHeader, Data: utils.MarshalOrPanic(newConfigUpdateEnv)} - paylBytes := utils.MarshalOrPanic(payload) - - var sig []byte - if signer != nil { - // sign the payload - sig, err = signer.Sign(paylBytes) - if err != nil { - return nil, err - } - } - - return &cb.Envelope{Payload: paylBytes, Signature: sig}, nil -} diff --git a/common/configtx/template_test.go b/common/configtx/template_test.go index 98d40842945..30a83c8ff3b 100644 --- a/common/configtx/template_test.go +++ b/common/configtx/template_test.go @@ -20,13 +20,8 @@ import ( "fmt" "testing" - "github.com/hyperledger/fabric/common/config/channel" - configmsp "github.com/hyperledger/fabric/common/config/channel/msp" - mmsp "github.com/hyperledger/fabric/common/mocks/msp" cb "github.com/hyperledger/fabric/protos/common" - "github.com/hyperledger/fabric/protos/utils" - "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" ) @@ -118,81 +113,3 @@ func TestModPolicySettingTemplate(t *testing.T) { assert.Equal(t, existingModPolicy, configUpdate.WriteSet.Groups[subGroup].Policies[policyExistingModPolicy].ModPolicy) assert.Equal(t, existingModPolicy, configUpdate.WriteSet.Groups[subGroupExistingModPolicy].ModPolicy) } - -func TestNewChainTemplate(t *testing.T) { - consortiumName := "Test" - orgs := []string{"org1", "org2", "org3"} - nct := NewChainCreationTemplate(consortiumName, orgs) - - newChainID := "foo" - configEnv, err := nct.Envelope(newChainID) - if err != nil { - t.Fatalf("Error creation a chain creation config") - } - - configUpdate, err := UnmarshalConfigUpdate(configEnv.ConfigUpdate) - if err != nil { - t.Fatalf("Should not have errored: %s", err) - } - - consortiumProto := &cb.Consortium{} - err = proto.Unmarshal(configUpdate.WriteSet.Values[config.ConsortiumKey].Value, consortiumProto) - assert.NoError(t, err) - assert.Equal(t, consortiumName, consortiumProto.Name, "Should have set correct consortium name") - - assert.Equal(t, configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Version, uint64(1)) - - assert.Len(t, configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups, len(orgs)) - - for _, org := range orgs { - group, ok := configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups[org] - assert.True(t, ok, "Expected to find %s but did not", org) - for _, policy := range group.Policies { - assert.Equal(t, configmsp.AdminsPolicyKey, policy.ModPolicy) - } - } -} - -func TestMakeChainCreationTransactionWithSigner(t *testing.T) { - channelID := "foo" - - signer, err := mmsp.NewNoopMsp().GetDefaultSigningIdentity() - assert.NoError(t, err, "Creating noop MSP") - - cct, err := MakeChainCreationTransaction(channelID, "test", signer) - assert.NoError(t, err, "Making chain creation tx") - - assert.NotEmpty(t, cct.Signature, "Should have signature") - - payload, err := utils.UnmarshalPayload(cct.Payload) - assert.NoError(t, err, "Unmarshaling payload") - - configUpdateEnv, err := UnmarshalConfigUpdateEnvelope(payload.Data) - assert.NoError(t, err, "Unmarshaling ConfigUpdateEnvelope") - - assert.NotEmpty(t, configUpdateEnv.Signatures, "Should have config env sigs") - - sigHeader, err := utils.GetSignatureHeader(payload.Header.SignatureHeader) - assert.NoError(t, err, "Unmarshaling SignatureHeader") - assert.NotEmpty(t, sigHeader.Creator, "Creator specified") -} - -func TestMakeChainCreationTransactionNoSigner(t *testing.T) { - channelID := "foo" - cct, err := MakeChainCreationTransaction(channelID, "test", nil) - assert.NoError(t, err, "Making chain creation tx") - - assert.Empty(t, cct.Signature, "Should have empty signature") - - payload, err := utils.UnmarshalPayload(cct.Payload) - assert.NoError(t, err, "Unmarshaling payload") - - configUpdateEnv, err := UnmarshalConfigUpdateEnvelope(payload.Data) - assert.NoError(t, err, "Unmarshaling ConfigUpdateEnvelope") - - assert.Empty(t, configUpdateEnv.Signatures, "Should have no config env sigs") - - sigHeader, err := utils.GetSignatureHeader(payload.Header.SignatureHeader) - assert.NoError(t, err, "Unmarshaling SignatureHeader") - assert.Empty(t, sigHeader.Creator, "No creator specified") -} diff --git a/common/configtx/update.go b/common/configtx/update.go index 99569faea09..3bb8154f101 100644 --- a/common/configtx/update.go +++ b/common/configtx/update.go @@ -170,7 +170,7 @@ func (cm *configManager) authorizeUpdate(configUpdateEnv *cb.ConfigUpdateEnvelop func (cm *configManager) policyForItem(item comparable) (policies.Policy, bool) { // path is always at least of length 1 - manager, ok := cm.PolicyManager().Manager(item.path[1:]) + manager, ok := cm.initializer.PolicyManager().Manager(item.path[1:]) if !ok { return nil, ok } diff --git a/common/configtx/update_test.go b/common/configtx/update_test.go index e7437c0aac2..589756965e4 100644 --- a/common/configtx/update_test.go +++ b/common/configtx/update_test.go @@ -74,7 +74,7 @@ func TestComputeDeltaSet(t *testing.T) { func TestVerifyDeltaSet(t *testing.T) { cm := &configManager{ - Resources: &mockconfigtx.Resources{ + initializer: &mockconfigtx.Initializer{ PolicyManagerVal: &mockpolicies.Manager{ Policy: &mockpolicies.Policy{}, }, @@ -122,7 +122,7 @@ func TestVerifyDeltaSet(t *testing.T) { deltaSet := make(map[string]comparable) deltaSet["foo"] = comparable{ConfigValue: &cb.ConfigValue{Version: 1, ModPolicy: "foo"}} - cm.Resources.(*mockconfigtx.Resources).PolicyManagerVal.Policy = &mockpolicies.Policy{Err: fmt.Errorf("Err")} + cm.initializer.(*mockconfigtx.Initializer).PolicyManagerVal.Policy = &mockpolicies.Policy{Err: fmt.Errorf("Err")} assert.Error(t, cm.verifyDeltaSet(deltaSet, nil), "Policy evaluation should have failed") }) @@ -140,7 +140,7 @@ func TestPolicyForItem(t *testing.T) { fooPolicy := &mockpolicies.Policy{Err: fmt.Errorf("fooPolicy")} cm := &configManager{ - Resources: &mockconfigtx.Resources{ + initializer: &mockconfigtx.Initializer{ PolicyManagerVal: &mockpolicies.Manager{ BasePathVal: "root", Policy: rootPolicy, diff --git a/common/mocks/config/resources.go b/common/mocks/config/resources.go new file mode 100644 index 00000000000..6bc12a3e5e7 --- /dev/null +++ b/common/mocks/config/resources.go @@ -0,0 +1,71 @@ +/* +Copyright IBM Corp. 2016 All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package config + +import ( + channelconfig "github.com/hyperledger/fabric/common/config/channel" + configtxapi "github.com/hyperledger/fabric/common/configtx/api" + "github.com/hyperledger/fabric/common/policies" + "github.com/hyperledger/fabric/msp" +) + +type Resources struct { + // ConfigtxManagerVal is returned as the result of ConfigtxManager + ConfigtxManagerVal configtxapi.Manager + + // PolicyManagerVal is returned as the result of PolicyManager() + PolicyManagerVal policies.Manager + + // ChannelConfigVal is returned as the result of ChannelConfig() + ChannelConfigVal channelconfig.Channel + + // OrdererConfigVal is returned as the result of OrdererConfig() + OrdererConfigVal channelconfig.Orderer + + // ApplicationConfigVal is returned as the result of ApplicationConfig() + ApplicationConfigVal channelconfig.Application + + // ConsortiumsConfigVal is returned as the result of ConsortiumsConfig() + ConsortiumsConfigVal channelconfig.Consortiums + + // MSPManagerVal is returned as the result of MSPManager() + MSPManagerVal msp.MSPManager +} + +// ConfigtxMangaer returns ConfigtxManagerVal +func (r *Resources) ConfigtxManager() configtxapi.Manager { + return r.ConfigtxManagerVal +} + +// Returns the PolicyManagerVal +func (r *Resources) PolicyManager() policies.Manager { + return r.PolicyManagerVal +} + +// Returns the ChannelConfigVal +func (r *Resources) ChannelConfig() channelconfig.Channel { + return r.ChannelConfigVal +} + +// Returns the OrdererConfigVal +func (r *Resources) OrdererConfig() (channelconfig.Orderer, bool) { + return r.OrdererConfigVal, r.OrdererConfigVal == nil +} + +// Returns the ApplicationConfigVal +func (r *Resources) ApplicationConfig() (channelconfig.Application, bool) { + return r.ApplicationConfigVal, r.ApplicationConfigVal == nil +} + +func (r *Resources) ConsortiumsConfig() (channelconfig.Consortiums, bool) { + return r.ConsortiumsConfigVal, r.ConsortiumsConfigVal != nil +} + +// Returns the MSPManagerVal +func (r *Resources) MSPManager() msp.MSPManager { + return r.MSPManagerVal +} diff --git a/common/mocks/config/resources_test.go b/common/mocks/config/resources_test.go new file mode 100644 index 00000000000..6feb504471d --- /dev/null +++ b/common/mocks/config/resources_test.go @@ -0,0 +1,17 @@ +/* +Copyright IBM Corp. 2016 All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package config + +import ( + "testing" + + channelconfig "github.com/hyperledger/fabric/common/config/channel" +) + +func TestConfigtxResourcesInterface(t *testing.T) { + _ = channelconfig.Resources(&Resources{}) +} diff --git a/common/mocks/configtx/configtx.go b/common/mocks/configtx/configtx.go index 202943f2c15..23b12f5f529 100644 --- a/common/mocks/configtx/configtx.go +++ b/common/mocks/configtx/configtx.go @@ -18,64 +18,13 @@ package configtx import ( "github.com/hyperledger/fabric/common/config" - channelconfig "github.com/hyperledger/fabric/common/config/channel" mockpolicies "github.com/hyperledger/fabric/common/mocks/policies" "github.com/hyperledger/fabric/common/policies" - "github.com/hyperledger/fabric/msp" cb "github.com/hyperledger/fabric/protos/common" "github.com/golang/protobuf/proto" ) -type Resources struct { - // PolicyManagerVal is returned as the result of PolicyManager() - PolicyManagerVal *mockpolicies.Manager - - // ChannelConfigVal is returned as the result of ChannelConfig() - ChannelConfigVal channelconfig.Channel - - // OrdererConfigVal is returned as the result of OrdererConfig() - OrdererConfigVal channelconfig.Orderer - - // ApplicationConfigVal is returned as the result of ApplicationConfig() - ApplicationConfigVal channelconfig.Application - - // ConsortiumsConfigVal is returned as the result of ConsortiumsConfig() - ConsortiumsConfigVal channelconfig.Consortiums - - // MSPManagerVal is returned as the result of MSPManager() - MSPManagerVal msp.MSPManager -} - -// Returns the PolicyManagerVal -func (r *Resources) PolicyManager() policies.Manager { - return r.PolicyManagerVal -} - -// Returns the ChannelConfigVal -func (r *Resources) ChannelConfig() channelconfig.Channel { - return r.ChannelConfigVal -} - -// Returns the OrdererConfigVal -func (r *Resources) OrdererConfig() (channelconfig.Orderer, bool) { - return r.OrdererConfigVal, r.OrdererConfigVal == nil -} - -// Returns the ApplicationConfigVal -func (r *Resources) ApplicationConfig() (channelconfig.Application, bool) { - return r.ApplicationConfigVal, r.ApplicationConfigVal == nil -} - -func (r *Resources) ConsortiumsConfig() (channelconfig.Consortiums, bool) { - return r.ConsortiumsConfigVal, r.ConsortiumsConfigVal != nil -} - -// Returns the MSPManagerVal -func (r *Resources) MSPManager() msp.MSPManager { - return r.MSPManagerVal -} - // Transactional implements the configtxapi.Transactional type Transactional struct{} @@ -90,14 +39,15 @@ func (t *Transactional) RollbackProposals(tx interface{}) {} // Initializer mocks the configtxapi.Initializer interface type Initializer struct { - Resources - // PolicyProposerVal is returned by PolicyProposers PolicyProposerVal *PolicyProposer // ValueProposerVal is returned by ValueProposers ValueProposerVal *ValueProposer + // PolicyManagerVal is returned by PolicyManager + PolicyManagerVal *mockpolicies.Manager + // RootGroupKeyVal is returned by RootGroupKey RootGroupKeyVal string } @@ -107,6 +57,11 @@ func (i *Initializer) RootGroupKey() string { return i.RootGroupKeyVal } +// PolicyManager returns PolicyManagerVal +func (i *Initializer) PolicyManager() policies.Manager { + return i.PolicyManagerVal +} + // PolicyProposers returns PolicyProposerVal func (i *Initializer) PolicyProposer() policies.Proposer { return i.PolicyProposerVal diff --git a/common/mocks/configtx/configtx_test.go b/common/mocks/configtx/configtx_test.go index 86bd3e63562..50738f8c622 100644 --- a/common/mocks/configtx/configtx_test.go +++ b/common/mocks/configtx/configtx_test.go @@ -31,14 +31,10 @@ func TestConfigtxPolicyProposerInterface(t *testing.T) { _ = policies.Proposer(&PolicyProposer{}) } -func TestConfigtxInitializerInterface(t *testing.T) { - _ = configtxapi.Initializer(&Initializer{}) +func TestConfigtxProposerInterface(t *testing.T) { + _ = configtxapi.Proposer(&Initializer{}) } func TestConfigtxManagerInterface(t *testing.T) { _ = configtxapi.Manager(&Manager{}) } - -func TestConfigtxResourcesInterface(t *testing.T) { - _ = configtxapi.Resources(&Resources{}) -} diff --git a/common/policies/policy.go b/common/policies/policy.go index 9d85d226442..32ab65597fc 100644 --- a/common/policies/policy.go +++ b/common/policies/policy.go @@ -135,6 +135,7 @@ type ManagerImpl struct { // SuppressSanityLogMessages when set to true will prevent the sanity checking log // messages. Useful for novel cases like channel templates + // TODO, pull the sanity checking into chanel config SuppressSanityLogMessages bool } diff --git a/common/tools/configtxgen/main.go b/common/tools/configtxgen/main.go index 626506d5f46..e4bbb4090e2 100644 --- a/common/tools/configtxgen/main.go +++ b/common/tools/configtxgen/main.go @@ -14,9 +14,8 @@ import ( "strings" "github.com/hyperledger/fabric/bccsp/factory" - "github.com/hyperledger/fabric/common/config/channel" + channelconfig "github.com/hyperledger/fabric/common/config/channel" mspconfig "github.com/hyperledger/fabric/common/config/channel/msp" - "github.com/hyperledger/fabric/common/configtx" "github.com/hyperledger/fabric/common/flogging" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/common/tools/configtxgen/metadata" @@ -69,7 +68,7 @@ func doOutputChannelCreateTx(conf *genesisconfig.Profile, channelID string, outp for _, org := range conf.Application.Organizations { orgNames = append(orgNames, org.Name) } - configtx, err := configtx.MakeChainCreationTransaction(channelID, conf.Consortium, nil, orgNames...) + configtx, err := channelconfig.MakeChainCreationTransaction(channelID, conf.Consortium, nil, orgNames...) if err != nil { return fmt.Errorf("Error generating configtx: %s", err) } @@ -110,8 +109,8 @@ func doOutputAnchorPeersUpdate(conf *genesisconfig.Profile, channelID string, ou } } - configGroup := config.TemplateAnchorPeers(org.Name, anchorPeers) - configGroup.Groups[config.ApplicationGroupKey].Groups[org.Name].Values[config.AnchorPeersKey].ModPolicy = mspconfig.AdminsPolicyKey + configGroup := channelconfig.TemplateAnchorPeers(org.Name, anchorPeers) + configGroup.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Values[channelconfig.AnchorPeersKey].ModPolicy = mspconfig.AdminsPolicyKey configUpdate := &cb.ConfigUpdate{ ChannelId: channelID, WriteSet: configGroup, @@ -119,24 +118,24 @@ func doOutputAnchorPeersUpdate(conf *genesisconfig.Profile, channelID string, ou } // Add all the existing config to the readset - configUpdate.ReadSet.Groups[config.ApplicationGroupKey] = cb.NewConfigGroup() - configUpdate.ReadSet.Groups[config.ApplicationGroupKey].Version = 1 - configUpdate.ReadSet.Groups[config.ApplicationGroupKey].ModPolicy = mspconfig.AdminsPolicyKey - configUpdate.ReadSet.Groups[config.ApplicationGroupKey].Groups[org.Name] = cb.NewConfigGroup() - configUpdate.ReadSet.Groups[config.ApplicationGroupKey].Groups[org.Name].Values[config.MSPKey] = &cb.ConfigValue{} - configUpdate.ReadSet.Groups[config.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.ReadersPolicyKey] = &cb.ConfigPolicy{} - configUpdate.ReadSet.Groups[config.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.WritersPolicyKey] = &cb.ConfigPolicy{} - configUpdate.ReadSet.Groups[config.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.AdminsPolicyKey] = &cb.ConfigPolicy{} + configUpdate.ReadSet.Groups[channelconfig.ApplicationGroupKey] = cb.NewConfigGroup() + configUpdate.ReadSet.Groups[channelconfig.ApplicationGroupKey].Version = 1 + configUpdate.ReadSet.Groups[channelconfig.ApplicationGroupKey].ModPolicy = mspconfig.AdminsPolicyKey + configUpdate.ReadSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name] = cb.NewConfigGroup() + configUpdate.ReadSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Values[channelconfig.MSPKey] = &cb.ConfigValue{} + configUpdate.ReadSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.ReadersPolicyKey] = &cb.ConfigPolicy{} + configUpdate.ReadSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.WritersPolicyKey] = &cb.ConfigPolicy{} + configUpdate.ReadSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.AdminsPolicyKey] = &cb.ConfigPolicy{} // Add all the existing at the same versions to the writeset - configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Version = 1 - configUpdate.WriteSet.Groups[config.ApplicationGroupKey].ModPolicy = mspconfig.AdminsPolicyKey - configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups[org.Name].Version = 1 - configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups[org.Name].ModPolicy = mspconfig.AdminsPolicyKey - configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups[org.Name].Values[config.MSPKey] = &cb.ConfigValue{} - configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.ReadersPolicyKey] = &cb.ConfigPolicy{} - configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.WritersPolicyKey] = &cb.ConfigPolicy{} - configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.AdminsPolicyKey] = &cb.ConfigPolicy{} + configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Version = 1 + configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].ModPolicy = mspconfig.AdminsPolicyKey + configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Version = 1 + configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].ModPolicy = mspconfig.AdminsPolicyKey + configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Values[channelconfig.MSPKey] = &cb.ConfigValue{} + configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.ReadersPolicyKey] = &cb.ConfigPolicy{} + configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.WritersPolicyKey] = &cb.ConfigPolicy{} + configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups[org.Name].Policies[mspconfig.AdminsPolicyKey] = &cb.ConfigPolicy{} configUpdateEnvelope := &cb.ConfigUpdateEnvelope{ ConfigUpdate: utils.MarshalOrPanic(configUpdate), diff --git a/common/tools/configtxlator/sanitycheck/sanitycheck.go b/common/tools/configtxlator/sanitycheck/sanitycheck.go index 4764d3e1ef9..73a31981500 100644 --- a/common/tools/configtxlator/sanitycheck/sanitycheck.go +++ b/common/tools/configtxlator/sanitycheck/sanitycheck.go @@ -20,7 +20,6 @@ import ( "fmt" channelconfig "github.com/hyperledger/fabric/common/config/channel" - "github.com/hyperledger/fabric/common/configtx" cb "github.com/hyperledger/fabric/protos/common" mspprotos "github.com/hyperledger/fabric/protos/msp" "github.com/hyperledger/fabric/protos/utils" @@ -47,7 +46,7 @@ func Check(config *cb.Config) (*Messages, error) { result := &Messages{} - cm, err := configtx.NewManagerImpl(envConfig, channelconfig.NewInitializer(), nil) + cm, err := channelconfig.New(envConfig, nil) if err != nil { result.GeneralErrors = []string{err.Error()} return result, nil diff --git a/core/chaincode/chaincode_support_test.go b/core/chaincode/chaincode_support_test.go index c1bc207f9e0..edc19845f90 100644 --- a/core/chaincode/chaincode_support_test.go +++ b/core/chaincode/chaincode_support_test.go @@ -510,7 +510,7 @@ func cc2cc(t *testing.T, chainID, chainID2, ccname string, ccSide *mockpeer.Mock ctxt, txsim, sprop, prop = startTx(t, chainID, cis, txid) if _, _, err := ccprovider.GetChaincodeProvider().GetCCValidationInfoFromLSCC(ctxt, "getccdata", sprop, prop, chainID, calledCC); err != nil { - t.Fatalf("Could not get chaincode data from lscc for %s", calledCC) + t.Fatalf("Could not get chaincode data from lscc for %s: %s", calledCC, err) } sysCCVers := util.GetSysCCVersion() diff --git a/core/common/validation/config_test.go b/core/common/validation/config_test.go index 907bb67b62f..5708434bb3d 100644 --- a/core/common/validation/config_test.go +++ b/core/common/validation/config_test.go @@ -19,7 +19,7 @@ package validation import ( "testing" - "github.com/hyperledger/fabric/common/configtx" + channelconfig "github.com/hyperledger/fabric/common/config/channel" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/common/util" cb "github.com/hyperledger/fabric/protos/common" @@ -29,7 +29,7 @@ import ( func TestValidateConfigTx(t *testing.T) { chainID := util.GetTestChainID() - chCrtEnv, err := configtx.MakeChainCreationTransaction(genesisconfig.SampleConsortiumName, chainID, signer) + chCrtEnv, err := channelconfig.MakeChainCreationTransaction(genesisconfig.SampleConsortiumName, chainID, signer) if err != nil { t.Fatalf("MakeChainCreationTransaction failed, err %s", err) return diff --git a/core/peer/peer.go b/core/peer/peer.go index 50d54e101ad..9eb0c3f0596 100644 --- a/core/peer/peer.go +++ b/core/peer/peer.go @@ -12,11 +12,11 @@ import ( "net" "sync" - "github.com/hyperledger/fabric/common/config/channel" - "github.com/hyperledger/fabric/common/configtx" + channelconfig "github.com/hyperledger/fabric/common/config/channel" configtxapi "github.com/hyperledger/fabric/common/configtx/api" configtxtest "github.com/hyperledger/fabric/common/configtx/test" "github.com/hyperledger/fabric/common/flogging" + mockchannelconfig "github.com/hyperledger/fabric/common/mocks/config" mockconfigtx "github.com/hyperledger/fabric/common/mocks/configtx" mockpolicies "github.com/hyperledger/fabric/common/mocks/policies" "github.com/hyperledger/fabric/common/policies" @@ -45,7 +45,8 @@ var rootCASupport = comm.GetCASupport() type chainSupport struct { configtxapi.Manager - config.Application + channelconfig.Resources + channelconfig.Application ledger ledger.PeerLedger } @@ -168,18 +169,17 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error { return err } - configtxInitializer := config.NewInitializer() - gossipEventer := service.GetGossipService().NewConfigEventer() - gossipCallbackWrapper := func(cm configtxapi.Manager) { - ac, ok := configtxInitializer.ApplicationConfig() + gossipCallbackWrapper := func(channelConf *channelconfig.Initializer) { + ac, ok := channelConf.ApplicationConfig() if !ok { // TODO, handle a missing ApplicationConfig more gracefully ac = nil } gossipEventer.ProcessConfigUpdate(&chainSupport{ - Manager: cm, + Resources: channelConf, + Manager: channelConf.ConfigtxManager(), Application: ac, }) service.GetGossipService().SuspectPeers(func(identity api.PeerIdentityType) bool { @@ -191,14 +191,13 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error { }) } - trustedRootsCallbackWrapper := func(cm configtxapi.Manager) { - updateTrustedRoots(cm) + trustedRootsCallbackWrapper := func(channelConf *channelconfig.Initializer) { + updateTrustedRoots(channelConf) } - configtxManager, err := configtx.NewManagerImpl( + configtxManager, err := channelconfig.New( envelopeConfig, - configtxInitializer, - []func(cm configtxapi.Manager){gossipCallbackWrapper, trustedRootsCallbackWrapper}, + []func(channelConf *channelconfig.Initializer){gossipCallbackWrapper, trustedRootsCallbackWrapper}, ) if err != nil { return err @@ -207,12 +206,13 @@ func createChain(cid string, ledger ledger.PeerLedger, cb *common.Block) error { // TODO remove once all references to mspmgmt are gone from peer code mspmgmt.XXXSetMSPManager(cid, configtxManager.MSPManager()) - ac, ok := configtxInitializer.ApplicationConfig() + ac, ok := configtxManager.ApplicationConfig() if !ok { ac = nil } cs := &chainSupport{ Manager: configtxManager, + Resources: configtxManager, Application: ac, // TODO, refactor as this is accessible through Manager ledger: ledger, } @@ -272,11 +272,6 @@ func MockCreateChain(cid string) error { // Here we need to mock also the policy manager // in order for the ACL to be checked initializer := mockconfigtx.Initializer{ - Resources: mockconfigtx.Resources{ - PolicyManagerVal: &mockpolicies.Manager{ - Policy: &mockpolicies.Policy{}, - }, - }, PolicyProposerVal: &mockconfigtx.PolicyProposer{ Transactional: mockconfigtx.Transactional{}, }, @@ -294,7 +289,12 @@ func MockCreateChain(cid string) error { chains.list[cid] = &chain{ cs: &chainSupport{ Manager: manager, - ledger: ledger}, + Resources: &mockchannelconfig.Resources{ + PolicyManagerVal: &mockpolicies.Manager{ + Policy: &mockpolicies.Policy{}, + }, + }, + ledger: ledger}, } return nil @@ -334,9 +334,9 @@ func GetCurrConfigBlock(cid string) *common.Block { } // updates the trusted roots for the peer based on updates to channels -func updateTrustedRoots(cm configtxapi.Manager) { +func updateTrustedRoots(cm channelconfig.Resources) { // this is triggered on per channel basis so first update the roots for the channel - peerLogger.Debugf("Updating trusted root authorities for channel %s", cm.ChainID()) + peerLogger.Debugf("Updating trusted root authorities for channel %s", cm.ConfigtxManager().ChainID()) var secureConfig comm.SecureServerConfig var err error // only run is TLS is enabled @@ -367,7 +367,7 @@ func updateTrustedRoots(cm configtxapi.Manager) { msg := "Failed to update trusted roots for peer from latest config " + "block. This peer may not be able to communicate " + "with members of channel %s (%s)" - peerLogger.Warningf(msg, cm.ChainID(), err) + peerLogger.Warningf(msg, cm.ConfigtxManager().ChainID(), err) } } } @@ -375,7 +375,7 @@ func updateTrustedRoots(cm configtxapi.Manager) { // populates the appRootCAs and orderRootCAs maps by getting the // root and intermediate certs for all msps associated with the MSPManager -func buildTrustedRootsForChain(cm configtxapi.Manager) { +func buildTrustedRootsForChain(cm channelconfig.Resources) { rootCASupport.Lock() defer rootCASupport.Unlock() @@ -390,7 +390,7 @@ func buildTrustedRootsForChain(cm configtxapi.Manager) { } } - cid := cm.ChainID() + cid := cm.ConfigtxManager().ChainID() peerLogger.Debugf("updating root CAs for channel [%s]", cid) msps, err := cm.MSPManager().GetMSPs() if err != nil { diff --git a/orderer/common/msgprocessor/standardchannel.go b/orderer/common/msgprocessor/standardchannel.go index 4df9aa8d658..02cfd601d7d 100644 --- a/orderer/common/msgprocessor/standardchannel.go +++ b/orderer/common/msgprocessor/standardchannel.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package msgprocessor import ( - configtxapi "github.com/hyperledger/fabric/common/configtx/api" + channelconfig "github.com/hyperledger/fabric/common/config/channel" "github.com/hyperledger/fabric/common/crypto" "github.com/hyperledger/fabric/common/policies" cb "github.com/hyperledger/fabric/protos/common" @@ -45,7 +45,7 @@ func NewStandardChannel(support StandardChannelSupport, filters *RuleSet) *Stand } // CreateStandardChannelFilters creates the set of filters for a normal (non-system) chain -func CreateStandardChannelFilters(filterSupport configtxapi.Manager) *RuleSet { +func CreateStandardChannelFilters(filterSupport channelconfig.Resources) *RuleSet { ordererConfig, ok := filterSupport.OrdererConfig() if !ok { logger.Panicf("Missing orderer config") diff --git a/orderer/common/msgprocessor/systemchannel.go b/orderer/common/msgprocessor/systemchannel.go index 141617b7c28..03aa5a81a39 100644 --- a/orderer/common/msgprocessor/systemchannel.go +++ b/orderer/common/msgprocessor/systemchannel.go @@ -9,7 +9,7 @@ package msgprocessor import ( "fmt" - "github.com/hyperledger/fabric/common/config/channel" + channelconfig "github.com/hyperledger/fabric/common/config/channel" "github.com/hyperledger/fabric/common/configtx" configtxapi "github.com/hyperledger/fabric/common/configtx/api" "github.com/hyperledger/fabric/common/crypto" @@ -42,7 +42,7 @@ func NewSystemChannel(support StandardChannelSupport, templator ChannelConfigTem } // CreateSystemChannelFilters creates the set of filters for the ordering system chain. -func CreateSystemChannelFilters(chainCreator ChainCreator, ledgerResources configtxapi.Manager) *RuleSet { +func CreateSystemChannelFilters(chainCreator ChainCreator, ledgerResources channelconfig.Resources) *RuleSet { ordererConfig, ok := ledgerResources.OrdererConfig() if !ok { logger.Panicf("Cannot create system channel filters without orderer config") @@ -131,10 +131,10 @@ func (s *SystemChannel) ProcessConfigUpdateMsg(envConfigUpdate *cb.Envelope) (co // DefaultTemplatorSupport is the subset of the channel config required by the DefaultTemplator. type DefaultTemplatorSupport interface { // ConsortiumsConfig returns the ordering system channel's Consortiums config. - ConsortiumsConfig() (config.Consortiums, bool) + ConsortiumsConfig() (channelconfig.Consortiums, bool) - // ConfigEnvelope returns the config envelope corresponding to the system channel's current config. - ConfigEnvelope() *cb.ConfigEnvelope + // ConfigtxManager returns the configtx manager corresponding to the system channel's current config. + ConfigtxManager() configtxapi.Manager // Signer returns the local signer suitable for signing forwarded messages. Signer() crypto.LocalSigner @@ -186,15 +186,15 @@ func (dt *DefaultTemplator) NewChannelConfig(envConfigUpdate *cb.Envelope) (conf return nil, fmt.Errorf("Config update has an empty writeset") } - if configUpdate.WriteSet.Groups == nil || configUpdate.WriteSet.Groups[config.ApplicationGroupKey] == nil { + if configUpdate.WriteSet.Groups == nil || configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey] == nil { return nil, fmt.Errorf("Config update has missing application group") } - if uv := configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Version; uv != 1 { + if uv := configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Version; uv != 1 { return nil, fmt.Errorf("Config update for channel creation does not set application group version to 1, was %d", uv) } - consortiumConfigValue, ok := configUpdate.WriteSet.Values[config.ConsortiumKey] + consortiumConfigValue, ok := configUpdate.WriteSet.Values[channelconfig.ConsortiumKey] if !ok { return nil, fmt.Errorf("Consortium config value missing") } @@ -216,26 +216,26 @@ func (dt *DefaultTemplator) NewChannelConfig(envConfigUpdate *cb.Envelope) (conf return nil, fmt.Errorf("Unknown consortium name: %s", consortium.Name) } - applicationGroup.Policies[config.ChannelCreationPolicyKey] = &cb.ConfigPolicy{ + applicationGroup.Policies[channelconfig.ChannelCreationPolicyKey] = &cb.ConfigPolicy{ Policy: consortiumConf.ChannelCreationPolicy(), } - applicationGroup.ModPolicy = config.ChannelCreationPolicyKey + applicationGroup.ModPolicy = channelconfig.ChannelCreationPolicyKey // Get the current system channel config - systemChannelGroup := dt.support.ConfigEnvelope().Config.ChannelGroup + systemChannelGroup := dt.support.ConfigtxManager().ConfigEnvelope().Config.ChannelGroup // If the consortium group has no members, allow the source request to have no members. However, // if the consortium group has any members, there must be at least one member in the source request - if len(systemChannelGroup.Groups[config.ConsortiumsGroupKey].Groups[consortium.Name].Groups) > 0 && - len(configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups) == 0 { + if len(systemChannelGroup.Groups[channelconfig.ConsortiumsGroupKey].Groups[consortium.Name].Groups) > 0 && + len(configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups) == 0 { return nil, fmt.Errorf("Proposed configuration has no application group members, but consortium contains members") } // If the consortium has no members, allow the source request to contain arbitrary members // Otherwise, require that the supplied members are a subset of the consortium members - if len(systemChannelGroup.Groups[config.ConsortiumsGroupKey].Groups[consortium.Name].Groups) > 0 { - for orgName := range configUpdate.WriteSet.Groups[config.ApplicationGroupKey].Groups { - consortiumGroup, ok := systemChannelGroup.Groups[config.ConsortiumsGroupKey].Groups[consortium.Name].Groups[orgName] + if len(systemChannelGroup.Groups[channelconfig.ConsortiumsGroupKey].Groups[consortium.Name].Groups) > 0 { + for orgName := range configUpdate.WriteSet.Groups[channelconfig.ApplicationGroupKey].Groups { + consortiumGroup, ok := systemChannelGroup.Groups[channelconfig.ConsortiumsGroupKey].Groups[consortium.Name].Groups[orgName] if !ok { return nil, fmt.Errorf("Attempted to include a member which is not in the consortium") } @@ -248,7 +248,7 @@ func (dt *DefaultTemplator) NewChannelConfig(envConfigUpdate *cb.Envelope) (conf // Copy the system channel Channel level config to the new config for key, value := range systemChannelGroup.Values { channelGroup.Values[key] = value - if key == config.ConsortiumKey { + if key == channelconfig.ConsortiumKey { // Do not set the consortium name, we do this later continue } @@ -259,9 +259,9 @@ func (dt *DefaultTemplator) NewChannelConfig(envConfigUpdate *cb.Envelope) (conf } // Set the new config orderer group to the system channel orderer group and the application group to the new application group - channelGroup.Groups[config.OrdererGroupKey] = systemChannelGroup.Groups[config.OrdererGroupKey] - channelGroup.Groups[config.ApplicationGroupKey] = applicationGroup - channelGroup.Values[config.ConsortiumKey] = config.TemplateConsortium(consortium.Name).Values[config.ConsortiumKey] + channelGroup.Groups[channelconfig.OrdererGroupKey] = systemChannelGroup.Groups[channelconfig.OrdererGroupKey] + channelGroup.Groups[channelconfig.ApplicationGroupKey] = applicationGroup + channelGroup.Values[channelconfig.ConsortiumKey] = channelconfig.TemplateConsortium(consortium.Name).Values[channelconfig.ConsortiumKey] templateConfig, _ := utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, configUpdate.ChannelId, dt.support.Signer(), &cb.ConfigEnvelope{ Config: &cb.Config{ @@ -269,17 +269,5 @@ func (dt *DefaultTemplator) NewChannelConfig(envConfigUpdate *cb.Envelope) (conf }, }, msgVersion, epoch) - initializer := config.NewInitializer() - - // This is a very hacky way to disable the sanity check logging in the policy manager - // for the template configuration, but it is the least invasive near a release - pm, ok := initializer.PolicyManager().(*policies.ManagerImpl) - if ok { - pm.SuppressSanityLogMessages = true - defer func() { - pm.SuppressSanityLogMessages = false - }() - } - - return configtx.NewManagerImpl(templateConfig, initializer, nil) + return channelconfig.New(templateConfig, nil) } diff --git a/orderer/common/msgprocessor/systemchannel_test.go b/orderer/common/msgprocessor/systemchannel_test.go index ec77574d5d9..edad4661887 100644 --- a/orderer/common/msgprocessor/systemchannel_test.go +++ b/orderer/common/msgprocessor/systemchannel_test.go @@ -10,8 +10,7 @@ import ( "fmt" "testing" - "github.com/hyperledger/fabric/common/config/channel" - "github.com/hyperledger/fabric/common/configtx" + channelconfig "github.com/hyperledger/fabric/common/config/channel" configtxapi "github.com/hyperledger/fabric/common/configtx/api" "github.com/hyperledger/fabric/common/crypto" mockconfigtx "github.com/hyperledger/fabric/common/mocks/configtx" @@ -204,7 +203,7 @@ func TestSystemChannelConfigUpdateMsg(t *testing.T) { } type mockDefaultTemplatorSupport struct { - configtxapi.Manager + channelconfig.Resources } func (mdts *mockDefaultTemplatorSupport) Signer() crypto.LocalSigner { @@ -213,11 +212,11 @@ func (mdts *mockDefaultTemplatorSupport) Signer() crypto.LocalSigner { func TestNewChannelConfig(t *testing.T) { singleMSPGenesisBlock := provisional.New(genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile)).GenesisBlock() - ctxm, err := configtx.NewManagerImpl(utils.ExtractEnvelopeOrPanic(singleMSPGenesisBlock, 0), config.NewInitializer(), nil) + ctxm, err := channelconfig.New(utils.ExtractEnvelopeOrPanic(singleMSPGenesisBlock, 0), nil) assert.Nil(t, err) templator := NewDefaultTemplator(&mockDefaultTemplatorSupport{ - Manager: ctxm, + Resources: ctxm, }) t.Run("BadPayload", func(t *testing.T) { @@ -312,7 +311,7 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - config.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ Version: 100, }, }, @@ -332,7 +331,7 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - config.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ Version: 1, }, }, @@ -353,12 +352,12 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - config.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ Version: 1, }, }, Values: map[string]*cb.ConfigValue{ - config.ConsortiumKey: &cb.ConfigValue{ + channelconfig.ConsortiumKey: &cb.ConfigValue{ Value: []byte("bad consortium value"), }, }, @@ -378,12 +377,12 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - config.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ Version: 1, }, }, Values: map[string]*cb.ConfigValue{ - config.ConsortiumKey: &cb.ConfigValue{ + channelconfig.ConsortiumKey: &cb.ConfigValue{ Value: utils.MarshalOrPanic( &cb.Consortium{ Name: "NotTheNameYouAreLookingFor", @@ -407,12 +406,12 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - config.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ Version: 1, }, }, Values: map[string]*cb.ConfigValue{ - config.ConsortiumKey: &cb.ConfigValue{ + channelconfig.ConsortiumKey: &cb.ConfigValue{ Value: utils.MarshalOrPanic( &cb.Consortium{ Name: genesisconfig.SampleConsortiumName, @@ -436,7 +435,7 @@ func TestNewChannelConfig(t *testing.T) { &cb.ConfigUpdate{ WriteSet: &cb.ConfigGroup{ Groups: map[string]*cb.ConfigGroup{ - config.ApplicationGroupKey: &cb.ConfigGroup{ + channelconfig.ApplicationGroupKey: &cb.ConfigGroup{ Version: 1, Groups: map[string]*cb.ConfigGroup{ "BadOrgName": &cb.ConfigGroup{}, @@ -444,7 +443,7 @@ func TestNewChannelConfig(t *testing.T) { }, }, Values: map[string]*cb.ConfigValue{ - config.ConsortiumKey: &cb.ConfigValue{ + channelconfig.ConsortiumKey: &cb.ConfigValue{ Value: utils.MarshalOrPanic( &cb.Consortium{ Name: genesisconfig.SampleConsortiumName, @@ -470,7 +469,7 @@ func TestNewChannelConfig(t *testing.T) { // Successful t.Run("Success", func(t *testing.T) { - createTx, err := configtx.MakeChainCreationTransaction("foo", genesisconfig.SampleConsortiumName, nil, genesisconfig.SampleOrgName) + createTx, err := channelconfig.MakeChainCreationTransaction("foo", genesisconfig.SampleConsortiumName, nil, genesisconfig.SampleOrgName) assert.Nil(t, err) _, err = templator.NewChannelConfig(createTx) assert.Nil(t, err) diff --git a/orderer/common/msgprocessor/systemchannelfilter.go b/orderer/common/msgprocessor/systemchannelfilter.go index a9655131357..7c16f5ae990 100644 --- a/orderer/common/msgprocessor/systemchannelfilter.go +++ b/orderer/common/msgprocessor/systemchannelfilter.go @@ -9,8 +9,7 @@ package msgprocessor import ( "fmt" - "github.com/hyperledger/fabric/common/config/channel" - "github.com/hyperledger/fabric/common/configtx" + channelconfig "github.com/hyperledger/fabric/common/config/channel" configtxapi "github.com/hyperledger/fabric/common/configtx/api" cb "github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric/protos/utils" @@ -29,7 +28,7 @@ type ChainCreator interface { // LimitedSupport defines the subset of the channel resources required by the systemchannel filter. type LimitedSupport interface { - OrdererConfig() (config.Orderer, bool) + OrdererConfig() (channelconfig.Orderer, bool) } // SystemChainFilter implements the filter.Rule interface. @@ -156,8 +155,7 @@ func (scf *SystemChainFilter) authorizeAndInspect(configTx *cb.Envelope) error { return err } - initializer := config.NewInitializer() - configManager, err := configtx.NewManagerImpl(configTx, initializer, nil) + configManager, err := channelconfig.New(configTx, nil) if err != nil { return fmt.Errorf("failed to create config manager and handlers: %s", err) } diff --git a/orderer/common/msgprocessor/systemchannelfilter_test.go b/orderer/common/msgprocessor/systemchannelfilter_test.go index 308a9bf7c8e..e2a63bff8b4 100644 --- a/orderer/common/msgprocessor/systemchannelfilter_test.go +++ b/orderer/common/msgprocessor/systemchannelfilter_test.go @@ -10,7 +10,7 @@ import ( "fmt" "testing" - "github.com/hyperledger/fabric/common/config/channel" + channelconfig "github.com/hyperledger/fabric/common/config/channel" "github.com/hyperledger/fabric/common/configtx" configtxapi "github.com/hyperledger/fabric/common/configtx/api" "github.com/hyperledger/fabric/common/crypto" @@ -60,7 +60,7 @@ func newMockSupport() *mockSupport { } } -func (ms *mockSupport) OrdererConfig() (config.Orderer, bool) { +func (ms *mockSupport) OrdererConfig() (channelconfig.Orderer, bool) { return ms.msc, true } @@ -105,11 +105,11 @@ func TestGoodProposal(t *testing.T) { configEnv, err := configtx.NewCompositeTemplate( configtx.NewSimpleTemplate( - config.DefaultHashingAlgorithm(), - config.DefaultBlockDataHashingStructure(), - config.TemplateOrdererAddresses([]string{"foo"}), + channelconfig.DefaultHashingAlgorithm(), + channelconfig.DefaultBlockDataHashingStructure(), + channelconfig.TemplateOrdererAddresses([]string{"foo"}), ), - configtx.NewChainCreationTemplate("SampleConsortium", []string{}), + channelconfig.NewChainCreationTemplate("SampleConsortium", []string{}), ).Envelope(newChainID) assert.Nil(t, err, "Error constructing configtx") @@ -127,11 +127,11 @@ func TestProposalRejectedByConfig(t *testing.T) { configEnv, err := configtx.NewCompositeTemplate( configtx.NewSimpleTemplate( - config.DefaultHashingAlgorithm(), - config.DefaultBlockDataHashingStructure(), - config.TemplateOrdererAddresses([]string{"foo"}), + channelconfig.DefaultHashingAlgorithm(), + channelconfig.DefaultBlockDataHashingStructure(), + channelconfig.TemplateOrdererAddresses([]string{"foo"}), ), - configtx.NewChainCreationTemplate("SampleConsortium", []string{}), + channelconfig.NewChainCreationTemplate("SampleConsortium", []string{}), ).Envelope(newChainID) if err != nil { t.Fatalf("Error constructing configtx") @@ -155,11 +155,11 @@ func TestNumChainsExceeded(t *testing.T) { configEnv, err := configtx.NewCompositeTemplate( configtx.NewSimpleTemplate( - config.DefaultHashingAlgorithm(), - config.DefaultBlockDataHashingStructure(), - config.TemplateOrdererAddresses([]string{"foo"}), + channelconfig.DefaultHashingAlgorithm(), + channelconfig.DefaultBlockDataHashingStructure(), + channelconfig.TemplateOrdererAddresses([]string{"foo"}), ), - configtx.NewChainCreationTemplate("SampleConsortium", []string{}), + channelconfig.NewChainCreationTemplate("SampleConsortium", []string{}), ).Envelope(newChainID) if err != nil { t.Fatalf("Error constructing configtx") diff --git a/orderer/common/multichannel/chainsupport.go b/orderer/common/multichannel/chainsupport.go index 3eaf2c8186a..f704df8bf30 100644 --- a/orderer/common/multichannel/chainsupport.go +++ b/orderer/common/multichannel/chainsupport.go @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package multichannel import ( + configtxapi "github.com/hyperledger/fabric/common/configtx/api" "github.com/hyperledger/fabric/common/crypto" "github.com/hyperledger/fabric/orderer/common/blockcutter" "github.com/hyperledger/fabric/orderer/common/ledger" @@ -19,6 +20,7 @@ import ( // ChainSupport holds the resources for a particular channel. type ChainSupport struct { *ledgerResources + configtxapi.Manager msgprocessor.Processor *BlockWriter consensus.Chain @@ -39,7 +41,7 @@ func newChainSupport( // Assuming a block created with cb.NewBlock(), this should not // error even if the orderer metadata is an empty byte slice if err != nil { - logger.Fatalf("[channel: %s] Error extracting orderer metadata: %s", ledgerResources.ChainID(), err) + logger.Fatalf("[channel: %s] Error extracting orderer metadata: %s", ledgerResources.ConfigtxManager().ChainID(), err) } // Construct limited support needed as a parameter for additional support @@ -47,6 +49,7 @@ func newChainSupport( ledgerResources: ledgerResources, LocalSigner: signer, cutter: blockcutter.NewReceiverImpl(ledgerResources.SharedConfig()), + Manager: ledgerResources.ConfigtxManager(), } // Set up the msgprocessor diff --git a/orderer/common/multichannel/registrar.go b/orderer/common/multichannel/registrar.go index 7900656f246..21a7a4a8efb 100644 --- a/orderer/common/multichannel/registrar.go +++ b/orderer/common/multichannel/registrar.go @@ -12,8 +12,7 @@ package multichannel import ( "fmt" - "github.com/hyperledger/fabric/common/config/channel" - "github.com/hyperledger/fabric/common/configtx" + channelconfig "github.com/hyperledger/fabric/common/config/channel" configtxapi "github.com/hyperledger/fabric/common/configtx/api" "github.com/hyperledger/fabric/orderer/common/ledger" "github.com/hyperledger/fabric/orderer/common/msgprocessor" @@ -34,13 +33,13 @@ const ( ) type configResources struct { - configtxapi.Manager + channelconfig.Resources } -func (cr *configResources) SharedConfig() config.Orderer { +func (cr *configResources) SharedConfig() channelconfig.Orderer { oc, ok := cr.OrdererConfig() if !ok { - logger.Panicf("[channel %s] has no orderer configuration", cr.ChainID()) + logger.Panicf("[channel %s] has no orderer configuration", cr.ConfigtxManager().ChainID()) } return oc } @@ -95,7 +94,7 @@ func NewRegistrar(ledgerFactory ledger.Factory, consenters map[string]consensus. logger.Panic("Programming error, configTx should never be nil here") } ledgerResources := r.newLedgerResources(configTx) - chainID := ledgerResources.ChainID() + chainID := ledgerResources.ConfigtxManager().ChainID() if _, ok := ledgerResources.ConsortiumsConfig(); ok { if r.systemChannelID != "" { @@ -187,8 +186,7 @@ func (r *Registrar) GetChain(chainID string) (*ChainSupport, bool) { } func (r *Registrar) newLedgerResources(configTx *cb.Envelope) *ledgerResources { - initializer := config.NewInitializer() - configManager, err := configtx.NewManagerImpl(configTx, initializer, nil) + configManager, err := channelconfig.New(configTx, nil) if err != nil { logger.Panicf("Error creating configtx manager and handlers: %s", err) } @@ -201,7 +199,7 @@ func (r *Registrar) newLedgerResources(configTx *cb.Envelope) *ledgerResources { } return &ledgerResources{ - configResources: &configResources{Manager: configManager}, + configResources: &configResources{Resources: configManager}, ReadWriter: ledger, } } @@ -217,7 +215,7 @@ func (r *Registrar) newChain(configtx *cb.Envelope) { } cs := newChainSupport(r, ledgerResources, r.consenters, r.signer) - chainID := ledgerResources.ChainID() + chainID := ledgerResources.ConfigtxManager().ChainID() logger.Infof("Created and starting new chain %s", chainID) diff --git a/orderer/common/multichannel/registrar_test.go b/orderer/common/multichannel/registrar_test.go index 0759b18ce76..adfad6a416e 100644 --- a/orderer/common/multichannel/registrar_test.go +++ b/orderer/common/multichannel/registrar_test.go @@ -12,7 +12,7 @@ import ( "time" "github.com/golang/protobuf/proto" - "github.com/hyperledger/fabric/common/configtx" + channelconfig "github.com/hyperledger/fabric/common/config/channel" "github.com/hyperledger/fabric/common/crypto" mockcrypto "github.com/hyperledger/fabric/common/mocks/crypto" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" @@ -180,7 +180,7 @@ func TestNewChain(t *testing.T) { manager := NewRegistrar(lf, consenters, mockCrypto()) - envConfigUpdate, err := configtx.MakeChainCreationTransaction(newChainID, genesisconfig.SampleConsortiumName, mockSigningIdentity) + envConfigUpdate, err := channelconfig.MakeChainCreationTransaction(newChainID, genesisconfig.SampleConsortiumName, mockSigningIdentity) assert.NoError(t, err, "Constructing chain creation tx") cm, err := manager.NewChannelConfig(envConfigUpdate) diff --git a/orderer/common/performance/utils.go b/orderer/common/performance/utils.go index 6e466dda960..398efe46e35 100644 --- a/orderer/common/performance/utils.go +++ b/orderer/common/performance/utils.go @@ -12,7 +12,7 @@ import ( "sync" "time" - "github.com/hyperledger/fabric/common/configtx" + channelconfig "github.com/hyperledger/fabric/common/config/channel" "github.com/hyperledger/fabric/common/localmsp" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/msp" @@ -110,7 +110,7 @@ func CreateChannel(server *BenchmarkServer) string { defer client.Close() channelID := RandomID(10) - createChannelTx, _ := configtx.MakeChainCreationTransaction( + createChannelTx, _ := channelconfig.MakeChainCreationTransaction( channelID, genesisconfig.SampleConsortiumName, signer, diff --git a/orderer/sample_clients/broadcast_config/newchain.go b/orderer/sample_clients/broadcast_config/newchain.go index 5e0b369bb74..d564dacf9fd 100644 --- a/orderer/sample_clients/broadcast_config/newchain.go +++ b/orderer/sample_clients/broadcast_config/newchain.go @@ -17,13 +17,13 @@ limitations under the License. package main import ( - "github.com/hyperledger/fabric/common/configtx" + channelconfig "github.com/hyperledger/fabric/common/config/channel" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" cb "github.com/hyperledger/fabric/protos/common" ) func newChainRequest(consensusType, creationPolicy, newChannelId string) *cb.Envelope { - env, err := configtx.MakeChainCreationTransaction(newChannelId, genesisconfig.SampleConsortiumName, signer) + env, err := channelconfig.MakeChainCreationTransaction(newChannelId, genesisconfig.SampleConsortiumName, signer) if err != nil { panic(err) } diff --git a/peer/channel/create.go b/peer/channel/create.go index a1ba2c5bc1b..ec6c52221cc 100644 --- a/peer/channel/create.go +++ b/peer/channel/create.go @@ -23,6 +23,7 @@ import ( "errors" "github.com/golang/protobuf/proto" + channelconfig "github.com/hyperledger/fabric/common/config/channel" "github.com/hyperledger/fabric/common/configtx" localsigner "github.com/hyperledger/fabric/common/localmsp" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" @@ -75,7 +76,7 @@ func createChannelFromDefaults(cf *ChannelCmdFactory) (*cb.Envelope, error) { return nil, err } - chCrtEnv, err := configtx.MakeChainCreationTransaction(chainID, genesisconfig.SampleConsortiumName, signer) + chCrtEnv, err := channelconfig.MakeChainCreationTransaction(chainID, genesisconfig.SampleConsortiumName, signer) if err != nil { return nil, err diff --git a/peer/common/common.go b/peer/common/common.go index ed01dac3e4a..d27e9615913 100644 --- a/peer/common/common.go +++ b/peer/common/common.go @@ -22,8 +22,6 @@ import ( "github.com/hyperledger/fabric/bccsp/factory" channelconfig "github.com/hyperledger/fabric/common/config/channel" - "github.com/hyperledger/fabric/common/configtx" - configtxapi "github.com/hyperledger/fabric/common/configtx/api" "github.com/hyperledger/fabric/common/errors" "github.com/hyperledger/fabric/common/flogging" "github.com/hyperledger/fabric/common/viperutil" @@ -192,11 +190,9 @@ func GetOrdererEndpointOfChain(chainID string, signer msp.SigningIdentity, endor if err != nil { return nil, fmt.Errorf("Error extracting config block envelope: %s", err) } - configtxInitializer := channelconfig.NewInitializer() - configtxManager, err := configtx.NewManagerImpl( + configtxManager, err := channelconfig.New( envelopeConfig, - configtxInitializer, - []func(cm configtxapi.Manager){}, + nil, ) if err != nil { return nil, fmt.Errorf("Error loadding config block: %s", err)