hyperledger/fabric · error

lscc's state for [%s] is invalid, policy field must be set

Error message

lscc's state for [%s] is invalid, policy field must be set

What it means

The lscc ChaincodeData record has no endorsement policy bytes (cd.Policy is empty). The endorsement policy is mandatory because VSCC uses it to decide whether the transaction's endorsements satisfy the required signature set. Records lacking it are rejected with this error.

Source

Thrown at core/committer/txvalidator/v14/vscc_validator.go:322

		}
	}

	if bytes == nil {
		return nil, errors.Errorf("lscc's state for [%s] not found.", ccid)
	}

	cd := &ccprovider.ChaincodeData{}
	err = proto.Unmarshal(bytes, cd)
	if err != nil {
		return nil, errors.Wrap(err, "unmarshalling ChaincodeQueryResponse failed")
	}

	if cd.Vscc == "" {
		return nil, errors.Errorf("lscc's state for [%s] is invalid, vscc field must be set", ccid)
	}

	if len(cd.Policy) == 0 {
		return nil, errors.Errorf("lscc's state for [%s] is invalid, policy field must be set", ccid)
	}

	return cd, err
}

// GetInfoForValidate gets the ChaincodeInstance(with latest version) of tx, vscc and policy from lscc
func (v *VsccValidatorImpl) GetInfoForValidate(chdr *common.ChannelHeader, ccID string) (*sysccprovider.ChaincodeInstance, *sysccprovider.ChaincodeInstance, []byte, error) {
	cc := &sysccprovider.ChaincodeInstance{
		ChannelID:     chdr.ChannelId,
		ChaincodeName: ccID,
	}
	vscc := &sysccprovider.ChaincodeInstance{
		ChannelID:     chdr.ChannelId,
		ChaincodeName: "vscc", // default vscc for system chaincodes
	}
	var policy []byte
	var err error
	if !IsSysCC(ccID) {

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Upgrade/re-instantiate the chaincode with a valid endorsement policy (e.g. -P "AND('Org1MSP.member','Org2MSP.member')")
  2. Verify the policy expression syntax resolves against the channel's MSPs
  3. Rebuild the state database if lscc records are corrupted
  4. If using custom lifecycle tooling, ensure it populates the Policy field in ChaincodeData

Example fix

// before
peer chaincode instantiate -C mychannel -n mycc -v 1.0 -c '{...}' -P ""
// after
peer chaincode instantiate -C mychannel -n mycc -v 1.0 -c '{...}' -P "AND('Org1MSP.member')"
Defensive patterns

Strategy: validation

Validate before calling

const policy = parsePolicyString(args.endorsementPolicy);
if (!policy || policy.trim() === '') throw new Error('endorsement policy required');

Type guard

function hasPolicy(cd) {
  return cd && Array.isArray(cd.policy) && cd.policy.length > 0;
}

Try / catch

try { await instantiate(cc, {policy}); } catch (e) {
  if (String(e).includes('policy field must be set')) { /* upgrade with a valid -P policy */ }
}

Prevention

When it happens

Trigger: getCDataForCC validates cd.Vscc then checks len(cd.Policy) == 0 — the lscc record was written without an endorsement policy, e.g. deployment with an empty/unresolvable -P policy.

Common situations: Instantiation with a malformed or empty endorsement policy expression; corrupted lscc state; custom lifecycle tooling omitting the policy field; failed policy parsing at deploy time.

Related errors


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