hyperledger/fabric · error

stateFetcher not passed in init

Error message

stateFetcher not passed in init

What it means

Init() of the built-in validation (VSCC) handler returns this error when the StateFetcher dependency was not supplied. The handler needs a StateFetcher to read chaincode state (e.g. instantiation policies and collection configs) during transaction validation, so it refuses to initialize without one. This is a startup-time wiring error, not a runtime failure.

Source

Thrown at core/handlers/validation/builtin/default_validation.go:128

	for _, dep := range dependencies {
		if deserializer, isIdentityDeserializer := dep.(vi.IdentityDeserializer); isIdentityDeserializer {
			d = deserializer
		}
		if capabilities, isCapabilities := dep.(vc.Capabilities); isCapabilities {
			c = capabilities
		}
		if stateFetcher, isStateFetcher := dep.(vs.StateFetcher); isStateFetcher {
			sf = stateFetcher
		}
		if policyEvaluator, isPolicyFetcher := dep.(vp.PolicyEvaluator); isPolicyFetcher {
			pe = policyEvaluator
		}
		if collectionResources, isCollectionResources := dep.(plugindispatcher.CollectionResources); isCollectionResources {
			cor = collectionResources
		}
	}
	if sf == nil {
		return errors.New("stateFetcher not passed in init")
	}
	if d == nil {
		return errors.New("identityDeserializer not passed in init")
	}
	if c == nil {
		return errors.New("capabilities not passed in init")
	}
	if pe == nil {
		return errors.New("policy fetcher not passed in init")
	}
	if cor == nil {
		return errors.New("collection resources not passed in init")
	}

	v.Capabilities = c
	v.TxValidatorV1_2 = v12.New(c, sf, d, pe)
	v.TxValidatorV1_3 = v13.New(c, sf, d, pe)
	v.TxValidatorV2_0 = v20.New(c, sf, d, pe, cor)

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Pass a valid StateFetcher in the dependencies map supplied to Init()
  2. Check that the dependency factory/builder that constructs the validation handler is invoked after the ledger/StateFetcher is available
  3. Add an early assertion in tests that all of sf, d, c, pe, cor are non-nil before calling Init

Example fix

// before
handler := &DefaultValidation{}
err := handler.Init(nil, deserializer, capabilities, policyEvaluator, collectionResources)
// after
sf := &statefetcher.Fetcher{...}
err := handler.Init(sf, deserializer, capabilities, policyEvaluator, collectionResources)
Defensive patterns

Strategy: validation

Validate before calling

if sf == nil {
    return errors.New("cannot init validation handler: StateFetcher dependency is nil")
}
err := handler.Init(sf, d, c, pe, cor)

Type guard

func depsComplete(sf StateFetcher) bool { return sf != nil }

Prevention

When it happens

Trigger: Calling Init() with sf == nil: constructing the DefaultValidation handler (or the v12 validator built on it) without registering a StateFetcher in the dependency map passed to Init.

Common situations: Booting a peer with a custom validation plugin assembly that forgets to provide the StateFetcher; unit-testing the validator with a partial dependency set; refactoring dependency injection code and dropping one key.

Related errors


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