diff --git a/Makefile b/Makefile index b0ba9d24ab1..4ef6efcb986 100644 --- a/Makefile +++ b/Makefile @@ -178,16 +178,16 @@ build/image/javaenv/payload: build/javashim.tar.bz2 \ build/image/peer/payload: build/docker/bin/peer \ peer/core.yaml \ build/msp-sampleconfig.tar.bz2 \ - common/configtx/tool/genesis.yaml + common/configtx/tool/configtx.yaml build/image/orderer/payload: build/docker/bin/orderer \ build/msp-sampleconfig.tar.bz2 \ orderer/orderer.yaml \ - common/configtx/tool/genesis.yaml + common/configtx/tool/configtx.yaml build/image/buildenv/payload: build/gotools.tar.bz2 \ build/docker/gotools/bin/protoc-gen-go build/image/testenv/payload: build/docker/bin/orderer \ orderer/orderer.yaml \ - common/configtx/tool/genesis.yaml \ + common/configtx/tool/configtx.yaml \ build/docker/bin/peer \ peer/core.yaml \ build/msp-sampleconfig.tar.bz2 \ diff --git a/common/configtx/test/helper.go b/common/configtx/test/helper.go index 480b07f3c74..fd9ccc13bdc 100644 --- a/common/configtx/test/helper.go +++ b/common/configtx/test/helper.go @@ -81,7 +81,7 @@ func MakeGenesisBlock(chainID string) (*cb.Block, error) { // OrderererTemplate returns the test orderer template func OrdererTemplate() configtx.Template { - genConf := genesisconfig.Load() + genConf := genesisconfig.Load(genesisconfig.SampleInsecureProfile) return provisional.New(genConf).ChannelTemplate() } diff --git a/common/configtx/test/helper_test.go b/common/configtx/test/helper_test.go index f85cd5a17d4..d7771f9ca37 100644 --- a/common/configtx/test/helper_test.go +++ b/common/configtx/test/helper_test.go @@ -17,12 +17,19 @@ limitations under the License. package test import ( + "os" + "path/filepath" "testing" 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, "") } diff --git a/common/configtx/tool/genesis.yaml b/common/configtx/tool/configtx.yaml similarity index 70% rename from common/configtx/tool/genesis.yaml rename to common/configtx/tool/configtx.yaml index 5111fd2a355..c69105cfb57 100644 --- a/common/configtx/tool/genesis.yaml +++ b/common/configtx/tool/configtx.yaml @@ -1,4 +1,34 @@ --- +################################################################################ +# +# Profile +# +# - Different configuration profiles may be encoded here to be specified +# as parameters to the configtxgen tool +# +################################################################################ +Profiles: + + # SampleInsecureSol defines a configuration which contains no MSP definitions + # and allows all transactions and channel creation requests + SampleInsecureSolo: + Orderer: + <<: *OrdererDefaults + Application: + <<: *ApplicationDefaults + + # SampleSingleMSPSolo defines a configuration which contains a single MSP + # definition (the MSP sampleconfig). + SampleSingleMSPSolo: + Orderer: + <<: *OrdererDefaults + Organizations: + - *SampleOrg + Application: + <<: *ApplicationDefaults + Organizations: + - *SampleOrg + ################################################################################ # # Section: Organizations @@ -9,10 +39,12 @@ ################################################################################ Organizations: - - &defaultOrg + # SampleOrg defines an MSP using the sampleconfig. It should never be used + # in production but may be used as a template for other definitions + - &SampleOrg # DefaultOrg defines the organization which is used in the sampleconfig # of the fabric.git development environment - Name: defaultOrg + Name: SampleOrg # ID to load the MSP definition as ID: DEFAULT @@ -20,7 +52,6 @@ Organizations: # MSPDir is the filesystem path which contains the MSP configuration MSPDir: msp/sampleconfig - AnchorPeers: # AnchorPeers defines the location of peers which can be used # for cross org gossip communication. Note, this value is only @@ -36,7 +67,7 @@ Organizations: # genesis block for orderer related parameters # ################################################################################ -Orderer: +Orderer: &OrdererDefaults # Orderer Type: The orderer implementation to start # Available types are "solo" and "kafka" @@ -73,9 +104,6 @@ Orderer: # the orderer side of the network Organizations: - # The default organization as defined in the organization section - - *defaultOrg - ################################################################################ # # SECTION: Application @@ -84,11 +112,8 @@ Orderer: # genesis block for application related parameters # ################################################################################ -Application: +Application: &ApplicationDefaults # Organizations is the list of orgs which are defined as participants on # the application side of the network Organizations: - - # The default organization as defined in the organization section - - *defaultOrg diff --git a/common/configtx/tool/localconfig/config.go b/common/configtx/tool/localconfig/config.go index 06cac4ad74b..f9751b555c4 100644 --- a/common/configtx/tool/localconfig/config.go +++ b/common/configtx/tool/localconfig/config.go @@ -29,6 +29,14 @@ import ( "github.com/spf13/viper" ) +const ( + // SampleInsecureProfile references the sample profile which does not include any MSPs and uses solo for consensus + SampleInsecureProfile = "SampleInsecureSolo" + + // SampleSingleMSPSoloProfile references the sample profile which includes only the sample MSP and uses solo for consensus + SampleSingleMSPSoloProfile = "SampleSingleMSPSolo" +) + var logger = logging.MustGetLogger("configtx/tool/localconfig") func init() { @@ -40,11 +48,19 @@ const Prefix string = "CONFIGTX" // TopLevel contains the genesis structures for use by the provisional bootstrapper type TopLevel struct { - Application Application + Profiles map[string]*Profile Organizations []*Organization - Orderer Orderer + Application *Application + Orderer *Orderer } +// TopLevel contains the genesis structures for use by the provisional bootstrapper +type Profile struct { + Application *Application + Orderer *Orderer +} + +// Application encodes the configuration needed for the config transaction type Application struct { Organizations []*Organization } @@ -92,7 +108,7 @@ type Kafka struct { } var genesisDefaults = TopLevel{ - Orderer: Orderer{ + Orderer: &Orderer{ OrdererType: "solo", Addresses: []string{"127.0.0.1:7050"}, BatchTimeout: 10 * time.Second, @@ -107,7 +123,7 @@ var genesisDefaults = TopLevel{ }, } -func (g *TopLevel) completeInitialization() { +func (g *Profile) completeInitialization() { for { switch { case g.Orderer.OrdererType == "": @@ -140,10 +156,10 @@ func (g *TopLevel) completeInitialization() { } } -func Load() *TopLevel { +func Load(profile string) *Profile { config := viper.New() - config.SetConfigName("genesis") + config.SetConfigName("configtx") var cfgPath string // Path to look for the config file in based on GOPATH @@ -157,8 +173,8 @@ func Load() *TopLevel { } for _, genesisPath := range searchPath { - logger.Infof("Checking for genesis.yaml at: %s", genesisPath) - if _, err := os.Stat(filepath.Join(genesisPath, "genesis.yaml")); err != nil { + logger.Infof("Checking for configtx.yaml at: %s", genesisPath) + if _, err := os.Stat(filepath.Join(genesisPath, "configtx.yaml")); err != nil { // The yaml file does not exist in this component of the path continue } @@ -166,7 +182,7 @@ func Load() *TopLevel { } if cfgPath == "" { - logger.Fatalf("Could not find genesis.yaml in paths of %s. Try setting ORDERER_CFG_PATH, PEER_CFG_PATH, or GOPATH correctly", searchPath) + logger.Fatalf("Could not find configtx.yaml in paths of %s. Try setting ORDERER_CFG_PATH, PEER_CFG_PATH, or GOPATH correctly", searchPath) } config.AddConfigPath(cfgPath) // Path to look for the config file in @@ -188,7 +204,11 @@ func Load() *TopLevel { panic(fmt.Errorf("Error unmarshaling into structure: %s", err)) } - uconf.completeInitialization() + result, ok := uconf.Profiles[profile] + if !ok { + logger.Panicf("Could not find profile %s", profile) + } + result.completeInitialization() - return &uconf + return result } diff --git a/common/configtx/tool/provisional/provisional.go b/common/configtx/tool/provisional/provisional.go index 08b59faf4b5..429ef54eed9 100644 --- a/common/configtx/tool/provisional/provisional.go +++ b/common/configtx/tool/provisional/provisional.go @@ -28,11 +28,16 @@ import ( configvaluesmsp "github.com/hyperledger/fabric/common/configvalues/msp" "github.com/hyperledger/fabric/common/genesis" "github.com/hyperledger/fabric/common/policies" + "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" + + logging "github.com/op/go-logging" ) +var logger = logging.MustGetLogger("common/configtx/tool/provisional") + // Generator can either create an orderer genesis block or config template type Generator interface { bootstrap.Helper @@ -63,19 +68,33 @@ const ( var DefaultChainCreationPolicyNames = []string{AcceptAllPolicyKey} type bootstrapper struct { - minimalGroups []*cb.ConfigGroup - systemChainGroups []*cb.ConfigGroup + channelGroups []*cb.ConfigGroup + ordererGroups []*cb.ConfigGroup + applicationGroups []*cb.ConfigGroup + ordererSystemChannelGroups []*cb.ConfigGroup } // New returns a new provisional bootstrap helper. -func New(conf *genesisconfig.TopLevel) Generator { +func New(conf *genesisconfig.Profile) Generator { bs := &bootstrapper{ - minimalGroups: []*cb.ConfigGroup{ + channelGroups: []*cb.ConfigGroup{ // Chain Config Types configtxchannel.DefaultHashingAlgorithm(), configtxchannel.DefaultBlockDataHashingStructure(), - configtxchannel.TemplateOrdererAddresses(conf.Orderer.Addresses), + configtxchannel.TemplateOrdererAddresses(conf.Orderer.Addresses), // TODO, move to conf.Channel when it exists + // Default policies + policies.TemplateImplicitMetaAnyPolicy([]string{}, configvaluesmsp.ReadersPolicyKey), + policies.TemplateImplicitMetaAnyPolicy([]string{}, configvaluesmsp.WritersPolicyKey), + policies.TemplateImplicitMetaMajorityPolicy([]string{}, configvaluesmsp.AdminsPolicyKey), + + // Temporary AcceptAllPolicy XXX, remove + cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy), + }, + } + + if conf.Orderer != nil { + bs.ordererGroups = []*cb.ConfigGroup{ // Orderer Config Types configtxorderer.TemplateConsensusType(conf.Orderer.OrdererType), configtxorderer.TemplateBatchSize(&ab.BatchSize{ @@ -87,49 +106,67 @@ func New(conf *genesisconfig.TopLevel) Generator { configtxorderer.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}), configtxorderer.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}), - // Policies - cauthdsl.TemplatePolicy(AcceptAllPolicyKey, cauthdsl.AcceptAllPolicy), - - // Initialize the default Reader/Writer/Admins channel policies - policies.TemplateImplicitMetaAnyPolicy([]string{}, configvaluesmsp.ReadersPolicyKey), - policies.TemplateImplicitMetaAnyPolicy([]string{}, configvaluesmsp.WritersPolicyKey), - policies.TemplateImplicitMetaMajorityPolicy([]string{}, configvaluesmsp.AdminsPolicyKey), - // Initialize the default Reader/Writer/Admins orderer policies policies.TemplateImplicitMetaAnyPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.ReadersPolicyKey), policies.TemplateImplicitMetaAnyPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.WritersPolicyKey), policies.TemplateImplicitMetaMajorityPolicy([]string{configtxorderer.GroupKey}, configvaluesmsp.AdminsPolicyKey), + } + + for _, org := range conf.Orderer.Organizations { + mspConfig, err := msp.GetLocalMspConfig(org.MSPDir, org.ID) + if err != nil { + logger.Panicf("Error loading MSP configuration for org %s: %s", org.Name, err) + } + bs.ordererGroups = append(bs.ordererGroups, configvaluesmsp.TemplateGroupMSP([]string{configtxorderer.GroupKey, org.Name}, mspConfig)) + } + + switch conf.Orderer.OrdererType { + case ConsensusTypeSolo, ConsensusTypeSbft: + case ConsensusTypeKafka: + bs.ordererGroups = append(bs.ordererGroups, configtxorderer.TemplateKafkaBrokers(conf.Orderer.Kafka.Brokers)) + default: + panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Orderer.OrdererType)) + } + + bs.ordererSystemChannelGroups = []*cb.ConfigGroup{ + // Policies + configtxorderer.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames), + } + } + if conf.Application != nil { + + bs.applicationGroups = []*cb.ConfigGroup{ // Initialize the default Reader/Writer/Admins application policies policies.TemplateImplicitMetaAnyPolicy([]string{configtxapplication.GroupKey}, configvaluesmsp.ReadersPolicyKey), policies.TemplateImplicitMetaAnyPolicy([]string{configtxapplication.GroupKey}, configvaluesmsp.WritersPolicyKey), policies.TemplateImplicitMetaMajorityPolicy([]string{configtxapplication.GroupKey}, configvaluesmsp.AdminsPolicyKey), - }, - - systemChainGroups: []*cb.ConfigGroup{ - configtxorderer.TemplateChainCreationPolicyNames(DefaultChainCreationPolicyNames), - }, - } + } + for _, org := range conf.Application.Organizations { + mspConfig, err := msp.GetLocalMspConfig(org.MSPDir, org.ID) + if err != nil { + logger.Panicf("Error loading MSP configuration for org %s: %s", org.Name, err) + } + bs.ordererGroups = append(bs.ordererGroups, configvaluesmsp.TemplateGroupMSP([]string{configtxapplication.GroupKey, org.Name}, mspConfig)) + } - switch conf.Orderer.OrdererType { - case ConsensusTypeSolo, ConsensusTypeSbft: - case ConsensusTypeKafka: - bs.minimalGroups = append(bs.minimalGroups, configtxorderer.TemplateKafkaBrokers(conf.Orderer.Kafka.Brokers)) - default: - panic(fmt.Errorf("Wrong consenter type value given: %s", conf.Orderer.OrdererType)) } return bs } func (bs *bootstrapper) ChannelTemplate() configtx.Template { - return configtx.NewSimpleTemplate(bs.minimalGroups...) + return configtx.NewCompositeTemplate( + configtx.NewSimpleTemplate(bs.channelGroups...), + configtx.NewSimpleTemplate(bs.ordererGroups...), + configtx.NewSimpleTemplate(bs.applicationGroups...), + ) } func (bs *bootstrapper) GenesisBlock() *cb.Block { block, err := genesis.NewFactoryImpl( configtx.NewCompositeTemplate( - configtx.NewSimpleTemplate(bs.systemChainGroups...), + configtx.NewSimpleTemplate(bs.ordererSystemChannelGroups...), bs.ChannelTemplate(), ), ).Block(TestChainID) diff --git a/common/configtx/tool/provisional/provisional_test.go b/common/configtx/tool/provisional/provisional_test.go index 5ebecfe7226..bdbc6319c4d 100644 --- a/common/configtx/tool/provisional/provisional_test.go +++ b/common/configtx/tool/provisional/provisional_test.go @@ -18,20 +18,27 @@ package provisional import ( "bytes" + "os" + "path/filepath" "testing" genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" cb "github.com/hyperledger/fabric/protos/common" ) -var confSolo, confKafka *genesisconfig.TopLevel -var testCases []*genesisconfig.TopLevel +var confSolo, confKafka *genesisconfig.Profile +var testCases []*genesisconfig.Profile func init() { - confSolo = genesisconfig.Load() - confKafka = genesisconfig.Load() + // 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/tool/provisional + os.Chdir(filepath.Join("..", "..", "..", "..")) + + confSolo = genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile) + confKafka = genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile) confKafka.Orderer.OrdererType = ConsensusTypeKafka - testCases = []*genesisconfig.TopLevel{confSolo, confKafka} + testCases = []*genesisconfig.Profile{confSolo, confKafka} } func TestGenesisBlockHeader(t *testing.T) { diff --git a/common/viperutil/config_util.go b/common/viperutil/config_util.go index 4be9fb8b7bc..199f374607a 100644 --- a/common/viperutil/config_util.go +++ b/common/viperutil/config_util.go @@ -198,15 +198,27 @@ func pemBlocksFromFileDecodeHook() mapstructure.DecodeHookFunc { case reflect.String: return data, nil case reflect.Map: - d := data.(map[string]interface{}) - fileName, ok := d["File"] - if !ok { - fileName, ok = d["file"] + var fileName string + var ok bool + switch d := data.(type) { + case map[string]string: + fileName, ok = d["File"] + if !ok { + fileName, ok = d["file"] + } + case map[string]interface{}: + var fileI interface{} + fileI, ok = d["File"] + if !ok { + fileI, ok = d["file"] + } + fileName, ok = fileI.(string) } + switch { - case ok && fileName != nil: + case ok && fileName != "": var result []string - bytes, err := ioutil.ReadFile(fileName.(string)) + bytes, err := ioutil.ReadFile(fileName) if err != nil { return data, err } diff --git a/images/orderer/Dockerfile.in b/images/orderer/Dockerfile.in index 60c4b9bfa6f..ff917e42b2d 100644 --- a/images/orderer/Dockerfile.in +++ b/images/orderer/Dockerfile.in @@ -3,6 +3,7 @@ ENV ORDERER_CFG_PATH /etc/hyperledger/fabric ENV ORDERER_GENERAL_LOCALMSPDIR $ORDERER_CFG_PATH/msp/sampleconfig RUN mkdir -p /var/hyperledger/production $ORDERER_CFG_PATH COPY payload/orderer /usr/local/bin +COPY payload/configtx.yaml $ORDERER_CFG_PATH/ COPY payload/orderer.yaml $ORDERER_CFG_PATH/ ADD payload/msp-sampleconfig.tar.bz2 $ORDERER_CFG_PATH/ EXPOSE 7050 diff --git a/images/peer/Dockerfile.in b/images/peer/Dockerfile.in index 4987ddb1c12..5e46cf3927d 100644 --- a/images/peer/Dockerfile.in +++ b/images/peer/Dockerfile.in @@ -5,5 +5,5 @@ RUN mkdir -p /var/hyperledger/production $PEER_CFG_PATH COPY payload/peer /usr/local/bin COPY payload/core.yaml $PEER_CFG_PATH ADD payload/msp-sampleconfig.tar.bz2 $PEER_CFG_PATH -ADD payload/genesis.yaml $PEER_CFG_PATH +ADD payload/configtx.yaml $PEER_CFG_PATH CMD peer node start diff --git a/images/testenv/Dockerfile.in b/images/testenv/Dockerfile.in index ea226a2367c..5b4ef0c7056 100644 --- a/images/testenv/Dockerfile.in +++ b/images/testenv/Dockerfile.in @@ -14,7 +14,7 @@ RUN mkdir -p \ # fabric configuration files COPY payload/orderer.yaml $ORDERER_CFG_PATH -COPY payload/genesis.yaml $ORDERER_CFG_PATH +COPY payload/configtx.yaml $ORDERER_CFG_PATH COPY payload/core.yaml $PEER_CFG_PATH ADD payload/msp-sampleconfig.tar.bz2 $PEER_CFG_PATH diff --git a/orderer/common/deliver/deliver_test.go b/orderer/common/deliver/deliver_test.go index d87910ebced..fa14d59a372 100644 --- a/orderer/common/deliver/deliver_test.go +++ b/orderer/common/deliver/deliver_test.go @@ -21,7 +21,6 @@ import ( "testing" "time" - genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" "github.com/hyperledger/fabric/common/configtx/tool/provisional" configvaluesapi "github.com/hyperledger/fabric/common/configvalues" mockconfigvaluesorderer "github.com/hyperledger/fabric/common/mocks/configvalues/channel/orderer" @@ -36,7 +35,7 @@ import ( "google.golang.org/grpc" ) -var genesisBlock *cb.Block +var genesisBlock = cb.NewBlock(0, nil) var systemChainID = "systemChain" @@ -44,7 +43,6 @@ const ledgerSize = 10 func init() { logging.SetLevel(logging.DEBUG, "") - genesisBlock = provisional.New(genesisconfig.Load()).GenesisBlock() } type mockD struct { diff --git a/orderer/kafka/config_test.go b/orderer/kafka/config_test.go index 57c56bda828..40e2d42866b 100644 --- a/orderer/kafka/config_test.go +++ b/orderer/kafka/config_test.go @@ -39,7 +39,7 @@ var ( ) var testGenesisConf = &genesisconfig.TopLevel{ - Orderer: genesisconfig.Orderer{ + Orderer: &genesisconfig.Orderer{ Kafka: genesisconfig.Kafka{ Brokers: []string{"127.0.0.1:9092"}, }, diff --git a/orderer/ledger/file/fileledger_test.go b/orderer/ledger/file/fileledger_test.go index 9d6d2e8be66..ab838d9dd07 100644 --- a/orderer/ledger/file/fileledger_test.go +++ b/orderer/ledger/file/fileledger_test.go @@ -22,7 +22,6 @@ import ( "os" "testing" - genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" "github.com/hyperledger/fabric/common/configtx/tool/provisional" ordererledger "github.com/hyperledger/fabric/orderer/ledger" cb "github.com/hyperledger/fabric/protos/common" @@ -31,11 +30,10 @@ import ( logging "github.com/op/go-logging" ) -var genesisBlock *cb.Block +var genesisBlock = cb.NewBlock(0, nil) func init() { logging.SetLevel(logging.DEBUG, "") - genesisBlock = provisional.New(genesisconfig.Load()).GenesisBlock() } type testEnv struct { diff --git a/orderer/ledger/fileledger_test.go b/orderer/ledger/fileledger_test.go index 571197e7f3f..c9aa6c8a8e8 100644 --- a/orderer/ledger/fileledger_test.go +++ b/orderer/ledger/fileledger_test.go @@ -20,17 +20,15 @@ import ( "io/ioutil" "os" - genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" "github.com/hyperledger/fabric/common/configtx/tool/provisional" . "github.com/hyperledger/fabric/orderer/ledger" fileledger "github.com/hyperledger/fabric/orderer/ledger/file" cb "github.com/hyperledger/fabric/protos/common" ) -var genesisBlock *cb.Block +var genesisBlock = cb.NewBlock(0, nil) func init() { - genesisBlock = provisional.New(genesisconfig.Load()).GenesisBlock() testables = append(testables, &fileLedgerTestEnv{}) } diff --git a/orderer/ledger/ram/ramledger_test.go b/orderer/ledger/ram/ramledger_test.go index fb0e38ba9b7..0322716ca52 100644 --- a/orderer/ledger/ram/ramledger_test.go +++ b/orderer/ledger/ram/ramledger_test.go @@ -19,18 +19,16 @@ package ramledger import ( "testing" - genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" "github.com/hyperledger/fabric/common/configtx/tool/provisional" cb "github.com/hyperledger/fabric/protos/common" logging "github.com/op/go-logging" ) -var genesisBlock *cb.Block +var genesisBlock = cb.NewBlock(0, nil) func init() { logging.SetLevel(logging.DEBUG, "") - genesisBlock = provisional.New(genesisconfig.Load()).GenesisBlock() } func NewTestChain(maxSize int) *ramLedger { diff --git a/orderer/localconfig/config.go b/orderer/localconfig/config.go index dde529f52d2..4f68b55d4be 100644 --- a/orderer/localconfig/config.go +++ b/orderer/localconfig/config.go @@ -41,18 +41,19 @@ const Prefix string = "ORDERER" // General contains config which should be common among all orderer types type General struct { - LedgerType string - QueueSize uint32 - MaxWindowSize uint32 - ListenAddress string - ListenPort uint16 - TLS TLS - GenesisMethod string - GenesisFile string - Profile Profile - LogLevel string - LocalMSPDir string - LocalMSPID string + LedgerType string + QueueSize uint32 + MaxWindowSize uint32 + ListenAddress string + ListenPort uint16 + TLS TLS + GenesisMethod string + GenesisProfile string + GenesisFile string + Profile Profile + LogLevel string + LocalMSPDir string + LocalMSPID string } //TLS contains config used to configure TLS @@ -143,13 +144,14 @@ type TopLevel struct { var defaults = TopLevel{ General: General{ - LedgerType: "ram", - QueueSize: 1000, - MaxWindowSize: 1000, - ListenAddress: "127.0.0.1", - ListenPort: 7050, - GenesisMethod: "provisional", - GenesisFile: "./genesisblock", + LedgerType: "ram", + QueueSize: 1000, + MaxWindowSize: 1000, + ListenAddress: "127.0.0.1", + ListenPort: 7050, + GenesisMethod: "provisional", + GenesisProfile: "SampleSingleMSPSolo", + GenesisFile: "./genesisblock", Profile: Profile{ Enabled: false, Address: "0.0.0.0:6060", @@ -219,6 +221,8 @@ func (c *TopLevel) completeInitialization() { c.General.GenesisMethod = defaults.General.GenesisMethod case c.General.GenesisFile == "": c.General.GenesisFile = defaults.General.GenesisFile + case c.General.GenesisProfile == "": + c.General.GenesisProfile = defaults.General.GenesisProfile case c.Kafka.TLS.Enabled && c.Kafka.TLS.Certificate == "": logger.Panicf("General.Kafka.TLS.Certificate must be set if General.Kafka.TLS.Enabled is set to true.") case c.Kafka.TLS.Enabled && c.Kafka.TLS.PrivateKey == "": diff --git a/orderer/main.go b/orderer/main.go index b7347f91671..4b6b974d26c 100644 --- a/orderer/main.go +++ b/orderer/main.go @@ -115,7 +115,7 @@ func main() { // Select the bootstrapping mechanism switch conf.General.GenesisMethod { case "provisional": - genesisBlock = provisional.New(genesisconfig.Load()).GenesisBlock() + genesisBlock = provisional.New(genesisconfig.Load(conf.General.GenesisProfile)).GenesisBlock() case "file": genesisBlock = file.New(conf.General.GenesisFile).GenesisBlock() default: diff --git a/orderer/multichain/manager.go b/orderer/multichain/manager.go index dde13011b77..f33c1138b67 100644 --- a/orderer/multichain/manager.go +++ b/orderer/multichain/manager.go @@ -105,11 +105,11 @@ func NewManagerImpl(ledgerFactory ordererledger.Factory, consenters map[string]C if ml.sysChain != nil { logger.Fatalf("There appear to be two system chains %s and %s", ml.sysChain.support.ChainID(), chainID) } - logger.Debugf("Starting with system chain: %x", chainID) chain := newChainSupport(createSystemChainFilters(ml, ledgerResources), ledgerResources, consenters, signer) + logger.Infof("Starting with system channel: %s and orderer type %s", chainID, chain.SharedConfig().ConsensusType()) ml.chains[string(chainID)] = chain ml.sysChain = newSystemChain(chain) // We delay starting this chain, as it might try to copy and replace the chains map via newChain before the map is fully built diff --git a/orderer/multichain/manager_test.go b/orderer/multichain/manager_test.go index 7e2a4309bdb..4ee516ecd03 100644 --- a/orderer/multichain/manager_test.go +++ b/orderer/multichain/manager_test.go @@ -35,11 +35,11 @@ import ( "github.com/stretchr/testify/assert" ) -var conf *genesisconfig.TopLevel -var genesisBlock *cb.Block +var conf *genesisconfig.Profile +var genesisBlock = cb.NewBlock(0, nil) // *cb.Block func init() { - conf = genesisconfig.Load() + conf = genesisconfig.Load(genesisconfig.SampleInsecureProfile) logging.SetLevel(logging.DEBUG, "") genesisBlock = provisional.New(conf).GenesisBlock() } @@ -217,7 +217,6 @@ func TestSignatureFilter(t *testing.T) { // This test brings up the entire system, with the mock consenter, including the broadcasters etc. and creates a new chain func TestNewChain(t *testing.T) { - conf := genesisconfig.Load() lf, rl := NewRAMLedgerAndFactory(10) consenters := make(map[string]Consenter) diff --git a/orderer/network_test.go b/orderer/network_test.go index 46dc8ab9fd7..df77c11cfe4 100644 --- a/orderer/network_test.go +++ b/orderer/network_test.go @@ -33,6 +33,7 @@ import ( "encoding/json" "github.com/golang/protobuf/proto" + genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" "github.com/hyperledger/fabric/common/configtx/tool/provisional" cb "github.com/hyperledger/fabric/protos/common" ab "github.com/hyperledger/fabric/protos/orderer" @@ -307,7 +308,8 @@ func generateConfigEnv(peerNum uint64, grpcPort int, peerCommPort string, certFi envs = append(envs, fmt.Sprintf("ORDERER_CFG_PATH=%s", ordererDir)) envs = append(envs, fmt.Sprintf("ORDERER_GENERAL_LOCALMSPDIR=%s", ordererDir+"/../msp/sampleconfig")) envs = append(envs, fmt.Sprintf("ORDERER_GENERAL_LISTENPORT=%d", grpcPort)) - envs = append(envs, fmt.Sprintf("CONFIGTX_ORDERER_ORDERERTYPE=%s", "sbft")) + envs = append(envs, fmt.Sprintf("CONFIGTX_PROFILES_SAMPLEINSECURESOLO_ORDERER_ORDERERTYPE=%s", "sbft")) + envs = append(envs, fmt.Sprintf("ORDERER_GENERAL_GENESISPROFILE=%s", genesisconfig.SampleInsecureProfile)) envs = append(envs, fmt.Sprintf("ORDERER_GENESIS_DEPRECATEDBATCHTIMEOUT=%d", 1000)) envs = append(envs, fmt.Sprintf("ORDERER_GENESIS_DEPRECATED=%d", 1000000000)) envs = append(envs, fmt.Sprintf("ORDERER_GENESIS_SBFTSHARED_REQUESTTIMEOUTNSEC=%d", 1000000000)) diff --git a/orderer/orderer.yaml b/orderer/orderer.yaml index 97dc4652413..0a066147457 100644 --- a/orderer/orderer.yaml +++ b/orderer/orderer.yaml @@ -48,6 +48,10 @@ General: # block. GenesisMethod: provisional + # Genesis profile: The profile to use when using the provisional GenesisMethod + # See the configtx.yaml file for the descriptions of the available profiles + GenesisProfile: SampleSingleMSPSolo + # Genesis file: The file containing the genesis block. Used by the orderer # when GenesisMethod is set to "file". GenesisFile: ./genesisblock diff --git a/orderer/sample_clients/broadcast_config/client.go b/orderer/sample_clients/broadcast_config/client.go index 79d380c6415..11d4b21054c 100644 --- a/orderer/sample_clients/broadcast_config/client.go +++ b/orderer/sample_clients/broadcast_config/client.go @@ -30,7 +30,7 @@ import ( ) var conf *config.TopLevel -var genConf *genesisconfig.TopLevel +var genConf *genesisconfig.Profile type broadcastClient struct { ab.AtomicBroadcast_BroadcastClient @@ -69,7 +69,7 @@ type argsImpl struct { func init() { conf = config.Load() - genConf = genesisconfig.Load() + genConf = genesisconfig.Load(genesisconfig.SampleInsecureProfile) } func main() { diff --git a/orderer/sbft_test.go b/orderer/sbft_test.go index b23c6a49aaf..baebd2c875e 100644 --- a/orderer/sbft_test.go +++ b/orderer/sbft_test.go @@ -48,6 +48,24 @@ import ( "google.golang.org/grpc" ) +var genesisBlock *cb.Block +var pwd string + +func init() { + var err error + pwd, err = os.Getwd() + if err != nil { + panic(err) + } + os.Chdir("..") + + genConf := genesisconfig.Load(genesisconfig.SampleInsecureProfile) + genConf.Orderer.OrdererType = sbftName + genesisBlock = provisional.New(genConf).GenesisBlock() + + os.Chdir(pwd) +} + const update byte = 0 const sent byte = 1 @@ -64,10 +82,6 @@ type item struct { } func TestSbftPeer(t *testing.T) { - pwd, err := os.Getwd() - if err != nil { - panic(err) - } t.Parallel() skipInShortMode(t) @@ -100,11 +114,9 @@ func TestSbftPeer(t *testing.T) { // Start GRPC logger.Info("Creating a GRPC server.") conf := config.Load() - genConf := genesisconfig.Load() - genConf.Orderer.OrdererType = sbftName conf.General.LocalMSPDir = pwd + "/../msp/sampleconfig" conf.General.LocalMSPID = "DEFAULT" - lf := newRAMLedgerFactory(genConf) + lf := newRAMLedgerFactory() consenters := make(map[string]multichain.Consenter) consenters[sbftName] = sbftConsenter @@ -264,9 +276,8 @@ func broadcastSender(t *testing.T, resultch chan item, errorch chan error, clien resultch <- item{itemtype: sent, payload: mpl} } -func newRAMLedgerFactory(conf *genesisconfig.TopLevel) ordererledger.Factory { +func newRAMLedgerFactory() ordererledger.Factory { rlf := ramledger.New(10) - genesisBlock := provisional.New(conf).GenesisBlock() rl, err := rlf.GetOrCreate(provisional.TestChainID) if err != nil { panic(err)