Documentation
¶
Overview ¶
Package database is Dingo's storage abstraction. It provides a single Database type backed by two pluggable layers:
- a Blob store for full block and transaction CBOR — plugins in database/plugin/blob/ (badger [default], gcs, s3)
- a Metadata store for indexed queries over UTxOs, certs, pools, stake snapshots, and governance state — plugins in database/plugin/metadata/ (sqlite [default], postgres, mysql)
Composition code explicitly registers providers on an instance-owned plugin.Host. The selected stores are injected into New; Database does not select providers or own their lifecycle.
CBOR extraction ¶
UTxOs and transactions are not stored as full CBOR in the metadata layer. Instead, each reference is a fixed 52-byte CborOffset (magic "DOFF" + slot + hash + offset + length) that points into the block stored in the blob layer. The TieredCborCache resolves CBOR on demand through three tiers: hot entry cache → block LRU → cold extraction from the blob store.
See database/cbor_offset.go for the offset encoding, database/cbor_cache.go for the cache, and database/block_indexer.go for how per-block offset tables are built.
Writing queries ¶
Avoid N+1 query patterns. When loading state for many entities at once, prefer a single `WHERE id IN ?` batch query over a loop of per-entity reads. When certificates can share a slot, always order by (added_slot, cert_index) from the unified `certs` table as a tie-breaker — cert_index alone is meaningless across slots.
Index ¶
- Constants
- Variables
- func BlobOrphanCount() uint64
- func BlockBeforeSlot(db *Database, slotNumber uint64) (models.Block, error)
- func BlockBeforeSlotTxn(txn *Txn, slotNumber uint64) (models.Block, error)
- func BlockBlobKeyToPoint(key []byte) (ocommon.Point, error)
- func BlockByHash(db *Database, hash []byte) (models.Block, error)
- func BlockByHashStats() (hits, misses uint64)
- func BlockByHashTxn(txn *Txn, hash []byte) (models.Block, error)
- func BlockByNumber(db *Database, number uint64) (models.Block, error)
- func BlockByNumberBounded(db *Database, number uint64, bound BlockNumberBound) (models.Block, error)
- func BlockByNumberBoundedTxn(txn *Txn, number uint64, bound BlockNumberBound) (models.Block, error)
- func BlockByNumberTxn(txn *Txn, number uint64) (models.Block, error)
- func BlockByPoint(db *Database, point ocommon.Point) (models.Block, error)
- func BlockByPointTxn(txn *Txn, point ocommon.Point) (models.Block, error)
- func BlockBySlot(db *Database, slot uint64) (models.Block, error)
- func BlockBySlotTxn(txn *Txn, slot uint64) (models.Block, error)
- func BlockDeleteTxn(txn *Txn, block models.Block) error
- func BlockIDByPointLocal(db *Database, point ocommon.Point) (uint64, error)
- func BlockURL(ctx context.Context, db *Database, point ocommon.Point) (types.SignedURL, types.BlockMetadata, error)
- func BlocksAfterSlotTxn(txn *Txn, slotNumber uint64) ([]models.Block, error)
- func BlocksRecent(db *Database, count int) ([]models.Block, error)
- func BlocksRecentTxn(txn *Txn, count int) ([]models.Block, error)
- func DelegatorInactivityActivationEpoch(d *Database, txn *Txn) (epoch uint64, activated bool, err error)
- func EncodeTxOffset(offset *CborOffset) []byte
- func EncodeUtxoOffset(offset *CborOffset) []byte
- func EpochBySlot(d *Database, slot uint64, txn *Txn) (models.Epoch, error)
- func ForEachBlockInRange(txn *Txn, startSlot, endSlot uint64, fn func(block models.Block) error) error
- func ForEachBlockInRangeDB(db *Database, startSlot, endSlot uint64, fn func(block models.Block) error) error
- func IsTxCborPartsStorage(data []byte) bool
- func IsTxOffsetStorage(data []byte) bool
- func IsUtxoOffsetStorage(data []byte) bool
- func NewTxnPanicError(context string, r any) error
- func RecomputeAccountExpirationsAfterTruncate(d *Database, txn *Txn, delegatorInactivityEnabled bool, ...) error
- func RecomputeSyntheticV2CostModelMarkerAfterTruncate(d *Database, txn *Txn, rollbackSlot uint64) error
- func RegisterBlobOrphanMetrics(reg prometheus.Registerer) error
- func RegisterBlockByHashMetrics(reg prometheus.Registerer) error
- func RegisterTruncateMetrics(reg prometheus.Registerer) error
- func RollbackActivationFloor(ref models.StakeCredentialRef, clampApplies bool, activationEpoch uint64, ...) (uint64, bool)
- func SetSyntheticV2CostModelClearedEpoch(d *Database, txn *Txn, epoch uint64) error
- func SyntheticV2CostModelClearedEpoch(d *Database, txn *Txn) (epoch uint64, cleared bool, err error)
- type BatchAccumulator
- type BatchedTxIngestOpts
- type BlobBlockIterator
- type BlobBlockResult
- type BlockIndexer
- type BlockIngestionResult
- type BlockLRUCache
- type BlockNumberBound
- type CacheMetrics
- func (m *CacheMetrics) IncBlockLRUHit()
- func (m *CacheMetrics) IncBlockLRUMiss()
- func (m *CacheMetrics) IncColdExtraction()
- func (m *CacheMetrics) IncTxHotHit()
- func (m *CacheMetrics) IncTxHotMiss()
- func (m *CacheMetrics) IncUtxoHotHit()
- func (m *CacheMetrics) IncUtxoHotMiss()
- func (m *CacheMetrics) Register(registry prometheus.Registerer)
- type CachedBlock
- type CborCacheConfig
- type CborOffset
- type CommitTimestampError
- type Config
- type Database
- func (d *Database) AccountInactivityActivationMembership(refs []models.StakeCredentialRef, txn *Txn) (map[string]struct{}, error)
- func (d *Database) AccountLastWitnessSlots(refs []models.StakeCredentialRef, maxSlot uint64, txn *Txn) (map[string]uint64, error)
- func (d *Database) AccountsWitnessedAfterSlot(slot uint64, txn *Txn) ([]models.StakeCredentialRef, error)
- func (d *Database) AddAccountRewardByCredential(credentialTag uint8, stakeKey []byte, amount uint64, slot uint64, ...) error
- func (d *Database) AddPostSnapshotAccountRewardByCredential(credentialTag uint8, stakeKey []byte, amount uint64, slot uint64, ...) error
- func (d *Database) ApplyPParamUpdates(slot, epoch uint64, era uint, quorum int, ...) error
- func (d *Database) Blob() blob.BlobStore
- func (d *Database) BlobTxn(readWrite bool) *Txn
- func (d *Database) BlockAtOrAfterIndex(blockIndex uint64, txn *Txn) (models.Block, error)
- func (d *Database) BlockByIndex(blockIndex uint64, txn *Txn) (models.Block, error)
- func (d *Database) BlockCreate(block models.Block, txn *Txn) error
- func (d *Database) BlockPointByIndex(blockIndex uint64, txn *Txn) (ocommon.Point, error)
- func (d *Database) BlocksFromSlot(startSlot uint64) *BlobBlockIterator
- func (d *Database) BlocksInRange(startSlot, endSlot uint64) *BlobBlockIterator
- func (d *Database) CborCache() *TieredCborCache
- func (d *Database) CheckNodeSettings() error
- func (d *Database) ClearCommitteeQuorum(slot uint64, txn *Txn) error
- func (d *Database) ClearDanglingDRepDelegations(atSlot uint64, txn *Txn) (int, error)
- func (d *Database) ClearGovernanceProposalRatification(txHash []byte, actionIndex uint32, transitionSlot uint64, txn *Txn) error
- func (d *Database) ClearSyncState(txn *Txn) error
- func (d *Database) Close() error
- func (d *Database) ComputeAndApplyPParamUpdates(slot, epoch uint64, era uint, quorum int, ...) (lcommon.ProtocolParameters, bool, error)
- func (d *Database) Config() *Config
- func (d *Database) CountAccountDelegationHistoryByCredential(credentialTag uint8, stakeKey []byte, txn *Txn) (int, error)
- func (d *Database) CountAccountRegistrationHistoryByCredential(credentialTag uint8, stakeKey []byte, txn *Txn) (int, error)
- func (d *Database) CountAccountWithdrawalHistoryByCredential(credentialTag uint8, stakeKey []byte, txn *Txn) (int, error)
- func (d *Database) CountAddressTransactionsByCredential(credentialTag uint8, stakeKey []byte, from *models.AddressTransactionPosition, ...) (int, error)
- func (d *Database) CountAddressesByCredential(credentialTag uint8, stakingKey []byte, txn *Txn) (int, error)
- func (d *Database) CountBlocksAndOldestSlot(txn *Txn) (count uint64, oldestSlot uint64, err error)
- func (d *Database) CountRewardAccountOutputsByCredential(credentialTag uint8, stakingKey []byte, txn *Txn) (int, error)
- func (d *Database) CountTransactionsByAddress(addr lcommon.Address, txn *Txn) (int, error)
- func (d *Database) CountTransactionsByAddressKeys(paymentKey []byte, credentialTag uint8, stakingKey []byte, txn *Txn) (int, error)
- func (d *Database) CountTransactionsByMetadataLabel(label uint64, txn *Txn) (int, error)
- func (d *Database) CountTransactionsByPaymentCred(paymentKey []byte, txn *Txn) (int, error)
- func (d *Database) CountUtxosByAddressWithOrdering(q *models.UtxoWithOrderingQuery, txn *Txn) (int, error)
- func (d *Database) CreateAccount(txn *Txn, account *models.Account) error
- func (d *Database) CreateDrep(txn *Txn, drep *models.Drep) error
- func (d *Database) CreateUtxo(txn *Txn, utxo *models.Utxo) error
- func (d *Database) DataDir() string
- func (d *Database) DeleteAccountRewardsAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeleteBlockNoncesAfterPoint(point ocommon.Point, txn *Txn) error
- func (d *Database) DeleteBlockNoncesBeforeSlot(slotNumber uint64, txn *Txn) error
- func (d *Database) DeleteBlockNoncesBeforeSlotWithoutCheckpoints(slotNumber uint64, txn *Txn) error
- func (d *Database) DeleteCertificatesAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeleteCommitteeMembersAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeleteConstitutionsAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeleteEpochsAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeleteGovernanceProposalsAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeleteGovernanceVotesAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeleteNetworkDonationsAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeleteNetworkStateAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeletePParamUpdatesAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeletePParamsAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeleteRewardStateAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) DeleteSyncState(key string, txn *Txn) error
- func (d *Database) DeleteTransactionMetadataLabelsAfterSlot(slot uint64, txn *Txn) error
- func (d *Database) EnforceNodeSettings(values nodesettings.Values) error
- func (d *Database) FlushBatch(acc BatchAccumulator, txn *Txn) error
- func (d *Database) ForecastPParamUpdates(epoch uint64, quorum int, currentPParams lcommon.ProtocolParameters, ...) (lcommon.ProtocolParameters, error)
- func (d *Database) GetAccountByCredential(credentialTag uint8, stakeKey []byte, includeInactive bool, txn *Txn) (*models.Account, error)
- func (d *Database) GetAccountDelegationHistoryByCredential(credentialTag uint8, stakeKey []byte, limit int, offset int, order string, ...) ([]models.AccountDelegationHistoryRow, error)
- func (d *Database) GetAccountImportRegistrationByCredential(credentialTag uint8, stakeKey []byte, txn *Txn) (*models.AccountImportRegistration, error)
- func (d *Database) GetAccountRegistrationHistoryByCredential(credentialTag uint8, stakeKey []byte, limit int, offset int, order string, ...) ([]models.AccountRegistrationHistoryRow, error)
- func (d *Database) GetAccountSumsByCredential(credentialTag uint8, stakeKey []byte, txn *Txn) (models.AccountSums, error)
- func (d *Database) GetAccountWithdrawalHistoryByCredential(credentialTag uint8, stakeKey []byte, limit int, offset int, order string, ...) ([]models.AccountWithdrawalHistoryRow, error)
- func (d *Database) GetAccountsByCredential(refs []models.StakeCredentialRef, includeInactive bool, txn *Txn) (map[string]*models.Account, error)
- func (d *Database) GetActiveCommitteeMembers(txn *Txn) ([]*models.AuthCommitteeHot, error)
- func (d *Database) GetActiveDreps(txn *Txn) ([]*models.Drep, error)
- func (d *Database) GetActiveGovernanceProposals(epoch uint64, txn *Txn) ([]*models.GovernanceProposal, error)
- func (d *Database) GetActivePoolKeyHashes(txn *Txn) ([][]byte, error)
- func (d *Database) GetActivePoolKeyHashesOrdered(txn *Txn) ([][]byte, error)
- func (d *Database) GetActivePoolRelays(txn *Txn) ([]models.PoolRegistrationRelay, error)
- func (d *Database) GetAddressTransactionsByCredential(credentialTag uint8, stakeKey []byte, limit int, offset int, order string, ...) ([]models.AccountTransactionAssociationRow, error)
- func (d *Database) GetAddressesByCredential(credentialTag uint8, stakingKey []byte, limit int, offset int, order string, ...) ([]models.AddressTransaction, error)
- func (d *Database) GetBlockNonce(point ocommon.Point, txn *Txn) ([]byte, error)
- func (d *Database) GetBlockNoncesInSlotRange(startSlot uint64, endSlot uint64, txn *Txn) ([]models.BlockNonce, error)
- func (d *Database) GetChildGovernanceProposals(parentTxHash []byte, parentActionIdx uint32, txn *Txn) ([]*models.GovernanceProposal, error)
- func (d *Database) GetCommitteeActiveCount(txn *Txn) (int, error)
- func (d *Database) GetCommitteeMember(coldCredentialTag uint8, coldKey []byte, termStartSlot uint64, txn *Txn) (*models.AuthCommitteeHot, error)
- func (d *Database) GetCommitteeMembers(txn *Txn) ([]*models.CommitteeMember, error)
- func (d *Database) GetCommitteeMembersIncludeDeleted(txn *Txn) ([]*models.CommitteeMember, error)
- func (d *Database) GetCommitteeQuorum(txn *Txn) (*big.Rat, error)
- func (d *Database) GetConstitution(txn *Txn) (*models.Constitution, error)
- func (d *Database) GetControlledAmountByCredential(credentialTag uint8, stakingKey []byte, txn *Txn) (uint64, error)
- func (d *Database) GetDRepDelegators(credentialTag uint8, drepCredential []byte, txn *Txn) ([]models.StakeCredentialRef, error)
- func (d *Database) GetDRepVotingPower(credentialTag uint8, drepCredential []byte, expiryEpoch uint64, txn *Txn) (uint64, error)
- func (d *Database) GetDRepVotingPowerBatch(drepCredentials []models.StakeCredentialRef, expiryEpoch uint64, txn *Txn) (map[string]uint64, error)
- func (d *Database) GetDRepVotingPowerByType(drepTypes []uint64, expiryEpoch uint64, txn *Txn) (map[uint64]uint64, error)
- func (d *Database) GetDatum(hash []byte, txn *Txn) (*models.Datum, error)
- func (d *Database) GetDrep(cred []byte, includeInactive bool, txn *Txn) (*models.Drep, error)
- func (d *Database) GetDrepByCredential(credentialTag uint8, cred []byte, includeInactive bool, txn *Txn) (*models.Drep, error)
- func (d *Database) GetDrepLastRegistrationDeposit(credentialTag uint8, credential []byte, txn *Txn) (*uint64, error)
- func (d *Database) GetDrepLastRegistrationDeposits(txn *Txn) (map[string]uint64, error)
- func (d *Database) GetEnactedGovernanceProposalsAt(epoch uint64, slot uint64, txn *Txn) ([]*models.GovernanceProposal, error)
- func (d *Database) GetEpoch(epochId uint64, txn *Txn) (*models.Epoch, error)
- func (d *Database) GetEpochBySlot(slot uint64, txn *Txn) (*models.Epoch, error)
- func (d *Database) GetEpochs(txn *Txn) ([]models.Epoch, error)
- func (d *Database) GetEpochsByEra(eraId uint, txn *Txn) ([]models.Epoch, error)
- func (d *Database) GetExpiredDReps(epoch uint64, txn *Txn) ([]*models.Drep, error)
- func (d *Database) GetExpiredGovernanceProposalsAt(epoch uint64, slot uint64, txn *Txn) ([]*models.GovernanceProposal, error)
- func (d *Database) GetExpiringGovernanceProposals(epoch uint64, txn *Txn) ([]*models.GovernanceProposal, error)
- func (d *Database) GetGovernanceProposal(txHash []byte, actionIndex uint32, txn *Txn) (*models.GovernanceProposal, error)
- func (d *Database) GetGovernanceVotes(proposalID uint, txn *Txn) ([]*models.GovernanceVote, error)
- func (d *Database) GetLastBlockNonceInRange(startSlot uint64, endSlot uint64, txn *Txn) ([]byte, error)
- func (d *Database) GetLastEnactedGovernanceProposal(actionTypes []uint8, txn *Txn) (*models.GovernanceProposal, error)
- func (d *Database) GetLatestBlockNonce(txn *Txn) (models.BlockNonce, bool, error)
- func (d *Database) GetLatestMidnightAriadneParams() (*models.MidnightAriadneParams, error)
- func (d *Database) GetLatestMidnightGovernanceDatum(datumType string, blockNumber uint64) (*models.MidnightGovernanceDatum, error)
- func (d *Database) GetLeiosEBManifest(hash []byte, slot uint64) (manifestRaw []byte, err error)
- func (d *Database) GetLeiosEBTxs(hash []byte, slot uint64) ([]cbor.RawMessage, error)
- func (d *Database) GetMIRCertsInSlotRange(startSlot, endSlot uint64, txn *Txn) ([]models.MIREffect, error)
- func (d *Database) GetMidnightAriadneParamsAtOrBeforeEpoch(epoch uint64) (*models.MidnightAriadneParams, error)
- func (d *Database) GetMidnightCandidates(address string) ([]models.Utxo, error)
- func (d *Database) GetMidnightCommitteeCandidateRegistrationsByTxHashes(txHashes [][]byte) ([]models.MidnightCommitteeCandidateRegistration, error)
- func (d *Database) GetMidnightEpochCandidatesByEpoch(epoch uint64) (*models.MidnightEpochCandidates, error)
- func (d *Database) GetPParams(epoch uint64, eraId uint, ...) (lcommon.ProtocolParameters, error)
- func (d *Database) GetPool(pkh lcommon.PoolKeyHash, includeInactive bool, txn *Txn) (*models.Pool, error)
- func (d *Database) GetPoolByVrfKeyHash(vrfKeyHash []byte, txn *Txn) (*models.Pool, error)
- func (d *Database) GetPoolCertificateHistory(pkh lcommon.PoolKeyHash, txn *Txn) ([][]byte, [][]byte, error)
- func (d *Database) GetPoolRegistrations(poolKeyHash lcommon.PoolKeyHash, txn *Txn) ([]lcommon.PoolRegistrationCertificate, error)
- func (d *Database) GetPoolStakeSnapshotsByEpoch(epoch uint64, snapshotType string, txn *Txn) ([]*models.PoolStakeSnapshot, error)
- func (d *Database) GetPools(pkhs []lcommon.PoolKeyHash, txn *Txn) ([]models.Pool, error)
- func (d *Database) GetPoolsRetiringAtEpoch(epoch uint64, boundarySlot uint64, txn *Txn) ([]models.PoolRetirementRefund, error)
- func (d *Database) GetRatifiedGovernanceProposals(txn *Txn) ([]*models.GovernanceProposal, error)
- func (d *Database) GetResignedCommitteeMembers(coldCredentials []models.CommitteeCredential, txn *Txn) (map[string]bool, error)
- func (d *Database) GetRewardAccountOutputsByCredential(credentialTag uint8, stakingKey []byte, limit int, offset int, order string, ...) ([]*models.RewardAccountOutput, error)
- func (d *Database) GetStakeRegistrationsByCredential(credentialTag uint8, stakingKey []byte, txn *Txn) ([]lcommon.StakeRegistrationCertificate, error)
- func (d *Database) GetSyncState(key string, txn *Txn) (string, error)
- func (d *Database) GetTip(txn *Txn) (ochainsync.Tip, error)
- func (d *Database) GetTransactionByHash(hash []byte, txn *Txn) (*models.Transaction, error)
- func (d *Database) GetTransactionMetadataByHash(hash []byte, txn *Txn) ([]byte, error)
- func (d *Database) GetTransactionsByAddress(addr lcommon.Address, limit int, offset int, txn *Txn) ([]models.Transaction, error)
- func (d *Database) GetTransactionsByAddressKeys(paymentKey []byte, credentialTag uint8, stakingKey []byte, limit int, ...) ([]models.Transaction, error)
- func (d *Database) GetTransactionsByAddressWithOrder(addr lcommon.Address, limit int, offset int, order string, txn *Txn) ([]models.Transaction, error)
- func (d *Database) GetTransactionsByBlockHash(blockHash []byte, txn *Txn) ([]models.Transaction, error)
- func (d *Database) GetTransactionsByHashes(hashes [][]byte, txn *Txn) ([]models.Transaction, error)
- func (d *Database) GetTransactionsByMetadataLabel(label uint64, limit int, offset int, descending bool, txn *Txn) ([]models.Transaction, error)
- func (d *Database) GetUtxoPaymentScriptByCredential(credentialTag uint8, stakingKey []byte, paymentKeys [][]byte, txn *Txn) (map[string]bool, error)
- func (d *Database) HasAnyGenesisCbor(slot uint64) bool
- func (d *Database) HasGenesisCbor(slot uint64, hash []byte) bool
- func (d *Database) HasTransactionsByAddress(addr lcommon.Address, txn *Txn) (bool, error)
- func (d *Database) ImportPool(txn *Txn, pool *models.Pool, reg *models.PoolRegistration) error
- func (d *Database) InsertDrepIfAbsent(credentialTag uint8, cred []byte, slot uint64, url string, hash []byte, ...) error
- func (d *Database) InsertMidnightGovernanceDatum(datum *models.MidnightGovernanceDatum) error
- func (d *Database) IsCommitteeMemberResigned(coldCredentialTag uint8, coldKey []byte, termStartSlot uint64, txn *Txn) (bool, error)
- func (d *Database) IterateLiveUtxos(txn *Txn, fn func(*models.Utxo) error) error
- func (d *Database) LatestPoolOpCertSequence(pkh lcommon.PoolKeyHash, txn *Txn) (uint64, bool, error)
- func (d *Database) LatestPoolOpCertSequenceAfter(pkh lcommon.PoolKeyHash, afterSlot uint64, txn *Txn) (uint64, bool, error)
- func (d *Database) LatestPoolOpCertSequenceAtOrBefore(pkh lcommon.PoolKeyHash, slot uint64, txn *Txn) (uint64, bool, error)
- func (d *Database) LatestPoolOpCertSequences(txn *Txn) (map[string]uint64, error)
- func (d *Database) ListSyncStateKeysByPrefix(prefix string, txn *Txn) ([]string, error)
- func (d *Database) Logger() *slog.Logger
- func (d *Database) MarkUtxosDeletedAtSlot(txn *Txn, refs []types.UtxoKey, atSlot uint64) error
- func (d *Database) MatchingUtxoRefsByAddressWithOrdering(q *models.UtxoWithOrderingQuery, txn *Txn) ([]models.UtxoId, error)
- func (d *Database) MaxLeiosEBSlot() (uint64, error)
- func (d *Database) Metadata() metadata.MetadataStore
- func (d *Database) MetadataTxn(readWrite bool) *Txn
- func (d *Database) MithrilTrustBoundarySlot(txn *Txn) uint64
- func (d *Database) MithrilTrustBoundarySlotStrict(txn *Txn) (uint64, error)
- func (d *Database) NewBatchAccumulator() BatchAccumulator
- func (d *Database) PauseCommits() (resume func())
- func (d *Database) PauseCommitsContext(ctx context.Context) (resume func(), err error)
- func (d *Database) PinBlob() (blob.BlobStore, func())
- func (d *Database) PruneBlock(slot uint64, hash []byte) (int, error)
- func (d *Database) RebuildRewardLiveStake(slot uint64, txn *Txn) error
- func (d *Database) RenewAccountExpirations(refs []models.StakeCredentialRef, expirationEpoch uint64, txn *Txn) error
- func (d *Database) ResetAccountExpirationActivation(txn *Txn) ([]models.StakeCredentialRef, error)
- func (d *Database) ResolvePoolRewardAccountAutoVotes(snapshots []*models.PoolStakeSnapshot, txn *Txn) error
- func (d *Database) RestoreAccountStateAtSlot(slot uint64, txn *Txn) error
- func (d *Database) RestoreDrepStateAtSlot(slot uint64, txn *Txn) error
- func (d *Database) RestorePoolStateAtSlot(slot uint64, txn *Txn) error
- func (d *Database) SetBlobStore(b blob.BlobStore) (prev blob.BlobStore, drain func())
- func (d *Database) SetBlockNonce(blockHash []byte, slotNumber uint64, nonce []byte, isCheckpoint bool, txn *Txn) error
- func (d *Database) SetCommitteeMembers(members []*models.CommitteeMember, txn *Txn) error
- func (d *Database) SetCommitteeQuorum(quorum *big.Rat, slot uint64, txn *Txn) error
- func (d *Database) SetConstitution(constitution *models.Constitution, txn *Txn) error
- func (d *Database) SetDatum(rawDatum []byte, addedSlot uint64, txn *Txn) error
- func (d *Database) SetEpoch(slot, epoch uint64, ...) error
- func (d *Database) SetGapBlockTransaction(tx lcommon.Transaction, point ocommon.Point, idx uint32, ...) error
- func (d *Database) SetGenesisCbor(slot uint64, hash []byte, cborData []byte, txn *Txn) error
- func (d *Database) SetGenesisGovernance(initialDReps conway.ConwayGenesisInitialDReps, ...) error
- func (d *Database) SetGenesisStaking(pools map[string]lcommon.PoolRegistrationCertificate, ...) error
- func (d *Database) SetGenesisTransaction(txHash []byte, blockHash []byte, outputs []lcommon.Utxo, ...) error
- func (d *Database) SetGovernanceProposal(proposal *models.GovernanceProposal, txn *Txn) error
- func (d *Database) SetGovernanceVote(vote *models.GovernanceVote, txn *Txn) error
- func (d *Database) SetLeiosEB(slot uint64, hash []byte, manifestRaw []byte, txsRaw []cbor.RawMessage) error
- func (d *Database) SetLeiosEBManifest(slot uint64, hash []byte, manifestRaw []byte) error
- func (d *Database) SetLeiosEBTxs(slot uint64, hash []byte, txsRaw []cbor.RawMessage) error
- func (d *Database) SetPParamUpdate(genesis, params []byte, slot, epoch uint64, txn *Txn) error
- func (d *Database) SetPParams(params []byte, slot, epoch uint64, era uint, txn *Txn) error
- func (d *Database) SetSyncState(key, value string, txn *Txn) error
- func (d *Database) SetTip(tip ochainsync.Tip, txn *Txn) error
- func (d *Database) SetTransaction(tx lcommon.Transaction, point ocommon.Point, idx uint32, updateEpoch uint64, ...) error
- func (d *Database) SetTransactionBatched(tx lcommon.Transaction, point ocommon.Point, idx uint32, updateEpoch uint64, ...) (retErr error)
- func (d *Database) SetTransactionBatchedWithOpts(tx lcommon.Transaction, point ocommon.Point, idx uint32, updateEpoch uint64, ...) (retErr error)
- func (d *Database) SetTransactionMetadataOnly(tx lcommon.Transaction, point ocommon.Point, idx uint32, ...) error
- func (d *Database) SetTransactionWithOpts(tx lcommon.Transaction, point ocommon.Point, idx uint32, updateEpoch uint64, ...) error
- func (d *Database) SoftDeleteAllCommitteeMembers(slot uint64, txn *Txn) error
- func (d *Database) SoftDeleteCommitteeMembers(coldCredentials []models.CommitteeCredential, slot uint64, txn *Txn) error
- func (d *Database) StampAllActiveAccountExpirations(expirationEpoch uint64, txn *Txn) (int64, error)
- func (d *Database) StorageMode() string
- func (d *Database) Transaction(readWrite bool) *Txn
- func (d *Database) TransactionsDeleteRolledback(slot uint64, txn *Txn) error
- func (d *Database) TruncateAfterSlot(point ocommon.Point, mithrilFloor uint64, txn *Txn) (retTip ochainsync.Tip, retNonce []byte, retErr error)
- func (d *Database) UpdateDRepActivity(credentialTag uint8, drepCredential []byte, activityEpoch uint64, ...) error
- func (d *Database) UpdatePoolOpCertSequence(pkh lcommon.PoolKeyHash, sequence uint64, slot uint64, txn *Txn) error
- func (d *Database) UpsertMidnightAriadneParams(params *models.MidnightAriadneParams) error
- func (d *Database) UpsertMidnightEpochCandidates(ec *models.MidnightEpochCandidates) error
- func (d *Database) UtxoByRef(txId []byte, outputIdx uint32, txn *Txn) (*models.Utxo, error)
- func (d *Database) UtxoByRefIncludingSpent(txId []byte, outputIdx uint32, txn *Txn) (*models.Utxo, error)
- func (d *Database) UtxoExists(txId []byte, outputIdx uint32, txn *Txn) (bool, error)
- func (d *Database) UtxosByAddress(addrs []ledger.Address, maxResults int, txn *Txn) ([]models.Utxo, error)
- func (d *Database) UtxosByAddressAtSlot(addr lcommon.Address, slot uint64, txn *Txn) ([]models.Utxo, error)
- func (d *Database) UtxosByAddressWithOrdering(q *models.UtxoWithOrderingQuery, txn *Txn) ([]models.UtxoWithOrdering, error)
- func (d *Database) UtxosByAssets(policyId []byte, assetName []byte, txn *Txn) ([]models.Utxo, error)
- func (d *Database) UtxosByRefs(refs []models.UtxoId, txn *Txn) ([]models.Utxo, error)
- func (d *Database) UtxosByRefsAsOf(refs []models.UtxoId, atSlot uint64, txn *Txn) ([]models.Utxo, error)
- func (d *Database) UtxosDeleteConsumed(slot uint64, limit int, txn *Txn) (int, error)
- func (d *Database) UtxosDeleteRolledback(slot uint64, txn *Txn) error
- func (d *Database) UtxosUnspend(slot uint64, txn *Txn) error
- type HotCache
- func (c *HotCache) CASStats() HotCacheCASStats
- func (c *HotCache) Get(key []byte) ([]byte, bool)
- func (c *HotCache) Put(key []byte, cbor []byte)
- func (c *HotCache) RegisterCASMetrics(registry prometheus.Registerer, cacheName string) error
- func (c *HotCache) SetLogger(logger *slog.Logger, name string)
- type HotCacheCASStats
- type Location
- type NodeSettingsError
- type OutputKey
- type PartialCommitError
- type PositionReader
- type Stores
- type TieredCborCache
- func (c *TieredCborCache) Metrics() *CacheMetrics
- func (c *TieredCborCache) RegisterCASMetrics(registry prometheus.Registerer) error
- func (c *TieredCborCache) ResolveTxCbor(txn *Txn, txHash []byte) ([]byte, error)
- func (c *TieredCborCache) ResolveTxCborBatch(txHashes [][32]byte) (map[[32]byte][]byte, error)
- func (c *TieredCborCache) ResolveUtxoCbor(txId []byte, outputIdx uint32, dbTxn ...*Txn) ([]byte, error)
- func (c *TieredCborCache) ResolveUtxoCborBatch(refs []UtxoRef) (map[UtxoRef][]byte, error)
- func (c *TieredCborCache) SetLogger(logger *slog.Logger)
- type TxCborParts
- type Txn
- func (t *Txn) AfterCommit(fn func())
- func (t *Txn) Blob() types.Txn
- func (t *Txn) BlobStore() blob.BlobStore
- func (t *Txn) Commit() error
- func (t *Txn) DB() *Database
- func (t *Txn) Do(fn func(*Txn) error) (err error)
- func (t *Txn) IsReadWrite() bool
- func (t *Txn) Metadata() types.Txn
- func (t *Txn) Release()
- func (t *Txn) Rollback() error
- func (t *Txn) RollbackTo(name string) error
- func (t *Txn) SavePoint(name string) error
- type UtxoRef
Constants ¶
const (
BlockInitialIndex uint64 = 1
)
const CborOffsetSize = 52
CborOffsetSize is the size in bytes of an encoded CborOffset. Layout: Magic (4) + BlockSlot (8) + BlockHash (32) + ByteOffset (4) + ByteLength (4) = 52
const DelegatorInactivityActivatedSyncKey = "delegator_inactivity_activated"
DelegatorInactivityActivatedSyncKey is the durable sync_state marker key guarding the one-time CIP-0163 activation stamp. Its value is the activation epoch A (the epoch entered at the boundary activation ran on), stored as a decimal string; a non-empty value means activation has already run. Shared between ledger (which writes it during forward processing, see ledger.LedgerState.activateDelegatorInactivityIfNeeded) and this package (which reads/clears it during rollback/truncate) so both agree on the exact same marker regardless of which caller performs the delegator-inactivity bookkeeping around a given database mutation.
const MaxUtxosByAddressResults = 100_000
MaxUtxosByAddressResults is the default bound passed to UtxosByAddress for callers with no more specific limit of their own. It caps how many candidate rows a broad multi-address query (or a single address with an unusually large UTxO set) may force the database layer to materialize.
const SyntheticV2CostModelClearedEpochSyncKey = "synthetic_v2_cost_model_cleared_epoch"
SyntheticV2CostModelClearedEpochSyncKey is the durable sync_state marker key recording the epoch at which real (non-synthetic) PlutusV2 cost-model data was last confirmed written -- either via CIP-1694 governance enactment or a pre-Conway protocol-parameter update. Its value is that epoch, stored as a decimal string; an empty value means no real write has been confirmed since the marker was last reset. This is the provenance signal RecomputeSyntheticV2CostModelMarkerAfterTruncate uses to decide whether a rollback or truncate crossed back before the confirmation, and so must undo it.
const SyntheticV2CostModelSyncKey = "synthetic_v2_cost_model"
SyntheticV2CostModelSyncKey is the durable sync_state marker key backing LedgerState.syntheticV2CostModel (blinklabs-io/dingo#3825): whether the PlutusV2 cost model currently in force is still HardForkBabbage's fabricated default rather than real governance/protocol-update data. Shared between ledger (which writes it during forward processing) and this package (which reads/resets it during rollback/truncate) so both agree on the exact same marker regardless of which caller performs the truncation.
const ( // TxBodyKeyCollateralReturn is the CBOR map key for the // collateral_return entry in a transaction body. Exported so the // node loader can reuse it without redeclaring the constant. TxBodyKeyCollateralReturn uint64 = 16 )
const TxCborPartsSize = 69
TxCborPartsSize is the size in bytes of an encoded TxCborParts. Layout: Magic (4) + BlockSlot (8) + BlockHash (32) +
BodyOffset (4) + BodyLength (4) + WitnessOffset (4) + WitnessLength (4) + MetadataOffset (4) + MetadataLength (4) + IsValid (1) = 69
Variables ¶
var DefaultConfig = &Config{
DataDir: ".dingo",
}
var ErrBlobDeleteIncomplete = errors.New(
"blob delete incomplete: unreachable objects retained",
)
ErrBlobDeleteIncomplete reports that some blob objects could not be deleted.
Blob deletion is supplementary -- metadata is the source of truth -- so the callers deliberately continue and remove the metadata anyway: a rolled-back UTxO must not stay in the live set just because its blob is stuck. What that leaves behind is an object nothing can name again, since the row that pointed at it is gone. Callers therefore log and count the condition rather than aborting on it, which is what separates a documented, observable outcome from a silent one.
var ErrDatumNotFound = errors.New("datum not found")
var ErrNotImplemented = errors.New("not implemented")
ErrNotImplemented is returned when functionality is not yet implemented.
var ErrTxnPanic = errors.New("transaction worker panicked")
ErrTxnPanic identifies an error produced by recovering a panic raised by transaction-related work, as opposed to an ordinary error a caller returned deliberately. Every transaction worker that can convert a panic into an error return (Txn.Do; ledger.DatabaseWorkerPool.executeOperation) wraps it with this sentinel via NewTxnPanicError, so a caller can tell "the underlying operation failed" (an ordinary error) apart from "something the operation didn't expect to fail this way panicked" (this) with a single errors.Is check, regardless of which worker recovered it.
ErrUtxoCborUnavailable signals that the metadata row for a UTxO exists but its CBOR could not be loaded from the blob store and could not be recovered from any indexed block — typically because the row was inserted directly (e.g. fixture seeding) without a corresponding blob, or because the producing block is missing. This is distinct from ErrUtxoNotFound: the row IS present in the live UTxO set; only the on-the-wire bytes are unrecoverable. Callers that only need indexed metadata fields can ignore this error.
var ErrUtxoNotFound = types.ErrUtxoNotFound
ErrUtxoNotFound signals that the metadata row for a UTxO does not exist (or was filtered out, e.g. by deleted_slot != 0 in the live view). Callers may use errors.Is to detect a genuinely-absent row.
Functions ¶
func BlobOrphanCount ¶ added in v0.70.2
func BlobOrphanCount() uint64
BlobOrphanCount returns the cumulative number of blob objects left unreachable by a failed delete.
func BlockBeforeSlot ¶ added in v0.4.2
func BlockBeforeSlotTxn ¶ added in v0.4.2
func BlockBlobKeyToPoint ¶ added in v0.22.0
BlockBlobKeyToPoint extracts slot and hash from a block blob key. Key format: "bp" (2 bytes) + slot (8 bytes big-endian) + hash (32 bytes).
func BlockByHash ¶ added in v0.21.0
func BlockByHashStats ¶ added in v0.55.0
func BlockByHashStats() (hits, misses uint64)
BlockByHashStats returns the cumulative hit/miss counts for the hash-index fast path used by BlockByHashTxn.
func BlockByHashTxn ¶ added in v0.21.0
func BlockByNumber ¶ added in v0.4.2
BlockByNumber resolves the block carrying the given chain block number (height). Block numbers are not indexed in the blob store -- only slot, hash, and the internal sequential ID are -- so this binary-searches the internal-ID space that block numbers increase with, bounded above by the highest indexed block. A number no block carries returns models.ErrBlockNotFound, so a caller can tell a genuine miss from a storage failure.
This resolves the bound itself and is therefore a single-lookup call. Resolve a BlockNumberBound once and use BlockByNumberBounded when answering more than one number.
database/lifecycle.ResolveTargetByNumber keeps its own tip-bounded search rather than calling this: a truncate target must not resolve past the persisted tip, while a read should serve any block the blob store actually holds.
func BlockByNumberBounded ¶ added in v0.70.7
func BlockByNumberBounded( db *Database, number uint64, bound BlockNumberBound, ) (models.Block, error)
BlockByNumberBounded resolves a block number against an already-resolved bound, so a batch of numbers costs one ResolveBlockNumberBound rather than one per number.
func BlockByNumberBoundedTxn ¶ added in v0.70.7
func BlockByNumberTxn ¶ added in v0.4.2
func BlockByPoint ¶ added in v0.4.2
func BlockByPointTxn ¶ added in v0.4.2
func BlockBySlot ¶ added in v0.47.0
func BlockBySlotTxn ¶ added in v0.47.0
func BlockIDByPointLocal ¶ added in v0.70.1
BlockIDByPointLocal returns the locally stored metadata ID for point without allowing a blob-store wrapper to fall through to a remote archive. Retained tombstones still carry the metadata needed for this lookup.
func BlocksAfterSlotTxn ¶ added in v0.4.2
BlocksAfterSlotTxn returns all blocks after the specified slot; keep txn valid until results are consumed.
func BlocksRecent ¶ added in v0.4.2
func BlocksRecentTxn ¶ added in v0.4.2
BlocksRecentTxn returns the N most recent blocks; keep txn valid until results are consumed.
func DelegatorInactivityActivationEpoch ¶ added in v0.69.0
func DelegatorInactivityActivationEpoch( d *Database, txn *Txn, ) (epoch uint64, activated bool, err error)
DelegatorInactivityActivationEpoch reads the durable CIP-0163 activation marker and reports the activation epoch A, whether activation has occurred, and any read/parse error. An empty marker means activation has not run yet (activated == false, epoch 0).
func EncodeTxOffset ¶ added in v0.22.0
func EncodeTxOffset(offset *CborOffset) []byte
EncodeTxOffset encodes a CborOffset for transaction storage. Returns a 52-byte encoded offset with magic prefix.
func EncodeUtxoOffset ¶ added in v0.22.0
func EncodeUtxoOffset(offset *CborOffset) []byte
EncodeUtxoOffset encodes a CborOffset for UTxO storage. Returns a 52-byte encoded offset with magic prefix.
func EpochBySlot ¶ added in v0.69.0
EpochBySlot returns the persisted epoch containing slot: the one with the greatest StartSlot <= slot. Unlike ledger.LedgerState.SlotToEpoch (which additionally consults the live hard-fork/era-transition summary so it can also reason about slots in the future), this only walks the persisted epoch table, with no dependency on genesis config or a live LedgerState -- sufficient for every caller here, since a truncate or rollback target is always at or before the already-committed tip, so the epoch containing it has always already been persisted.
func ForEachBlockInRange ¶ added in v0.22.0
func ForEachBlockInRange( txn *Txn, startSlot, endSlot uint64, fn func(block models.Block) error, ) error
ForEachBlockInRange iterates blocks in the slot range [startSlot, endSlot) from the blob store and calls fn for each block. Blocks are visited in ascending slot order. Iteration stops early if fn returns a non-nil error.
func ForEachBlockInRangeDB ¶ added in v0.22.0
func ForEachBlockInRangeDB( db *Database, startSlot, endSlot uint64, fn func(block models.Block) error, ) error
ForEachBlockInRangeDB is a convenience wrapper that creates a read-only transaction and calls ForEachBlockInRange.
func IsTxCborPartsStorage ¶ added in v0.22.0
IsTxCborPartsStorage checks if the data is TxCborParts storage. Returns true if data has the correct size and magic prefix.
This is format recognition only, deliberately independent of DecodeTxCborParts's canonical-value validation (e.g. a noncanonical IsValid byte): callers such as the UTxO-recovery dispatch in database/utxo.go use this to decide whether a blob is DTXP-shaped at all before calling DecodeTxCborParts. If this also rejected a recognizable-but-corrupt record, such a caller would take its not-DTXP-shaped fallback path and silently treat corrupted recovery data as simply absent, instead of reaching DecodeTxCborParts and surfacing a loud decode error.
func IsTxOffsetStorage ¶ added in v0.22.0
IsTxOffsetStorage checks if the data is offset-based transaction storage. Returns true if data has the correct size and magic prefix.
func IsUtxoOffsetStorage ¶ added in v0.22.0
IsUtxoOffsetStorage checks if the data is offset-based UTxO storage. Returns true if data has the correct size and magic prefix.
func NewTxnPanicError ¶ added in v0.70.8
NewTxnPanicError formats a recovered panic value r (from the given worker/context label) into an error wrapping ErrTxnPanic. It is the shared error half of the panic contract documented below; logTxnPanic is the shared logging half.
func RecomputeAccountExpirationsAfterTruncate ¶ added in v0.69.0
func RecomputeAccountExpirationsAfterTruncate( d *Database, txn *Txn, delegatorInactivityEnabled bool, delegatorInactivity uint64, rollbackSlot uint64, affectedRefs []models.StakeCredentialRef, ) error
RecomputeAccountExpirationsAfterTruncate restores the CIP-0163 expiration_epoch of the reward accounts affected by a rollback or truncate to point.Slot.
expiration_epoch is an epoch quantity, but the metadata layer that restores the rest of the account state on rollback only knows slots. This recomputes it here: for every affected credential (one whose expiration may have been renewed by a now-orphaned witness, gathered by AccountsWitnessedAfterSlot before the rolled-away certificate/ withdrawal rows were deleted) it finds the greatest surviving witnessing slot <= rollbackSlot and stamps expiration = that slot's epoch + delegatorInactivity. A credential with no surviving witness has its expiration reset to 0 (unset): its only renewals were orphaned. Doing nothing would leave a stale, too-high expiration and exclude the account later than the surviving chain would -- a consensus divergence.
Activation floor: the one-time activation stamp sets expiration = A + W for every account active at activation epoch A WITHOUT leaving any witness. A pure witness-history recompute therefore mis-restores an account that was active and stamped at activation but whose only post-activation witness is orphaned: it would drop to a far-past registration epoch (or reset to 0), below the activation floor the surviving chain still carries. So when activation actually ran at or before the rollback point (activated && A <= epoch(rollbackSlot)), the recomputed expiration is clamped up to the activation floor A + W for every account in the durable activation-membership set. Existence alone is not enough because a deregistered account present in the table was not stamped.
affectedRefs are deduped with any rows reset while crossing back before the activation boundary, so each credential is stamped exactly once. Refs are grouped by target expiration so identical epochs share a single RenewAccountExpirations batch.
It is a no-op when delegatorInactivityEnabled is false, and must run inside the same write transaction as the rest of the rollback/truncate sweep, after the metadata layer has restored the remaining account fields (e.g. via TruncateAfterSlot).
Shared by ledger.LedgerState.rollback (bounded rollback during normal sync, security-parameter-limited) and database/lifecycle.Truncate (offline and live CIP-0135 disaster-recovery truncate, which may go far deeper) so both apply the exact same CIP-0163 bookkeeping regardless of which path performs the truncation.
func RecomputeSyntheticV2CostModelMarkerAfterTruncate ¶ added in v0.70.7
func RecomputeSyntheticV2CostModelMarkerAfterTruncate( d *Database, txn *Txn, rollbackSlot uint64, ) error
RecomputeSyntheticV2CostModelMarkerAfterTruncate clears both SyntheticV2CostModelSyncKey and SyntheticV2CostModelClearedEpochSyncKey when a rollback or truncate to rollbackSlot crosses back before the epoch SyntheticV2CostModelClearedEpochSyncKey recorded, leaving the boolean marker absent rather than forcing it to "true": an absent marker falls back to comparing the live PlutusV2 cost model directly against the known synthetic default (ledger.resolveSyntheticV2CostModel), the same mechanism a database that predates these markers entirely already relies on, which correctly handles a chain whose real model has been in force since before the confirming epoch this function is undoing.
Without this, a rollback past the enactment or protocol-parameter update that confirmed real PlutusV2 cost-model data restores the fabricated default into the surviving pparams (via the normal pparams-row reload truncate already performs correctly) while the marker stays "false" -- GetCurrentProtocolParams then reports the fabricated model as real, permanently after a restart, and the same wrong answer survives a re-sync onto a fork that never re-enacts the confirming write. Mirrors the CIP-0163 delegator-inactivity-activation precedent (RecomputeAccountExpirationsAfterTruncate, DelegatorInactivityActivationEpoch): shared by ledger.LedgerState.rollback (bounded rollback during normal sync) and database/lifecycle.Truncate (offline/live disaster-recovery truncate, which may go far deeper), so both apply the exact same bookkeeping regardless of which path performs the truncation. See blinklabs-io/dingo#3825's PR review.
func RegisterBlobOrphanMetrics ¶ added in v0.70.2
func RegisterBlobOrphanMetrics(reg prometheus.Registerer) error
RegisterBlobOrphanMetrics exposes the unreachable-object counter on the given Prometheus registry.
There is no sweep that reclaims these objects, so this counter is the only signal that a blob store is accumulating dead data. reg.Register is used instead of promauto so a registration conflict never panics during Database.New; an AlreadyRegisteredError is ignored and any other error is returned.
func RegisterBlockByHashMetrics ¶ added in v0.55.0
func RegisterBlockByHashMetrics(reg prometheus.Registerer) error
RegisterBlockByHashMetrics exposes the block-hash index hit/miss counters on the given Prometheus registry. The underlying counters are process-wide atomics, so every registry observes the same totals; registering the same registry more than once is a no-op. reg.Register is used instead of promauto so a registration conflict never panics during Database.New; an AlreadyRegisteredError is ignored and any other error is returned.
func RegisterTruncateMetrics ¶ added in v0.70.10
func RegisterTruncateMetrics(reg prometheus.Registerer) error
RegisterTruncateMetrics exposes the rollback-truncation duration histogram on the given Prometheus registry. Registering the same registry more than once is a no-op.
func RollbackActivationFloor ¶ added in v0.69.0
func RollbackActivationFloor( ref models.StakeCredentialRef, clampApplies bool, activationEpoch uint64, activationMembership map[string]struct{}, ) (uint64, bool)
RollbackActivationFloor reports the CIP-0163 activation-floor epoch for one affected credential and whether the floor applies to it. The floor is the activation epoch A, and it applies only when the clamp is active for this rollback AND the account was actually stamped at activation. Durable activation membership distinguishes those accounts from credentials that existed but were deregistered at the activation boundary.
func SetSyntheticV2CostModelClearedEpoch ¶ added in v0.70.7
SetSyntheticV2CostModelClearedEpoch durably records that real PlutusV2 cost-model data was confirmed written as of epoch. Callers pair this with setting SyntheticV2CostModelSyncKey to "false" in the same transaction -- see ledger.LedgerState's persistSyntheticV2CostModel caller.
func SyntheticV2CostModelClearedEpoch ¶ added in v0.70.7
func SyntheticV2CostModelClearedEpoch( d *Database, txn *Txn, ) (epoch uint64, cleared bool, err error)
SyntheticV2CostModelClearedEpoch reads the durable marker and reports the epoch at which real PlutusV2 cost-model data was last confirmed, whether it has been confirmed at all, and any read/parse error. An empty marker means no real write has been confirmed (cleared == false, epoch 0).
Types ¶
type BatchAccumulator ¶ added in v0.45.0
type BatchAccumulator = types.MetadataBatchAccumulator
BatchAccumulator is an opaque accumulator owned by the active metadata plugin.
type BatchedTxIngestOpts ¶ added in v0.47.0
type BatchedTxIngestOpts struct {
// SkipProducedUtxoOffsetWrites elides blob.SetUtxo calls for produced
// outputs. Use when the produced-UTxO offset references for this block
// have already been written (e.g. by the Mithril immutable-copy phase
// reflected in the immutable_utxo_offsets_tip sync-state key). Offsets
// must still be computed and present in the BlockIngestionResult — the
// guarantee is verified, only the redundant blob write is dropped.
// TX offset writes, metadata writes, and consumed-input handling are
// unaffected.
SkipProducedUtxoOffsetWrites bool
// SkipConsumedInputRecovery elides the per-input GetUtxoIncludingSpent
// recovery checks in ensureTransactionConsumedUtxos. Use when replaying
// immutable blocks in slot order during Mithril historical backfill,
// where consumed inputs are guaranteed to already exist in the metadata
// store from earlier producer transactions. The in-flight producer lookup
// optimization (same-batch provenance) remains active. Do NOT enable for
// gap blocks, resumed backfill with potential missing rows, or normal
// replay paths where producer rows may be absent.
SkipConsumedInputRecovery bool
// StrictAppliedInputConservation marks the steady-state, at-tip, validated
// path. Past the Mithril trust boundary, a missing producer row is recovered
// only when the producer block is still on the applied primary chain. This
// allows rollback recovery after core-mode cleanup removed a spent row
// (issue #3170), while refusing recovery from a retained abandoned-fork block
// (issue #3005). The option is retained for callers that identify this path;
// the primary-chain check also protects validated catch-up paths. It takes
// effect only when StrictUtxoValidation is enabled on the Database.
StrictAppliedInputConservation bool
// Stats receives hot-path timings and row-ish counts for operator
// visibility during API-mode Mithril backfill. It is optional and is
// intentionally updated only at coarse stage boundaries.
Stats *types.BackfillHotPathStats
// SkipWithdrawalWitnessWrite elides the CIP-0163 account_withdrawal_witness
// insert for each reward withdrawal. That table is only ever read by the
// delegator-inactivity gate's rollback/renewal paths
// (MetadataStore.AccountsWitnessedAfterSlot, AccountLastWitnessSlots); with
// the gate off -- the default on every node not running CIP-0163 -- the
// insert is pure write amplification on a table nothing reads (issue
// #2919). The ledger sets this to !DelegatorInactivityEnabled on the live-
// apply path (ledger/delta.go), and internal/node.Backfill derives it the
// same way from its own delegatorInactivityEnabled field for the batched
// historical-replay path -- see that field's doc comment for why the
// gate can genuinely be on there too and why the value must always be set
// explicitly rather than assumed. Defaults to false here, preserving the
// unconditional write for any caller that does not opt in.
SkipWithdrawalWitnessWrite bool
// HistoricalBackfill records already-ledger-validated historical
// withdrawals without replaying account state over the imported snapshot.
// Live ledger ingestion leaves this false and enforces balance sufficiency.
HistoricalBackfill bool
}
BatchedTxIngestOpts toggles optional behaviors of SetTransactionBatched.
Defaults preserve the original full-write behavior; setters opt callers (currently API-mode Mithril backfill) into write-elision when the offsets are known to already be present.
type BlobBlockIterator ¶ added in v0.22.0
type BlobBlockIterator struct {
// contains filtered or unexported fields
}
BlobBlockIterator iterates blocks from the blob store in slot order. The blob store keys are formatted as "bp" + big-endian(slot) + hash, so forward iteration naturally yields blocks in ascending slot order.
The iterator fetches block keys in batches to avoid loading the entire chain index into memory, and retrieves CBOR data on demand for each call to NextRaw.
func (*BlobBlockIterator) Close ¶ added in v0.22.0
func (it *BlobBlockIterator) Close()
Close releases any resources held by the iterator. It is safe to call Close multiple times.
func (*BlobBlockIterator) NextRaw ¶ added in v0.22.0
func (it *BlobBlockIterator) NextRaw() (*BlobBlockResult, error)
NextRaw returns the next block as raw CBOR bytes along with its metadata. When iteration is complete, it returns (nil, nil). Blocks whose CBOR cannot be fetched from the blob store are skipped with a warning log.
func (*BlobBlockIterator) Progress ¶ added in v0.22.0
func (it *BlobBlockIterator) Progress() (current, end uint64)
Progress returns the current slot being iterated and the end slot. If no end slot was specified (iterate to tip), end returns 0.
type BlobBlockResult ¶ added in v0.22.0
type BlobBlockResult struct {
Slot uint64
Hash []byte
Cbor []byte
BlockType uint
Height uint64
PrevHash []byte
}
BlobBlockResult holds the data returned by BlobBlockIterator.NextRaw.
type BlockIndexer ¶ added in v0.22.0
type BlockIndexer struct {
// contains filtered or unexported fields
}
BlockIndexer computes byte offsets for all items within a block. It uses gouroboros's ExtractTransactionOffsets for efficient offset extraction.
func NewBlockIndexer ¶ added in v0.22.0
func NewBlockIndexer(slot uint64, hash []byte) *BlockIndexer
NewBlockIndexer creates a new BlockIndexer for the given block.
func (*BlockIndexer) ComputeOffsets ¶ added in v0.22.0
func (bi *BlockIndexer) ComputeOffsets( blockCbor []byte, block ledger.Block, ) (*BlockIngestionResult, error)
ComputeOffsets extracts byte offsets for all transactions, UTxOs, datums, redeemers, and scripts within the block CBOR.
TxOffsets and UtxoOffsets are always populated. TxParts is only populated when WithExtendedOffsets was called (nil otherwise). DatumOffsets, RedeemerOffsets, and ScriptOffsets are likewise nil by default and only allocated when WithExtendedOffsets was called.
func (*BlockIndexer) WithExtendedOffsets ¶ added in v0.24.0
func (bi *BlockIndexer) WithExtendedOffsets() *BlockIndexer
WithExtendedOffsets enables additional transaction-part and witness offset extraction. When not called, ComputeOffsets returns a BlockIngestionResult where TxParts, DatumOffsets, RedeemerOffsets, and ScriptOffsets are nil. Callers must check for nil before accessing these fields.
type BlockIngestionResult ¶ added in v0.22.0
type BlockIngestionResult struct {
// TxOffsets maps transaction hash to its CborOffset within the block.
// This stores only the transaction body offset for backward compatibility.
TxOffsets map[[32]byte]CborOffset
// TxParts maps transaction hash to all 4 component offsets within the block.
// This enables byte-perfect reconstruction of complete standalone transaction
// CBOR from the source block by extracting and reassembling:
// body, witness, is_valid, and metadata (optional).
TxParts map[[32]byte]TxCborParts
// UtxoOffsets maps UTxO reference to its CborOffset within the block
UtxoOffsets map[UtxoRef]CborOffset
// DatumOffsets maps datum hash to its CborOffset within the block
DatumOffsets map[[32]byte]CborOffset
// RedeemerOffsets maps redeemer key to its CborOffset within the block
RedeemerOffsets map[common.RedeemerKey]CborOffset
// ScriptOffsets maps script hash to its CborOffset within the block
ScriptOffsets map[[32]byte]CborOffset
}
BlockIngestionResult contains pre-computed offsets for all items in a block. This is computed during block ingestion and used to store offset references instead of duplicating CBOR data.
type BlockLRUCache ¶ added in v0.21.0
type BlockLRUCache struct {
// contains filtered or unexported fields
}
BlockLRUCache is a thread-safe, lock-striped LRU cache for recently accessed blocks. Blocks are keyed by (slot, hash) and routed to one of N independent shards by the block hash, so operations on different blocks rarely contend on the same lock. Each shard maintains its own LRU list and capacity; eviction is therefore per-shard rather than strictly global (the standard trade-off for a sharded cache). The total number of cached blocks never exceeds the configured maxEntries.
func NewBlockLRUCache ¶ added in v0.21.0
func NewBlockLRUCache(maxEntries int) *BlockLRUCache
NewBlockLRUCache creates a new BlockLRUCache with the specified maximum number of entries. If maxEntries is negative, it is treated as zero (cache disabled). The cache transparently shards its internal storage to reduce lock contention; the shard count is derived from maxEntries (small caches use a single shard, preserving exact global-LRU behavior).
func (*BlockLRUCache) Get ¶ added in v0.21.0
func (c *BlockLRUCache) Get(slot uint64, hash [32]byte) (*CachedBlock, bool)
Get retrieves a cached block by slot and hash. Returns the block and true if found, or nil and false if not found. Accessing a block moves it to the front of its shard's LRU list.
func (*BlockLRUCache) Put ¶ added in v0.21.0
func (c *BlockLRUCache) Put(slot uint64, hash [32]byte, block *CachedBlock)
Put adds or updates a block in the cache. The block is moved to the front of its shard's LRU list. If the shard exceeds its capacity, the least recently used block in that shard is evicted.
type BlockNumberBound ¶ added in v0.70.7
type BlockNumberBound struct {
// HighestID is the internal sequential ID of the highest indexed
// block, and the top of the ID space a search walks.
HighestID uint64
// HighestNumber is the chain block number that block carries. No
// larger number can resolve.
HighestNumber uint64
// Resolved reports that a highest indexed block was found. The zero
// value is deliberately unresolved rather than "bound of zero": an
// unresolved bound matches no block number at all, so a caller that
// forgets to resolve one gets ErrBlockNotFound instead of a search
// over an empty ID space that quietly reports the same thing for a
// different reason. An empty chain resolves to the same zero value.
Resolved bool
}
BlockNumberBound is the upper bound a block-number search runs against: the highest block currently indexed.
It is a value a caller resolves and carries, rather than something each lookup rediscovers, because resolving it is the expensive half. Reading the highest indexed block means a reverse iteration over the block-index ("bi") prefix, and the s3 and gcs blob plugins implement a reverse iterator by listing every object under the prefix into a temporary file with no early break (listKeysToFile). One resolution is therefore a full enumeration of every block-index object in the bucket. A caller resolving more than one block number -- the bark archive service answers up to DefaultMaxFetchBlockRefs of them per unauthenticated request -- must resolve the bound once and reuse it for the whole batch.
func ResolveBlockNumberBound ¶ added in v0.70.7
func ResolveBlockNumberBound(db *Database) (BlockNumberBound, error)
ResolveBlockNumberBound reads the highest indexed block to bound a block-number search. See BlockNumberBound for why the result is worth carrying across lookups.
func ResolveBlockNumberBoundTxn ¶ added in v0.70.7
func ResolveBlockNumberBoundTxn(txn *Txn) (BlockNumberBound, error)
ResolveBlockNumberBoundTxn resolves the bound within an existing transaction. It reads only the ordered block-index entries and the small per-block metadata object of the newest one, never block CBOR.
type CacheMetrics ¶ added in v0.21.0
type CacheMetrics struct {
UtxoHotHits atomic.Uint64
UtxoHotMisses atomic.Uint64
TxHotHits atomic.Uint64
TxHotMisses atomic.Uint64
BlockLRUHits atomic.Uint64
BlockLRUMisses atomic.Uint64
ColdExtractions atomic.Uint64
// contains filtered or unexported fields
}
CacheMetrics holds atomic counters for cache performance monitoring.
func (*CacheMetrics) IncBlockLRUHit ¶ added in v0.22.0
func (m *CacheMetrics) IncBlockLRUHit()
IncBlockLRUHit increments the block LRU cache hit counter.
func (*CacheMetrics) IncBlockLRUMiss ¶ added in v0.22.0
func (m *CacheMetrics) IncBlockLRUMiss()
IncBlockLRUMiss increments the block LRU cache miss counter.
func (*CacheMetrics) IncColdExtraction ¶ added in v0.22.0
func (m *CacheMetrics) IncColdExtraction()
IncColdExtraction increments the cold extraction counter.
func (*CacheMetrics) IncTxHotHit ¶ added in v0.22.0
func (m *CacheMetrics) IncTxHotHit()
IncTxHotHit increments the TX hot cache hit counter.
func (*CacheMetrics) IncTxHotMiss ¶ added in v0.22.0
func (m *CacheMetrics) IncTxHotMiss()
IncTxHotMiss increments the TX hot cache miss counter.
func (*CacheMetrics) IncUtxoHotHit ¶ added in v0.22.0
func (m *CacheMetrics) IncUtxoHotHit()
IncUtxoHotHit increments the UTxO hot cache hit counter.
func (*CacheMetrics) IncUtxoHotMiss ¶ added in v0.22.0
func (m *CacheMetrics) IncUtxoHotMiss()
IncUtxoHotMiss increments the UTxO hot cache miss counter.
func (*CacheMetrics) Register ¶ added in v0.22.0
func (m *CacheMetrics) Register(registry prometheus.Registerer)
Register registers Prometheus metrics with the given registry. If registry is nil, this is a no-op. This method is idempotent; subsequent calls after the first successful registration are no-ops.
type CachedBlock ¶ added in v0.21.0
type CachedBlock struct {
// RawBytes contains the block's raw CBOR data.
RawBytes []byte
// TxIndex maps transaction hashes to their location in RawBytes.
TxIndex map[[32]byte]Location
// OutputIndex maps UTxO output keys to their location in RawBytes.
OutputIndex map[OutputKey]Location
}
CachedBlock holds a block's raw CBOR data along with pre-computed indexes for fast extraction of transactions and UTxO outputs.
func (*CachedBlock) Extract ¶ added in v0.21.0
func (cb *CachedBlock) Extract(offset, length uint32) []byte
Extract returns a copy of RawBytes from offset to offset+length. Returns nil if the range is out of bounds. The returned slice is a defensive copy so callers may freely modify it without corrupting the cached block data.
type CborCacheConfig ¶ added in v0.21.0
type CborCacheConfig struct {
HotUtxoEntries int // Number of UTxO CBOR entries in hot cache
HotTxEntries int // Number of TX CBOR entries in hot cache
HotTxMaxBytes int64 // Memory limit for TX hot cache (0 = no limit)
BlockLRUEntries int // Number of blocks in LRU cache
}
CborCacheConfig holds configuration for the TieredCborCache.
type CborOffset ¶ added in v0.21.0
type CborOffset struct {
BlockSlot uint64 // Slot number of the block containing the CBOR
BlockHash [32]byte // Hash of the block containing the CBOR
ByteOffset uint32 // Byte offset within the block's CBOR data
ByteLength uint32 // Length of the CBOR data in bytes
}
CborOffset represents a reference to CBOR data within a block. Instead of storing duplicate CBOR data, we store an offset reference that points to the CBOR within the block's raw data.
func DecodeCborOffset ¶ added in v0.21.0
func DecodeCborOffset(data []byte) (*CborOffset, error)
DecodeCborOffset deserializes a 52-byte big-endian encoded slice into a CborOffset. Returns an error if the input data is not exactly 52 bytes or has wrong magic.
func DecodeTxOffset ¶ added in v0.22.0
func DecodeTxOffset(data []byte) (*CborOffset, error)
DecodeTxOffset decodes offset-based transaction storage data. Returns an error if the data is not exactly 52 bytes or has wrong magic.
func DecodeUtxoOffset ¶ added in v0.22.0
func DecodeUtxoOffset(data []byte) (*CborOffset, error)
DecodeUtxoOffset decodes offset-based UTxO storage data. Returns an error if the data is not exactly 52 bytes or has wrong magic.
func (*CborOffset) Encode ¶ added in v0.21.0
func (c *CborOffset) Encode() []byte
Encode serializes the CborOffset to a 52-byte big-endian encoded slice. Layout:
- bytes 0-3: Magic "DOFF" (identifies offset storage)
- bytes 4-11: BlockSlot (big-endian uint64)
- bytes 12-43: BlockHash (32 bytes)
- bytes 44-47: ByteOffset (big-endian uint32)
- bytes 48-51: ByteLength (big-endian uint32)
type CommitTimestampError ¶
CommitTimestampError contains the timestamps of the metadata and blob stores
func (CommitTimestampError) Error ¶
func (e CommitTimestampError) Error() string
Error returns the stringified error
type Config ¶ added in v0.12.1
type Config struct {
PromRegistry prometheus.Registerer
Logger *slog.Logger
DataDir string
StorageMode string // "core" or "api"
Network string // Cardano network name (e.g. "preview", "mainnet")
CacheConfig CborCacheConfig
// StrictUtxoValidation, when true, turns an unrecoverable consumed UTxO
// (not present in the metadata store and not reconstructable from the
// blob store) into a hard error for blocks past the recorded Mithril
// trust boundary (the "mithril_ledger_slot" sync state key), instead of
// silently skipping it. Past that boundary the node should have complete
// producer history, so a miss indicates real corruption or a bug rather
// than an expected gap. Leave disabled (the default) when bootstrapping
// from a non-genesis chainsync intersect point without a Mithril
// snapshot import, where pre-intersect UTxOs are legitimately absent.
StrictUtxoValidation bool
// NetworkMagic is the protocol magic. It is the real network
// discriminator: a custom or devnet database may have an empty Network
// while still needing identity enforcement.
NetworkMagic uint32
// StartEra is the experimental start era ("dijkstra" or empty).
StartEra string
// BlobPlugin and MetadataPlugin name the storage providers that
// produced this database.
BlobPlugin string
MetadataPlugin string
}
Config represents the configuration for a database instance
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database represents our data storage services
func New ¶ added in v0.4.3
New creates a database over injected stores. The caller owns the store lifecycle and must keep both stores alive until Database.Close returns.
func (*Database) AccountInactivityActivationMembership ¶ added in v0.67.0
func (d *Database) AccountInactivityActivationMembership( refs []models.StakeCredentialRef, txn *Txn, ) (map[string]struct{}, error)
AccountInactivityActivationMembership returns the requested credentials that were included in the one-time CIP-0163 activation stamp.
func (*Database) AccountLastWitnessSlots ¶ added in v0.67.0
func (d *Database) AccountLastWitnessSlots( refs []models.StakeCredentialRef, maxSlot uint64, txn *Txn, ) (map[string]uint64, error)
AccountLastWitnessSlots returns, per requested credential, the greatest CIP-0163 witnessing slot <= maxSlot across the stake-witnessing certificate tables and the reward-withdrawal history, keyed by StakeCredentialRef.MapKey(). A credential with no witness <= maxSlot is absent from the map. When txn is nil a read transaction is opened for the query; pass an existing txn to read within a wider unit of work.
func (*Database) AccountsWitnessedAfterSlot ¶ added in v0.67.0
func (d *Database) AccountsWitnessedAfterSlot( slot uint64, txn *Txn, ) ([]models.StakeCredentialRef, error)
AccountsWitnessedAfterSlot returns the distinct reward-account credentials witnessed (via a stake-witnessing certificate or a reward withdrawal) at a slot greater than the given slot — the CIP-0163 rollback affected set. It must be called before rolled-back certificate and reward-delta rows are deleted. When txn is nil a read transaction is opened for the query; pass an existing txn to read within a wider unit of work.
func (*Database) AddAccountRewardByCredential ¶ added in v0.55.0
func (d *Database) AddAccountRewardByCredential( credentialTag uint8, stakeKey []byte, amount uint64, slot uint64, sourceHash []byte, txn *Txn, ) error
AddAccountRewardByCredential credits the reward balance for a registered account identified by stake credential tag and key. sourceHash uniquely identifies the credit event (refunded proposal identity hash, reaped pool key hash, or synthetic MIR event discriminator); it makes each epoch-boundary credit a distinct rollback-aware journal row while letting a crash-replayed boundary map onto the existing row and skip idempotently. Pass nil when no per-event discriminator is available.
func (*Database) AddPostSnapshotAccountRewardByCredential ¶ added in v0.69.0
func (d *Database) AddPostSnapshotAccountRewardByCredential( credentialTag uint8, stakeKey []byte, amount uint64, slot uint64, sourceHash []byte, txn *Txn, ) error
AddPostSnapshotAccountRewardByCredential credits a reward account with an epoch-boundary credit that cardano-ledger applies AFTER the boundary stake snapshot (SNAP): POOLREAP deposit refunds, enacted treasury withdrawals and governance proposal-deposit refunds. The journal row is stamped AccountRewardDelta.PostSnapshot so the epoch-boundary stake reconstruction can exclude it while still retaining the pre-SNAP credits, which land at the same boundary slot. Use AddAccountRewardByCredential for those — the delayed reward update and MIR — and for transaction-driven credits.
func (*Database) ApplyPParamUpdates ¶ added in v0.4.4
func (d *Database) ApplyPParamUpdates( slot, epoch uint64, era uint, quorum int, currentPParams *lcommon.ProtocolParameters, decodeFunc func([]byte) (any, error), updateFunc func(lcommon.ProtocolParameters, any) (lcommon.ProtocolParameters, error), txn *Txn, ) error
ApplyPParamUpdates enacts, for the boundary INTO epoch, the pending pparam update submitted in epoch-1 (see selectPParamUpdateForEnactment for the submission-epoch semantics), mutating *currentPParams and persisting the result for epoch.
func (*Database) Blob ¶
Blob returns the currently installed blob store without pinning it. See the ownership notes at the top of this file: use the returned store within the call that obtained it, and use a Txn or PinBlob for anything longer.
func (*Database) BlobTxn ¶ added in v0.4.3
BlobTxn starts a new blob-only database transaction and returns a handle to it
func (*Database) BlockAtOrAfterIndex ¶ added in v0.67.0
BlockAtOrAfterIndex returns the first block whose chain index is greater than or equal to blockIndex. It seeks the ordered block-index keys so sparse imported chains do not require one lookup and transaction per missing index.
func (*Database) BlockByIndex ¶ added in v0.4.5
func (*Database) BlockCreate ¶ added in v0.4.5
func (*Database) BlockPointByIndex ¶ added in v0.70.1
BlockPointByIndex returns the point encoded in the current block-index entry without loading the referenced block CBOR or metadata. It is intended for primary-chain membership checks that need only the canonical slot and hash at an internal block index.
func (*Database) BlocksFromSlot ¶ added in v0.22.0
func (d *Database) BlocksFromSlot(startSlot uint64) *BlobBlockIterator
BlocksFromSlot returns an iterator that yields blocks starting from startSlot, continuing through all subsequent blocks in the blob store.
func (*Database) BlocksInRange ¶ added in v0.22.0
func (d *Database) BlocksInRange( startSlot, endSlot uint64, ) *BlobBlockIterator
BlocksInRange returns an iterator for a specific slot range [start, end]. Both endpoints are inclusive.
func (*Database) CborCache ¶ added in v0.22.0
func (d *Database) CborCache() *TieredCborCache
CborCache returns the tiered CBOR cache for accessing cached CBOR data. This can be used for metrics registration or direct cache access.
func (*Database) CheckNodeSettings ¶ added in v0.69.0
CheckNodeSettings validates the gates a bare database open can know and persists them on first start. Every value it supplies is treated as explicit: any override against a built-in default has already happened in the configuration layer, so this is a strict re-validation.
It is normally called once, by New (via init), and callers do not invoke it directly on that path. It is exported so node.go can re-invoke it after a commit-timestamp recovery: New returns before ever calling this when checkCommitTimestamp fails, so a startup that takes the recovery path never runs phase 1 on its own -- see node.go's dbNeedsRecovery handling, which calls this explicitly once RecoverCommitTimestampConflict succeeds.
func (*Database) ClearCommitteeQuorum ¶ added in v0.37.0
ClearCommitteeQuorum records at the given slot that no quorum is in effect (e.g. after a NoConfidence action is enacted). A later GetCommitteeQuorum will return nil until a subsequent SetCommitteeQuorum writes a new positive value.
func (*Database) ClearDanglingDRepDelegations ¶ added in v0.37.0
ClearDanglingDRepDelegations applies the cardano-ledger Conway HARDFORK STS rule for protocol major version 10 (Plomin, mainnet January 2025): any account with a credential-backed DRep delegation (DrepType 0 or 1) whose target DRep credential is not currently registered as an active DRep has its delegation cleared. Account.AddedSlot is updated to atSlot so the rewritten row is excluded from a rollback restore targeting any slot before atSlot (the restore filters on `added_slot <= targetSlot` and picks up the prior certificate history instead). Pseudo-DRep delegations (AlwaysAbstain, AlwaysNoConfidence) are preserved. Returns the number of accounts updated.
See cardano-ledger Conway/Rules/HardFork.hs (updateDRepDelegations).
func (*Database) ClearGovernanceProposalRatification ¶ added in v0.70.3
func (d *Database) ClearGovernanceProposalRatification( txHash []byte, actionIndex uint32, transitionSlot uint64, txn *Txn, ) error
ClearGovernanceProposalRatification moves a proposal back to the active, pending state at transitionSlot. Governance epoch processing uses it when a legacy ratified row fails a deterministic enactment precondition.
func (*Database) ClearSyncState ¶ added in v0.22.0
ClearSyncState removes all sync state entries.
func (*Database) ComputeAndApplyPParamUpdates ¶ added in v0.21.0
func (d *Database) ComputeAndApplyPParamUpdates( slot, epoch uint64, era uint, quorum int, currentPParams lcommon.ProtocolParameters, decodeFunc func([]byte) (any, error), updateFunc func( lcommon.ProtocolParameters, any, ) (lcommon.ProtocolParameters, error), hasPlutusV2CostModelFunc func(any) bool, txn *Txn, ) (lcommon.ProtocolParameters, bool, error)
ComputeAndApplyPParamUpdates computes the new protocol parameters by applying the pending update to enact for the given epoch, and persists the result for that epoch. The epoch parameter is the epoch where the updates take effect (currentEpoch + 1 during epoch rollover); per the Shelley update system the enacted proposal is the one submitted in epoch-1 (see selectPParamUpdateForEnactment). The quorum parameter is the minimum number of unique genesis-key delegates that must have submitted proposals (from shelley-genesis.json updateQuorum). Although the interface is passed by value, era-specific update functions may mutate its underlying concrete protocol-parameter pointer in place. Callers that need the original value preserved must pass an independently owned copy; the returned value is the authoritative updated parameter set.
hasPlutusV2CostModelFunc reports whether the enacted update itself (not the merged result) explicitly specifies a PlutusV2 cost model (map key 1). This is the pre-Conway equivalent of governance.EnactmentResult's PlutusV2CostModelWritten: on a network that forks into Babbage before receiving a real PlutusV2 cost model, that model can arrive through this classic Shelley-style update system (as it did on real mainnet, well before CIP-1694 governance existed), and the caller needs the same real-write provenance signal here that governance.EnactProposal provides for the Conway/Dijkstra path -- comparing the merged result's value before and after is unsound for the same reason it is there: HardForkBabbage's synthetic default is the real, canonical mainnet value, so a real update writing that exact value would otherwise look unchanged. See blinklabs-io/dingo#3825's PR review. May be nil (no signal available for this era, e.g. Byron), in which case the returned bool is always false.
func (*Database) Config ¶ added in v0.12.1
Config returns the config object used for the database instance
func (*Database) CountAccountDelegationHistoryByCredential ¶ added in v0.55.0
func (d *Database) CountAccountDelegationHistoryByCredential( credentialTag uint8, stakeKey []byte, txn *Txn, ) (int, error)
CountAccountDelegationHistoryByCredential returns the total number of delegation history rows for a stake credential.
func (*Database) CountAccountRegistrationHistoryByCredential ¶ added in v0.55.0
func (d *Database) CountAccountRegistrationHistoryByCredential( credentialTag uint8, stakeKey []byte, txn *Txn, ) (int, error)
CountAccountRegistrationHistoryByCredential returns the total number of registration history rows for a stake credential.
func (*Database) CountAccountWithdrawalHistoryByCredential ¶ added in v0.69.0
func (d *Database) CountAccountWithdrawalHistoryByCredential( credentialTag uint8, stakeKey []byte, txn *Txn, ) (int, error)
CountAccountWithdrawalHistoryByCredential returns the total number of withdrawal history rows for a stake credential.
func (*Database) CountAddressTransactionsByCredential ¶ added in v0.69.0
func (d *Database) CountAddressTransactionsByCredential( credentialTag uint8, stakeKey []byte, from *models.AddressTransactionPosition, to *models.AddressTransactionPosition, txn *Txn, ) (int, error)
CountAddressTransactionsByCredential returns the total number of (payment address, transaction) association rows for a stake credential within the same optional from/to range.
func (*Database) CountAddressesByCredential ¶ added in v0.55.0
func (d *Database) CountAddressesByCredential( credentialTag uint8, stakingKey []byte, txn *Txn, ) (int, error)
CountAddressesByCredential returns the total number of distinct address mappings for a stake credential.
func (*Database) CountBlocksAndOldestSlot ¶ added in v0.69.0
func (d *Database) CountBlocksAndOldestSlot( txn *Txn, ) (count uint64, oldestSlot uint64, err error)
CountBlocksAndOldestSlot iterates every block-content ("bp") key in the blob store once, returning the total count of retained blocks and the smallest slot among them. Block-content keys sort in ascending slot order, so the oldest slot is simply whichever one is seen first — no separate MIN pass is needed. A tombstoned entry (history-expiry pruned its content, keeping only the bp key alive so hash/index lookups still resolve — see TombstoneBlock) is excluded from both: its data isn't actually retained, so counting it would misrepresent both how much history is available and how far back it goes. The blob plugin's own ValueCopy already turns a tombstoned entry's read into types.ErrHistoryExpired (matching GetBlock's convention) rather than handing back the raw marker bytes, so that error — not a hand-rolled magic-byte check — is what this treats as "skip, don't count". Reading each entry's value at all (to tell a tombstone from a real block) is the dominant cost of this scan — negligible if history-expiry is disabled (no block is ever tombstoned), non-trivial on a large chain otherwise.
There is no maintained counter for either value, so this is a genuine full scan of the block-index keyspace: appropriate for an operator-facing diagnostic (bark's GetDatabaseInfo RPC) called occasionally, not a hot path.
func (*Database) CountRewardAccountOutputsByCredential ¶ added in v0.69.0
func (d *Database) CountRewardAccountOutputsByCredential( credentialTag uint8, stakingKey []byte, txn *Txn, ) (int, error)
CountRewardAccountOutputsByCredential returns the total count of reward account output rows for a stake credential.
func (*Database) CountTransactionsByAddress ¶ added in v0.33.0
CountTransactionsByAddress returns the total number of transactions involving a given address.
func (*Database) CountTransactionsByAddressKeys ¶ added in v0.33.0
func (d *Database) CountTransactionsByAddressKeys( paymentKey []byte, credentialTag uint8, stakingKey []byte, txn *Txn, ) (int, error)
CountTransactionsByAddressKeys returns the total number of transactions for a payment/staking credential tuple.
func (*Database) CountTransactionsByMetadataLabel ¶ added in v0.34.0
CountTransactionsByMetadataLabel returns the total number of transactions that include metadata for a given label key.
func (*Database) CountTransactionsByPaymentCred ¶ added in v0.68.0
CountTransactionsByPaymentCred returns the total number of transactions involving a payment credential across every address that carries it, regardless of staking part.
func (*Database) CountUtxosByAddressWithOrdering ¶ added in v0.70.3
func (d *Database) CountUtxosByAddressWithOrdering( q *models.UtxoWithOrderingQuery, txn *Txn, ) (int, error)
CountUtxosByAddressWithOrdering returns the number of live UTxOs matching q's coarse SQL predicate. See MetadataStore.CountUtxosByAddressWithOrdering: it errors if q's address patterns require CBOR-based exact-address filtering, since Dingo has no cheap way to compute an exact-address total without decoding every coarse candidate's output CBOR.
func (*Database) CreateAccount ¶ added in v0.37.0
CreateAccount inserts an Account row directly. See the MetadataStore interface for the difference between this and ImportAccount. When txn is nil a write transaction is opened, committed on success and rolled back on error via Txn.Do; pass an existing write txn to participate in a wider unit of work.
func (*Database) CreateDrep ¶ added in v0.37.0
CreateDrep inserts a Drep row directly. See the MetadataStore interface for the difference between this and ImportDrep. When txn is nil a write transaction is opened, committed on success and rolled back on error via Txn.Do; pass an existing write txn to participate in a wider unit of work.
func (*Database) CreateUtxo ¶ added in v0.37.0
CreateUtxo inserts a Utxo row directly. The normal block-application path uses AddUtxos with UtxoSlot inputs; this is the simple-insert variant for callers that already have a populated model. When txn is nil a write transaction is opened, committed on success and rolled back on error via Txn.Do.
func (*Database) DataDir ¶ added in v0.4.3
DataDir returns the path to the data directory used for storage
func (*Database) DeleteAccountRewardsAfterSlot ¶ added in v0.37.0
DeleteAccountRewardsAfterSlot reverts reward-account balance changes recorded after the given slot. Used during chain rollback for governance credits and transaction withdrawals.
func (*Database) DeleteBlockNoncesAfterPoint ¶ added in v0.38.0
DeleteBlockNoncesAfterPoint removes nonces that cannot belong to the active chain after rolling back to point. It keeps the exact point row and removes competing rows at the same slot.
func (*Database) DeleteBlockNoncesBeforeSlot ¶ added in v0.11.0
DeleteBlockNoncesBeforeSlot removes all block_nonces older than the given slot number
func (*Database) DeleteBlockNoncesBeforeSlotWithoutCheckpoints ¶ added in v0.11.0
func (d *Database) DeleteBlockNoncesBeforeSlotWithoutCheckpoints( slotNumber uint64, txn *Txn, ) error
DeleteBlockNoncesBeforeSlotWithoutCheckpoints removes non-checkpoint block_nonces older than the given slot number
func (*Database) DeleteCertificatesAfterSlot ¶ added in v0.22.0
DeleteCertificatesAfterSlot removes all certificate records added after the given slot. This is used during chain rollbacks to undo certificate state changes.
func (*Database) DeleteCommitteeMembersAfterSlot ¶ added in v0.37.0
DeleteCommitteeMembersAfterSlot removes committee state added after the given slot and clears deleted_slot for any members soft-deleted after that slot. Used during chain rollbacks.
func (*Database) DeleteConstitutionsAfterSlot ¶ added in v0.22.0
DeleteConstitutionsAfterSlot removes constitutions added after the given slot and clears deleted_slot for any that were soft-deleted after that slot. This is used during chain rollbacks.
func (*Database) DeleteEpochsAfterSlot ¶ added in v0.22.0
func (*Database) DeleteGovernanceProposalsAfterSlot ¶ added in v0.22.0
DeleteGovernanceProposalsAfterSlot removes governance proposals added after the given slot and clears deleted_slot for any that were soft-deleted after that slot. This is used during chain rollbacks.
func (*Database) DeleteGovernanceVotesAfterSlot ¶ added in v0.22.0
DeleteGovernanceVotesAfterSlot removes governance votes added after the given slot and clears deleted_slot for any that were soft-deleted after that slot. This is used during chain rollbacks.
func (*Database) DeleteNetworkDonationsAfterSlot ¶ added in v0.55.0
DeleteNetworkDonationsAfterSlot removes donation records added after the given slot. This is used during chain rollbacks, alongside DeleteNetworkStateAfterSlot.
func (*Database) DeleteNetworkStateAfterSlot ¶ added in v0.22.0
DeleteNetworkStateAfterSlot removes network state records added after the given slot. This is used during chain rollbacks.
func (*Database) DeletePParamUpdatesAfterSlot ¶ added in v0.22.0
DeletePParamUpdatesAfterSlot removes protocol parameter update records added after the given slot.
func (*Database) DeletePParamsAfterSlot ¶ added in v0.22.0
DeletePParamsAfterSlot removes protocol parameter records added after the given slot.
func (*Database) DeleteRewardStateAfterSlot ¶ added in v0.49.0
DeleteRewardStateAfterSlot deletes reward-state rows captured from rolled-back blocks.
func (*Database) DeleteSyncState ¶ added in v0.22.0
DeleteSyncState removes a sync state key.
func (*Database) DeleteTransactionMetadataLabelsAfterSlot ¶ added in v0.28.0
DeleteTransactionMetadataLabelsAfterSlot removes transaction metadata label index records added after the given slot.
func (*Database) EnforceNodeSettings ¶ added in v0.69.0
func (d *Database) EnforceNodeSettings(values nodesettings.Values) error
EnforceNodeSettings validates and persists the gates that only a full node startup can know: the era genesis hashes and the ledger-semantics gates (history expiry, pledge leverage, full-pot rewards, delegator inactivity, minimum pool margin, and the two validation taints). It is called once during node startup, after the cardano config has been parsed and before the ledger applies its first block; by that point phase 1 (database.New's CheckNodeSettings) has already validated everything a bare database open can know.
Every value in values is treated as explicit, the same rule CheckNodeSettings applies to phase 1's gates: the caller here is node.go, which assembles values from the fully-resolved node configuration rather than from a partial Config, so there is no "not yet known" case to leave room for.
The read/evaluate/persist/verify body is shared with CheckNodeSettings via evaluateAndPersistGates (database/commit_timestamp.go); this is just that call with phase 2's configured map.
func (*Database) FlushBatch ¶ added in v0.45.0
func (d *Database) FlushBatch( acc BatchAccumulator, txn *Txn, ) error
FlushBatch writes accumulated metadata rows for the active metadata plugin.
func (*Database) ForecastPParamUpdates ¶ added in v0.69.0
func (d *Database) ForecastPParamUpdates( epoch uint64, quorum int, currentPParams lcommon.ProtocolParameters, decodeFunc func([]byte) (any, error), updateFunc func( lcommon.ProtocolParameters, any, ) (lcommon.ProtocolParameters, error), cloneFunc func(lcommon.ProtocolParameters) (lcommon.ProtocolParameters, error), txn *Txn, ) (lcommon.ProtocolParameters, error)
ForecastPParamUpdates computes the protocol parameters that the epoch rollover will enact for the given epoch by applying the pending proposed protocol-parameter update already collected in ledger state, WITHOUT persisting anything. It mirrors ComputeAndApplyPParamUpdates' quorum, decode, and apply semantics exactly — same submission-epoch lookup (updates submitted in epoch-1), same unique-genesis quorum count, same latest-update selection via selectPParamUpdateForEnactment — but performs no writes, so it is safe to call from header verification and concurrently.
It does not mutate currentPParams: era update functions mutate their concrete pointer in place (see PParamsUpdateShelley), so before applying an update it clones currentPParams via cloneFunc and mutates the clone. The clone happens only when an update will actually be enacted, so the common no-op forecast pays no clone cost and returns the original currentPParams pointer. When no pending update meets quorum for the epoch — no proposals, quorum not met, or epoch is 0 — it returns currentPParams unchanged, matching the "nothing enacted" forecast.
func (*Database) GetAccountByCredential ¶ added in v0.55.0
func (d *Database) GetAccountByCredential( credentialTag uint8, stakeKey []byte, includeInactive bool, txn *Txn, ) (*models.Account, error)
GetAccountByCredential returns an account by staking credential tag and key.
func (*Database) GetAccountDelegationHistoryByCredential ¶ added in v0.55.0
func (d *Database) GetAccountDelegationHistoryByCredential( credentialTag uint8, stakeKey []byte, limit int, offset int, order string, txn *Txn, ) ([]models.AccountDelegationHistoryRow, error)
GetAccountDelegationHistoryByCredential returns delegation history rows for a stake credential.
func (*Database) GetAccountImportRegistrationByCredential ¶ added in v0.70.4
func (d *Database) GetAccountImportRegistrationByCredential( credentialTag uint8, stakeKey []byte, txn *Txn, ) (*models.AccountImportRegistration, error)
GetAccountImportRegistrationByCredential returns the virtual registration stored with a snapshot-imported account baseline.
func (*Database) GetAccountRegistrationHistoryByCredential ¶ added in v0.55.0
func (d *Database) GetAccountRegistrationHistoryByCredential( credentialTag uint8, stakeKey []byte, limit int, offset int, order string, txn *Txn, ) ([]models.AccountRegistrationHistoryRow, error)
GetAccountRegistrationHistoryByCredential returns registration history rows for a stake credential.
func (*Database) GetAccountSumsByCredential ¶ added in v0.59.0
func (d *Database) GetAccountSumsByCredential( credentialTag uint8, stakeKey []byte, txn *Txn, ) (models.AccountSums, error)
GetAccountSumsByCredential returns the aggregated withdrawal, reserves, and treasury lovelace totals for a stake credential.
func (*Database) GetAccountWithdrawalHistoryByCredential ¶ added in v0.69.0
func (d *Database) GetAccountWithdrawalHistoryByCredential( credentialTag uint8, stakeKey []byte, limit int, offset int, order string, txn *Txn, ) ([]models.AccountWithdrawalHistoryRow, error)
GetAccountWithdrawalHistoryByCredential returns withdrawal history rows for a stake credential.
func (*Database) GetAccountsByCredential ¶ added in v0.55.0
func (d *Database) GetAccountsByCredential( refs []models.StakeCredentialRef, includeInactive bool, txn *Txn, ) (map[string]*models.Account, error)
GetAccountsByCredential returns accounts for the given staking credentials in a single query, keyed by StakeCredentialRef.MapKey().
func (*Database) GetActiveCommitteeMembers ¶ added in v0.22.0
func (d *Database) GetActiveCommitteeMembers( txn *Txn, ) ([]*models.AuthCommitteeHot, error)
GetActiveCommitteeMembers returns all active committee members
func (*Database) GetActiveDreps ¶ added in v0.22.0
GetActiveDreps returns all active DReps
func (*Database) GetActiveGovernanceProposals ¶ added in v0.22.0
func (d *Database) GetActiveGovernanceProposals( epoch uint64, txn *Txn, ) ([]*models.GovernanceProposal, error)
GetActiveGovernanceProposals returns all governance proposals that are still in the active pool (not expired, not enacted, not soft-deleted).
func (*Database) GetActivePoolKeyHashes ¶ added in v0.55.0
GetActivePoolKeyHashes returns the key hashes of all currently active (registered, non-retired) stake pools. This backs the GetStakePools local-state-query.
func (*Database) GetActivePoolKeyHashesOrdered ¶ added in v0.69.0
GetActivePoolKeyHashesOrdered returns the key hashes of all currently active (registered, non-retired) stake pools, ordered oldest-first by each pool's earliest on-chain registration certificate. See metadata.MetadataStore.GetActivePoolKeyHashesOrdered for the full ordering semantics. This backs the Blockfrost pool_list endpoint.
func (*Database) GetActivePoolRelays ¶ added in v0.21.0
func (d *Database) GetActivePoolRelays( txn *Txn, ) ([]models.PoolRegistrationRelay, error)
GetActivePoolRelays returns all relays from currently active pools. This is used for ledger peer discovery.
func (*Database) GetAddressTransactionsByCredential ¶ added in v0.69.0
func (d *Database) GetAddressTransactionsByCredential( credentialTag uint8, stakeKey []byte, limit int, offset int, order string, from *models.AddressTransactionPosition, to *models.AddressTransactionPosition, txn *Txn, ) ([]models.AccountTransactionAssociationRow, error)
GetAddressTransactionsByCredential returns one page of (payment address, transaction) association rows for a stake credential, optionally bounded by an inclusive from/to (slot, tx_index) range.
func (*Database) GetAddressesByCredential ¶ added in v0.55.0
func (d *Database) GetAddressesByCredential( credentialTag uint8, stakingKey []byte, limit int, offset int, order string, txn *Txn, ) ([]models.AddressTransaction, error)
GetAddressesByCredential returns distinct address mappings for a stake credential.
func (*Database) GetBlockNonce ¶ added in v0.11.0
GetBlockNonce fetches the block nonce for a given chain point
func (*Database) GetBlockNoncesInSlotRange ¶ added in v0.22.0
func (d *Database) GetBlockNoncesInSlotRange( startSlot uint64, endSlot uint64, txn *Txn, ) ([]models.BlockNonce, error)
GetBlockNoncesInSlotRange fetches all block nonces in [startSlot, endSlot).
func (*Database) GetChildGovernanceProposals ¶ added in v0.55.0
func (d *Database) GetChildGovernanceProposals( parentTxHash []byte, parentActionIdx uint32, txn *Txn, ) ([]*models.GovernanceProposal, error)
GetChildGovernanceProposals returns all active proposals whose parent is the given proposal (parentTxHash + parentActionIdx). Only proposals not yet enacted, expired, or soft-deleted are returned. Used during epoch boundary orphan sweeps.
func (*Database) GetCommitteeActiveCount ¶ added in v0.22.0
GetCommitteeActiveCount returns the number of active (non-resigned) committee members.
func (*Database) GetCommitteeMember ¶ added in v0.22.0
func (d *Database) GetCommitteeMember( coldCredentialTag uint8, coldKey []byte, termStartSlot uint64, txn *Txn, ) (*models.AuthCommitteeHot, error)
GetCommitteeMember returns a committee member by cold key
func (*Database) GetCommitteeMembers ¶ added in v0.37.0
func (d *Database) GetCommitteeMembers( txn *Txn, ) ([]*models.CommitteeMember, error)
GetCommitteeMembers returns all active (non-deleted) governance-enacted committee members.
func (*Database) GetCommitteeMembersIncludeDeleted ¶ added in v0.37.0
func (d *Database) GetCommitteeMembersIncludeDeleted( txn *Txn, ) ([]*models.CommitteeMember, error)
GetCommitteeMembersIncludeDeleted returns all committee members including soft-deleted rows. Used to detect whether a committee was ever seated — after a NoConfidence action, GetCommitteeMembers returns no rows, but the committee was seated previously.
func (*Database) GetCommitteeQuorum ¶ added in v0.37.0
GetCommitteeQuorum returns the latest enacted committee quorum.
func (*Database) GetConstitution ¶ added in v0.22.0
func (d *Database) GetConstitution(txn *Txn) (*models.Constitution, error)
GetConstitution returns the current constitution
func (*Database) GetControlledAmountByCredential ¶ added in v0.55.0
func (d *Database) GetControlledAmountByCredential( credentialTag uint8, stakingKey []byte, txn *Txn, ) (uint64, error)
GetControlledAmountByCredential returns the sum of live UTxO amounts controlled by the given stake credential.
func (*Database) GetDRepDelegators ¶ added in v0.59.0
func (d *Database) GetDRepDelegators( credentialTag uint8, drepCredential []byte, txn *Txn, ) ([]models.StakeCredentialRef, error)
GetDRepDelegators returns the stake credentials currently delegating their voting power to the given DRep, in canonical (tag, hash) order. This is the `delegators` member of the GetDRepState ledger query result. credentialTag distinguishes key (0) from script (1) DRep credentials sharing the same hash.
func (*Database) GetDRepVotingPower ¶ added in v0.22.0
func (d *Database) GetDRepVotingPower( credentialTag uint8, drepCredential []byte, expiryEpoch uint64, txn *Txn, ) (uint64, error)
GetDRepVotingPower calculates the voting power for a DRep by summing the current stake of all delegated accounts, approximated from live UTxO balance plus reward-account balance. credentialTag distinguishes key (0) from script (1) DRep credentials sharing the same 28-byte hash. expiryEpoch is the CIP-0163 reward-account inactivity gate: 0 = off (byte-identical to the pre-CIP query), >0 = exclude accounts whose expiration_epoch is nonzero and less than expiryEpoch.
func (*Database) GetDRepVotingPowerBatch ¶ added in v0.37.0
func (d *Database) GetDRepVotingPowerBatch( drepCredentials []models.StakeCredentialRef, expiryEpoch uint64, txn *Txn, ) (map[string]uint64, error)
GetDRepVotingPowerBatch is the batch form of GetDRepVotingPower; see the metadata-store interface for the contract. expiryEpoch is the CIP-0163 gate; see GetDRepVotingPower.
func (*Database) GetDRepVotingPowerByType ¶ added in v0.37.0
func (d *Database) GetDRepVotingPowerByType( drepTypes []uint64, expiryEpoch uint64, txn *Txn, ) (map[uint64]uint64, error)
GetDRepVotingPowerByType returns voting power grouped by DRep delegation type. expiryEpoch is the CIP-0163 gate; see GetDRepVotingPower.
func (*Database) GetDrep ¶ added in v0.18.0
GetDrep returns a drep by credential hash only (no tag filter). Use for the protocol validation path where only a hash is available.
func (*Database) GetDrepByCredential ¶ added in v0.55.0
func (d *Database) GetDrepByCredential( credentialTag uint8, cred []byte, includeInactive bool, txn *Txn, ) (*models.Drep, error)
GetDrepByCredential returns a drep by the full credential identity (tag + hash).
func (*Database) GetDrepLastRegistrationDeposit ¶ added in v0.70.7
func (d *Database) GetDrepLastRegistrationDeposit( credentialTag uint8, credential []byte, txn *Txn, ) (*uint64, error)
GetDrepLastRegistrationDeposit returns the deposit amount recorded against the most recent registration certificate for the DRep credential, or nil when no recorded deposit exists.
func (*Database) GetDrepLastRegistrationDeposits ¶ added in v0.70.7
GetDrepLastRegistrationDeposits returns the most recent registration deposit of every active DRep, keyed by models.DrepDepositKey, so a caller listing all active DReps does not need one query per DRep. Credentials with no registration_drep row are absent from the map.
func (*Database) GetEnactedGovernanceProposalsAt ¶ added in v0.64.0
func (d *Database) GetEnactedGovernanceProposalsAt( epoch uint64, slot uint64, txn *Txn, ) ([]*models.GovernanceProposal, error)
GetEnactedGovernanceProposalsAt returns proposals enacted at the exact epoch-boundary slot. Used by epoch replay to restore enactment effects.
func (*Database) GetEpochBySlot ¶ added in v0.37.0
func (*Database) GetEpochsByEra ¶ added in v0.4.3
func (*Database) GetExpiredDReps ¶ added in v0.22.0
GetExpiredDReps returns all active DReps whose expiry epoch is at or before the given epoch.
func (*Database) GetExpiredGovernanceProposalsAt ¶ added in v0.64.0
func (d *Database) GetExpiredGovernanceProposalsAt( epoch uint64, slot uint64, txn *Txn, ) ([]*models.GovernanceProposal, error)
GetExpiredGovernanceProposalsAt returns proposals expired at the exact epoch-boundary slot. Used by epoch replay to restore deposit-return effects.
func (*Database) GetExpiringGovernanceProposals ¶ added in v0.37.0
func (d *Database) GetExpiringGovernanceProposals( epoch uint64, txn *Txn, ) ([]*models.GovernanceProposal, error)
GetExpiringGovernanceProposals returns proposals whose expires_epoch is strictly less than the given epoch and that have not yet been enacted, expired, or soft-deleted.
func (*Database) GetGovernanceProposal ¶ added in v0.22.0
func (d *Database) GetGovernanceProposal( txHash []byte, actionIndex uint32, txn *Txn, ) (*models.GovernanceProposal, error)
GetGovernanceProposal returns a governance proposal by transaction hash and action index
func (*Database) GetGovernanceVotes ¶ added in v0.22.0
func (d *Database) GetGovernanceVotes( proposalID uint, txn *Txn, ) ([]*models.GovernanceVote, error)
GetGovernanceVotes returns all votes for a governance proposal
func (*Database) GetLastBlockNonceInRange ¶ added in v0.35.1
func (d *Database) GetLastBlockNonceInRange( startSlot uint64, endSlot uint64, txn *Txn, ) ([]byte, error)
GetLastBlockNonceInRange retrieves the block nonce with the highest slot in [startSlot, endSlot). Returns nil nonce and no error if none found.
func (*Database) GetLastEnactedGovernanceProposal ¶ added in v0.37.0
func (d *Database) GetLastEnactedGovernanceProposal( actionTypes []uint8, txn *Txn, ) (*models.GovernanceProposal, error)
GetLastEnactedGovernanceProposal returns the most recently enacted proposal whose action_type is in actionTypes, or nil if none exist. Callers group per-purpose action types (CIP-1694 chain roots) in the slice; the single-type case passes a one-element slice.
func (*Database) GetLatestBlockNonce ¶ added in v0.69.0
GetLatestBlockNonce returns the highest-slot block_nonce row, the authoritative high-water mark of durably applied ledger state. The bool is false when no rows exist.
func (*Database) GetLatestMidnightAriadneParams ¶ added in v0.61.0
func (d *Database) GetLatestMidnightAriadneParams() (*models.MidnightAriadneParams, error)
GetLatestMidnightAriadneParams returns the most recently stored Ariadne parameters row (ordered by epoch DESC), or nil if none exist.
func (*Database) GetLatestMidnightGovernanceDatum ¶ added in v0.61.0
func (d *Database) GetLatestMidnightGovernanceDatum( datumType string, blockNumber uint64, ) (*models.MidnightGovernanceDatum, error)
GetLatestMidnightGovernanceDatum returns the newest datum of datumType at or before blockNumber, or nil when no matching datum exists.
func (*Database) GetLeiosEBManifest ¶ added in v0.61.1
GetLeiosEBManifest retrieves the raw Leios endorser-block manifest CBOR for the exact (slot, hash) occurrence named. Returns ErrBlobKeyNotFound when no manifest has been stored for that occurrence -- including when a manifest exists for the same hash under a different slot, since the manifest is content-addressed and that is a distinct occurrence (issue #3513 review).
On a miss it also tries the pre-issue-#3513 legacy key (hash only), so data persisted by a node running before the key format changed does not become silently unreachable after an upgrade: that format could only ever hold one occurrence per hash, and its value carries that occurrence's slot as an 8-byte big-endian prefix, which must match the requested slot before the legacy record is trusted (cubic review).
func (*Database) GetLeiosEBTxs ¶ added in v0.61.1
GetLeiosEBTxs retrieves the raw transaction bodies for the exact (slot, hash) occurrence named. Returns ErrBlobKeyNotFound when no txs have been stored for that occurrence. The returned slice is in the same CBOR-in-CBOR wrapped format used by the leios-fetch MsgBlockTxs wire message.
On a miss it also tries the pre-issue-#3513 legacy key (hash only, see GetLeiosEBManifest), gated on the legacy "em" record's embedded slot matching: the legacy format paired one "em" and one "et" record per hash (only one occurrence was ever trackable), so once that pairing is confirmed to be this occurrence, its "et" value is safe to use too (cubic review).
func (*Database) GetMIRCertsInSlotRange ¶ added in v0.55.0
func (d *Database) GetMIRCertsInSlotRange( startSlot, endSlot uint64, txn *Txn, ) ([]models.MIREffect, error)
GetMIRCertsInSlotRange returns the processed effects of all MIR certificates whose added_slot is >= startSlot and < endSlot. Used to apply the Shelley-era INSTANT rule at each epoch boundary.
func (*Database) GetMidnightAriadneParamsAtOrBeforeEpoch ¶ added in v0.63.0
func (d *Database) GetMidnightAriadneParamsAtOrBeforeEpoch( epoch uint64, ) (*models.MidnightAriadneParams, error)
GetMidnightAriadneParamsAtOrBeforeEpoch returns the newest Ariadne params row at or before epoch, or nil when none exists.
func (*Database) GetMidnightCandidates ¶ added in v0.61.0
GetMidnightCandidates returns the live, materialized UTxOs at the configured committee-candidate address so the in-memory index survives restarts.
func (*Database) GetMidnightCommitteeCandidateRegistrationsByTxHashes ¶ added in v0.63.0
func (d *Database) GetMidnightCommitteeCandidateRegistrationsByTxHashes( txHashes [][]byte, ) ([]models.MidnightCommitteeCandidateRegistration, error)
GetMidnightCommitteeCandidateRegistrationsByTxHashes returns every candidate-registration provenance row whose tx_hash is in txHashes.
func (*Database) GetMidnightEpochCandidatesByEpoch ¶ added in v0.63.0
func (d *Database) GetMidnightEpochCandidatesByEpoch( epoch uint64, ) (*models.MidnightEpochCandidates, error)
GetMidnightEpochCandidatesByEpoch returns the committee-candidate snapshot for one epoch, or nil when none exists.
func (*Database) GetPParams ¶ added in v0.4.4
func (d *Database) GetPParams( epoch uint64, eraId uint, decodeFunc func([]byte) (lcommon.ProtocolParameters, error), txn *Txn, ) (lcommon.ProtocolParameters, error)
GetPParams resolves the protocol-parameters row at epoch <= the supplied epoch whose era_id matches eraId, then decodes it with decodeFunc. The era filter is required because at era boundaries the rollover path writes both an old-era row (post-pparams-update) and a new-era row (transitionToEra) at the same epoch — without the filter, the latest insert wins regardless of shape and the caller's era-specific decoder rejects the CBOR on element count.
func (*Database) GetPool ¶ added in v0.17.0
func (d *Database) GetPool( pkh lcommon.PoolKeyHash, includeInactive bool, txn *Txn, ) (*models.Pool, error)
GetPool returns a pool by its key hash
func (*Database) GetPoolByVrfKeyHash ¶ added in v0.22.0
GetPoolByVrfKeyHash retrieves an active pool by its VRF key hash. Returns nil if no active pool uses this VRF key.
func (*Database) GetPoolCertificateHistory ¶ added in v0.69.0
func (d *Database) GetPoolCertificateHistory( pkh lcommon.PoolKeyHash, txn *Txn, ) ([][]byte, [][]byte, error)
GetPoolCertificateHistory returns the transaction hashes of a pool's registration and retirement certificates, in chronological order.
func (*Database) GetPoolRegistrations ¶ added in v0.4.3
func (d *Database) GetPoolRegistrations( poolKeyHash lcommon.PoolKeyHash, txn *Txn, ) ([]lcommon.PoolRegistrationCertificate, error)
GetPoolRegistrations returns a list of pool registration certificates
func (*Database) GetPoolStakeSnapshotsByEpoch ¶ added in v0.63.0
func (d *Database) GetPoolStakeSnapshotsByEpoch( epoch uint64, snapshotType string, txn *Txn, ) ([]*models.PoolStakeSnapshot, error)
GetPoolStakeSnapshotsByEpoch returns all pool stake snapshots of snapshotType for the given epoch.
func (*Database) GetPoolsRetiringAtEpoch ¶ added in v0.55.0
func (d *Database) GetPoolsRetiringAtEpoch( epoch uint64, boundarySlot uint64, txn *Txn, ) ([]models.PoolRetirementRefund, error)
GetPoolsRetiringAtEpoch returns the pools whose effective retirement takes effect at the given epoch as of the boundary slot, with the reward account and deposit needed to refund their POOLREAP deposit.
func (*Database) GetRatifiedGovernanceProposals ¶ added in v0.37.0
func (d *Database) GetRatifiedGovernanceProposals( txn *Txn, ) ([]*models.GovernanceProposal, error)
GetRatifiedGovernanceProposals returns proposals ratified but not yet enacted, ordered by (ratified_epoch, ratified_slot, id). Used at epoch start for enactment.
func (*Database) GetResignedCommitteeMembers ¶ added in v0.37.0
func (d *Database) GetResignedCommitteeMembers( coldCredentials []models.CommitteeCredential, txn *Txn, ) (map[string]bool, error)
GetResignedCommitteeMembers returns cold credentials with a resignation record in each credential's selected membership term.
func (*Database) GetRewardAccountOutputsByCredential ¶ added in v0.69.0
func (d *Database) GetRewardAccountOutputsByCredential( credentialTag uint8, stakingKey []byte, limit int, offset int, order string, txn *Txn, ) ([]*models.RewardAccountOutput, error)
GetRewardAccountOutputsByCredential returns reward account output rows for a stake credential across every epoch that has not yet been pruned, paginated and ordered by epoch. Used by the Blockfrost account reward-history endpoint (GET /accounts/{stake_address}/rewards).
func (*Database) GetStakeRegistrationsByCredential ¶ added in v0.55.0
func (d *Database) GetStakeRegistrationsByCredential( credentialTag uint8, stakingKey []byte, txn *Txn, ) ([]lcommon.StakeRegistrationCertificate, error)
GetStakeRegistrationsByCredential returns stake registration certificates for the full stake credential identity.
func (*Database) GetSyncState ¶ added in v0.22.0
GetSyncState retrieves a sync state value by key. Returns empty string if the key does not exist.
func (*Database) GetTip ¶ added in v0.4.3
func (d *Database) GetTip(txn *Txn) (ochainsync.Tip, error)
GetTip returns the current tip as represented by the protocol
func (*Database) GetTransactionByHash ¶ added in v0.21.0
func (*Database) GetTransactionMetadataByHash ¶ added in v0.63.1
GetTransactionMetadataByHash returns only the stored metadata blob for the transaction with the given hash, without loading any associations. Returns (nil, nil) when no such transaction exists or it carries no metadata.
func (*Database) GetTransactionsByAddress ¶ added in v0.22.0
func (d *Database) GetTransactionsByAddress( addr lcommon.Address, limit int, offset int, txn *Txn, ) ([]models.Transaction, error)
GetTransactionsByAddress returns transactions that involve a given address as either a sender (input) or receiver (output). Results are returned in descending on-chain order.
func (*Database) GetTransactionsByAddressKeys ¶ added in v0.22.0
func (d *Database) GetTransactionsByAddressKeys( paymentKey []byte, credentialTag uint8, stakingKey []byte, limit int, offset int, order string, txn *Txn, ) ([]models.Transaction, error)
GetTransactionsByAddressKeys returns transactions for a payment/staking credential tuple with pagination and explicit order (asc|desc).
func (*Database) GetTransactionsByAddressWithOrder ¶ added in v0.33.0
func (d *Database) GetTransactionsByAddressWithOrder( addr lcommon.Address, limit int, offset int, order string, txn *Txn, ) ([]models.Transaction, error)
GetTransactionsByAddressWithOrder returns transactions involving a given address with explicit ordering.
func (*Database) GetTransactionsByBlockHash ¶ added in v0.22.0
func (d *Database) GetTransactionsByBlockHash( blockHash []byte, txn *Txn, ) ([]models.Transaction, error)
GetTransactionsByBlockHash returns all transactions for a given block hash, ordered by their position within the block.
func (*Database) GetTransactionsByHashes ¶ added in v0.33.0
func (d *Database) GetTransactionsByHashes( hashes [][]byte, txn *Txn, ) ([]models.Transaction, error)
GetTransactionsByHashes returns transactions for the provided hashes.
func (*Database) GetTransactionsByMetadataLabel ¶ added in v0.28.0
func (d *Database) GetTransactionsByMetadataLabel( label uint64, limit int, offset int, descending bool, txn *Txn, ) ([]models.Transaction, error)
GetTransactionsByMetadataLabel returns transactions that include metadata for a given label key.
func (*Database) GetUtxoPaymentScriptByCredential ¶ added in v0.69.0
func (d *Database) GetUtxoPaymentScriptByCredential( credentialTag uint8, stakingKey []byte, paymentKeys [][]byte, txn *Txn, ) (map[string]bool, error)
GetUtxoPaymentScriptByCredential returns, for the given bounded set of payment-key hashes previously observed under a stake credential, whether each payment credential is a script hash. See the metadata store interface doc comment for the full contract.
func (*Database) HasAnyGenesisCbor ¶ added in v0.22.0
HasAnyGenesisCbor checks whether any genesis CBOR data exists at the given slot, regardless of hash. This is used to distinguish between "no genesis CBOR" (e.g., after Mithril bootstrap) and "genesis CBOR exists but with a different hash" (true network mismatch).
func (*Database) HasGenesisCbor ¶ added in v0.22.0
HasGenesisCbor checks whether genesis CBOR data exists at the expected blob key for the given slot and hash. This is used to validate that existing chain data matches the current genesis configuration.
func (*Database) HasTransactionsByAddress ¶ added in v0.68.0
HasTransactionsByAddress reports whether at least one transaction involves the given exact address.
func (*Database) ImportPool ¶ added in v0.64.0
ImportPool upserts a pool and creates a registration record. A supplied txn must be writable and include a metadata handle. When txn is nil a write transaction is opened, committed on success and rolled back on error via Txn.Do.
func (*Database) InsertDrepIfAbsent ¶ added in v0.37.0
func (d *Database) InsertDrepIfAbsent( credentialTag uint8, cred []byte, slot uint64, url string, hash []byte, active bool, txn *Txn, ) error
InsertDrepIfAbsent inserts a minimal DRep row when no record exists for the given credential. Existing rows are left untouched so real registration metadata (added_slot, anchor_url, anchor_hash, active) is never overwritten by the vote-replay recovery path.
func (*Database) InsertMidnightGovernanceDatum ¶ added in v0.61.0
func (d *Database) InsertMidnightGovernanceDatum( datum *models.MidnightGovernanceDatum, ) error
InsertMidnightGovernanceDatum inserts a new governance datum row. Always inserts — never overwrites — so the latest datum is found by querying with ORDER BY block_number DESC.
func (*Database) IsCommitteeMemberResigned ¶ added in v0.22.0
func (d *Database) IsCommitteeMemberResigned( coldCredentialTag uint8, coldKey []byte, termStartSlot uint64, txn *Txn, ) (bool, error)
IsCommitteeMemberResigned checks if a committee member has resigned
func (*Database) IterateLiveUtxos ¶ added in v0.37.0
IterateLiveUtxos invokes fn once for each live UTxO row (DeletedSlot == 0). The callback receives a pointer to a row whose Cbor field has been populated from blob storage (or recovered from the producing block) — copy out anything you intend to retain because the underlying buffer is reused between callbacks. Returning a non-nil error from fn aborts iteration and that error is propagated up; CBOR-loading failures are also propagated. When txn is nil a read transaction is opened internally.
func (*Database) LatestPoolOpCertSequence ¶ added in v0.46.0
func (d *Database) LatestPoolOpCertSequence( pkh lcommon.PoolKeyHash, txn *Txn, ) (uint64, bool, error)
LatestPoolOpCertSequence returns the highest observed op-cert sequence for a pool.
func (*Database) LatestPoolOpCertSequenceAfter ¶ added in v0.70.2
func (d *Database) LatestPoolOpCertSequenceAfter( pkh lcommon.PoolKeyHash, afterSlot uint64, txn *Txn, ) (uint64, bool, error)
LatestPoolOpCertSequenceAfter returns the highest observed op-cert sequence for a pool strictly after afterSlot.
func (*Database) LatestPoolOpCertSequenceAtOrBefore ¶ added in v0.70.2
func (d *Database) LatestPoolOpCertSequenceAtOrBefore( pkh lcommon.PoolKeyHash, slot uint64, txn *Txn, ) (uint64, bool, error)
LatestPoolOpCertSequenceAtOrBefore returns the highest observed op-cert sequence for a pool at or before slot. It provides a historical chain-dependent view without changing or restoring the live database tip.
func (*Database) LatestPoolOpCertSequences ¶ added in v0.69.0
LatestPoolOpCertSequences returns the highest observed op-cert sequence for every pool that has issued a block, keyed by pool key hash. This backs the GetChainDepState local-state-query, whose counters cover every cold key the chain has accepted a certificate for rather than only the active pools.
func (*Database) ListSyncStateKeysByPrefix ¶ added in v0.70.6
ListSyncStateKeysByPrefix returns every sync_state key beginning with prefix.
func (*Database) MarkUtxosDeletedAtSlot ¶ added in v0.37.0
MarkUtxosDeletedAtSlot marks every live UTxO row matching one of refs as deleted at atSlot. Refs that don't match any live row are silently ignored; rollback un-deletion is handled by the existing rollback path (SetUtxosNotDeletedAfterSlot). When txn is nil a write transaction is opened, committed on success and rolled back on error via Txn.Do.
func (*Database) MatchingUtxoRefsByAddressWithOrdering ¶ added in v0.70.3
func (d *Database) MatchingUtxoRefsByAddressWithOrdering( q *models.UtxoWithOrderingQuery, txn *Txn, ) ([]models.UtxoId, error)
MatchingUtxoRefsByAddressWithOrdering returns the (TxId, OutputIdx) references of every live UTxO matching q's address patterns, in ascending producing-transaction-position order, without loading assets or retaining full rows. Unlike CountUtxosByAddressWithOrdering, this works for exact-address patterns too: it scans coarse SQL candidates in keyset batches (see UtxosByAddressWithOrdering's identical loop) and CBOR-decodes each to confirm the match, which is the same per-candidate cost the coarse predicate alone cannot avoid, but skips the asset loading and full UtxoWithOrdering retention a straight fetch would pay for every candidate instead of only the page a caller goes on to request via UtxosByRefs.
The result both is the accurate total (its length) and can be sliced for a page's worth of references to pass to UtxosByRefs, letting a caller avoid materializing more than one page of an address's UTxO history.
func (*Database) MaxLeiosEBSlot ¶ added in v0.70.10
MaxLeiosEBSlot returns the highest slot represented by a persisted Leios endorser-block manifest. Current records encode the slot in the key; legacy records (pre-issue-#3513, "em"+hash with no slot) encode it in the first eight bytes of the value.
COST. The full prefix scan is inherent, not an oversight: the current key layout is "em"+hash+slot, so keys sort by hash and no bounded reverse seek can find the maximum slot. The scan runs synchronously from newOuroboros at startup. On badger it is key-only -- the iterator options leave PrefetchValues false and only the legacy branch copies a value -- while on the S3 and GCS blob plugins the same call is a paginated object listing over the whole prefix, with no deadline on the startup path. Ordering the keys by slot, or maintaining the maximum as its own record, is what would make it bounded.
func (*Database) Metadata ¶
func (d *Database) Metadata() metadata.MetadataStore
Metadata returns the underlying metadata store instance
func (*Database) MetadataTxn ¶ added in v0.4.3
MetadataTxn starts a new metadata-only database transaction and returns a handle to it
func (*Database) MithrilTrustBoundarySlot ¶ added in v0.69.0
MithrilTrustBoundarySlot returns the recorded Mithril trust boundary slot, or 0 if none is recorded (genesis sync, or a non-genesis chainsync intersect point with no snapshot import). A failure to read the sync state is logged and also treated as 0 (the caller cannot distinguish it from "no boundary recorded" by return value alone), but the log lets an operator tell a transient storage problem apart from a genuinely unrecoverable UTxO when StrictUtxoValidation turns the latter into an ingest error.
This fail-open behavior is intentional for that caller (a best-effort recovery heuristic), but wrong for a caller enforcing a safety check — see MithrilTrustBoundarySlotStrict, used by database/lifecycle.Truncate, where treating a failed read as "no boundary recorded" would silently let a truncate proceed past a boundary that could not actually be verified, rather than merely under-informing a heuristic.
func (*Database) MithrilTrustBoundarySlotStrict ¶ added in v0.69.0
MithrilTrustBoundarySlotStrict is MithrilTrustBoundarySlot, but returns the underlying read error instead of swallowing it as "no boundary recorded" — for a caller that must fail closed (refuse the operation) rather than fail open when the boundary can't be verified. A malformed stored value is also propagated as an error here (unlike MithrilTrustBoundarySlot, which still treats it as absent): a corrupted persisted boundary must not be indistinguishable from "no snapshot was ever imported" for a caller enforcing a safety check, or the check is defeated exactly when it matters most.
That includes a recorded empty value. GetSyncState reports an absent key as the empty string, so an empty return alone cannot tell "no snapshot was ever imported" from "a boundary row exists and holds nothing"; only the second is malformed, and the two are separated here by asking the sync_state keyspace whether the row exists at all. The extra query runs only on that path.
func (*Database) NewBatchAccumulator ¶ added in v0.45.0
func (d *Database) NewBatchAccumulator() BatchAccumulator
NewBatchAccumulator creates an accumulator for the configured metadata plugin.
func (*Database) PauseCommits ¶ added in v0.69.0
func (d *Database) PauseCommits() (resume func())
PauseCommits blocks until every currently open read-write Txn that participates in this barrier (see acquireCommitBarrier) has reached Commit, Rollback, or Release — not merely until one already inside its Commit call finishes, but until every such Txn opened before this call, however far along it currently is, concludes one way or another — then blocks any new one from being constructed until the returned resume func is called. It does not stop reads, and it is not a quiesce — nothing is torn down, no peers are disconnected, callers just see a new read-write Txn's construction (not its eventual Commit) block briefly.
database/lifecycle.Snapshot uses this to bracket its blob and metadata backup calls: each backup is independently consistent as of whenever it runs, but a commit landing between the two would write its timestamp to one store's backup and not the other's, so the restored copy fails checkCommitTimestamp's cross-check. Pausing commits for that window keeps both backups describing the same set of committed writes.
func (*Database) PauseCommitsContext ¶ added in v0.69.0
PauseCommitsContext is PauseCommits, but the wait for the barrier can be abandoned via ctx: if a long-running write transaction is currently open, acquiring the exclusive side can block for as long as that transaction takes to commit, and plain PauseCommits gives a caller like lifecycle.Snapshot (which already accepts a ctx for the rest of its work) no way to give up on that wait if its own operation is cancelled.
If ctx is cancelled before the barrier is acquired, this returns ctx.Err() and a nil resume, having fully withdrawn its claim on the barrier: unlike a plain sync.RWMutex (which has no cancellable Lock and so would leave an abandoned Lock() call queued, blocking every new read-write Txn behind it via writer preference until whatever it was waiting on eventually releases — see cancellableBarrier's doc comment), a cancelled wait here does not stall anything else.
func (*Database) PinBlob ¶ added in v0.70.7
PinBlob pins the currently installed blob store for the duration of one operation and returns it alongside the func that releases the pin. Call the release func exactly once, normally with defer:
store, release := db.PinBlob()
defer release()
if store == nil {
return types.ErrBlobStoreUnavailable
}
A concurrent SetBlobStore's drain does not return while the pin is held, so the store cannot be closed out from under the operation. Work that already runs inside a database Txn does not need this — the Txn holds a pin for its whole lifetime and Txn.BlobStore returns the store it pinned.
func (*Database) PruneBlock ¶ added in v0.37.0
PruneBlock expires the given block's local CBOR in the blob store after materializing any active UTxOs that still reference it. The block's CBOR is replaced with a small expired-history marker; index pointers (bi, bh) and metadata are kept so local reads can return ErrHistoryExpired and an optional archive proxy can still resolve the block by (slot, hash).
UTxO blob entries are stored as 52-byte CborOffset references that point into a source block's CBOR. Tombstoning a block while live UTxOs still reference it would leave those UTxOs unresolvable. To preserve them, PruneBlock first finds every UTxO with added_slot equal to the pruned block's slot, decodes its offset, slices the underlying CBOR out of the block, and rewrites the UTxO blob entry as raw CBOR (which the resolver treats as the legacy non-offset format). The block expiry marker and all UTxO rewrites happen in a single blob transaction, so the block is never expired while live UTxOs still depend on it.
In core storage mode only live (deleted_slot = 0) UTxOs at the slot are considered, because spent UTxOs are hard-deleted by the periodic stability-window cleanup and need no historical resolution. In API storage mode the cleanup is skipped and spent UTxO rows are retained indefinitely for historical transaction queries; in that mode every UTxO at the slot (including spent rows whose blob entries still hold offset references) is materialized so CBOR resolution survives the expired block without requiring a wrapping archive proxy.
Returns the number of UTxOs that were materialized.
func (*Database) RebuildRewardLiveStake ¶ added in v0.65.0
RebuildRewardLiveStake rebuilds the live reward stake aggregate from canonical account and live UTxO metadata.
func (*Database) RenewAccountExpirations ¶ added in v0.67.0
func (d *Database) RenewAccountExpirations( refs []models.StakeCredentialRef, expirationEpoch uint64, txn *Txn, ) error
RenewAccountExpirations sets the CIP-0163 expirationEpoch for the given reward-account credentials. See the metadata store implementation for semantics (refs with no matching account row are ignored). When txn is nil a write transaction is opened, committed on success and rolled back on error via Txn.Do; pass an existing write txn to participate in a wider unit of work.
func (*Database) ResetAccountExpirationActivation ¶ added in v0.67.0
func (d *Database) ResetAccountExpirationActivation( txn *Txn, ) ([]models.StakeCredentialRef, error)
ResetAccountExpirationActivation clears expiration from every account in the durable activation-membership set, deletes that set, and returns the affected credentials so the ledger can reconstruct any overwritten pre-activation witness expiration. When txn is nil, the operation runs in its own write transaction.
func (*Database) ResolvePoolRewardAccountAutoVotes ¶ added in v0.49.0
func (d *Database) ResolvePoolRewardAccountAutoVotes( snapshots []*models.PoolStakeSnapshot, txn *Txn, ) error
ResolvePoolRewardAccountAutoVotes classifies each PoolStakeSnapshot with the CIP-1694 reward-account DRep-delegation outcome and writes the result onto snapshot.RewardAccountAutoVote in place. Callers invoke this immediately before persisting the snapshots so the auto-vote signal is frozen with the snapshot rather than re-derived from live state at tally time.
Resolution proceeds in two batched lookups:
- Pool rows yield each pool's reward-account stake credential.
- Account rows (active and inactive) yield the DRep delegation type for each credential.
RewardAccountAutoVoteResolved is set true only when the outcome is determined from real data, at exactly three terminal conditions:
- The pool row exists and carries no reward account → confirmed None.
- The pool row exists, its reward-account row is present and ACTIVE → classified by DRep delegation (Abstain / NoConfidence / None).
- The pool row exists, its reward-account row is present but INACTIVE (deregistered) → confirmed None, since CIP-1694 treats unregistered reward accounts as implicit no.
Resolved is left false (so the tally falls back to implicit no without freezing a value) when:
- The pool row is absent from the DB (cannot determine the reward account at all), or
- The pool's reward-account credential has no row in the account table at all. An absent row is ambiguous: it may mean the account was never registered, OR that account data has not yet been imported (e.g. a Mithril restore that imported pools from the snapshot fallback before cert-state accounts were loaded). Persisting Resolved=true here would conflate "account input unavailable" with "confirmed none".
func (*Database) RestoreAccountStateAtSlot ¶ added in v0.22.0
RestoreAccountStateAtSlot reverts account delegation state to the given slot. For accounts modified after the slot, this restores their Pool and Drep delegations to the state they had at the given slot, or deletes them if they were registered after that slot.
func (*Database) RestoreDrepStateAtSlot ¶ added in v0.22.0
RestoreDrepStateAtSlot reverts DRep state to the given slot. DReps registered only after the slot are deleted; remaining DReps have their anchor and active status restored.
func (*Database) RestorePoolStateAtSlot ¶ added in v0.22.0
RestorePoolStateAtSlot reverts pool state to the given slot. Pools registered only after the slot are deleted; remaining pools have their denormalized fields restored from the most recent registration at or before the slot.
func (*Database) SetBlobStore ¶ added in v0.22.0
SetBlobStore installs b as the database's blob store and returns the store it replaced along with a drain func.
Operations already in flight keep running against the store they pinned; operations started after this call get b. drain blocks until every operation pinned on the replaced store has finished, which is the point at which prev may be closed — nothing can reach it afterwards. A caller that keeps prev alive (the bark wrapper in node.go and node_lifecycle.go wraps the store it was handed and forwards Close to it) has nothing to drain and may ignore both results; SetBlobStore itself never closes prev.
drain covers the reference this call retires, which is the only route by which prev can still be reached: the pins taken on it before the swap, and no new ones. Installing prev again before drain returns creates a second reference to the same store whose pins are counted separately, so drain would then report only the first reference as idle while the second is in use. A caller that intends to close prev must therefore not re-install it -- install a fresh store, or drain before re-installing. Neither production caller closes prev at all, so neither can reach that case.
drain is never nil, so it is always safe to call.
func (*Database) SetBlockNonce ¶ added in v0.11.0
func (*Database) SetCommitteeMembers ¶ added in v0.37.0
func (d *Database) SetCommitteeMembers( members []*models.CommitteeMember, txn *Txn, ) error
SetCommitteeMembers upserts governance-enacted committee members. Used by UpdateCommittee action enactment and snapshot import.
func (*Database) SetCommitteeQuorum ¶ added in v0.37.0
SetCommitteeQuorum stores the quorum threshold enacted with a committee.
func (*Database) SetConstitution ¶ added in v0.22.0
func (d *Database) SetConstitution( constitution *models.Constitution, txn *Txn, ) error
SetConstitution saves the constitution
func (*Database) SetDatum ¶ added in v0.9.0
SetDatum saves the raw datum into the database by computing the hash before inserting.
func (*Database) SetGapBlockTransaction ¶ added in v0.22.0
func (d *Database) SetGapBlockTransaction( tx lcommon.Transaction, point ocommon.Point, idx uint32, certDeposits map[int]uint64, offsets *BlockIngestionResult, txn *Txn, ) error
SetGapBlockTransaction stores a transaction from a mithril gap block. It records blob offsets (TX and UTxO) for CBOR resolution and creates a minimal metadata record, but does NOT look up or consume input UTxOs because the mithril snapshot already reflects the correct spent/unspent state.
func (*Database) SetGenesisCbor ¶ added in v0.22.0
SetGenesisCbor stores synthetic genesis CBOR data without creating a block index entry. This allows the CBOR to be retrieved for offset-based UTxO extraction while preventing the chain iterator from trying to decode it as a real block (which would fail since genesis CBOR is just concatenated UTxO data, not a valid block structure).
func (*Database) SetGenesisGovernance ¶ added in v0.46.1
func (d *Database) SetGenesisGovernance( initialDReps conway.ConwayGenesisInitialDReps, delegs conway.ConwayGenesisDelegs, blockHash []byte, txn *Txn, ) error
SetGenesisGovernance stores initial DReps and delegations from the Conway genesis bootstrap section. This is metadata-only.
func (*Database) SetGenesisStaking ¶ added in v0.22.0
func (d *Database) SetGenesisStaking( pools map[string]lcommon.PoolRegistrationCertificate, stakeDelegations map[string]string, keyDeposit uint64, blockHash []byte, txn *Txn, ) error
SetGenesisStaking stores genesis pool registrations and stake delegations. This is metadata-only (no blob operations needed).
func (*Database) SetGenesisTransaction ¶ added in v0.22.0
func (d *Database) SetGenesisTransaction( txHash []byte, blockHash []byte, outputs []lcommon.Utxo, offsets map[UtxoRef]CborOffset, txn *Txn, ) error
SetGenesisTransaction stores a genesis transaction with its UTxO outputs. Genesis transactions have no inputs, witnesses, or fees - just outputs. The offsets map contains pre-computed byte offsets into the synthetic genesis block.
func (*Database) SetGovernanceProposal ¶ added in v0.22.0
func (d *Database) SetGovernanceProposal( proposal *models.GovernanceProposal, txn *Txn, ) error
SetGovernanceProposal creates or updates a governance proposal
func (*Database) SetGovernanceVote ¶ added in v0.22.0
func (d *Database) SetGovernanceVote( vote *models.GovernanceVote, txn *Txn, ) error
SetGovernanceVote records a vote on a governance proposal
func (*Database) SetLeiosEB ¶ added in v0.61.2
func (d *Database) SetLeiosEB( slot uint64, hash []byte, manifestRaw []byte, txsRaw []cbor.RawMessage, ) error
SetLeiosEB persists an endorser block's manifest and, when txsRaw is non-nil, its transaction bodies in a SINGLE blob-store transaction (one commit), merging what SetLeiosEBManifest + SetLeiosEBTxs do in two, for the exact (slot, hash) occurrence identified by slot and hash. The stored values are byte-identical to those setters, so GetLeiosEBManifest / GetLeiosEBTxs and the reload path are unchanged. Pass txsRaw==nil to write only the manifest (an incomplete endorser block); pass the complete tx set otherwise. Note the nil contract differs from SetLeiosEBTxs: SetLeiosEBTxs(nil) writes an empty tx list under the "et" key, whereas SetLeiosEB(..., nil) omits the "et" key entirely (manifest-only), so the two must not be treated as interchangeable nil handlers. Used by the asynchronous EB-persistence writer so historical-serving storage costs one commit per endorser block off the leios-fetch hot path.
func (*Database) SetLeiosEBManifest ¶ added in v0.61.1
SetLeiosEBManifest persists the raw Leios endorser-block manifest CBOR (received over leios-fetch MsgBlock) to the blob store, keyed by the exact (slot, hash) occurrence it was received under. key: "em" + hash(32) + slot(8 bytes big-endian) → value: manifest CBOR.
func (*Database) SetLeiosEBTxs ¶ added in v0.61.1
SetLeiosEBTxs persists the complete raw transaction bodies of a Leios endorser block to the blob store, keyed by the exact (slot, hash) occurrence. txsRaw is the CBOR-in-CBOR wrapped tx list from leios-fetch MsgBlockTxs, stored as a CBOR-encoded []cbor.RawMessage. Only call this when the transaction cache is complete (all txCount txs). key: "et" + hash(32) + slot(8) → value: CBOR-encoded []cbor.RawMessage.
func (*Database) SetPParamUpdate ¶ added in v0.4.4
func (*Database) SetPParams ¶ added in v0.4.4
func (*Database) SetSyncState ¶ added in v0.22.0
SetSyncState stores or updates a sync state value.
func (*Database) SetTip ¶ added in v0.4.3
func (d *Database) SetTip(tip ochainsync.Tip, txn *Txn) error
SetTip saves the current tip
func (*Database) SetTransaction ¶ added in v0.18.0
func (d *Database) SetTransaction( tx lcommon.Transaction, point ocommon.Point, idx uint32, updateEpoch uint64, pparamUpdates map[lcommon.Blake2b224]lcommon.ProtocolParameterUpdate, certDeposits map[int]uint64, offsets *BlockIngestionResult, txn *Txn, ) error
func (*Database) SetTransactionBatched ¶ added in v0.45.0
func (d *Database) SetTransactionBatched( tx lcommon.Transaction, point ocommon.Point, idx uint32, updateEpoch uint64, pparamUpdates map[lcommon.Blake2b224]lcommon.ProtocolParameterUpdate, certDeposits map[int]uint64, offsets *BlockIngestionResult, acc BatchAccumulator, txn *Txn, ) (retErr error)
SetTransactionBatched stores transaction blob offsets and immediate metadata, while accumulating bulk metadata rows into acc for a later FlushBatch.
func (*Database) SetTransactionBatchedWithOpts ¶ added in v0.47.0
func (d *Database) SetTransactionBatchedWithOpts( tx lcommon.Transaction, point ocommon.Point, idx uint32, updateEpoch uint64, pparamUpdates map[lcommon.Blake2b224]lcommon.ProtocolParameterUpdate, certDeposits map[int]uint64, offsets *BlockIngestionResult, acc BatchAccumulator, txn *Txn, opts BatchedTxIngestOpts, ) (retErr error)
SetTransactionBatchedWithOpts is the option-aware form of SetTransactionBatched. See BatchedTxIngestOpts for the available toggles.
func (*Database) SetTransactionMetadataOnly ¶ added in v0.63.0
func (d *Database) SetTransactionMetadataOnly( tx lcommon.Transaction, point ocommon.Point, idx uint32, certDeposits map[int]uint64, txn *Txn, ) error
SetTransactionMetadataOnly records transaction metadata, certificates, and other non-UTxO metadata without writing blob offsets, produced outputs, spent inputs, collateral, reference inputs, reward withdrawals, or pparam updates.
This is a general primitive for recording a transaction's certificate and governance data without applying its UTxO effects. It is no longer on the Leios endorser-block apply path: the Musashi path now applies endorser transactions with their full effects (see ledger/leios_apply.go and SetTransactionWithOpts), matching the reference ledger.
func (*Database) SetTransactionWithOpts ¶ added in v0.66.0
func (d *Database) SetTransactionWithOpts( tx lcommon.Transaction, point ocommon.Point, idx uint32, updateEpoch uint64, pparamUpdates map[lcommon.Blake2b224]lcommon.ProtocolParameterUpdate, certDeposits map[int]uint64, offsets *BlockIngestionResult, txn *Txn, opts BatchedTxIngestOpts, ) error
SetTransactionWithOpts is SetTransaction with control over UTxO ingest behavior via opts. Leios endorser-block application on the Musashi/ Haskell-conformant path passes SkipConsumedInputRecovery so a transaction's effects are applied without the consumed-utxo recovery/repair pass: produced outputs and input spends are written, but a consumed input that is absent from the store is left as a no-op instead of triggering blob recovery. This matches the reference ledger's endorser-closure apply (ruleApplyTxValidation ValidateNone), which folds the closure's transactions onto the ledger state without validation or recovery.
func (*Database) SoftDeleteAllCommitteeMembers ¶ added in v0.37.0
SoftDeleteAllCommitteeMembers marks all active committee members as removed. Used by NoConfidence action enactment.
func (*Database) SoftDeleteCommitteeMembers ¶ added in v0.37.0
func (d *Database) SoftDeleteCommitteeMembers( coldCredentials []models.CommitteeCredential, slot uint64, txn *Txn, ) error
SoftDeleteCommitteeMembers marks the given cold credential hashes as removed. Used by UpdateCommittee action enactment to remove members.
func (*Database) StampAllActiveAccountExpirations ¶ added in v0.67.0
func (d *Database) StampAllActiveAccountExpirations( expirationEpoch uint64, txn *Txn, ) (int64, error)
StampAllActiveAccountExpirations sets the CIP-0163 expirationEpoch for every active account row. Used once at activation to give every pre-existing account a full inactivity window from the activation epoch, including accounts witnessed before activation. Returns the number of rows stamped. When txn is nil a write transaction is opened, committed on success and rolled back on error via Txn.Do; pass an existing write txn to participate in a wider unit of work.
func (*Database) StorageMode ¶ added in v0.22.0
StorageMode returns the configured storage mode ("core" or "api").
func (*Database) Transaction ¶
Transaction starts a new database transaction and returns a handle to it
func (*Database) TransactionsDeleteRolledback ¶ added in v0.22.0
TransactionsDeleteRolledback deletes transaction offset blobs and metadata for transactions added after the given slot. This is used during rollback to clean up both blob storage and metadata for rolled-back transactions.
func (*Database) TruncateAfterSlot ¶ added in v0.69.0
func (d *Database) TruncateAfterSlot( point ocommon.Point, mithrilFloor uint64, txn *Txn, ) (retTip ochainsync.Tip, retNonce []byte, retErr error)
TruncateAfterSlot reverts all metadata rows and blob-referenced UTxO/ transaction CBOR added strictly after point.Slot: certificates, account reward deltas, account/pool/DRep delegation state, protocol parameters, governance proposals/votes, constitutions, committee state, epochs, reward state, block nonces, network state/donations, and UTxOs/ transactions. UTxOs spent after point.Slot are restored as unspent. It then sets the tip to point and returns the resulting tip and block nonce.
mithrilFloor floors the UTxO/transaction deletion slot at the Mithril ledger boundary, if any (pass 0 if there is none). UTxOs produced by gap blocks during Mithril bootstrap are written via SetGapBlockTransaction without advancing the ledger tip, so their added_slot values can be well above the persisted tip; deleting below the Mithril boundary would bulk-delete every gap-block-produced UTxO, leaving the chain unable to validate the first post-gap block that consumes one of them. The Mithril snapshot is the trust anchor and is never rewound past, so the authoritative deletion slot is point.Slot or mithrilFloor, whichever is later.
This is the shared metadata+blob truncation sweep used by both live ledger rollback (ledger.LedgerState.rollback, bounded by the security parameter) and offline/live database truncation (database/lifecycle, which may go far deeper for CIP-0135 disaster recovery). It performs no in-memory cache updates of its own — callers that hold additional in-memory state (epoch cache, era, protocol parameters, chain tip) must reload it themselves from the database after this returns successfully.
If txn is nil, a new read-write transaction is opened and committed internally; otherwise the caller is responsible for committing txn.
func (*Database) UpdateDRepActivity ¶ added in v0.22.0
func (d *Database) UpdateDRepActivity( credentialTag uint8, drepCredential []byte, activityEpoch uint64, inactivityPeriod uint64, txn *Txn, ) error
UpdateDRepActivity updates the DRep's last activity epoch and recalculates the expiry epoch.
func (*Database) UpdatePoolOpCertSequence ¶ added in v0.46.0
func (d *Database) UpdatePoolOpCertSequence( pkh lcommon.PoolKeyHash, sequence uint64, slot uint64, txn *Txn, ) error
UpdatePoolOpCertSequence records an observed op-cert sequence for a pool and updates the pool's denormalized maximum.
func (*Database) UpsertMidnightAriadneParams ¶ added in v0.61.0
func (d *Database) UpsertMidnightAriadneParams( params *models.MidnightAriadneParams, ) error
UpsertMidnightAriadneParams inserts or updates the Ariadne params row for the given epoch. If a row for that epoch already exists, its datum is updated with the new value.
func (*Database) UpsertMidnightEpochCandidates ¶ added in v0.61.0
func (d *Database) UpsertMidnightEpochCandidates( ec *models.MidnightEpochCandidates, ) error
UpsertMidnightEpochCandidates inserts or replaces the committee-candidate snapshot for the given epoch.
func (*Database) UtxoByRefIncludingSpent ¶ added in v0.22.0
func (d *Database) UtxoByRefIncludingSpent( txId []byte, outputIdx uint32, txn *Txn, ) (*models.Utxo, error)
UtxoByRefIncludingSpent returns a Utxo by reference, including spent (consumed) UTxOs.
func (*Database) UtxoExists ¶ added in v0.70.5
UtxoExists reports whether a live UTxO is recorded for the reference, without materializing its CBOR.
UtxoByRef resolves the output's bytes from the blob store and, on a miss, reconstructs them by decoding the producing block. A caller that only needs to know whether the output is still there pays for all of that, and — worse — turns a CBOR that cannot be recovered into a hard error about a UTxO that demonstrably exists. Replay recovery asks exactly that question of every referenced input of a failing transaction (see LedgerState.findReplayRecoveryCandidate), so it uses this instead.
func (*Database) UtxosByAddress ¶ added in v0.4.3
func (d *Database) UtxosByAddress( addrs []ledger.Address, maxResults int, txn *Txn, ) ([]models.Utxo, error)
UtxosByAddress returns all UTxOs belonging to any of the given addresses. maxResults is a required, positive bound on the number of candidate rows the query may materialize; callers with no more specific limit of their own should pass MaxUtxosByAddressResults. Exceeding the bound returns models.ErrTooManyUtxoResults.
func (*Database) UtxosByAddressAtSlot ¶ added in v0.22.0
func (*Database) UtxosByAddressWithOrdering ¶ added in v0.27.5
func (d *Database) UtxosByAddressWithOrdering( q *models.UtxoWithOrderingQuery, txn *Txn, ) ([]models.UtxoWithOrdering, error)
func (*Database) UtxosByAssets ¶ added in v0.21.0
func (d *Database) UtxosByAssets( policyId []byte, assetName []byte, txn *Txn, ) ([]models.Utxo, error)
UtxosByAssets returns UTxOs that contain the specified assets policyId: the policy ID of the asset (required) assetName: the asset name (pass nil to match all assets under the policy, or empty []byte{} to match assets with empty names)
func (*Database) UtxosByRefs ¶ added in v0.70.0
UtxosByRefs returns the live UTxOs matching the given references in a single batch. Refs with no matching live UTxO are simply absent from the result.
func (*Database) UtxosByRefsAsOf ¶ added in v0.70.9
func (d *Database) UtxosByRefsAsOf( refs []models.UtxoId, atSlot uint64, txn *Txn, ) ([]models.Utxo, error)
UtxosByRefsAsOf returns the UTxOs matching refs as they stood at atSlot: a ref is included when it was created at-or-before atSlot and is either still live or was spent strictly after atSlot. As with UtxosByRefs, a ref with no matching row is simply absent from the result -- but unlike UtxosByRefs, that absence is ambiguous once atSlot is older than this node's spent-UTxO retention floor: it could mean "genuinely never live at atSlot" or "was live at atSlot but its spend record has since been hard-deleted by the periodic stability-window cleanup" (UtxosDeleteConsumed). Callers pinning a historical point (ledger.Query, blinklabs-io/dingo#382/#1900) must reject that case themselves before calling this -- see ledger's checkUtxoRetentionWindow.
func (*Database) UtxosDeleteConsumed ¶ added in v0.4.4
func (*Database) UtxosDeleteRolledback ¶ added in v0.4.3
type HotCache ¶ added in v0.21.0
type HotCache struct {
// contains filtered or unexported fields
}
HotCache provides a sharded cache for frequently accessed CBOR data. Reads take a shard read lock, while writes are serialized only long enough to keep global size and byte accounting exact. Eviction follows an approximate Least-Frequently-Used (LFU) policy with probabilistic counting.
func NewHotCache ¶ added in v0.21.0
NewHotCache creates a new HotCache with the given size and memory limits. Set maxSize to 0 for unlimited entries (limited only by maxBytes). Set maxBytes to 0 for unlimited memory (limited only by maxSize).
func (*HotCache) CASStats ¶ added in v0.69.0
func (c *HotCache) CASStats() HotCacheCASStats
CASStats returns a snapshot of update-contention counters, suitable for diagnostics or metrics export. Its name is retained for compatibility.
func (*HotCache) Get ¶ added in v0.21.0
Get retrieves a value from the cache by key. Returns the value and true if found, nil and false otherwise. This operation is safe for concurrent use and locks only one shard. Access counts are updated probabilistically (1 in accessSampleRate calls) to reduce overhead while maintaining approximate LFU behavior.
func (*HotCache) Put ¶ added in v0.21.0
Put adds or updates a value in the cache. If maxBytes > 0 and the entry size exceeds maxBytes/10, the entry is skipped. This operation uses a bounded, non-blocking attempt to enter the serialized update path. If the insert pushes the cache over maxSize/maxBytes, eviction is completed before the update lock is released, so the cache cannot remain over its configured limits after Put returns.
func (*HotCache) RegisterCASMetrics ¶ added in v0.69.0
func (c *HotCache) RegisterCASMetrics( registry prometheus.Registerer, cacheName string, ) error
RegisterCASMetrics exposes this cache's update-contention counters (see HotCacheCASStats) on the given Prometheus registry, labeled by cacheName (e.g. "utxo", "tx"). The method and metric names retain their historical CAS terminology for compatibility. If registry is nil, this is a no-op. This method is safe to call more than once with the same registry.
func (*HotCache) SetLogger ¶ added in v0.69.0
SetLogger wires an optional logger into the cache for diagnostics: it logs a warning whenever an update is dropped after exhausting the retry budget (see HotCacheCASStats.WritersAbortedAfterBudget). name identifies this cache instance in the log fields (e.g. "utxo", "tx"). A nil logger disables this logging, which is the default.
type HotCacheCASStats ¶ added in v0.69.0
type HotCacheCASStats struct {
// Attempts is the total number of non-blocking lock attempts across Put
// and access-count tracking.
Attempts uint64
// WritersAbortedAfterBudget is the number of best-effort updates that
// exhausted their retry budget and were dropped as best-effort.
WritersAbortedAfterBudget uint64
// SuccessfulCommitsAfterBackoff is the number of updates that succeeded
// only after backing off at least once, i.e. actual forward progress
// under contention rather than just bounded termination.
SuccessfulCommitsAfterBackoff uint64
// SuccessfulCommitBackoffTime is the cumulative backoff duration spent
// by updates counted in SuccessfulCommitsAfterBackoff.
SuccessfulCommitBackoffTime time.Duration
}
HotCacheCASStats describes contention in HotCache's update path. The type and field names predate the sharded implementation and remain stable for API and metrics compatibility. Values are cumulative for the cache's life.
type NodeSettingsError ¶ added in v0.31.0
type NodeSettingsError struct {
Mismatches []string
}
NodeSettingsError is returned when the configured node settings differ from those persisted in the database. Changing immutable settings after initial sync would leave the database in an inconsistent state.
func (NodeSettingsError) Error ¶ added in v0.31.0
func (e NodeSettingsError) Error() string
Error's message does not append a generic remedy: each entry in e.Mismatches is a rendered Mismatch (see nodesettings.Mismatch.String()) that already carries its own gate-specific reason -- appending a blanket "requires re-syncing from scratch" on top would both duplicate that text for the common case and misdirect for a gate whose Remedy says otherwise (e.g. blob_store_id, whose fix is pointing at the right blob store, not a resync).
type OutputKey ¶ added in v0.21.0
OutputKey uniquely identifies a transaction output within a block.
type PartialCommitError ¶ added in v0.21.0
type PartialCommitError struct {
MetadataErr error // The underlying metadata commit error
CommitTimestamp int64 // Timestamp written to the blob store
}
PartialCommitError is returned when blob commits but metadata fails. This indicates the database is in an inconsistent state requiring recovery.
func (PartialCommitError) Error ¶ added in v0.21.0
func (e PartialCommitError) Error() string
func (PartialCommitError) Is ¶ added in v0.21.0
func (e PartialCommitError) Is(target error) bool
Is allows errors.Is(err, types.ErrPartialCommit) to match this error.
func (PartialCommitError) Unwrap ¶ added in v0.21.0
func (e PartialCommitError) Unwrap() error
type PositionReader ¶ added in v0.21.0
type PositionReader struct {
// contains filtered or unexported fields
}
PositionReader wraps an io.Reader and tracks the current byte position. This is useful for tracking offsets during CBOR parsing to compute positions of transactions and UTxOs within block data.
func NewPositionReader ¶ added in v0.21.0
func NewPositionReader(r io.Reader) *PositionReader
NewPositionReader creates a new PositionReader wrapping the given reader. The initial position is 0.
func (*PositionReader) Position ¶ added in v0.21.0
func (pr *PositionReader) Position() int64
Position returns the current byte position in the reader.
type Stores ¶ added in v0.68.0
type Stores struct {
Blob blob.BlobStore
Metadata metadata.MetadataStore
}
Stores contains the provider-owned storage services injected into a Database. Their lifecycle remains owned by the plugin host.
type TieredCborCache ¶ added in v0.21.0
type TieredCborCache struct {
// contains filtered or unexported fields
}
TieredCborCache orchestrates the tiered cache system for CBOR data resolution. It checks hot caches first, then falls back to block extraction.
Cache tiers:
- Tier 1: Hot caches (hotUtxo for UTxO CBOR, hotTx for transaction CBOR)
- Tier 2: Block LRU cache (shared block cache with pre-computed indexes)
- Tier 3: Cold extraction from blob store
func NewTieredCborCache ¶ added in v0.21.0
func NewTieredCborCache(config CborCacheConfig, db *Database) *TieredCborCache
NewTieredCborCache creates a new TieredCborCache with the given configuration. The db parameter provides access to the blob store for cold path resolution.
func (*TieredCborCache) Metrics ¶ added in v0.21.0
func (c *TieredCborCache) Metrics() *CacheMetrics
Metrics returns the cache metrics for monitoring and observability.
func (*TieredCborCache) RegisterCASMetrics ¶ added in v0.69.0
func (c *TieredCborCache) RegisterCASMetrics( registry prometheus.Registerer, ) error
RegisterCASMetrics exposes both hot caches' update-contention counters on the given Prometheus registry (see HotCache.RegisterCASMetrics). The name is retained for compatibility. If registry is nil, this is a no-op.
func (*TieredCborCache) ResolveTxCbor ¶ added in v0.21.0
func (c *TieredCborCache) ResolveTxCbor( txn *Txn, txHash []byte, ) ([]byte, error)
ResolveTxCbor resolves transaction body CBOR data by transaction hash. It checks caches in order: hot TX cache, block LRU cache, then blob store.
NOTE: This returns only the transaction BODY CBOR, not a complete standalone transaction. Cardano blocks store bodies and witnesses in separate arrays, so reconstructing a complete transaction ([body, witness, is_valid, aux_data]) would require fetching multiple components. Use tx.Cbor() from the parsed block if you need complete transaction CBOR for decoding.
func (*TieredCborCache) ResolveTxCborBatch ¶ added in v0.22.0
func (c *TieredCborCache) ResolveTxCborBatch( txHashes [][32]byte, ) (map[[32]byte][]byte, error)
ResolveTxCborBatch resolves multiple transaction CBOR entries in a single batch. It groups requests by block to minimize blob store fetches.
func (*TieredCborCache) ResolveUtxoCbor ¶ added in v0.21.0
func (c *TieredCborCache) ResolveUtxoCbor( txId []byte, outputIdx uint32, dbTxn ...*Txn, ) ([]byte, error)
ResolveUtxoCbor resolves UTxO CBOR data by transaction ID and output index. It checks caches in order: hot UTxO cache, block LRU cache, then blob store. An optional database transaction can be provided to see uncommitted writes within the same transaction (important for intra-batch UTxO lookups during validation).
The parameter is the database transaction rather than its bare blob handle because the cold path has to run against the store that handle belongs to. A bare types.Txn does not say which store that is, so pairing it with the currently installed store would break across a concurrent SetBlobStore.
func (*TieredCborCache) ResolveUtxoCborBatch ¶ added in v0.21.0
func (c *TieredCborCache) ResolveUtxoCborBatch( refs []UtxoRef, ) (map[UtxoRef][]byte, error)
ResolveUtxoCborBatch resolves multiple UTxO CBOR entries in a single batch. It groups requests by block to minimize blob store fetches.
func (*TieredCborCache) SetLogger ¶ added in v0.69.0
func (c *TieredCborCache) SetLogger(logger *slog.Logger)
SetLogger wires a logger into both hot caches for update-retry-budget diagnostics (see HotCache.SetLogger). A nil logger disables this logging.
type TxCborParts ¶ added in v0.22.0
type TxCborParts struct {
BlockSlot uint64 // Slot number of the block containing the transaction
BlockHash [32]byte // Hash of the block containing the transaction
BodyOffset uint32 // Byte offset of transaction body within block CBOR
BodyLength uint32 // Length of transaction body in bytes
WitnessOffset uint32 // Byte offset of witness set within block CBOR
WitnessLength uint32 // Length of witness set in bytes
MetadataOffset uint32 // Byte offset of metadata within block CBOR (0 if none)
MetadataLength uint32 // Length of metadata in bytes (0 if none)
IsValid bool // True if transaction is valid (not in invalid_txs)
}
TxCborParts stores byte offsets for all 4 components of a Cardano transaction. This enables byte-perfect reconstruction of standalone transaction CBOR from the source block.
A complete standalone transaction has the CBOR structure:
[body, witness, is_valid, metadata]
However, in Cardano blocks, these components are stored in separate arrays:
[header, [bodies...], [witnesses...], {metadata_map}, [invalid_txs]]
TxCborParts stores the location of each component so they can be extracted and reassembled into a complete transaction.
func DecodeTxCborParts ¶ added in v0.22.0
func DecodeTxCborParts(data []byte) (*TxCborParts, error)
DecodeTxCborParts deserializes a 69-byte big-endian encoded slice into TxCborParts. Returns an error if the input data is not exactly 69 bytes or has wrong magic.
func (*TxCborParts) Encode ¶ added in v0.22.0
func (t *TxCborParts) Encode() []byte
Encode serializes TxCborParts to a 69-byte big-endian encoded slice. Layout:
- bytes 0-3: Magic "DTXP"
- bytes 4-11: BlockSlot (big-endian uint64)
- bytes 12-43: BlockHash (32 bytes)
- bytes 44-47: BodyOffset (big-endian uint32)
- bytes 48-51: BodyLength (big-endian uint32)
- bytes 52-55: WitnessOffset (big-endian uint32)
- bytes 56-59: WitnessLength (big-endian uint32)
- bytes 60-63: MetadataOffset (big-endian uint32)
- bytes 64-67: MetadataLength (big-endian uint32)
- byte 68: IsValid (0 = false, 1 = true)
func (*TxCborParts) HasMetadata ¶ added in v0.22.0
func (t *TxCborParts) HasMetadata() bool
HasMetadata returns true if the transaction has metadata.
func (*TxCborParts) ReassembleTxCbor ¶ added in v0.22.0
func (t *TxCborParts) ReassembleTxCbor(blockCbor []byte) ([]byte, error)
ReassembleTxCbor extracts all transaction components from the block CBOR and reassembles them into a complete standalone transaction CBOR.
The returned CBOR has the structure: [body, witness, is_valid, metadata] where metadata is null if the transaction has no auxiliary data.
This produces byte-perfect output when the original transaction had this exact structure. Note that Cardano blocks store components in separate arrays, so the reassembled CBOR may differ from tx.Cbor() which may use a different encoding order or structure.
type Txn ¶
type Txn struct {
// contains filtered or unexported fields
}
Txn is a wrapper that coordinates both metadata and blob transactions. Metadata and blob are first-class siblings, not nested.
func NewBlobOnlyTxn ¶ added in v0.4.3
func NewMetadataOnlyTxn ¶ added in v0.4.3
func (*Txn) AfterCommit ¶ added in v0.66.0
func (t *Txn) AfterCommit(fn func())
AfterCommit registers fn to run after this transaction commits durably. Callbacks run in registration order, once, only on a successful Commit; a rollback or a failed commit never fires them. Use it for side effects that must reflect committed state only — e.g. metrics that must not count work a rollback discards. Registration concurrent with, or after, a successful Commit joins the serialized callback drain instead of being lost. Callbacks run without the transaction lock held, so they may register another callback. A callback that panics has its panic recovered and logged: it does not propagate to Commit's caller, abort the other callbacks in the drain, or wedge the dispatch loop for callbacks registered afterward.
func (*Txn) BlobStore ¶ added in v0.70.7
BlobStore returns the blob store this transaction was opened on, which is the store its Blob transaction handle belongs to and the one every blob operation in the transaction must use. It is stable for the transaction's lifetime even if the database's installed store is replaced meanwhile, and it is nil when no blob store was installed at construction.
func (*Txn) Do ¶
Do executes the specified function in the context of the transaction. Any errors returned will result in the transaction being rolled back. If the function panics, the transaction is rolled back and Do returns an error wrapping ErrTxnPanic instead of letting the panic escape -- see the panic contract above runAfterCommitCallback for how this fits the same contract as executeOperation and why runAfterCommitCallback itself cannot do the same.
func (*Txn) IsReadWrite ¶ added in v0.27.7
IsReadWrite reports whether the transaction was opened for writing.
func (*Txn) Release ¶ added in v0.21.0
func (t *Txn) Release()
Release releases transaction resources. For read-only transactions, this releases locks and resources. For read-write transactions, this is equivalent to Rollback. Use this in defer statements for clean resource cleanup. Errors are logged but not returned, making this safe for deferred calls.
func (*Txn) RollbackTo ¶ added in v0.61.1
RollbackTo rolls the metadata transaction back to a previous savepoint. Blob writes are unaffected; see SavePoint.
Source Files
¶
- account.go
- account_expiry_truncate.go
- account_history.go
- batch.go
- blob_iterator.go
- blob_orphan.go
- blob_store.go
- blob_store_id.go
- block.go
- block_indexer.go
- block_lru_cache.go
- block_nonce.go
- block_range.go
- cbor_cache.go
- cbor_offset.go
- certs.go
- commit_barrier.go
- commit_timestamp.go
- committee.go
- constitution.go
- database.go
- datum.go
- doc.go
- drep.go
- enforce_node_settings.go
- epoch.go
- governance.go
- hot_cache.go
- leios.go
- midnight.go
- mir.go
- network_donation.go
- network_state.go
- pool.go
- poolreap.go
- position_reader.go
- pparams.go
- prune.go
- reward_state.go
- stake_snapshot.go
- synthetic_cost_model.go
- tip.go
- transaction.go
- truncate.go
- tx_body_offsets.go
- txn.go
- utxo.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dbinfo records, in a small JSON sidecar file beside a dingo data directory, which metadata plugin produced the database it belongs to.
|
Package dbinfo records, in a small JSON sidecar file beside a dingo data directory, which metadata plugin produced the database it belongs to. |
|
Package lifecycle implements database snapshot, restore, and truncate operations shared by the offline CLI and (later) a live-node code path.
|
Package lifecycle implements database snapshot, restore, and truncate operations shared by the offline CLI and (later) a live-node code path. |
|
Package nodesettings holds the policy for settings that are persisted on first start and enforced on every subsequent start.
|
Package nodesettings holds the policy for settings that are persisted on first start and enforced on every subsequent start. |
|
plugin
|
|
|
blob/internal/blobbackup
Package blobbackup implements the shared backup/restore stream format used by cloud blob store plugins (s3, gcs) that have no native point-in-time snapshot primitive of their own -- a plain length-prefixed key/value stream produced by walking the store's existing Get/Set/NewIterator interface, distinct from badger's own native Backup/Load format.
|
Package blobbackup implements the shared backup/restore stream format used by cloud blob store plugins (s3, gcs) that have no native point-in-time snapshot primitive of their own -- a plain length-prefixed key/value stream produced by walking the store's existing Get/Set/NewIterator interface, distinct from badger's own native Backup/Load format. |
|
blob/internal/committimestamp
Package committimestamp decodes a blob-stored commit timestamp shared by every blob backend (badger, S3, GCS), rejecting a value that does not actually fit the int64 the rest of the codebase carries it as, rather than each backend separately risking silent truncation or wraparound.
|
Package committimestamp decodes a blob-stored commit timestamp shared by every blob backend (badger, S3, GCS), rejecting a value that does not actually fit the int64 the rest of the codebase carries it as, rather than each backend separately risking silent truncation or wraparound. |
|
blob/internal/compensate
Package compensate provides a disk-spooled compensation log for cloud blob transactions.
|
Package compensate provides a disk-spooled compensation log for cloud blob transactions. |
|
metadata/deferred
Package deferred holds the bulk-load deferred-index manifest.
|
Package deferred holds the bulk-load deferred-index manifest. |
|
metadata/internal/utxocond
Package utxocond builds fixed-shape "(tx_id = ? AND output_idx = ?)" OR-list conditions for the UTxO block-apply UPDATEs (consume, collateral, reference inputs) used by the shared metadata store.
|
Package utxocond builds fixed-shape "(tx_id = ? AND output_idx = ?)" OR-list conditions for the UTxO block-apply UPDATEs (consume, collateral, reference inputs) used by the shared metadata store. |
|
metadata/sqlstore
Package sqlstore contains the shared database/sql metadata store.
|
Package sqlstore contains the shared database/sql metadata store. |
|
metadata/sqlstore/migrations
Package migrations implements offline, forward-only metadata upgrades.
|
Package migrations implements offline, forward-only metadata upgrades. |