hyperledger/fabric · error

data mismatch

Error message

data mismatch

What it means

As its final check, ValidateCC unmarshals ccdata.Data into a fresh CDSData and requires it to be proto.Equal to the package's stored data. 'data mismatch' means the serialized chaincode data does not equal the data computed from the deployment spec, indicating tampered, stale, or corrupted ChaincodeData.

Source

Thrown at core/common/ccprovider/cdspackage.go:173

	// protobuf will gladly deserialize garbage and there are paths where we assume that
	// a successful unmarshal means everything works but, if it fails, we try to unmarshal
	// into something different.
	if !isPrintable(ccdata.Name) {
		return fmt.Errorf("invalid chaincode name: %q", ccdata.Name)
	}

	if ccdata.Name != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Name || ccdata.Version != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Version {
		return fmt.Errorf("invalid chaincode data %v (%v)", ccdata, ccpack.depSpec.ChaincodeSpec.ChaincodeId)
	}

	otherdata := &CDSData{}
	err := proto.Unmarshal(ccdata.Data, otherdata)
	if err != nil {
		return err
	}

	if !proto.Equal(ccpack.data, otherdata) {
		return errors.New("data mismatch")
	}

	return nil
}

// InitFromBuffer sets the buffer if valid and returns ChaincodeData
func (ccpack *CDSPackage) InitFromBuffer(buf []byte) (*ChaincodeData, error) {
	depSpec := &pb.ChaincodeDeploymentSpec{}
	err := proto.Unmarshal(buf, depSpec)
	if err != nil {
		return nil, errors.New("failed to unmarshal deployment spec from bytes")
	}

	databytes, id, data, err := ccpack.getCDSData(depSpec)
	if err != nil {
		return nil, err
	}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Regenerate ChaincodeData from the current package via InitFromBuffer/InitFromPath
  2. Reinstall the chaincode so stored data matches the deployment spec
  3. Verify the chaincode source/binaries were not modified after packaging
  4. Ensure all peers use the same package bytes for the same name:version

Example fix

// before
staleCCData.Data = oldDataBytes // from previous build
// after
ccdata, err := ccpack.InitFromBuffer(currentBuf) // recomputed matching data
Defensive patterns

Strategy: validation

Validate before calling

// verify data integrity before validate
other := &ccprovider.CDSData{}
if err := proto.Unmarshal(ccdata.Data, other); err != nil {
    return fmt.Errorf("corrupt chaincode data blob: %w", err)
}
// rebuild expected data from the same CDS to compare
_, _, expected, err := computeCDSData(depSpec)
if err != nil { return err }
if !proto.Equal(expected, other) {
    return errors.New("stale or tampered chaincode data; reinstall required")
}

Try / catch

if err := ccpack.ValidateCC(ccdata); err != nil {
    if err.Error() == "data mismatch" {
        // force repackage/reinstall path
        return fmt.Errorf("chaincode data does not match package, reinstall: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: ccdata.Data was produced from a different CDS than the package's depSpec — e.g. chaincode code changed after data was computed, metadata from one install paired with a package from another, or bytes corrupted in storage.

Common situations: Rebuilding a chaincode binary without reinstalling (hash changes); swapping package files while reusing old ChaincodeData; version-skew between peers.

Related errors


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