hyperledger/fabric · error
failed marshaling signed data
Error message
failed marshaling signed data
What it means
signedDataToKey in discovery/authcache.go:191 marshals protoutil.SignedData to bytes (asBytes), SHA-256 hashes them, and hex-encodes the result as the eligibility cache key. If asBytes fails to marshal the data, the error is wrapped with 'failed marshaling signed data' and propagated to EligibleForService.
Solutions
- Ensure SignedData fields (Identity, Data, Signature) contain valid, non-nil byte slices produced by the normal signing flow
- Validate the client certificate/identity bytes are well-formed before making discovery requests
- Check the wrapped inner error (%+v) to identify the exact marshaling failure
- If in tests, use valid fixture identities instead of hand-crafted byte slices
Example fix
// before: nil signature in SignedData
sd := protoutil.SignedData{Identity: idBytes, Data: msg}
// after: fully populated SignedData
sig, err := signer.Sign(msg)
if err != nil { return err }
sd := protoutil.SignedData{Identity: idBytes, Data: msg, Signature: sig} Defensive patterns
Strategy: validation
Validate before calling
if _, err := proto.Marshal(&pb.SerializedIdentity{IdBytes: sd.Identity}); err != nil {
return fmt.Errorf("invalid identity bytes: %w", err)
} Try / catch
key, err := signedDataToKey(data)
if err != nil {
return fmt.Errorf("cannot cache eligibility: %w", err) // surfaces 'failed marshaling signed data' cause
} Prevention
- Never hand-craft SignedData byte fields; derive them from the standard signing flow
- Validate client certificates parse as X.509 before sending discovery requests
- In tests, use realistic identity fixtures
When it happens
Trigger: Direct calls from EligibleForService (or the test TestSignedDataToKey) with a SignedData struct whose Identity/Data/Signature fields cannot be proto-marshaled into bytes.
Common situations: Identity bytes that are not valid protobuf-encodable content; nil or corrupted identity/signature slices; test fixtures with malformed SignedData.
Related errors
- failed computing key of signed data
- access denied, no authentication info in request
- cannot marshal metadata for orderer type
- chaincode interest is nil
- could not decode the PEM structure
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/b5b0465dcadd7f26.
Report an issue: GitHub.
Appendix: source
Thrown at discovery/authcache.go:191
cache.Lock()
defer cache.Unlock()
cache.lastSequence = currSeq
// Invalidate entries
cache.entries = make(map[string]error)
}
func (cache *accessCache) lookup(key string) (cacheHit bool, lookupResult error) {
cache.RLock()
defer cache.RUnlock()
lookupResult, cacheHit = cache.entries[key]
return
}
func signedDataToKey(data protoutil.SignedData) (string, error) {
b, err := asBytes(data)
if err != nil {
return "", errors.Wrap(err, "failed marshaling signed data")
}
return hex.EncodeToString(util.ComputeSHA256(b)), nil
}
View on GitHub (pinned to 2736b63f8f)