diff --git a/common/channelconfig/realconfig_test.go b/common/channelconfig/realconfig_test.go index 057abca4dab..f7892be2f7c 100644 --- a/common/channelconfig/realconfig_test.go +++ b/common/channelconfig/realconfig_test.go @@ -10,8 +10,8 @@ import ( "testing" newchannelconfig "github.com/hyperledger/fabric/common/channelconfig" + "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" "github.com/hyperledger/fabric/protos/utils" "github.com/stretchr/testify/assert" @@ -34,7 +34,7 @@ func TestWithRealConfigtx(t *testing.T) { Port: 7, }, } - gb := provisional.New(conf).GenesisBlockForChannel("foo") + gb := encoder.New(conf).GenesisBlockForChannel("foo") env := utils.ExtractEnvelopeOrPanic(gb, 0) _, err := newchannelconfig.NewBundleFromEnvelope(env) assert.NoError(t, err) diff --git a/common/configtx/test/helper.go b/common/configtx/test/helper.go index 4a954366a78..dd7bb3eb9a7 100644 --- a/common/configtx/test/helper.go +++ b/common/configtx/test/helper.go @@ -8,76 +8,59 @@ package test import ( "github.com/hyperledger/fabric/common/channelconfig" - "github.com/hyperledger/fabric/common/configtx" "github.com/hyperledger/fabric/common/flogging" "github.com/hyperledger/fabric/common/genesis" + "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" - cf "github.com/hyperledger/fabric/core/config" - "github.com/hyperledger/fabric/msp" cb "github.com/hyperledger/fabric/protos/common" mspproto "github.com/hyperledger/fabric/protos/msp" + pb "github.com/hyperledger/fabric/protos/peer" + "github.com/hyperledger/fabric/protos/utils" ) var logger = flogging.MustGetLogger("common/configtx/test") -const ( - // AcceptAllPolicyKey is the key of the AcceptAllPolicy. - AcceptAllPolicyKey = "AcceptAllPolicy" -) - -func getConfigDir() string { - mspDir, err := cf.GetDevMspDir() +// MakeGenesisBlock creates a genesis block using the test templates for the given chainID +func MakeGenesisBlock(chainID string) (*cb.Block, error) { + profile := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile) + channelGroup, err := encoder.NewChannelGroup(profile) if err != nil { - logger.Panicf("Could not find genesis.yaml, try setting GOPATH correctly") + logger.Panicf("Error creating channel config: %s", err) } - return mspDir -} - -// MakeGenesisBlock creates a genesis block using the test templates for the given chainID -func MakeGenesisBlock(chainID string) (*cb.Block, error) { - return genesis.NewFactoryImpl(CompositeTemplate()).Block(chainID) + return genesis.NewFactoryImpl(channelGroup).Block(chainID) } // MakeGenesisBlockWithMSPs creates a genesis block using the MSPs provided for the given chainID func MakeGenesisBlockFromMSPs(chainID string, appMSPConf, ordererMSPConf *mspproto.MSPConfig, appOrgID, ordererOrgID string) (*cb.Block, error) { - appOrgTemplate := configtx.NewSimpleTemplate(channelconfig.TemplateGroupMSP([]string{channelconfig.ApplicationGroupKey, appOrgID}, appMSPConf)) - ordererOrgTemplate := configtx.NewSimpleTemplate(channelconfig.TemplateGroupMSP([]string{channelconfig.OrdererGroupKey, ordererOrgID}, ordererMSPConf)) - composite := configtx.NewCompositeTemplate(OrdererTemplate(), appOrgTemplate, ApplicationOrgTemplate(), ordererOrgTemplate) - return genesis.NewFactoryImpl(composite).Block(chainID) -} - -// OrderererTemplate returns the test orderer template -func OrdererTemplate() configtx.Template { - genConf := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile) - return provisional.New(genConf).ChannelTemplate() -} - -// sampleOrgID apparently _must_ be set to DEFAULT or things break -// Beware when changing! -const sampleOrgID = "DEFAULT" - -// ApplicationOrgTemplate returns the SAMPLE org with MSP template -func ApplicationOrgTemplate() configtx.Template { - mspConf, err := msp.GetLocalMspConfig(getConfigDir(), nil, sampleOrgID) + profile := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile) + profile.Orderer.Organizations = nil + channelGroup, err := encoder.NewChannelGroup(profile) if err != nil { - logger.Panicf("Could not load sample MSP config: %s", err) + logger.Panicf("Error creating channel config: %s", err) } - return configtx.NewSimpleTemplate(channelconfig.TemplateGroupMSP([]string{channelconfig.ApplicationGroupKey, sampleOrgID}, mspConf)) -} -// OrdererOrgTemplate returns the SAMPLE org with MSP template -func OrdererOrgTemplate() configtx.Template { - mspConf, err := msp.GetLocalMspConfig(getConfigDir(), nil, sampleOrgID) - if err != nil { - logger.Panicf("Could not load sample MSP config: %s", err) + ordererOrg := cb.NewConfigGroup() + ordererOrg.ModPolicy = channelconfig.AdminsPolicyKey + ordererOrg.Values[channelconfig.MSPKey] = &cb.ConfigValue{ + Value: utils.MarshalOrPanic(channelconfig.MSPValue(ordererMSPConf).Value()), + ModPolicy: channelconfig.AdminsPolicyKey, } - return configtx.NewSimpleTemplate(channelconfig.TemplateGroupMSP([]string{channelconfig.OrdererGroupKey, sampleOrgID}, mspConf)) -} -// CompositeTemplate returns the composite template of peer, orderer, and MSP -func CompositeTemplate() configtx.Template { - return configtx.NewCompositeTemplate(OrdererTemplate(), ApplicationOrgTemplate(), OrdererOrgTemplate()) + applicationOrg := cb.NewConfigGroup() + applicationOrg.ModPolicy = channelconfig.AdminsPolicyKey + applicationOrg.Values[channelconfig.MSPKey] = &cb.ConfigValue{ + Value: utils.MarshalOrPanic(channelconfig.MSPValue(appMSPConf).Value()), + ModPolicy: channelconfig.AdminsPolicyKey, + } + applicationOrg.Values[channelconfig.AnchorPeersKey] = &cb.ConfigValue{ + Value: utils.MarshalOrPanic(channelconfig.AnchorPeersValue([]*pb.AnchorPeer{}).Value()), + ModPolicy: channelconfig.AdminsPolicyKey, + } + + channelGroup.Groups[channelconfig.OrdererGroupKey].Groups[ordererOrgID] = ordererOrg + channelGroup.Groups[channelconfig.ApplicationGroupKey].Groups[ordererOrgID] = applicationOrg + + return genesis.NewFactoryImpl(channelGroup).Block(chainID) } diff --git a/common/configtx/test/helper_test.go b/common/configtx/test/helper_test.go deleted file mode 100644 index f90bf760716..00000000000 --- a/common/configtx/test/helper_test.go +++ /dev/null @@ -1,82 +0,0 @@ -/* -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 test - -import ( - "os" - "path/filepath" - "testing" - - "github.com/hyperledger/fabric/core/config" - "github.com/hyperledger/fabric/msp" - logging "github.com/op/go-logging" -) - -func init() { - // Configuration is always specified relative to $GOPATH/github.com/hyperledger/fabric - // This test will fail with the default configuration if executed in the package dir - // We are in common/configtx/test - os.Chdir(filepath.Join("..", "..", "..")) - - logging.SetLevel(logging.DEBUG, "") -} - -func TestMakeGenesisBlock(t *testing.T) { - _, err := MakeGenesisBlock("foo") - if err != nil { - t.Fatalf("Error making genesis block: %s", err) - } -} - -func TestMakeGenesisBlockFromMSPs(t *testing.T) { - - mspDir, err := config.GetDevMspDir() - if err != nil { - t.Fatalf("Error getting DevMspDir: %s", err) - } - - ordererOrgID := "TestOrdererOrg" - appOrgID := "TestAppOrg" - appMSPConf, err := msp.GetLocalMspConfig(mspDir, nil, appOrgID) - if err != nil { - t.Fatalf("Error making genesis block from MSPs: %s", err) - } - ordererMSPConf, err := msp.GetLocalMspConfig(mspDir, nil, ordererOrgID) - if err != nil { - t.Fatalf("Error making genesis block from MSPs: %s", err) - } - _, err = MakeGenesisBlockFromMSPs("foo", appMSPConf, ordererMSPConf, appOrgID, ordererOrgID) - if err != nil { - t.Fatalf("Error making genesis block from MSPs: %s", err) - } -} - -func TestOrdererTemplate(t *testing.T) { - _ = OrdererTemplate() -} - -func TestOrdererOrgTemplate(t *testing.T) { - _ = OrdererOrgTemplate() -} - -func TestApplicationOrgTemplate(t *testing.T) { - _ = ApplicationOrgTemplate() -} - -func TestCompositeTemplate(t *testing.T) { - _ = CompositeTemplate() -} diff --git a/common/genesis/genesis.go b/common/genesis/genesis.go index f63e8f3daa1..7482bc2ae59 100644 --- a/common/genesis/genesis.go +++ b/common/genesis/genesis.go @@ -17,8 +17,6 @@ limitations under the License. package genesis import ( - "github.com/golang/protobuf/proto" - "github.com/hyperledger/fabric/common/configtx" cb "github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric/protos/utils" ) @@ -37,32 +35,21 @@ type Factory interface { } type factory struct { - template configtx.Template + channelGroup *cb.ConfigGroup } // NewFactoryImpl creates a new Factory. -func NewFactoryImpl(template configtx.Template) Factory { - return &factory{template: template} +func NewFactoryImpl(channelGroup *cb.ConfigGroup) Factory { + return &factory{channelGroup: channelGroup} } // Block constructs and returns a genesis block for a given channel ID. func (f *factory) Block(channelID string) (*cb.Block, error) { - configEnv, err := f.template.Envelope(channelID) - if err != nil { - return nil, err - } - - configUpdate := &cb.ConfigUpdate{} - err = proto.Unmarshal(configEnv.ConfigUpdate, configUpdate) - if err != nil { - return nil, err - } - payloadChannelHeader := utils.MakeChannelHeader(cb.HeaderType_CONFIG, msgVersion, channelID, epoch) payloadSignatureHeader := utils.MakeSignatureHeader(nil, utils.CreateNonceOrPanic()) utils.SetTxID(payloadChannelHeader, payloadSignatureHeader) payloadHeader := utils.MakePayloadHeader(payloadChannelHeader, payloadSignatureHeader) - payload := &cb.Payload{Header: payloadHeader, Data: utils.MarshalOrPanic(&cb.ConfigEnvelope{Config: &cb.Config{ChannelGroup: configUpdate.WriteSet}})} + payload := &cb.Payload{Header: payloadHeader, Data: utils.MarshalOrPanic(&cb.ConfigEnvelope{Config: &cb.Config{ChannelGroup: f.channelGroup}})} envelope := &cb.Envelope{Payload: utils.MarshalOrPanic(payload), Signature: nil} block := cb.NewBlock(0, nil) diff --git a/common/genesis/genesis_test.go b/common/genesis/genesis_test.go index 8afcf23b4cf..c27c488cd98 100644 --- a/common/genesis/genesis_test.go +++ b/common/genesis/genesis_test.go @@ -19,19 +19,19 @@ package genesis import ( "testing" - "github.com/hyperledger/fabric/common/configtx" + cb "github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric/protos/utils" "github.com/stretchr/testify/assert" ) func TestBasicSanity(t *testing.T) { - impl := NewFactoryImpl(configtx.NewSimpleTemplate()) + impl := NewFactoryImpl(cb.NewConfigGroup()) _, err := impl.Block("testchainid") assert.NoError(t, err, "Basic sanity fails") } func TestForTransactionID(t *testing.T) { - impl := NewFactoryImpl(configtx.NewSimpleTemplate()) + impl := NewFactoryImpl(cb.NewConfigGroup()) block, _ := impl.Block("testchainid") configEnv, _ := utils.ExtractEnvelope(block, 0) configEnvPayload, _ := utils.ExtractPayload(configEnv) diff --git a/common/tools/configtxgen/encoder/encoder.go b/common/tools/configtxgen/encoder/encoder.go index 0b35eaac4bb..bd6712e9a83 100644 --- a/common/tools/configtxgen/encoder/encoder.go +++ b/common/tools/configtxgen/encoder/encoder.go @@ -10,6 +10,7 @@ import ( "github.com/hyperledger/fabric/common/cauthdsl" "github.com/hyperledger/fabric/common/channelconfig" "github.com/hyperledger/fabric/common/flogging" + "github.com/hyperledger/fabric/common/genesis" "github.com/hyperledger/fabric/common/policies" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/msp" @@ -272,3 +273,37 @@ func NewConsortiumGroup(conf *genesisconfig.Consortium) (*cb.ConfigGroup, error) consortiumGroup.ModPolicy = ordererAdminsPolicyName return consortiumGroup, nil } + +// Bootstrapper is a wrapper around NewChannelConfigGroup which can produce genesis blocks +type Bootstrapper struct { + channelGroup *cb.ConfigGroup +} + +// New creates a new Bootstrapper for generating genesis blocks +func New(config *genesisconfig.Profile) *Bootstrapper { + channelGroup, err := NewChannelGroup(config) + if err != nil { + logger.Panicf("Error creating channel group: %s", err) + } + return &Bootstrapper{ + channelGroup: channelGroup, + } +} + +// GenesisBlock produces a genesis block for the default test chain id +func (bs *Bootstrapper) GenesisBlock() *cb.Block { + block, err := genesis.NewFactoryImpl(bs.channelGroup).Block(genesisconfig.TestChainID) + if err != nil { + logger.Panicf("Error creating genesis block from channel group: %s", err) + } + return block +} + +// GenesisBlockForChannel produces a genesis block for a given channel ID +func (bs *Bootstrapper) GenesisBlockForChannel(channelID string) *cb.Block { + block, err := genesis.NewFactoryImpl(bs.channelGroup).Block(channelID) + if err != nil { + logger.Panicf("Error creating genesis block from channel group: %s", err) + } + return block +} diff --git a/common/tools/configtxgen/encoder/encoder_test.go b/common/tools/configtxgen/encoder/encoder_test.go index d88be7ee733..f28c455765b 100644 --- a/common/tools/configtxgen/encoder/encoder_test.go +++ b/common/tools/configtxgen/encoder/encoder_test.go @@ -12,11 +12,8 @@ import ( "github.com/hyperledger/fabric/common/channelconfig" "github.com/hyperledger/fabric/common/flogging" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" cb "github.com/hyperledger/fabric/protos/common" - "github.com/hyperledger/fabric/protos/utils" - "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" ) @@ -41,22 +38,6 @@ func hasModPolicySet(t *testing.T, groupName string, cg *cb.ConfigGroup) { } func TestConfigParsing(t *testing.T) { - config := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile) - group, err := NewChannelGroup(config) - assert.NoError(t, err) - assert.NotNil(t, group) - - _, err = channelconfig.NewBundle("test", &cb.Config{ - ChannelGroup: group, - }) - assert.NoError(t, err) - - hasModPolicySet(t, "Channel", group) -} - -// This test will be removed with the legacy provisional package, but demonstrates -// that the old and new encoders produce identical output -func TestEquivalentParsing(t *testing.T) { for _, profile := range []string{ genesisconfig.SampleInsecureSoloProfile, genesisconfig.SampleSingleMSPSoloProfile, @@ -65,15 +46,18 @@ func TestEquivalentParsing(t *testing.T) { genesisconfig.SampleSingleMSPKafkaProfile, genesisconfig.SampleDevModeKafkaProfile, } { - config := genesisconfig.Load(profile) - group, err := NewChannelGroup(config) - assert.NoError(t, err) - assert.NotNil(t, group) - - gb := provisional.New(config).GenesisBlockForChannel("foo") - env := utils.ExtractEnvelopeOrPanic(gb, 0) - configEnv := &cb.ConfigEnvelope{} - utils.UnmarshalEnvelopeOfType(env, cb.HeaderType_CONFIG, configEnv) - assert.True(t, proto.Equal(configEnv.Config.ChannelGroup, group)) + t.Run(profile, func(t *testing.T) { + config := genesisconfig.Load(profile) + group, err := NewChannelGroup(config) + assert.NoError(t, err) + assert.NotNil(t, group) + + _, err = channelconfig.NewBundle("test", &cb.Config{ + ChannelGroup: group, + }) + assert.NoError(t, err) + + hasModPolicySet(t, "Channel", group) + }) } } diff --git a/common/tools/configtxgen/localconfig/config.go b/common/tools/configtxgen/localconfig/config.go index 39af6461725..eaef9be82f2 100644 --- a/common/tools/configtxgen/localconfig/config.go +++ b/common/tools/configtxgen/localconfig/config.go @@ -44,6 +44,9 @@ func init() { } const ( + // TestChainID is the channel name used for testing purposes when one is not given + TestChainID = "testchainid" + // SampleInsecureSoloProfile references the sample profile which does not include any MSPs and uses solo for ordering. SampleInsecureSoloProfile = "SampleInsecureSolo" // SampleDevModeSoloProfile references the sample profile which requires only basic membership for admin privileges and uses solo for ordering. diff --git a/common/tools/configtxgen/main.go b/common/tools/configtxgen/main.go index 13b9dd57fe4..05deae8b63d 100644 --- a/common/tools/configtxgen/main.go +++ b/common/tools/configtxgen/main.go @@ -16,9 +16,9 @@ import ( "github.com/hyperledger/fabric/bccsp/factory" "github.com/hyperledger/fabric/common/channelconfig" "github.com/hyperledger/fabric/common/flogging" + "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/common/tools/configtxgen/metadata" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" "github.com/hyperledger/fabric/common/tools/protolator" cb "github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric/protos/peer" @@ -32,7 +32,7 @@ var exitCode = 0 var logger = flogging.MustGetLogger("common/tools/configtxgen") func doOutputBlock(config *genesisconfig.Profile, channelID string, outputBlock string) error { - pgen := provisional.New(config) + pgen := encoder.New(config) logger.Info("Generating genesis block") if config.Orderer == nil { return fmt.Errorf("config does not contain an Orderers section, necessary for all config blocks, aborting") @@ -204,7 +204,7 @@ func main() { var outputBlock, outputChannelCreateTx, profile, channelID, inspectBlock, inspectChannelCreateTx, outputAnchorPeersUpdate, asOrg string flag.StringVar(&outputBlock, "outputBlock", "", "The path to write the genesis block to (if set)") - flag.StringVar(&channelID, "channelID", provisional.TestChainID, "The channel ID to use in the configtx") + flag.StringVar(&channelID, "channelID", genesisconfig.TestChainID, "The channel ID to use in the configtx") flag.StringVar(&outputChannelCreateTx, "outputCreateChannelTx", "", "The path to write a channel creation configtx to (if set)") flag.StringVar(&profile, "profile", genesisconfig.SampleInsecureSoloProfile, "The profile from configtx.yaml to use for generation.") flag.StringVar(&inspectBlock, "inspectBlock", "", "Prints the configuration contained in the block at the specified path") diff --git a/common/tools/configtxgen/main_test.go b/common/tools/configtxgen/main_test.go index 3ba26527531..34dd4a097af 100644 --- a/common/tools/configtxgen/main_test.go +++ b/common/tools/configtxgen/main_test.go @@ -63,7 +63,7 @@ func TestMissingOrdererSection(t *testing.T) { config := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile) config.Orderer = nil - assert.Error(t, doOutputBlock(config, "foo", blockDest), "Missing orderer section") + assert.Panics(t, func() { doOutputBlock(config, "foo", blockDest) }, "Missing orderer section") } func TestMissingConsortiumValue(t *testing.T) { diff --git a/common/tools/configtxgen/provisional/provisional.go b/common/tools/configtxgen/provisional/provisional.go deleted file mode 100644 index 7ed8cbcf3e0..00000000000 --- a/common/tools/configtxgen/provisional/provisional.go +++ /dev/null @@ -1,278 +0,0 @@ -/* -Copyright IBM Corp. 2016 All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package provisional - -import ( - "fmt" - - "github.com/hyperledger/fabric/common/cauthdsl" - "github.com/hyperledger/fabric/common/channelconfig" - "github.com/hyperledger/fabric/common/configtx" - "github.com/hyperledger/fabric/common/flogging" - "github.com/hyperledger/fabric/common/genesis" - "github.com/hyperledger/fabric/common/policies" - genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - "github.com/hyperledger/fabric/msp" - "github.com/hyperledger/fabric/orderer/common/bootstrap" - cb "github.com/hyperledger/fabric/protos/common" - ab "github.com/hyperledger/fabric/protos/orderer" - pb "github.com/hyperledger/fabric/protos/peer" - "github.com/hyperledger/fabric/protos/utils" - logging "github.com/op/go-logging" -) - -const ( - pkgLogID = "common/tools/configtxgen/provisional" -) - -var ( - logger *logging.Logger -) - -func init() { - logger = flogging.MustGetLogger(pkgLogID) - flogging.SetModuleLevel(pkgLogID, "info") -} - -// Generator can either create an orderer genesis block or config template -type Generator interface { - bootstrap.Helper - - // ChannelTemplate returns a template which can be used to help initialize a channel - ChannelTemplate() configtx.Template - - // GenesisBlockForChannel TODO - GenesisBlockForChannel(channelID string) *cb.Block -} - -const ( - // ConsensusTypeSolo identifies the solo consensus implementation. - ConsensusTypeSolo = "solo" - // ConsensusTypeKafka identifies the Kafka-based consensus implementation. - ConsensusTypeKafka = "kafka" - - // TestChainID is the default value of ChainID. It is used by all testing - // networks. It is necessary to set and export this variable so that test - // clients can connect without being rejected for targeting a chain which - // does not exist. - TestChainID = "testchainid" - - // BlockValidationPolicyKey TODO - BlockValidationPolicyKey = "BlockValidation" - - // OrdererAdminsPolicy is the absolute path to the orderer admins policy - OrdererAdminsPolicy = "/Channel/Orderer/Admins" -) - -type bootstrapper struct { - channelGroups []*cb.ConfigGroup - ordererGroups []*cb.ConfigGroup - applicationGroups []*cb.ConfigGroup - consortiumsGroups []*cb.ConfigGroup -} - -// New returns a new provisional bootstrap helper. -func New(conf *genesisconfig.Profile) Generator { - bs := &bootstrapper{ - channelGroups: []*cb.ConfigGroup{ - // Chain Config Types - channelconfig.DefaultHashingAlgorithm(), - channelconfig.DefaultBlockDataHashingStructure(), - - // Default policies - policies.TemplateImplicitMetaAnyPolicy([]string{}, channelconfig.ReadersPolicyKey), - policies.TemplateImplicitMetaAnyPolicy([]string{}, channelconfig.WritersPolicyKey), - policies.TemplateImplicitMetaMajorityPolicy([]string{}, channelconfig.AdminsPolicyKey), - }, - } - - if len(conf.Capabilities) > 0 { - bs.channelGroups = append(bs.channelGroups, channelconfig.TemplateChannelCapabilities(conf.Capabilities)) - } - - if conf.Orderer != nil { - // Orderer addresses - oa := channelconfig.TemplateOrdererAddresses(conf.Orderer.Addresses) - oa.Values[channelconfig.OrdererAddressesKey].ModPolicy = OrdererAdminsPolicy - - bs.ordererGroups = []*cb.ConfigGroup{ - oa, - - // Orderer Config Types - channelconfig.TemplateConsensusType(conf.Orderer.OrdererType), - channelconfig.TemplateBatchSize(&ab.BatchSize{ - MaxMessageCount: conf.Orderer.BatchSize.MaxMessageCount, - AbsoluteMaxBytes: conf.Orderer.BatchSize.AbsoluteMaxBytes, - PreferredMaxBytes: conf.Orderer.BatchSize.PreferredMaxBytes, - }), - channelconfig.TemplateBatchTimeout(conf.Orderer.BatchTimeout.String()), - channelconfig.TemplateChannelRestrictions(conf.Orderer.MaxChannels), - - // Initialize the default Reader/Writer/Admins orderer policies, as well as block validation policy - policies.TemplateImplicitMetaPolicyWithSubPolicy([]string{channelconfig.OrdererGroupKey}, BlockValidationPolicyKey, channelconfig.WritersPolicyKey, cb.ImplicitMetaPolicy_ANY), - policies.TemplateImplicitMetaAnyPolicy([]string{channelconfig.OrdererGroupKey}, channelconfig.ReadersPolicyKey), - policies.TemplateImplicitMetaAnyPolicy([]string{channelconfig.OrdererGroupKey}, channelconfig.WritersPolicyKey), - policies.TemplateImplicitMetaMajorityPolicy([]string{channelconfig.OrdererGroupKey}, channelconfig.AdminsPolicyKey), - } - - if len(conf.Orderer.Capabilities) > 0 { - bs.ordererGroups = append(bs.ordererGroups, channelconfig.TemplateOrdererCapabilities(conf.Orderer.Capabilities)) - } - - for _, org := range conf.Orderer.Organizations { - mspConfig, err := msp.GetVerifyingMspConfig(org.MSPDir, org.ID) - if err != nil { - logger.Panicf("1 - Error loading MSP configuration for org %s: %s", org.Name, err) - } - bs.ordererGroups = append(bs.ordererGroups, - channelconfig.TemplateGroupMSPWithAdminRolePrincipal([]string{channelconfig.OrdererGroupKey, org.Name}, - mspConfig, org.AdminPrincipal == genesisconfig.AdminRoleAdminPrincipal, - ), - ) - } - - switch conf.Orderer.OrdererType { - case ConsensusTypeSolo: - case ConsensusTypeKafka: - bs.ordererGroups = append(bs.ordererGroups, channelconfig.TemplateKafkaBrokers(conf.Orderer.Kafka.Brokers)) - default: - panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Orderer.OrdererType)) - } - } - - if conf.Application != nil { - - bs.applicationGroups = []*cb.ConfigGroup{ - // Initialize the default Reader/Writer/Admins application policies - policies.TemplateImplicitMetaAnyPolicy([]string{channelconfig.ApplicationGroupKey}, channelconfig.ReadersPolicyKey), - policies.TemplateImplicitMetaAnyPolicy([]string{channelconfig.ApplicationGroupKey}, channelconfig.WritersPolicyKey), - policies.TemplateImplicitMetaMajorityPolicy([]string{channelconfig.ApplicationGroupKey}, channelconfig.AdminsPolicyKey), - } - - if len(conf.Application.Capabilities) > 0 { - bs.applicationGroups = append(bs.applicationGroups, channelconfig.TemplateApplicationCapabilities(conf.Application.Capabilities)) - } - - for _, org := range conf.Application.Organizations { - mspConfig, err := msp.GetVerifyingMspConfig(org.MSPDir, org.ID) - if err != nil { - logger.Panicf("2- Error loading MSP configuration for org %s: %s", org.Name, err) - } - - bs.applicationGroups = append(bs.applicationGroups, - channelconfig.TemplateGroupMSPWithAdminRolePrincipal([]string{channelconfig.ApplicationGroupKey, org.Name}, - mspConfig, org.AdminPrincipal == genesisconfig.AdminRoleAdminPrincipal, - ), - ) - var anchorProtos []*pb.AnchorPeer - for _, anchorPeer := range org.AnchorPeers { - anchorProtos = append(anchorProtos, &pb.AnchorPeer{ - Host: anchorPeer.Host, - Port: int32(anchorPeer.Port), - }) - } - - bs.applicationGroups = append(bs.applicationGroups, channelconfig.TemplateAnchorPeers(org.Name, anchorProtos)) - } - - } - - if conf.Consortiums != nil { - tcg := channelconfig.TemplateConsortiumsGroup() - tcg.Groups[channelconfig.ConsortiumsGroupKey].ModPolicy = OrdererAdminsPolicy - - // Fix for https://jira.hyperledger.org/browse/FAB-4373 - // Note, AcceptAllPolicy in this context, does not grant any unrestricted - // access, but allows the /Channel/Admins policy to evaluate to true - // for the ordering system channel while set to MAJORITY with the addition - // to the successful evaluation of the /Channel/Orderer/Admins policy (which - // is not AcceptAll - tcg.Groups[channelconfig.ConsortiumsGroupKey].Policies[channelconfig.AdminsPolicyKey] = &cb.ConfigPolicy{ - Policy: &cb.Policy{ - Type: int32(cb.Policy_SIGNATURE), - Value: utils.MarshalOrPanic(cauthdsl.AcceptAllPolicy), - }, - ModPolicy: OrdererAdminsPolicy, - } - - bs.consortiumsGroups = append(bs.consortiumsGroups, tcg) - - for consortiumName, consortium := range conf.Consortiums { - cg := channelconfig.TemplateConsortiumChannelCreationPolicy(consortiumName, policies.ImplicitMetaPolicyWithSubPolicy( - channelconfig.AdminsPolicyKey, - cb.ImplicitMetaPolicy_ANY, - ).Policy) - - cg.Groups[channelconfig.ConsortiumsGroupKey].Groups[consortiumName].ModPolicy = OrdererAdminsPolicy - cg.Groups[channelconfig.ConsortiumsGroupKey].Groups[consortiumName].Values[channelconfig.ChannelCreationPolicyKey].ModPolicy = OrdererAdminsPolicy - bs.consortiumsGroups = append(bs.consortiumsGroups, cg) - - for _, org := range consortium.Organizations { - mspConfig, err := msp.GetVerifyingMspConfig(org.MSPDir, org.ID) - if err != nil { - logger.Panicf("3 - Error loading MSP configuration for org %s: %s", org.Name, err) - } - bs.consortiumsGroups = append(bs.consortiumsGroups, - channelconfig.TemplateGroupMSPWithAdminRolePrincipal( - []string{channelconfig.ConsortiumsGroupKey, consortiumName, org.Name}, - mspConfig, org.AdminPrincipal == genesisconfig.AdminRoleAdminPrincipal, - ), - ) - } - } - } - - return bs -} - -// ChannelTemplate TODO -func (bs *bootstrapper) ChannelTemplate() configtx.Template { - return configtx.NewModPolicySettingTemplate( - channelconfig.AdminsPolicyKey, - configtx.NewCompositeTemplate( - configtx.NewSimpleTemplate(bs.channelGroups...), - configtx.NewSimpleTemplate(bs.ordererGroups...), - configtx.NewSimpleTemplate(bs.applicationGroups...), - ), - ) -} - -// GenesisBlock TODO Deprecate and remove -func (bs *bootstrapper) GenesisBlock() *cb.Block { - block, err := genesis.NewFactoryImpl( - configtx.NewModPolicySettingTemplate( - channelconfig.AdminsPolicyKey, - configtx.NewCompositeTemplate( - configtx.NewSimpleTemplate(bs.consortiumsGroups...), - bs.ChannelTemplate(), - ), - ), - ).Block(TestChainID) - - if err != nil { - panic(err) - } - return block -} - -// GenesisBlockForChannel TODO -func (bs *bootstrapper) GenesisBlockForChannel(channelID string) *cb.Block { - block, err := genesis.NewFactoryImpl( - configtx.NewModPolicySettingTemplate( - channelconfig.AdminsPolicyKey, - configtx.NewCompositeTemplate( - configtx.NewSimpleTemplate(bs.consortiumsGroups...), - bs.ChannelTemplate(), - ), - ), - ).Block(channelID) - - if err != nil { - panic(err) - } - return block -} diff --git a/common/tools/configtxgen/provisional/provisional_test.go b/common/tools/configtxgen/provisional/provisional_test.go deleted file mode 100644 index c94d23f295c..00000000000 --- a/common/tools/configtxgen/provisional/provisional_test.go +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright IBM Corp. 2016 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 provisional - -import ( - "bytes" - "testing" - - genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - cb "github.com/hyperledger/fabric/protos/common" - "github.com/stretchr/testify/assert" -) - -var confSolo *genesisconfig.Profile -var confKafka *genesisconfig.Profile -var testCases []*genesisconfig.Profile - -func init() { - confSolo = genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile) - confKafka = genesisconfig.Load("SampleInsecureKafka") - testCases = []*genesisconfig.Profile{confSolo, confKafka} -} - -func TestGenesisBlockHeader(t *testing.T) { - expectedHeaderNumber := uint64(0) - - for _, tc := range testCases { - genesisBlock := New(tc).GenesisBlock() - if genesisBlock.Header.Number != expectedHeaderNumber { - t.Fatalf("Case %s: Expected header number %d, got %d", tc.Orderer.OrdererType, expectedHeaderNumber, genesisBlock.Header.Number) - } - if !bytes.Equal(genesisBlock.Header.PreviousHash, nil) { - t.Fatalf("Case %s: Expected header previousHash to be nil, got %x", tc.Orderer.OrdererType, genesisBlock.Header.PreviousHash) - } - } -} - -func TestGenesisMetadata(t *testing.T) { - for _, tc := range testCases { - genesisBlock := New(tc).GenesisBlock() - if genesisBlock.Metadata == nil { - t.Fatalf("Expected non-nil metadata") - } - - if genesisBlock.Metadata.Metadata[cb.BlockMetadataIndex_LAST_CONFIG] == nil { - t.Fatalf("Should have last config set") - } - } -} - -func TestGenesisBlockForChannelHeader(t *testing.T) { - expectedHeaderNumber := uint64(0) - - for _, tc := range testCases { - genesisBlock := New(tc).GenesisBlockForChannel("mychannel") - assert.Equal(t, expectedHeaderNumber, genesisBlock.Header.Number, "Case %s: Header number should be equal", tc.Orderer.OrdererType) - assert.Nil(t, genesisBlock.Header.PreviousHash, "Case %s: Header previousHash to be nil", tc.Orderer.OrdererType) - } -} diff --git a/common/tools/configtxlator/sanitycheck/sanitycheck_test.go b/common/tools/configtxlator/sanitycheck/sanitycheck_test.go index 402b70010b9..54c3b8a7d9e 100644 --- a/common/tools/configtxlator/sanitycheck/sanitycheck_test.go +++ b/common/tools/configtxlator/sanitycheck/sanitycheck_test.go @@ -22,9 +22,8 @@ import ( "github.com/hyperledger/fabric/bccsp/factory" "github.com/hyperledger/fabric/common/cauthdsl" "github.com/hyperledger/fabric/common/channelconfig" - "github.com/hyperledger/fabric/common/configtx" + "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" cb "github.com/hyperledger/fabric/protos/common" mspprotos "github.com/hyperledger/fabric/protos/msp" "github.com/hyperledger/fabric/protos/utils" @@ -41,15 +40,17 @@ var ( func init() { factory.InitFactories(nil) - insecureConf := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile) - insecureGB := provisional.New(insecureConf).GenesisBlockForChannel(provisional.TestChainID) - insecureCtx := utils.ExtractEnvelopeOrPanic(insecureGB, 0) - insecureConfig = configtx.UnmarshalConfigEnvelopeOrPanic(utils.UnmarshalPayloadOrPanic(insecureCtx.Payload).Data).Config + insecureChannelGroup, err := encoder.NewChannelGroup(genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile)) + if err != nil { + panic(err) + } + insecureConfig = &cb.Config{ChannelGroup: insecureChannelGroup} - singleMSPConf := genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile) - singleMSPGB := provisional.New(singleMSPConf).GenesisBlockForChannel(provisional.TestChainID) - singleMSPCtx := utils.ExtractEnvelopeOrPanic(singleMSPGB, 0) - singleMSPConfig = configtx.UnmarshalConfigEnvelopeOrPanic(utils.UnmarshalPayloadOrPanic(singleMSPCtx.Payload).Data).Config + singleMSPChannelGroup, err := encoder.NewChannelGroup(genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile)) + if err != nil { + panic(err) + } + singleMSPConfig = &cb.Config{ChannelGroup: singleMSPChannelGroup} } func TestSimpleCheck(t *testing.T) { diff --git a/common/tools/protolator/blackbox_test.go b/common/tools/protolator/blackbox_test.go index dabe2537856..b381230015c 100644 --- a/common/tools/protolator/blackbox_test.go +++ b/common/tools/protolator/blackbox_test.go @@ -20,9 +20,11 @@ import ( "bytes" "testing" + "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" . "github.com/hyperledger/fabric/common/tools/protolator" + cb "github.com/hyperledger/fabric/protos/common" + "github.com/hyperledger/fabric/protos/utils" "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" @@ -53,18 +55,20 @@ func bidirectionalMarshal(t *testing.T, doc proto.Message) { } func TestConfigUpdate(t *testing.T) { - p := provisional.New(genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile)) - ct := p.ChannelTemplate() - cue, err := ct.Envelope("Foo") + cg, err := encoder.NewChannelGroup(genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile)) assert.NoError(t, err) - bidirectionalMarshal(t, cue) + bidirectionalMarshal(t, &cb.ConfigUpdateEnvelope{ + ConfigUpdate: utils.MarshalOrPanic(&cb.ConfigUpdate{ + ReadSet: cg, + WriteSet: cg, + }), + }) } func TestGenesisBlock(t *testing.T) { - p := provisional.New(genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile)) + p := encoder.New(genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile)) gb := p.GenesisBlockForChannel("foo") bidirectionalMarshal(t, gb) - } diff --git a/core/committer/committer_test.go b/core/committer/committer_test.go index 5b2f143589c..5d2a4498e9b 100644 --- a/core/committer/committer_test.go +++ b/core/committer/committer_test.go @@ -22,8 +22,8 @@ import ( "github.com/hyperledger/fabric/common/configtx/test" "github.com/hyperledger/fabric/common/ledger/testutil" + "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" "github.com/hyperledger/fabric/common/util" "github.com/hyperledger/fabric/core/ledger/ledgermgmt" "github.com/hyperledger/fabric/protos/common" @@ -101,7 +101,7 @@ func TestNewLedgerCommitterReactive(t *testing.T) { assert.NoError(t, err) profile := localconfig.Load(localconfig.SampleSingleMSPSoloProfile) - block := provisional.New(profile).GenesisBlockForChannel(chainID) + block := encoder.New(profile).GenesisBlockForChannel(chainID) committer.Commit(block) assert.Equal(t, int32(1), atomic.LoadInt32(&configArrived)) diff --git a/core/scc/cscc/configure_test.go b/core/scc/cscc/configure_test.go index 402a8f9121e..abf1da3cf9c 100644 --- a/core/scc/cscc/configure_test.go +++ b/core/scc/cscc/configure_test.go @@ -28,6 +28,8 @@ import ( "github.com/hyperledger/fabric/common/localmsp" "github.com/hyperledger/fabric/common/mocks/scc" "github.com/hyperledger/fabric/common/policies" + "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/core/aclmgmt" aclmocks "github.com/hyperledger/fabric/core/aclmgmt/mocks" "github.com/hyperledger/fabric/core/chaincode" @@ -318,8 +320,11 @@ func TestPeerConfiger_SubmittingOrdererGenesis(t *testing.T) { fmt.Println("Init failed", string(res.Message)) t.FailNow() } - - block, err := genesis.NewFactoryImpl(configtxtest.OrdererTemplate()).Block("testChainID") + conf := genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile) + conf.Application = nil + cg, err := encoder.NewChannelGroup(conf) + assert.NoError(t, err) + block, err := genesis.NewFactoryImpl(cg).Block("mytestchainid") assert.NoError(t, err) blockBytes := utils.MarshalOrPanic(block) diff --git a/orderer/common/deliver/deliver_test.go b/orderer/common/deliver/deliver_test.go index 7a16eb20a35..ba8021fdef8 100644 --- a/orderer/common/deliver/deliver_test.go +++ b/orderer/common/deliver/deliver_test.go @@ -25,7 +25,7 @@ import ( "github.com/hyperledger/fabric/common/flogging" mockpolicies "github.com/hyperledger/fabric/common/mocks/policies" "github.com/hyperledger/fabric/common/policies" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/orderer/common/ledger" ramledger "github.com/hyperledger/fabric/orderer/common/ledger/ram" cb "github.com/hyperledger/fabric/protos/common" @@ -144,7 +144,7 @@ func (mcs *mockSupport) Reader() ledger.Reader { func NewRAMLedger() ledger.ReadWriter { rlf := ramledger.New(ledgerSize + 1) - rl, _ := rlf.GetOrCreate(provisional.TestChainID) + rl, _ := rlf.GetOrCreate(genesisconfig.TestChainID) rl.Append(genesisBlock) return rl } diff --git a/orderer/common/ledger/file/factory_test.go b/orderer/common/ledger/file/factory_test.go index 143eddf05a3..0f210520e35 100644 --- a/orderer/common/ledger/file/factory_test.go +++ b/orderer/common/ledger/file/factory_test.go @@ -22,7 +22,7 @@ import ( "testing" "github.com/hyperledger/fabric/common/ledger/blkstorage" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/orderer/common/ledger" "github.com/stretchr/testify/assert" ) @@ -73,7 +73,7 @@ func TestMultiReinitialization(t *testing.T) { assert.NoError(t, err, "Error creating temp dir: %s", err) flf := New(dir) - _, err = flf.GetOrCreate(provisional.TestChainID) + _, err = flf.GetOrCreate(genesisconfig.TestChainID) assert.NoError(t, err, "Error GetOrCreate chain") assert.Equal(t, 1, len(flf.ChainIDs()), "Expected 1 chain") flf.Close() diff --git a/orderer/common/ledger/file/impl_test.go b/orderer/common/ledger/file/impl_test.go index e8d51254dd1..d5b0db02bf8 100644 --- a/orderer/common/ledger/file/impl_test.go +++ b/orderer/common/ledger/file/impl_test.go @@ -25,7 +25,7 @@ import ( "github.com/hyperledger/fabric/common/flogging" cl "github.com/hyperledger/fabric/common/ledger" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/orderer/common/ledger" cb "github.com/hyperledger/fabric/protos/common" ab "github.com/hyperledger/fabric/protos/orderer" @@ -51,7 +51,7 @@ func initialize(t *testing.T) (*testEnv, *fileLedger) { assert.NoError(t, err, "Error creating temp dir: %s", err) flf := New(name).(*fileLedgerFactory) - fl, err := flf.GetOrCreate(provisional.TestChainID) + fl, err := flf.GetOrCreate(genesisconfig.TestChainID) assert.NoError(t, err, "Error GetOrCreate chain") fl.Append(genesisBlock) @@ -154,7 +154,7 @@ func TestReinitialization(t *testing.T) { // add the block to the ledger ledger1.Append(b1) - fl, err := tev.flf.GetOrCreate(provisional.TestChainID) + fl, err := tev.flf.GetOrCreate(genesisconfig.TestChainID) ledger1, ok := fl.(*fileLedger) assert.NoError(t, err, "Expected to sucessfully get test chain") assert.Equal(t, 1, len(tev.flf.ChainIDs()), "Exptected not new chain to be created") diff --git a/orderer/common/ledger/file_test.go b/orderer/common/ledger/file_test.go index 1b656ce1098..761f524d8bb 100644 --- a/orderer/common/ledger/file_test.go +++ b/orderer/common/ledger/file_test.go @@ -20,7 +20,7 @@ import ( "io/ioutil" "os" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" . "github.com/hyperledger/fabric/orderer/common/ledger" fileledger "github.com/hyperledger/fabric/orderer/common/ledger/file" ) @@ -64,7 +64,7 @@ func (env *fileLedgerTestFactory) Persistent() bool { func (env *fileLedgerTestFactory) New() (Factory, ReadWriter) { flf := fileledger.New(env.location) - fl, err := flf.GetOrCreate(provisional.TestChainID) + fl, err := flf.GetOrCreate(genesisconfig.TestChainID) if err != nil { panic(err) } diff --git a/orderer/common/ledger/json/impl_test.go b/orderer/common/ledger/json/impl_test.go index 5e6c4f36680..f45af71a485 100644 --- a/orderer/common/ledger/json/impl_test.go +++ b/orderer/common/ledger/json/impl_test.go @@ -23,7 +23,7 @@ import ( "time" "github.com/hyperledger/fabric/common/flogging" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/orderer/common/ledger" cb "github.com/hyperledger/fabric/protos/common" ab "github.com/hyperledger/fabric/protos/orderer" @@ -48,7 +48,7 @@ func initialize(t *testing.T) (*testEnv, *jsonLedger) { t.Fatalf("Error creating temp dir: %s", err) } flf := New(name).(*jsonLedgerFactory) - fl, err := flf.GetOrCreate(provisional.TestChainID) + fl, err := flf.GetOrCreate(genesisconfig.TestChainID) if err != nil { panic(err) } diff --git a/orderer/common/ledger/json_test.go b/orderer/common/ledger/json_test.go index b1984e4acdf..5d49965dd8e 100644 --- a/orderer/common/ledger/json_test.go +++ b/orderer/common/ledger/json_test.go @@ -20,7 +20,7 @@ import ( "io/ioutil" "os" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" . "github.com/hyperledger/fabric/orderer/common/ledger" jsonledger "github.com/hyperledger/fabric/orderer/common/ledger/json" cb "github.com/hyperledger/fabric/protos/common" @@ -63,7 +63,7 @@ func (env *jsonLedgerTestFactory) Persistent() bool { func (env *jsonLedgerTestFactory) New() (Factory, ReadWriter) { flf := jsonledger.New(env.location) - fl, err := flf.GetOrCreate(provisional.TestChainID) + fl, err := flf.GetOrCreate(genesisconfig.TestChainID) if err != nil { panic(err) } diff --git a/orderer/common/ledger/ram/factory_test.go b/orderer/common/ledger/ram/factory_test.go index 52d9a91af8d..b6c1bf1236f 100644 --- a/orderer/common/ledger/ram/factory_test.go +++ b/orderer/common/ledger/ram/factory_test.go @@ -19,7 +19,7 @@ package ramledger import ( "testing" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" logging "github.com/op/go-logging" ) @@ -30,11 +30,11 @@ func init() { func TestGetOrCreate(t *testing.T) { rlf := New(3) - channel, err := rlf.GetOrCreate(provisional.TestChainID) + channel, err := rlf.GetOrCreate(genesisconfig.TestChainID) if err != nil { panic(err) } - channel2, err := rlf.GetOrCreate(provisional.TestChainID) + channel2, err := rlf.GetOrCreate(genesisconfig.TestChainID) if err != nil { panic(err) } diff --git a/orderer/common/ledger/ram/impl_test.go b/orderer/common/ledger/ram/impl_test.go index 7146b0eb64c..8da2a94f595 100644 --- a/orderer/common/ledger/ram/impl_test.go +++ b/orderer/common/ledger/ram/impl_test.go @@ -20,7 +20,7 @@ import ( "testing" "github.com/hyperledger/fabric/common/flogging" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/orderer/common/ledger" cb "github.com/hyperledger/fabric/protos/common" ab "github.com/hyperledger/fabric/protos/orderer" @@ -34,7 +34,7 @@ func init() { func newTestChain(maxSize int) *ramLedger { rlf := New(maxSize) - chain, err := rlf.GetOrCreate(provisional.TestChainID) + chain, err := rlf.GetOrCreate(genesisconfig.TestChainID) if err != nil { panic(err) } diff --git a/orderer/common/ledger/ram_test.go b/orderer/common/ledger/ram_test.go index a086dd370e5..adcce64056e 100644 --- a/orderer/common/ledger/ram_test.go +++ b/orderer/common/ledger/ram_test.go @@ -17,7 +17,7 @@ limitations under the License. package ledger_test import ( - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" . "github.com/hyperledger/fabric/orderer/common/ledger" ramledger "github.com/hyperledger/fabric/orderer/common/ledger/ram" ) @@ -49,7 +49,7 @@ func (env *ramledgerTestFactory) Persistent() bool { func (env *ramledgerTestFactory) New() (Factory, ReadWriter) { historySize := 10 rlf := ramledger.New(historySize) - rl, err := rlf.GetOrCreate(provisional.TestChainID) + rl, err := rlf.GetOrCreate(genesisconfig.TestChainID) if err != nil { panic(err) } diff --git a/orderer/common/localconfig/config.go b/orderer/common/localconfig/config.go index a7fd29bd8a5..c189025d128 100644 --- a/orderer/common/localconfig/config.go +++ b/orderer/common/localconfig/config.go @@ -32,7 +32,7 @@ import ( "path/filepath" bccsp "github.com/hyperledger/fabric/bccsp/factory" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" ) const ( @@ -177,7 +177,7 @@ var defaults = TopLevel{ ListenPort: 7050, GenesisMethod: "provisional", GenesisProfile: "SampleSingleMSPSolo", - SystemChannel: provisional.TestChainID, + SystemChannel: genesisconfig.TestChainID, GenesisFile: "genesisblock", Profile: Profile{ Enabled: false, diff --git a/orderer/common/localconfig/config_test.go b/orderer/common/localconfig/config_test.go index 2a6a2569940..701fa049c69 100644 --- a/orderer/common/localconfig/config_test.go +++ b/orderer/common/localconfig/config_test.go @@ -25,7 +25,7 @@ import ( "time" "github.com/hyperledger/fabric/common/flogging" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/stretchr/testify/assert" ) @@ -119,7 +119,7 @@ func TestKafkaTLSConfig(t *testing.T) { func TestSystemChannel(t *testing.T) { conf := Load() - assert.Equal(t, provisional.TestChainID, conf.General.SystemChannel, "System channel ID should be '%s' by default", provisional.TestChainID) + assert.Equal(t, genesisconfig.TestChainID, conf.General.SystemChannel, "System channel ID should be '%s' by default", genesisconfig.TestChainID) } func TestProfileConfig(t *testing.T) { diff --git a/orderer/common/msgprocessor/systemchannel_test.go b/orderer/common/msgprocessor/systemchannel_test.go index 99af4c2f785..b9dc77dee57 100644 --- a/orderer/common/msgprocessor/systemchannel_test.go +++ b/orderer/common/msgprocessor/systemchannel_test.go @@ -12,12 +12,11 @@ import ( "github.com/hyperledger/fabric/common/capabilities" "github.com/hyperledger/fabric/common/channelconfig" - "github.com/hyperledger/fabric/common/configtx" "github.com/hyperledger/fabric/common/crypto" mockchannelconfig "github.com/hyperledger/fabric/common/mocks/config" mockconfigtx "github.com/hyperledger/fabric/common/mocks/configtx" + "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" cb "github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric/protos/utils" "github.com/stretchr/testify/assert" @@ -413,14 +412,9 @@ func TestNewChannelConfig(t *testing.T) { gConf.Orderer.Capabilities = map[string]bool{ capabilities.OrdererV1_1: true, } - singleMSPGenesisBlock := provisional.New(gConf).GenesisBlockForChannel(channelID) - configEnv := configtx.UnmarshalConfigEnvelopeOrPanic( - utils.UnmarshalPayloadOrPanic( - utils.ExtractEnvelopeOrPanic(singleMSPGenesisBlock, 0).Payload, - ).Data, - ) - ctxm, err := channelconfig.NewBundle(channelID, configEnv.Config) - assert.Nil(t, err) + channelGroup, err := encoder.NewChannelGroup(gConf) + assert.NoError(t, err) + ctxm, err := channelconfig.NewBundle(channelID, &cb.Config{ChannelGroup: channelGroup}) templator := NewDefaultTemplator(&mockDefaultTemplatorSupport{ Resources: ctxm, diff --git a/orderer/common/multichannel/blockwriter_test.go b/orderer/common/multichannel/blockwriter_test.go index 912ebb8d536..b82a9b5d01f 100644 --- a/orderer/common/multichannel/blockwriter_test.go +++ b/orderer/common/multichannel/blockwriter_test.go @@ -22,7 +22,7 @@ import ( newchannelconfig "github.com/hyperledger/fabric/common/channelconfig" "github.com/hyperledger/fabric/common/crypto" mockconfigtx "github.com/hyperledger/fabric/common/mocks/configtx" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/orderer/common/ledger" cb "github.com/hyperledger/fabric/protos/common" "github.com/hyperledger/fabric/protos/utils" @@ -175,7 +175,7 @@ func TestGoodWriteConfig(t *testing.T) { }, } - ctx := makeConfigTx(provisional.TestChainID, 1) + ctx := makeConfigTx(genesisconfig.TestChainID, 1) block := cb.NewBlock(1, genesisBlock.Header.Hash()) block.Data.Data = [][]byte{utils.MarshalOrPanic(ctx)} consenterMetadata := []byte("foo") diff --git a/orderer/common/multichannel/registrar_test.go b/orderer/common/multichannel/registrar_test.go index 6b14a6cc669..694cafc21da 100644 --- a/orderer/common/multichannel/registrar_test.go +++ b/orderer/common/multichannel/registrar_test.go @@ -18,8 +18,8 @@ import ( mockchannelconfig "github.com/hyperledger/fabric/common/mocks/config" mockcrypto "github.com/hyperledger/fabric/common/mocks/crypto" mockpolicies "github.com/hyperledger/fabric/common/mocks/policies" + "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" "github.com/hyperledger/fabric/msp" "github.com/hyperledger/fabric/orderer/common/ledger" ramledger "github.com/hyperledger/fabric/orderer/common/ledger/ram" @@ -44,7 +44,7 @@ func init() { mockSigningIdentity, _ = mmsp.NewNoopMsp().GetDefaultSigningIdentity() conf = genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile) - genesisBlock = provisional.New(conf).GenesisBlock() + genesisBlock = encoder.New(conf).GenesisBlock() } func mockCrypto() crypto.LocalSigner { @@ -53,7 +53,7 @@ func mockCrypto() crypto.LocalSigner { func NewRAMLedgerAndFactory(maxSize int) (ledger.Factory, ledger.ReadWriter) { rlf := ramledger.New(10) - rl, err := rlf.GetOrCreate(provisional.TestChainID) + rl, err := rlf.GetOrCreate(genesisconfig.TestChainID) if err != nil { panic(err) } @@ -73,13 +73,13 @@ func NewRAMLedger(maxSize int) ledger.ReadWriter { func TestGetConfigTx(t *testing.T) { rl := NewRAMLedger(10) for i := 0; i < 5; i++ { - rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{makeNormalTx(provisional.TestChainID, i)})) + rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{makeNormalTx(genesisconfig.TestChainID, i)})) } - rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{makeConfigTx(provisional.TestChainID, 5)})) - ctx := makeConfigTx(provisional.TestChainID, 6) + rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{makeConfigTx(genesisconfig.TestChainID, 5)})) + ctx := makeConfigTx(genesisconfig.TestChainID, 6) rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{ctx})) - block := ledger.CreateNextBlock(rl, []*cb.Envelope{makeNormalTx(provisional.TestChainID, 7)}) + block := ledger.CreateNextBlock(rl, []*cb.Envelope{makeNormalTx(genesisconfig.TestChainID, 7)}) block.Metadata.Metadata[cb.BlockMetadataIndex_LAST_CONFIG] = utils.MarshalOrPanic(&cb.Metadata{Value: utils.MarshalOrPanic(&cb.LastConfig{Index: 7})}) rl.Append(block) @@ -92,14 +92,14 @@ func TestGetConfigTxFailure(t *testing.T) { rl := NewRAMLedger(10) for i := 0; i < 10; i++ { rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{ - makeNormalTx(provisional.TestChainID, i), - makeConfigTx(provisional.TestChainID, i), + makeNormalTx(genesisconfig.TestChainID, i), + makeConfigTx(genesisconfig.TestChainID, i), })) } - rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{makeNormalTx(provisional.TestChainID, 11)})) + rl.Append(ledger.CreateNextBlock(rl, []*cb.Envelope{makeNormalTx(genesisconfig.TestChainID, 11)})) assert.Panics(t, func() { getConfigTx(rl) }, "Should have panicked because there was no config tx") - block := ledger.CreateNextBlock(rl, []*cb.Envelope{makeNormalTx(provisional.TestChainID, 12)}) + block := ledger.CreateNextBlock(rl, []*cb.Envelope{makeNormalTx(genesisconfig.TestChainID, 12)}) block.Metadata.Metadata[cb.BlockMetadataIndex_LAST_CONFIG] = []byte("bad metadata") assert.Panics(t, func() { getConfigTx(rl) }, "Should have panicked because of bad last config metadata") } @@ -122,7 +122,7 @@ func TestMultiSystemChannel(t *testing.T) { rl, err := lf.GetOrCreate(id) assert.NoError(t, err) - err = rl.Append(provisional.New(conf).GenesisBlockForChannel(id)) + err = rl.Append(encoder.New(conf).GenesisBlockForChannel(id)) assert.NoError(t, err) } @@ -144,12 +144,12 @@ func TestManagerImpl(t *testing.T) { _, ok := manager.GetChain("Fake") assert.False(t, ok, "Should not have found a chain that was not created") - chainSupport, ok := manager.GetChain(provisional.TestChainID) + chainSupport, ok := manager.GetChain(genesisconfig.TestChainID) assert.True(t, ok, "Should have gotten chain which was initialized by ramledger") messages := make([]*cb.Envelope, conf.Orderer.BatchSize.MaxMessageCount) for i := 0; i < int(conf.Orderer.BatchSize.MaxMessageCount); i++ { - messages[i] = makeNormalTx(provisional.TestChainID, i) + messages[i] = makeNormalTx(genesisconfig.TestChainID, i) } for _, message := range messages { diff --git a/orderer/common/multichannel/util_test.go b/orderer/common/multichannel/util_test.go index f65ed647b8a..c723db9f3ff 100644 --- a/orderer/common/multichannel/util_test.go +++ b/orderer/common/multichannel/util_test.go @@ -11,7 +11,7 @@ import ( "github.com/hyperledger/fabric/common/channelconfig" "github.com/hyperledger/fabric/common/configtx" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/orderer/common/blockcutter" "github.com/hyperledger/fabric/orderer/common/msgprocessor" "github.com/hyperledger/fabric/orderer/consensus" @@ -118,7 +118,7 @@ func makeConfigTx(chainID string, i int) *cb.Envelope { } func wrapConfigTx(env *cb.Envelope) *cb.Envelope { - result, err := utils.CreateSignedEnvelope(cb.HeaderType_ORDERER_TRANSACTION, provisional.TestChainID, mockCrypto(), env, msgVersion, epoch) + result, err := utils.CreateSignedEnvelope(cb.HeaderType_ORDERER_TRANSACTION, genesisconfig.TestChainID, mockCrypto(), env, msgVersion, epoch) if err != nil { panic(err) } diff --git a/orderer/common/server/main.go b/orderer/common/server/main.go index 9239bc31c05..e3e9b0e7795 100644 --- a/orderer/common/server/main.go +++ b/orderer/common/server/main.go @@ -16,8 +16,8 @@ import ( "github.com/hyperledger/fabric/common/crypto" "github.com/hyperledger/fabric/common/flogging" + "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" "github.com/hyperledger/fabric/core/comm" "github.com/hyperledger/fabric/orderer/common/bootstrap/file" "github.com/hyperledger/fabric/orderer/common/ledger" @@ -164,7 +164,7 @@ func initializeBootstrapChannel(conf *config.TopLevel, lf ledger.Factory) { // Select the bootstrapping mechanism switch conf.General.GenesisMethod { case "provisional": - genesisBlock = provisional.New(genesisconfig.Load(conf.General.GenesisProfile)).GenesisBlockForChannel(conf.General.SystemChannel) + genesisBlock = encoder.New(genesisconfig.Load(conf.General.GenesisProfile)).GenesisBlockForChannel(conf.General.SystemChannel) case "file": genesisBlock = file.New(conf.General.GenesisFile).GenesisBlock() default: diff --git a/orderer/common/server/main_test.go b/orderer/common/server/main_test.go index ebec5f2988d..e8c38f8d92e 100644 --- a/orderer/common/server/main_test.go +++ b/orderer/common/server/main_test.go @@ -20,7 +20,7 @@ import ( "github.com/hyperledger/fabric/bccsp/factory" "github.com/hyperledger/fabric/common/flogging" "github.com/hyperledger/fabric/common/localmsp" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" coreconfig "github.com/hyperledger/fabric/core/config" "github.com/hyperledger/fabric/orderer/common/localconfig" "github.com/op/go-logging" @@ -161,7 +161,7 @@ func TestInitializeBootstrapChannel(t *testing.T) { GenesisMethod: tc.genesisMethod, GenesisProfile: "SampleSingleMSPSolo", GenesisFile: "genesisblock", - SystemChannel: provisional.TestChainID, + SystemChannel: genesisconfig.TestChainID, }, } @@ -223,7 +223,7 @@ func TestInitializeMultiChainManager(t *testing.T) { LedgerType: "ram", GenesisMethod: "provisional", GenesisProfile: "SampleSingleMSPSolo", - SystemChannel: provisional.TestChainID, + SystemChannel: genesisconfig.TestChainID, LocalMSPDir: localMSPDir, LocalMSPID: "DEFAULT", BCCSP: &factory.FactoryOpts{ diff --git a/orderer/sample_clients/broadcast_msg/client.go b/orderer/sample_clients/broadcast_msg/client.go index 3a1bde70970..8d3e86573d6 100644 --- a/orderer/sample_clients/broadcast_msg/client.go +++ b/orderer/sample_clients/broadcast_msg/client.go @@ -14,7 +14,7 @@ import ( "github.com/hyperledger/fabric/common/crypto" "github.com/hyperledger/fabric/common/localmsp" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" mspmgmt "github.com/hyperledger/fabric/msp/mgmt" "github.com/hyperledger/fabric/orderer/common/localconfig" cb "github.com/hyperledger/fabric/protos/common" @@ -76,7 +76,7 @@ func main() { var bar *pb.ProgressBar flag.StringVar(&serverAddr, "server", fmt.Sprintf("%s:%d", config.General.ListenAddress, config.General.ListenPort), "The RPC server to connect to.") - flag.StringVar(&channelID, "channelID", provisional.TestChainID, "The channel ID to broadcast to.") + flag.StringVar(&channelID, "channelID", genesisconfig.TestChainID, "The channel ID to broadcast to.") flag.Uint64Var(&messages, "messages", 1, "The number of messages to broadcast.") flag.Uint64Var(&goroutines, "goroutines", 1, "The number of concurrent go routines to broadcast the messages on") flag.Uint64Var(&msgSize, "size", 1024, "The size in bytes of the data section for the payload") diff --git a/orderer/sample_clients/deliver_stdout/client.go b/orderer/sample_clients/deliver_stdout/client.go index 2062eb1dfe8..da787d8ee3f 100644 --- a/orderer/sample_clients/deliver_stdout/client.go +++ b/orderer/sample_clients/deliver_stdout/client.go @@ -14,7 +14,7 @@ import ( "github.com/hyperledger/fabric/common/crypto" "github.com/hyperledger/fabric/common/localmsp" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" + genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" "github.com/hyperledger/fabric/common/tools/protolator" mspmgmt "github.com/hyperledger/fabric/msp/mgmt" "github.com/hyperledger/fabric/orderer/common/localconfig" @@ -112,7 +112,7 @@ func main() { var quiet bool flag.StringVar(&serverAddr, "server", fmt.Sprintf("%s:%d", config.General.ListenAddress, config.General.ListenPort), "The RPC server to connect to.") - flag.StringVar(&channelID, "channelID", provisional.TestChainID, "The channel ID to deliver from.") + flag.StringVar(&channelID, "channelID", genesisconfig.TestChainID, "The channel ID to deliver from.") flag.BoolVar(&quiet, "quiet", false, "Only print the block number, will not attempt to print its block contents.") flag.IntVar(&seek, "seek", -2, "Specify the range of requested blocks."+ "Acceptable values:"+ diff --git a/peer/chaincode/common_test.go b/peer/chaincode/common_test.go index 811b8f91261..ba91b01bc0f 100644 --- a/peer/chaincode/common_test.go +++ b/peer/chaincode/common_test.go @@ -21,8 +21,8 @@ import ( "testing" "github.com/hyperledger/fabric/bccsp/factory" + "github.com/hyperledger/fabric/common/tools/configtxgen/encoder" genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig" - "github.com/hyperledger/fabric/common/tools/configtxgen/provisional" "github.com/hyperledger/fabric/peer/common" pb "github.com/hyperledger/fabric/protos/peer" "github.com/hyperledger/fabric/protos/utils" @@ -139,7 +139,7 @@ func TestGetOrdererEndpointFromConfigTx(t *testing.T) { mockchain := "mockchain" factory.InitFactories(nil) config := genesisconfig.Load(genesisconfig.SampleInsecureSoloProfile) - pgen := provisional.New(config) + pgen := encoder.New(config) genesisBlock := pgen.GenesisBlockForChannel(mockchain) mockResponse := &pb.ProposalResponse{