types

package
v0.61.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockBlobKeyPrefix         = "bp"
	BlockBlobIndexKeyPrefix    = "bi"
	BlockBlobMetadataKeySuffix = "_metadata"
	UtxoBlobKeyPrefix          = "u"
	TxBlobKeyPrefix            = "t"
)
View Source
const (
	// StorageModeCore stores only consensus and chain state data.
	StorageModeCore = "core"
	// StorageModeAPI stores everything needed for API queries.
	StorageModeAPI = "api"
)

Storage mode constants shared by the metadata plugins.

View Source
const BlockBlobKeySize = 2 + 8 + 32

BlockBlobKeySize is the on-disk length of a fully-formed block bp key: prefix (2) + slot (8) + hash (32) = 42 bytes. Plugins use this to decide whether a key is a base bp key (vs a metadata-suffixed one).

View Source
const BlockHashIndexKeyPrefix = "bh"

BlockHashIndexKeyPrefix is the key prefix for the hash→block-key index. Key format: "bh" + hash(32 bytes), value: BlockBlobKey (slot+hash).

Variables

View Source
var BlockTombstoneMagic = [4]byte{'D', 'B', 'T', '1'}

BlockTombstoneMagic is the four-byte prefix that identifies an expired history marker stored at a block's bp key. The bytes "DBT1" do not appear at the start of any valid Cardano block CBOR (blocks begin with a CBOR array header byte such as 0x82/0x83), so detection is unambiguous.

View Source
var ErrBlobKeyNotFound = errors.New("blob key not found")

ErrBlobKeyNotFound is returned by blob operations when a key is missing

View Source
var ErrBlobStoreUnavailable = errors.New("blob store unavailable")

ErrBlobStoreUnavailable is returned when blob store cannot be accessed

View Source
var ErrBlockTombstoned = ErrHistoryExpired

ErrBlockTombstoned and BlockTombstonedError are retained as aliases for older callers. New code should use ErrHistoryExpired and HistoryExpiredError.

View Source
var ErrHistoryExpired = errors.New("history expired")

ErrHistoryExpired is returned when a block's local CBOR has expired from history storage. Callers can use errors.Is(err, ErrHistoryExpired) for existence checks. To get the (slot, hash), use errors.As to extract a *HistoryExpiredError. Archive-proxy wrappers can intercept this typed error and resolve the block from remote history; unwrapped consumers should surface the condition as unavailable expired history.

View Source
var ErrNilTxn = errors.New("nil transaction")

ErrNilTxn is returned when a nil transaction is provided where a valid transaction is required

View Source
var ErrNoEpochData = errors.New(
	"no epoch data available for requested slot",
)

ErrNoEpochData is returned when epoch data has not been synced yet for the requested slot. Callers should distinguish this from "no active pools" and handle it appropriately (e.g., retry after sync progresses).

View Source
var ErrNoStoreAvailable = errors.New("no store available")

ErrNoStoreAvailable is returned when no blob or metadata store is available

View Source
var ErrPartialCommit = errors.New(
	"partial commit: blob committed but metadata failed",
)

ErrPartialCommit is returned when blob commits but metadata fails, leaving the database in an inconsistent state that requires recovery.

View Source
var ErrTxnWrongType = errors.New("invalid transaction type")

ErrTxnWrongType is returned when a transaction has the wrong type

View Source
var ErrUtxoConflict = errors.New("UTxO already spent")

ErrUtxoConflict is returned when a UTxO spend fails because the UTxO was already consumed by another transaction or restored by a rollback. This sentinel error allows callers to distinguish optimistic locking conflicts from other errors and retry or reject accordingly.

View Source
var ErrUtxoNotFound = errors.New("utxo not found")

ErrUtxoNotFound is returned when a requested UTxO row does not exist.

Functions

func BlockBlobIndexKey added in v0.20.0

func BlockBlobIndexKey(blockNumber uint64) []byte

func BlockBlobKey added in v0.20.0

func BlockBlobKey(slot uint64, hash []byte) []byte

func BlockBlobKeyUint64ToBytes added in v0.20.0

func BlockBlobKeyUint64ToBytes(input uint64) []byte

func BlockBlobMetadataKey added in v0.20.0

func BlockBlobMetadataKey(baseKey []byte) []byte

func BlockHashIndexKey added in v0.35.0

func BlockHashIndexKey(hash []byte) []byte

BlockHashIndexKey builds the key for a hash→slot lookup index entry.

func BlockTombstone added in v0.39.1

func BlockTombstone() []byte

BlockTombstone returns a fresh copy of the tombstone marker that replaces a block's CBOR when the block has expired from local history. The marker carries no embedded (slot, hash) — the bp key already does, and surfacing the typed HistoryExpiredError is the responsibility of each blob plugin (which knows its own key format).

func IsBlockTombstone added in v0.39.1

func IsBlockTombstone(data []byte) bool

IsBlockTombstone reports whether the given bytes are a tombstone marker. Tested by prefix so any payload starting with the magic is treated as a tombstone — a partial or unexpectedly extended marker must never be misread as block CBOR.

func ParseBlockBlobKey added in v0.39.1

func ParseBlockBlobKey(key []byte) (uint64, []byte, error)

ParseBlockBlobKey is the inverse of BlockBlobKey: it pulls (slot, hash) back out of a fully-formed bp key. Used by blob plugins that need to attach the (slot, hash) of a tombstoned block to a typed error surfaced from iteration. Returns an error for any key whose shape doesn't match what BlockBlobKey produced.

func TxBlobKey added in v0.22.0

func TxBlobKey(txHash []byte) []byte

TxBlobKey creates a key for storing transaction offset data. Key format: 't' + txHash (32 bytes)

func UtxoBlobKey added in v0.20.0

func UtxoBlobKey(txId []byte, outputIdx uint32) []byte

Types

type BackfillHotPathStats added in v0.50.0

type BackfillHotPathStats struct {
	Blocks    uint64
	Txs       uint64
	Utxos     uint64
	InputRefs uint64

	BlobTxOffsetWrites   uint64
	BlobUtxoOffsetWrites uint64
	SkippedUtxoOffsets   uint64
	SkippedInputRecovery uint64

	AddressTxs      uint64
	Witnesses       uint64
	Scripts         uint64
	WitnessScripts  uint64
	PlutusData      uint64
	Redeemers       uint64
	UtxoSpends      uint64
	CollateralRets  uint64
	DeleteTxIDs     uint64
	Certificates    uint64
	MetadataLabels  uint64
	PParamUpdates   uint64
	RecoveredInputs uint64

	BlockReadDecode       time.Duration
	OffsetComputation     time.Duration
	BlobOffsetWrites      time.Duration
	SetTransactionBatched time.Duration
	ConsumedInputRecovery time.Duration
	UtxoAddressLookup     time.Duration
	AddressIndex          time.Duration
	FlushBatch            time.Duration
	CheckpointWrites      time.Duration
}

BackfillHotPathStats captures low-overhead interval counters for API-mode Mithril metadata backfill. Callers aggregate these per progress interval so dense and sparse historical ranges can be compared without pprof.

func (*BackfillHotPathStats) Add added in v0.50.0

Add folds another stats snapshot into s.

func (*BackfillHotPathStats) Reset added in v0.50.0

func (s *BackfillHotPathStats) Reset()

Reset clears the interval counters while preserving the allocation.

type BlobItem added in v0.19.0

type BlobItem interface {
	Key() []byte
	ValueCopy(dst []byte) ([]byte, error)
}

BlobItem represents a value returned by an iterator

type BlobIterator added in v0.19.0

type BlobIterator interface {
	Rewind()
	Seek(prefix []byte)
	Valid() bool
	ValidForPrefix(prefix []byte) bool
	Next()
	Item() BlobItem
	Close()
	Err() error
}

BlobIterator provides key iteration over the blob store.

Important lifecycle constraint: items returned by `Item()` must only be accessed while the underlying transaction used to create the iterator is still active. Implementations may validate transaction state at access time (for example `ValueCopy` may fail if the transaction has been committed or rolled back). Typical usage iterates and accesses item values within the same transaction scope.

type BlobIteratorOptions added in v0.19.0

type BlobIteratorOptions struct {
	Prefix  []byte
	Reverse bool
}

BlobIteratorOptions configures blob iterator creation

type BlockMetadata added in v0.20.0

type BlockMetadata struct {
	cbor.StructAsArray
	ID       uint64
	Type     uint
	Height   uint64
	PrevHash []byte
}

BlockMetadata contains metadata for a block stored in blob. IMPORTANT: Field order must remain [ID, Type, Height, PrevHash] because cbor.StructAsArray encodes/decodes by position. Changing the order would break deserialization of existing stored data.

type BlockTombstonedError added in v0.39.1

type BlockTombstonedError = HistoryExpiredError

type HistoryExpiredError added in v0.52.0

type HistoryExpiredError struct {
	Slot uint64
	Hash []byte
}

HistoryExpiredError is the typed form of ErrHistoryExpired, returned by blob plugins when GetBlock or iterator ValueCopy observe an expired block. It carries the (slot, hash) so archive-proxy wrappers can resolve it without parsing blob keys — the wrapper extracts it via:

var h *types.HistoryExpiredError
if errors.As(err, &h) { fetchFromArchive(h.Slot, h.Hash) }

func (*HistoryExpiredError) Error added in v0.52.0

func (e *HistoryExpiredError) Error() string

func (*HistoryExpiredError) Unwrap added in v0.52.0

func (e *HistoryExpiredError) Unwrap() error

Unwrap returns ErrHistoryExpired so errors.Is(err, ErrHistoryExpired) keeps working for callers that only need to detect the condition.

type MetadataBatchAccumulator added in v0.45.0

type MetadataBatchAccumulator interface {
	Reset()
}

MetadataBatchAccumulator is an opaque plugin-owned accumulator used by metadata stores that support batched transaction ingestion.

type NodeSettings added in v0.31.0

type NodeSettings struct {
	StorageMode string
	Network     string
}

NodeSettings holds immutable node configuration that is persisted on first sync and enforced on every subsequent startup.

type NullableHash added in v0.58.0

type NullableHash []byte

NullableHash is a byte slice that serializes to SQL NULL when empty, rather than to an empty blob. It is used for nullable foreign-key columns that reference transaction(hash) (e.g. utxo.spent_at_tx_id) and are unset until the UTxO is spent/referenced.

Without a custom driver.Valuer, an empty/nil []byte can be bound by some GORM + SQLite driver versions as an empty blob instead of SQL NULL. SQLite enforces FK constraints against an empty blob (no transaction has an empty hash), so such a row fails with SQLITE_CONSTRAINT_FOREIGNKEY (787). This affects every UTxO not yet spent/referenced, including all genesis UTxOs. Returning a nil driver.Value guarantees SQL NULL on every driver version, so the FK is correctly skipped.

func (*NullableHash) Scan added in v0.58.0

func (h *NullableHash) Scan(val any) error

Scan implements sql.Scanner.

func (NullableHash) Value added in v0.58.0

func (h NullableHash) Value() (driver.Value, error)

Value implements driver.Valuer. An empty (or nil) slice serializes to SQL NULL; a non-empty slice serializes to its bytes.

type Rat

type Rat struct {
	*big.Rat
}

func (*Rat) Scan

func (r *Rat) Scan(val any) error

func (Rat) Value

func (r Rat) Value() (driver.Value, error)

type SignedURL added in v0.22.0

type SignedURL struct {
	URL     url.URL
	Expires time.Time
}

SignedURL is a url that has been pre-signed and has an expiration time

type Txn added in v0.19.0

type Txn interface {
	Commit() error
	Rollback() error
}

Txn is a simple transaction handle for commit/rollback only. Database layer (Txn) coordinates metadata and blob operations separately.

type Uint64

type Uint64 uint64

func (*Uint64) Scan

func (u *Uint64) Scan(val any) error

func (Uint64) Value

func (u Uint64) Value() (driver.Value, error)

type UtxoKey added in v0.37.0

type UtxoKey struct {
	TxId      []byte
	OutputIdx uint32
}

UtxoKey identifies a UTxO row by its transaction id and output index. Used as a parameter type for batch UTxO operations across the metadata-store interface (e.g. MarkUtxosDeletedAtSlot). The fixed-size UtxoRef in database/cbor_cache.go is for in-memory map keys; this variable-length form matches the byte slices stored on the UTxO row directly.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL