hyperledger/fabric · error

policy not found

Error message

policy not found

What it means

Thrown by computePrincipalSets when PoliciesByChaincode returns no inquireable policies for a chaincode (and its collections) on the given channel. This means the discovery service has no endorsement policy registered for that chaincode namespace, usually because the chaincode is not installed/committed (or not known) on the peers serving discovery, so no principal sets can be computed for endorsement selection.

Source

Thrown at discovery/endorsement/endorsement.go:268

		logger.Debugf("Merging state based policies: %v --> %v", stateBasedCPS, stateBasedPrincipalSet)

		return stateBasedPrincipalSet, nil
	}

	logger.Debugf("No state based policies requested")

	return nil, nil
}

func (ea *endorsementAnalyzer) computePrincipalSets(channelID common.ChannelID, interest *peer.ChaincodeInterest) (policies.PrincipalSets, error) {
	sessionLogger := logger.With("channel", string(channelID))
	var inquireablePoliciesForChaincodeAndCollections []policies.InquireablePolicy
	for _, chaincode := range interest.Chaincodes {
		policies := ea.PoliciesByChaincode(string(channelID), chaincode.Name, chaincode.CollectionNames...)
		if len(policies) == 0 {
			sessionLogger.Debug("Policy for chaincode '", chaincode, "'doesn't exist")
			return nil, errors.New("policy not found")
		}
		if chaincode.DisregardNamespacePolicy && len(chaincode.KeyPolicies) == 0 && len(policies) == 1 {
			sessionLogger.Warnf("Client requested to disregard chaincode %s's policy, but it did not specify any "+
				"collection policies or key policies. This is probably a bug in the client side code, as the client should"+
				"either not specify DisregardNamespacePolicy, or specify at least one key policy or at least one collection policy", chaincode.Name)
			return nil, errors.Errorf("requested to disregard chaincode %s's policy but key and collection policies are missing, either "+
				"disable DisregardNamespacePolicy or specify at least one key policy or at least one collection policy", chaincode.Name)
		}
		if chaincode.DisregardNamespacePolicy {
			if len(policies) == 1 {
				sessionLogger.Debugf("Client requested to disregard the namespace policy for chaincode %s,"+
					" and no collection policies are present", chaincode.Name)
				continue
			}
			sessionLogger.Debugf("Client requested to disregard the namespace policy for chaincode %s,"+
				" however there exist %d collection policies taken into account", chaincode.Name, len(policies)-1)
			policies = policies[1:]
		}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Verify the chaincode name spelling and that the query targets the correct channel
  2. Confirm the chaincode is installed and committed on the peers responding to discovery (peer lifecycle chaincode querycommitted)
  3. Re-check after commit completes / peer gossip syncs definitions
  4. If using collections, ensure collection names passed to the query are defined in the committed collection config

Example fix

// before
discoveryCli.PeersForEndorsement(ctx, interestWith("asset-transfer2")) // typo
// after
discoveryCli.PeersForEndorsement(ctx, interestWith("asset-transfer"))
Defensive patterns

Strategy: validation

Validate before calling

committed, _ := lc.QueryCommitted(ctx, channel, ccName)
if len(committed) == 0 { return fmt.Errorf("chaincode %s not committed on %s", ccName, channel) }

Type guard

func chaincodeKnown(name string, committed []lifecycle.ChaincodeDefinition) bool {
  for _, c := range committed { if c.Name == name { return true } }
  return false
}

Try / catch

peers, err := client.PeersForEndorsement(ctx, interest)
if err != nil && strings.Contains(err.Error(), "policy not found") {
  // verify chaincode name/channel and commit state before retry
}

Prevention

When it happens

Trigger: Calling PeersForEndorsement with a ChaincodeInterest whose Chaincodes include a chaincode.Name for which the local peer's lifecycle reports zero policies — chaincode not installed, not committed on the channel, wrong channel, or (pre-v2) not instantiated.

Common situations: Typo in the chaincode name; querying the wrong channel; chaincode committed only on another peer; using discovery before chaincode commit completes; lifecycle mismatch between _lifecycle and legacy LSCC in mixed-version networks.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/9ba3300c4c1a73db. Report an issue: GitHub.