hyperledger/fabric · error

history database is not enabled

Error message

history database is not enabled

What it means

HandleGetHistoryForKey guard: the peer answered a GetHistoryForKey query but the ledger history database is disabled in core.yaml (ledger.history.enableHistoryDatabase=false), so no history can be served.

Source

Thrown at core/chaincode/handler.go:1011

	if payload == nil {
		txContext.CleanupQueryContext(iterID)
		return nil, errors.New("marshal failed: proto: Marshal called with nil")
	}

	payloadBytes, err := proto.Marshal(payload)
	if err != nil {
		txContext.CleanupQueryContext(iterID)
		return nil, errors.Wrap(err, "marshal failed")
	}

	chaincodeLogger.Debugf("Got keys and values. Sending %s", pb.ChaincodeMessage_RESPONSE)
	return &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Payload: payloadBytes, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil
}

// Handles query to ledger history db
func (h *Handler) HandleGetHistoryForKey(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) {
	if txContext.HistoryQueryExecutor == nil {
		return nil, errors.New("history database is not enabled")
	}
	iterID := h.UUIDGenerator.New()
	namespaceID := txContext.NamespaceID

	getHistoryForKey := &pb.GetHistoryForKey{}
	err := proto.Unmarshal(msg.Payload, getHistoryForKey)
	if err != nil {
		return nil, errors.Wrap(err, "unmarshal failed")
	}

	historyIter, err := txContext.HistoryQueryExecutor.GetHistoryForKey(namespaceID, getHistoryForKey.Key)
	if err != nil {
		return nil, errors.WithStack(err)
	}

	totalReturnLimit := h.calculateTotalReturnLimit(nil)

	txContext.InitializeQueryContext(iterID, historyIter)

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Set ledger.history.enableHistoryDatabase: true and restart the peer (history accrues from then on)
  2. Rewrite the chaincode to avoid GetHistoryForKey if history is intentionally disabled
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at core/chaincode/handler.go:1011 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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