hyperledger/fabric · error
could not get peer BCCSP configuration
Error message
could not get peer BCCSP configuration
What it means
InitBCCSPConfig reads the BCCSP (crypto provider) section from Viper via viper.Sub("peer.BCCSP") and returns this error when that subsection is absent from the loaded configuration. It means the config file loaded into Viper has no 'peer.BCCSP' key, so no crypto provider options could be decoded. Callers are InitCrypto and tests.
Source
Thrown at internal/peer/common/common.go:156
if strings.Contains(fmt.Sprint(err), "Unsupported Config Type") {
return errors.New(fmt.Sprintf("Could not find config file. "+
"Please make sure that FABRIC_CFG_PATH is set to a path "+
"which contains %s.yaml", cmdRoot))
} else {
return errors.WithMessagef(err, "error when reading %s config file", cmdRoot)
}
}
return nil
}
// InitBCCSPConfig initializes BCCSP config
func InitBCCSPConfig(bccspConfig *factory.FactoryOpts) error {
SetBCCSPKeystorePath()
subv := viper.Sub("peer.BCCSP")
if subv == nil {
return fmt.Errorf("could not get peer BCCSP configuration")
}
opts := viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
mapstructure.StringToTimeDurationHookFunc(),
mapstructure.StringToWeakSliceHookFunc(","),
factory.StringToKeyIds(),
))
if err := subv.Unmarshal(&bccspConfig, opts); err != nil {
return errors.WithMessage(err, "could not decode peer BCCSP configuration")
}
return nil
}
// InitCrypto initializes crypto for this peer
func InitCrypto(mspMgrConfigDir, localMSPID, localMSPType string) error {
// Check whether msp folder existsView on GitHub (pinned to 2736b63f8f)
Solutions
- Ensure peer.yaml contains a peer.BCCSP section (with Security Provider, Default.Provider, etc.) — copy from sampleconfig/peer.yaml.
- Fix YAML indentation so BCCSP is nested under the 'peer:' key.
- Confirm InitConfig ran successfully (FABRIC_CFG_PATH set, file loaded) before InitBCCSPConfig is invoked.
- If configuring programmatically, set the values in the factory.FactoryOpts defaults instead of relying on Viper.
Example fix
// before: peer.yaml missing section
peer:
id: peer0
// after
peer:
id: peer0
BCCSP:
Default: SW
SW:
Hash: SHA2
Security: 256
FileKeyStore:
KeyStore: Defensive patterns
Strategy: validation
Validate before calling
cfgPath := os.Getenv("FABRIC_CFG_PATH")
if _, err := os.Stat(filepath.Join(cfgPath, "peer.yaml")); err == nil {
data, _ := ioutil.ReadFile(filepath.Join(cfgPath, "peer.yaml"))
var raw map[string]interface{}
if yaml.Unmarshal(data, &raw) == nil {
peer, _ := raw["peer"].(map[string]interface{})
if _, ok := peer["BCCSP"]; !ok {
return errors.New("peer.yaml is missing peer.BCCSP section")
}
}
} Try / catch
if err := common.InitBCCSPConfig(factory.GetDefaultOpts()); err != nil {
if strings.Contains(err.Error(), "could not get peer BCCSP configuration") {
return fmt.Errorf("add a peer.BCCSP block to peer.yaml (see fabric sampleconfig): %w", err)
}
return err
} Prevention
- Start from the sampleconfig peer.yaml for your fabric version and edit, don't write configs from scratch.
- Verify YAML indentation keeps BCCSP nested under 'peer:'.
- Validate config files in CI by loading them with viper and asserting required keys exist.
- Ensure InitConfig runs before any InitBCCSPConfig call.
When it happens
Trigger: Calling InitBCCSPConfig (directly or through InitCrypto) after InitConfig loaded a config file that lacks a peer.BCCSP section — e.g. a truncated/minimal peer.yaml, or InitConfig never ran so Viper has no config at all.
Common situations: Using a hand-written or stripped-down peer.yaml that omits peer.BCCSP; loading an orderer.yaml-style file for a peer command; forgetting to call InitConfig (or setting FABRIC_CFG_PATH wrong) so Viper has nothing loaded; YAML indentation putting BCCSP outside the 'peer' block.
Related errors
- Could not find config file. Please make sure that FABRIC_CFG
- Empty policy element
- failed to initialize block verifier function
- block numbers not maintained in index
- transaction IDs not maintained in index
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/8945ac7c13ed3891.
Report an issue: GitHub.