Skip to content

Commit a3e3940

Browse files
author
Jason Yellick
committed
[FAB-2696] Default chain broken in peer
https://jira.hyperledger.org/browse/FAB-2696 According to @aso, the default chain is currently broken because it does not appropriately encode the channel config, and additional config sanity checks are now rejecting the config as invalid. This CR switches the default chain to using the configtxgen supporting structures to generate the genesis block for the default chain, so that all of the config checks will pass. It also causes the configtxgen tool to search a few different paths for relative MSP directories (., PEER_CFG_PATH, ORDERER_CFG_PATH, and finally the GOPATH). Change-Id: Ib6b836212e335b57f0c2b3c23dc4f05e9a47c56e Signed-off-by: Jason Yellick <[email protected]>
1 parent bdc4c2a commit a3e3940

File tree

2 files changed

+60
-26
lines changed

2 files changed

+60
-26
lines changed

common/configtx/tool/provisional/provisional.go

+36-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package provisional
1818

1919
import (
2020
"fmt"
21+
"os"
22+
"path/filepath"
2123

2224
"github.com/hyperledger/fabric/common/cauthdsl"
2325
"github.com/hyperledger/fabric/common/config"
@@ -68,6 +70,38 @@ const (
6870
BlockValidationPolicyKey = "BlockValidation"
6971
)
7072

73+
func resolveMSPDir(path string) string {
74+
if path == "" || path[0] == os.PathSeparator {
75+
return path
76+
}
77+
78+
// Look for MSP dir first in current path, then in ORDERER_CFG_PATH, then PEER_CFG_PATH, and finally in GOPATH
79+
searchPath := []string{
80+
".",
81+
os.Getenv("ORDERER_CFG_PATH"),
82+
os.Getenv("PEER_CFG_PATH"),
83+
}
84+
85+
for _, p := range filepath.SplitList(os.Getenv("GOPATH")) {
86+
searchPath = append(searchPath, filepath.Join(p, "src/github.com/hyperledger/fabric/common/configtx/tool/"))
87+
}
88+
89+
for _, baseDir := range searchPath {
90+
logger.Infof("Checking for MSPDir at: %s", baseDir)
91+
fqPath := filepath.Join(baseDir, path)
92+
if _, err := os.Stat(fqPath); err != nil {
93+
// The mspdir does not exist
94+
continue
95+
}
96+
return fqPath
97+
}
98+
99+
logger.Panicf("Unable to resolve a path for MSPDir: %s", path)
100+
101+
// Unreachable
102+
return ""
103+
}
104+
71105
// DefaultChainCreationPolicyNames is the default value of ChainCreatorsKey.
72106
var DefaultChainCreationPolicyNames = []string{AcceptAllPolicyKey}
73107

@@ -116,7 +150,7 @@ func New(conf *genesisconfig.Profile) Generator {
116150
}
117151

118152
for _, org := range conf.Orderer.Organizations {
119-
mspConfig, err := msp.GetVerifyingMspConfig(org.MSPDir, org.BCCSP, org.ID)
153+
mspConfig, err := msp.GetVerifyingMspConfig(resolveMSPDir(org.MSPDir), org.BCCSP, org.ID)
120154
if err != nil {
121155
logger.Panicf("Error loading MSP configuration for org %s: %s", org.Name, err)
122156
}
@@ -146,7 +180,7 @@ func New(conf *genesisconfig.Profile) Generator {
146180
policies.TemplateImplicitMetaMajorityPolicy([]string{config.ApplicationGroupKey}, configvaluesmsp.AdminsPolicyKey),
147181
}
148182
for _, org := range conf.Application.Organizations {
149-
mspConfig, err := msp.GetVerifyingMspConfig(org.MSPDir, org.BCCSP, org.ID)
183+
mspConfig, err := msp.GetVerifyingMspConfig(resolveMSPDir(org.MSPDir), org.BCCSP, org.ID)
150184
if err != nil {
151185
logger.Panicf("Error loading MSP configuration for org %s: %s", org.Name, err)
152186
}

peer/node/start.go

+24-24
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ import (
2828
"syscall"
2929
"time"
3030

31-
"github.com/hyperledger/fabric/common/config"
32-
"github.com/hyperledger/fabric/common/config/msp"
33-
"github.com/hyperledger/fabric/common/configtx"
34-
"github.com/hyperledger/fabric/common/configtx/test"
35-
"github.com/hyperledger/fabric/common/genesis"
31+
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
32+
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
3633
"github.com/hyperledger/fabric/common/localmsp"
37-
"github.com/hyperledger/fabric/common/policies"
3834
"github.com/hyperledger/fabric/common/util"
3935
"github.com/hyperledger/fabric/core"
4036
"github.com/hyperledger/fabric/core/chaincode"
@@ -48,6 +44,7 @@ import (
4844
"github.com/hyperledger/fabric/msp/mgmt"
4945
"github.com/hyperledger/fabric/peer/common"
5046
"github.com/hyperledger/fabric/peer/gossip/mcs"
47+
cb "github.com/hyperledger/fabric/protos/common"
5148
pb "github.com/hyperledger/fabric/protos/peer"
5249
"github.com/spf13/cobra"
5350
"github.com/spf13/viper"
@@ -59,6 +56,12 @@ var chaincodeDevMode bool
5956
var peerDefaultChain bool
6057
var orderingEndpoint string
6158

59+
// XXXDefaultChannelMSPID should not be defined in production code
60+
// It should only be referenced in tests. However, it is necessary
61+
// to support the 'default chain' setup so temporarilly adding until
62+
// this concept can be removed to testing scenarios only
63+
const XXXDefaultChannelMSPID = "DEFAULT"
64+
6265
func startCmd() *cobra.Command {
6366
// Set the flags on the node start command.
6467
flags := nodeStartCmd.Flags()
@@ -180,24 +183,21 @@ func serve(args []string) error {
180183

181184
chainID := util.GetTestChainID()
182185

183-
// add readers, writers and admin policies for the default chain
184-
policyTemplate := configtx.NewSimpleTemplate(
185-
policies.TemplateImplicitMetaAnyPolicy([]string{config.ApplicationGroupKey}, msp.ReadersPolicyKey),
186-
policies.TemplateImplicitMetaAnyPolicy([]string{config.ApplicationGroupKey}, msp.WritersPolicyKey),
187-
policies.TemplateImplicitMetaMajorityPolicy([]string{config.ApplicationGroupKey}, msp.AdminsPolicyKey),
188-
)
189-
190-
// We create a genesis block for the test
191-
// chain with its MSP so that we can transact
192-
block, err := genesis.NewFactoryImpl(
193-
configtx.NewCompositeTemplate(
194-
test.ApplicationOrgTemplate(),
195-
configtx.NewSimpleTemplate(config.TemplateOrdererAddresses([]string{orderingEndpoint})),
196-
policyTemplate)).Block(chainID)
197-
198-
if nil != err {
199-
logger.Panicf("Unable to create genesis block for [%s] due to [%s]", chainID, err)
200-
}
186+
var block *cb.Block
187+
188+
func() {
189+
defer func() {
190+
if err := recover(); err != nil {
191+
logger.Fatalf("Peer configured to start with the default test chain, but supporting configuration files did not match. Please ensure that configtx.yaml contains the unmodified SampleSingleMSPSolo profile and that msp/sampleconfig is present.\n%s", err)
192+
}
193+
}()
194+
195+
genConf := genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile)
196+
genConf.Orderer.Addresses = []string{orderingEndpoint}
197+
genConf.Application.Organizations[0].Name = XXXDefaultChannelMSPID
198+
genConf.Application.Organizations[0].ID = XXXDefaultChannelMSPID
199+
block = provisional.New(genConf).GenesisBlockForChannel(chainID)
200+
}()
201201

202202
//this creates testchainid and sets up gossip
203203
if err = peer.CreateChainFromBlock(block); err == nil {

0 commit comments

Comments
 (0)