{"record":{"id":"2c8ec214a74f699f","repo":"hyperledger/fabric","slug":"attempted-to-set-key-s-to-version-d-but-key-doe","errorCode":null,"errorMessage":"attempted to set key %s to version %d, but key does not exist","messagePattern":"attempted to set key (.+?) to version (.+?), but key does not exist","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/configtx/update.go","lineNumber":82,"sourceCode":"\t}\n\treturn nil\n}\n\nfunc (vi *ValidatorImpl) verifyDeltaSet(deltaSet map[string]comparable, signedData []*protoutil.SignedData) error {\n\tif len(deltaSet) == 0 {\n\t\treturn errors.Errorf(\"delta set was empty -- update would have no effect\")\n\t}\n\n\tfor key, value := range deltaSet {\n\t\tlogger.Debugf(\"Processing change to key: %s\", key)\n\t\tif err := validateModPolicy(value.modPolicy()); err != nil {\n\t\t\treturn errors.Wrapf(err, \"invalid mod_policy for element %s\", key)\n\t\t}\n\n\t\texisting, ok := vi.configMap[key]\n\t\tif !ok {\n\t\t\tif value.version() != 0 {\n\t\t\t\treturn errors.Errorf(\"attempted to set key %s to version %d, but key does not exist\", key, value.version())\n\t\t\t}\n\n\t\t\tcontinue\n\t\t}\n\t\tif value.version() != existing.version()+1 {\n\t\t\treturn errors.Errorf(\"attempt to set key %s to version %d, but key is at version %d\", key, value.version(), existing.version())\n\t\t}\n\n\t\tpolicy, ok := vi.policyForItem(existing)\n\t\tif !ok {\n\t\t\treturn errors.Errorf(\"unexpected missing policy %s for item %s\", existing.modPolicy(), key)\n\t\t}\n\n\t\t// Ensure the policy is satisfied\n\t\tif err := policy.EvaluateSignedData(signedData); err != nil {\n\t\t\tlogger.Warnw(\"policy not satisfied for channel configuration update\", \"key\", key, \"policy\", policy, \"signingIdenties\", protoutil.LogMessageForSerializedIdentities(signedData))\n\t\t\treturn errors.Wrapf(err, \"policy for %s not satisfied\", key)\n\t\t}","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/configtx/update.go#L64-L100","documentation":"For a new element (absent from the current config map), the proposed version must be 0. This error means the update tries to add a key that doesn't currently exist but assigns it a non-zero version, which is inconsistent with how the versioning works.","triggerScenarios":"A delta-set entry for a key not in configMap with version() != 0 — e.g. reusing a cached comparable from an old config where the element previously existed but has since been deleted.","commonSituations":"Re-adding a removed org/group while carrying the old version number; copying a delta set from a different channel config.","solutions":["Set the new element's Version to 0 when adding a key that does not exist in current config.","Rebuild the write set from the current config rather than cached comparisons.","If the element should exist, first check whether a concurrent update deleted it and reconcile."],"exampleFix":"// before\ndelta[\"/Channel/Application/Org4\"] = comparable{ConfigGroup: &cb.ConfigGroup{Version: 2}} // key absent\n// after\ndelta[\"/Channel/Application/Org4\"] = comparable{ConfigGroup: &cb.ConfigGroup{Version: 0}}","handlingStrategy":"validation","validationCode":"if _, ok := currentConfigMap[key]; !ok && value.version() != 0 {\n  return fmt.Errorf(\"new key %s must have version 0\", key)\n}","typeGuard":"func newElementVersionOK(key string, value comparable, current map[string]comparable) bool {\n  _, exists := current[key]\n  return exists || value.version() == 0\n}","tryCatchPattern":"err := validator.ProposeUpdate(env)\nif err != nil && strings.Contains(err.Error(), \"but key does not exist\") {\n  resetVersionsToZeroForNewKeys(deltaSet, currentConfigMap)\n  env = rebuildEnvelope(deltaSet) // rebuild and retry once\n}","preventionTips":["Reset Version to 0 whenever adding an element absent from current config","Never reuse comparable values cached from older configs","Recompute write sets from the latest config on every submission"],"tags":["hyperledger-fabric","configtx","version-conflict"],"backgroundTag":"config-version-conflict","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}