diff --git a/Makefile b/Makefile index 9fc28d293dc..6d7f1d1de93 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,6 @@ GOSHIM_DEPS = $(shell ./scripts/goListFiles.sh $(PKGNAME)/core/chaincode/shim | JAVASHIM_DEPS = $(shell git ls-files core/chaincode/shim/java) PROTOS = $(shell git ls-files *.proto | grep -v vendor) MSP_SAMPLECONFIG = $(shell git ls-files msp/sampleconfig/*.pem) -GENESIS_SAMPLECONFIG = $(shell git ls-files common/configtx/test/*.template) PROJECT_FILES = $(shell git ls-files) IMAGES = peer orderer ccenv javaenv testenv zookeeper kafka @@ -176,7 +175,7 @@ build/image/javaenv/payload: build/javashim.tar.bz2 \ build/image/peer/payload: build/docker/bin/peer \ peer/core.yaml \ build/msp-sampleconfig.tar.bz2 \ - build/genesis-sampleconfig.tar.bz2 + common/configtx/tool/genesis.yaml build/image/orderer/payload: build/docker/bin/orderer \ build/msp-sampleconfig.tar.bz2 \ orderer/orderer.yaml \ @@ -222,7 +221,6 @@ build/goshim.tar.bz2: $(GOSHIM_DEPS) build/javashim.tar.bz2: $(JAVASHIM_DEPS) build/protos.tar.bz2: $(PROTOS) build/msp-sampleconfig.tar.bz2: $(MSP_SAMPLECONFIG) -build/genesis-sampleconfig.tar.bz2: $(GENESIS_SAMPLECONFIG) build/%.tar.bz2: @echo "Creating $@" diff --git a/common/configtx/handlers/msp/config_util.go b/common/configtx/handlers/msp/config_util.go new file mode 100644 index 00000000000..fff5b0a457c --- /dev/null +++ b/common/configtx/handlers/msp/config_util.go @@ -0,0 +1,41 @@ +/* +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 msp + +import ( + cb "github.com/hyperledger/fabric/protos/common" + "github.com/hyperledger/fabric/protos/msp" + "github.com/hyperledger/fabric/protos/utils" +) + +const ( + MSPKey = "MSP" +) + +// TemplateGroupMSP creates an MSP ConfigValue at the given configPath +func TemplateGroupMSP(configPath []string, mspConf *msp.MSPConfig) *cb.ConfigGroup { + result := cb.NewConfigGroup() + intermediate := result + for _, group := range configPath { + intermediate.Groups[group] = cb.NewConfigGroup() + intermediate = intermediate.Groups[group] + } + intermediate.Values[MSPKey] = &cb.ConfigValue{ + Value: utils.MarshalOrPanic(mspConf), + } + return result +} diff --git a/common/configtx/test/helper.go b/common/configtx/test/helper.go index e1793538fc8..705732c189d 100644 --- a/common/configtx/test/helper.go +++ b/common/configtx/test/helper.go @@ -17,15 +17,18 @@ limitations under the License. package test import ( - "io/ioutil" "os" + "path/filepath" "github.com/hyperledger/fabric/common/configtx" + configtxapplication "github.com/hyperledger/fabric/common/configtx/handlers/application" + configtxmsp "github.com/hyperledger/fabric/common/configtx/handlers/msp" + genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" + "github.com/hyperledger/fabric/common/configtx/tool/provisional" "github.com/hyperledger/fabric/common/genesis" + "github.com/hyperledger/fabric/msp" cb "github.com/hyperledger/fabric/protos/common" - "github.com/hyperledger/fabric/protos/utils" - "github.com/golang/protobuf/proto" logging "github.com/op/go-logging" ) @@ -36,91 +39,66 @@ const ( AcceptAllPolicyKey = "AcceptAllPolicy" ) -const ( - OrdererTemplateName = "orderer.template" - MSPTemplateName = "msp.template" - PeerTemplateName = "peer.template" -) - -var ordererTemplate configtx.Template -var mspTemplate configtx.Template -var peerTemplate configtx.Template - -var compositeTemplate configtx.Template - -var genesisFactory genesis.Factory +var sampleMSPPath string -func init() { - ordererTemplate = readTemplate(OrdererTemplateName) - mspTemplate = readTemplate(MSPTemplateName) - peerTemplate = readTemplate(PeerTemplateName) - - compositeTemplate = configtx.NewCompositeTemplate(mspTemplate, ordererTemplate, peerTemplate) - genesisFactory = genesis.NewFactoryImpl(compositeTemplate) +func dirExists(path string) bool { + _, err := os.Stat(path) + return err == nil } -func resolveName(name string) (string, []byte) { - path := os.Getenv("GOPATH") + "/src/github.com/hyperledger/fabric/common/configtx/test/" + name - data, err := ioutil.ReadFile(path) - if err == nil { - return path, data +func init() { + mspSampleConfig := "/msp/sampleconfig" + peerPath := filepath.Join(os.Getenv("PEER_CFG_PATH"), mspSampleConfig) + ordererPath := filepath.Join(os.Getenv("ORDERER_CFG_PATH"), mspSampleConfig) + switch { + case dirExists(peerPath): + sampleMSPPath = peerPath + return + case dirExists(ordererPath): + sampleMSPPath = ordererPath + return } - path = os.Getenv("PEER_CFG_PATH") + "/common/configtx/test/" + name - data, err = ioutil.ReadFile(path) - if err != nil { - panic(err) + gopath := os.Getenv("GOPATH") + for _, p := range filepath.SplitList(gopath) { + samplePath := filepath.Join(p, "src/github.com/hyperledger/fabric", mspSampleConfig) + if !dirExists(samplePath) { + continue + } + sampleMSPPath = samplePath } - return path, data -} - -func readTemplate(name string) configtx.Template { - _, data := resolveName(name) - - templateProto := &cb.ConfigTemplate{} - err := proto.Unmarshal(data, templateProto) - if err != nil { - panic(err) + if sampleMSPPath == "" { + logger.Panicf("Could not find genesis.yaml, try setting PEER_CFG_PATH, ORDERER_CFG_PATH, or GOPATH correctly") } - - return configtx.NewSimpleTemplate(templateProto.Items...) -} - -// WriteTemplate takes an output file and set of config items and writes them to that file as a marshaled ConfigTemplate -func WriteTemplate(name string, items ...*cb.ConfigItem) { - path, _ := resolveName(name) - - logger.Debugf("Encoding config template") - outputData := utils.MarshalOrPanic(&cb.ConfigTemplate{ - Items: items, - }) - - logger.Debugf("Writing config to %s", path) - ioutil.WriteFile(path, outputData, 0644) } // MakeGenesisBlock creates a genesis block using the test templates for the given chainID func MakeGenesisBlock(chainID string) (*cb.Block, error) { - return genesisFactory.Block(chainID) + return genesis.NewFactoryImpl(CompositeTemplate()).Block(chainID) } // OrderererTemplate returns the test orderer template func OrdererTemplate() configtx.Template { - return ordererTemplate + genConf := genesisconfig.Load() + return provisional.New(genConf).ChannelTemplate() } -// MSPerTemplate returns the test MSP template +// MSPTemplate returns the test MSP template func MSPTemplate() configtx.Template { - return mspTemplate + mspConf, err := msp.GetLocalMspConfig(sampleMSPPath, "SAMPLE") + if err != nil { + logger.Panicf("Could not load sample MSP config: %s", err) + } + return configtx.NewSimpleTemplateNext(configtxmsp.TemplateGroupMSP([]string{configtxapplication.GroupKey}, mspConf)) } -// MSPerTemplate returns the test peer template -func PeerTemplate() configtx.Template { - return peerTemplate +// ApplicationTemplate returns the test application template +func ApplicationTemplate() configtx.Template { + return configtx.NewSimpleTemplateNext(configtxapplication.DefaultAnchorPeers()) } // CompositeTemplate returns the composite template of peer, orderer, and MSP func CompositeTemplate() configtx.Template { - return compositeTemplate + return configtx.NewCompositeTemplate(MSPTemplate(), OrdererTemplate(), ApplicationTemplate()) } diff --git a/common/configtx/test/msp.template b/common/configtx/test/msp.template deleted file mode 100644 index 762ae36b793..00000000000 --- a/common/configtx/test/msp.template +++ /dev/null @@ -1,55 +0,0 @@ - -³"DEFAULT*¥¢ -DEFAULT÷-----BEGIN CERTIFICATE----- -MIICYjCCAgmgAwIBAgIUB3CTDOU47sUC5K4kn/Caqnh114YwCgYIKoZIzj0EAwIw -fzELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNh -biBGcmFuY2lzY28xHzAdBgNVBAoTFkludGVybmV0IFdpZGdldHMsIEluYy4xDDAK -BgNVBAsTA1dXVzEUMBIGA1UEAxMLZXhhbXBsZS5jb20wHhcNMTYxMDEyMTkzMTAw -WhcNMjExMDExMTkzMTAwWjB/MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv -cm5pYTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEfMB0GA1UEChMWSW50ZXJuZXQg -V2lkZ2V0cywgSW5jLjEMMAoGA1UECxMDV1dXMRQwEgYDVQQ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milM9lX2Fq4jWpAaRVB97OmVEeyAiEA -25aDPQHGGq2AvhKT0wvt08cX1GTGCIbfmuLpMwKQj38= ------END CERTIFICATE----- -ì -PEERã-----BEGIN EC PRIVATE KEY----- -MHcCAQEEIAsWwFunEzqz1Rh6nvD4MiPkKCtmoxzh3jTquG5MSbeLoAoGCCqGSM49 -AwEHoUQDQgAEHBuKsAO43hs4JGpFfiGMkB/xsILTsOvmN2WmwpsPHZNL6w8HWe3x -CPQtdG/XJJvZ+C756KEsUBM3yw5PTfku8g== ------END EC PRIVATE KEY----- diff --git a/common/configtx/test/orderer.template b/common/configtx/test/orderer.template deleted file mode 100644 index 9abd4fdef65..00000000000 --- a/common/configtx/test/orderer.template +++ /dev/null @@ -1,17 +0,0 @@ - - "HashingAlgorithm* - -SHAKE256 -%"BlockDataHashingStructure*ÿÿÿÿ -&"OrdererAddresses* -127.0.0.1:7050 -" ConsensusType* -solo -" BatchSize*  -€€À1€€ -" BatchTimeout* -10s -)"IngressPolicyNames* -AcceptAllPolicy -("EgressPolicyNames* -AcceptAllPolicy \ No newline at end of file diff --git a/common/configtx/test/peer.template b/common/configtx/test/peer.template deleted file mode 100644 index e4ec4eafd9c..00000000000 --- a/common/configtx/test/peer.template +++ /dev/null @@ -1,2 +0,0 @@ - -" AnchorPeers \ No newline at end of file diff --git a/common/configtx/tool/localconfig/config.go b/common/configtx/tool/localconfig/config.go index ba01a9f1a03..f4938695845 100644 --- a/common/configtx/tool/localconfig/config.go +++ b/common/configtx/tool/localconfig/config.go @@ -117,21 +117,29 @@ func Load() *TopLevel { config := viper.New() config.SetConfigName("genesis") - var cfgPath string - // Path to look for the config file in based on ORDERER_CFG_PATH and GOPATH - searchPath := os.Getenv("ORDERER_CFG_PATH") + ":" + os.Getenv("GOPATH") - for _, p := range filepath.SplitList(searchPath) { - genesisPath := filepath.Join(p, "src/github.com/hyperledger/fabric/common/configtx/tool/") + // Path to look for the config file in based on GOPATH + searchPath := []string{ + os.Getenv("ORDERER_CFG_PATH"), + os.Getenv("PEER_CFG_PATH"), + } + + for _, p := range filepath.SplitList(os.Getenv("GOPATH")) { + searchPath = append(searchPath, filepath.Join(p, "src/github.com/hyperledger/fabric/common/configtx/tool/")) + } + + for _, genesisPath := range searchPath { + logger.Infof("Checking for genesis.yaml at: %s", genesisPath) if _, err := os.Stat(filepath.Join(genesisPath, "genesis.yaml")); err != nil { - // The yaml file does not exist in this component of the go src + // The yaml file does not exist in this component of the path continue } cfgPath = genesisPath } + if cfgPath == "" { - logger.Fatalf("Could not find genesis.yaml, try setting GOPATH correctly") + logger.Fatalf("Could not find genesis.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 diff --git a/common/localmsp/signer_test.go b/common/localmsp/signer_test.go index 32bb314ec1d..4ac890e68fc 100644 --- a/common/localmsp/signer_test.go +++ b/common/localmsp/signer_test.go @@ -30,7 +30,7 @@ func TestMain(m *testing.M) { var mspMgrConfigDir string var alternativeCfgPath = os.Getenv("ORDERER_CFG_PATH") if alternativeCfgPath != "" { - mspMgrConfigDir = alternativeCfgPath + "/../msp/sampleconfig/" + mspMgrConfigDir = alternativeCfgPath + "/msp/sampleconfig/" } else if _, err := os.Stat("./msp/sampleconfig/"); err == nil { mspMgrConfigDir = "./msp/sampleconfig/" } else { diff --git a/images/orderer/Dockerfile.in b/images/orderer/Dockerfile.in index dda6136a703..65353dccc24 100644 --- a/images/orderer/Dockerfile.in +++ b/images/orderer/Dockerfile.in @@ -1,8 +1,8 @@ FROM hyperledger/fabric-baseos:_BASE_TAG_ -ENV ORDERER_CFG_PATH /etc/hyperledger/fabric/orderer -RUN mkdir -p /var/hyperledger/production /etc/hyperledger/fabric/orderer +ENV ORDERER_CFG_PATH /etc/hyperledger/fabric +RUN mkdir -p /var/hyperledger/production $ORDERER_CFG_PATH COPY payload/orderer /usr/local/bin -ADD payload/msp-sampleconfig.tar.bz2 $ORDERER_CFG_PATH/../ +COPY payload/genesis.yaml $ORDERER_CFG_PATH/ COPY payload/orderer.yaml $ORDERER_CFG_PATH/ COPY payload/genesis.yaml $ORDERER_CFG_PATH/ EXPOSE 7050 diff --git a/images/peer/Dockerfile.in b/images/peer/Dockerfile.in index 7610dbf4e3a..4987ddb1c12 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-sampleconfig.tar.bz2 $PEER_CFG_PATH +ADD payload/genesis.yaml $PEER_CFG_PATH CMD peer node start diff --git a/images/testenv/Dockerfile.in b/images/testenv/Dockerfile.in index 4d527dd23e3..a89febddc65 100644 --- a/images/testenv/Dockerfile.in +++ b/images/testenv/Dockerfile.in @@ -2,7 +2,7 @@ FROM hyperledger/fabric-baseimage:_BASE_TAG_ # fabric configuration locations ENV PEER_CFG_PATH /etc/hyperledger/fabric -ENV ORDERER_CFG_PATH /etc/hyperledger/fabric/orderer +ENV ORDERER_CFG_PATH /etc/hyperledger/fabric # create needed directories RUN mkdir -p \ diff --git a/msp/template_test.go b/msp/template_test.go deleted file mode 100644 index d6592a1e229..00000000000 --- a/msp/template_test.go +++ /dev/null @@ -1,41 +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 msp_test - -import ( - "testing" - - configtxtest "github.com/hyperledger/fabric/common/configtx/test" - . "github.com/hyperledger/fabric/msp" - "github.com/hyperledger/fabric/protos/common" - - "github.com/golang/protobuf/proto" - "github.com/stretchr/testify/assert" -) - -func TestTemplate(t *testing.T) { - conf, err := GetLocalMspConfig("sampleconfig/", "DEFAULT") - assert.NoError(t, err) - - confBytes, err := proto.Marshal(conf) - assert.NoError(t, err) - - // XXX We should really get the MSP name by inspecting it, but, we know it is DEFAULT so hardcoding for now - ci := &common.ConfigItem{Type: common.ConfigItem_MSP, Key: "DEFAULT", Value: confBytes} - - configtxtest.WriteTemplate(configtxtest.MSPTemplateName, ci) -}