mysql

package
v0.39.3 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFromCmdlineOptions

func NewFromCmdlineOptions() plugin.Plugin

Types

type BatchAccumulator added in v0.37.0

type BatchAccumulator struct {
	KeyWitnesses   []models.KeyWitness
	WitnessScripts []models.WitnessScripts
	Scripts        []models.Script
	PlutusData     []models.PlutusData
	Redeemers      []models.Redeemer
	AddressTxs     []models.AddressTransaction
	UtxoOutputs    []models.Utxo
	UtxoSpends     []utxoSpend
	CollateralRets []models.Utxo
	DeleteTxIDs    []uint
}

BatchAccumulator collects metadata rows across multiple transactions for bulk database insertion.

func NewBatchAccumulator added in v0.37.0

func NewBatchAccumulator() *BatchAccumulator

func (*BatchAccumulator) AddAddressTx added in v0.37.0

func (b *BatchAccumulator) AddAddressTx(at models.AddressTransaction)

AddAddressTx appends an address-transaction record to the batch.

func (*BatchAccumulator) AddCollateralReturn added in v0.37.0

func (b *BatchAccumulator) AddCollateralReturn(u models.Utxo)

AddCollateralReturn appends a collateral return UTxO to the batch.

func (*BatchAccumulator) AddDeleteTxID added in v0.37.0

func (b *BatchAccumulator) AddDeleteTxID(id uint)

AddDeleteTxID appends a transaction ID scheduled for idempotent retry deletion.

func (*BatchAccumulator) AddKeyWitness added in v0.37.0

func (b *BatchAccumulator) AddKeyWitness(kw models.KeyWitness)

AddKeyWitness appends a key witness record to the batch.

func (*BatchAccumulator) AddPlutusData added in v0.37.0

func (b *BatchAccumulator) AddPlutusData(pd models.PlutusData)

AddPlutusData appends a plutus data record to the batch.

func (*BatchAccumulator) AddRedeemer added in v0.37.0

func (b *BatchAccumulator) AddRedeemer(r models.Redeemer)

AddRedeemer appends a redeemer record to the batch.

func (*BatchAccumulator) AddScript added in v0.37.0

func (b *BatchAccumulator) AddScript(s models.Script)

AddScript appends a script record to the batch.

func (*BatchAccumulator) AddUtxoOutput added in v0.37.0

func (b *BatchAccumulator) AddUtxoOutput(u models.Utxo)

AddUtxoOutput appends a produced UTxO record to the batch.

func (*BatchAccumulator) AddUtxoSpend added in v0.37.0

func (b *BatchAccumulator) AddUtxoSpend(s utxoSpend)

AddUtxoSpend appends a consumed UTxO record to the batch.

func (*BatchAccumulator) AddWitnessScript added in v0.37.0

func (b *BatchAccumulator) AddWitnessScript(ws models.WitnessScripts)

AddWitnessScript appends a witness script record to the batch.

func (*BatchAccumulator) Reset added in v0.37.0

func (b *BatchAccumulator) Reset()

Reset clears all accumulated slices, reusing backing arrays to reduce GC pressure across flush cycles.

type CommitTimestamp

type CommitTimestamp struct {
	ID        uint `gorm:"primarykey"`
	Timestamp int64
}

CommitTimestamp represents the MySQL record used to track the current commit timestamp

func (CommitTimestamp) TableName

func (CommitTimestamp) TableName() string

type MetadataStoreMysql

type MetadataStoreMysql struct {
	// contains filtered or unexported fields
}

MetadataStoreMysql stores metadata in MySQL.

func New

func New(
	host string,
	port uint,
	user string,
	password string,
	database string,
	sslMode string,
	timeZone string,
	logger *slog.Logger,
	promRegistry prometheus.Registerer,
) (*MetadataStoreMysql, error)

New creates a new database

func NewWithOptions

func NewWithOptions(opts ...MysqlOptionFunc) (*MetadataStoreMysql, error)

NewWithOptions creates a new database with options

func (*MetadataStoreMysql) AddAccountReward added in v0.37.0

func (d *MetadataStoreMysql) AddAccountReward(
	stakeKey []byte,
	amount uint64,
	slot uint64,
	txn types.Txn,
) error

AddAccountReward credits a registered reward account.

func (*MetadataStoreMysql) AddUtxos

func (d *MetadataStoreMysql) AddUtxos(
	utxos []models.UtxoSlot,
	txn types.Txn,
) error

AddUtxos saves a batch of UTxOs

func (*MetadataStoreMysql) AutoMigrate

func (d *MetadataStoreMysql) AutoMigrate(dst ...any) error

AutoMigrate wraps the gorm AutoMigrate

func (*MetadataStoreMysql) BeginTxn

func (d *MetadataStoreMysql) BeginTxn() (types.Txn, error)

BeginTxn starts a transaction and returns the handle with an error. Callers that prefer explicit error handling can use this instead of Transaction().

func (*MetadataStoreMysql) ClearCommitteeQuorum added in v0.37.0

func (d *MetadataStoreMysql) ClearCommitteeQuorum(
	slot uint64,
	txn types.Txn,
) error

ClearCommitteeQuorum records that no quorum is in effect from the given slot onward. It inserts a zero-valued marker row so a later GetCommitteeQuorum returns nil (and callers fall back to Conway genesis) until a subsequent UpdateCommittee sets a new positive quorum. Shares the one-mutation-per-slot invariant documented on SetCommitteeQuorum.

func (*MetadataStoreMysql) ClearDanglingDRepDelegations added in v0.37.0

func (d *MetadataStoreMysql) ClearDanglingDRepDelegations(
	atSlot uint64,
	txn types.Txn,
) (int, error)

ClearDanglingDRepDelegations implements the Conway HARDFORK rule for protocol major version 10 (Plomin). See the MetadataStore interface documentation for semantics.

func (*MetadataStoreMysql) ClearSyncState added in v0.22.0

func (d *MetadataStoreMysql) ClearSyncState(
	txn types.Txn,
) error

ClearSyncState removes all sync state entries.

func (*MetadataStoreMysql) Close

func (d *MetadataStoreMysql) Close() error

Close gets the database handle from our MetadataStore and closes it

func (*MetadataStoreMysql) CountTransactionsByAddress added in v0.33.0

func (d *MetadataStoreMysql) CountTransactionsByAddress(
	paymentKey []byte,
	stakingKey []byte,
	txn types.Txn,
) (int, error)

CountTransactionsByAddress returns the total number of distinct transactions involving the given payment/staking key.

func (*MetadataStoreMysql) CountTransactionsByMetadataLabel added in v0.34.0

func (d *MetadataStoreMysql) CountTransactionsByMetadataLabel(
	label uint64,
	txn types.Txn,
) (int, error)

CountTransactionsByMetadataLabel returns the total number of transactions that include metadata for the requested label.

func (*MetadataStoreMysql) Create

func (d *MetadataStoreMysql) Create(value any) *gorm.DB

Create creates a record

func (*MetadataStoreMysql) CreateAccount added in v0.37.0

func (d *MetadataStoreMysql) CreateAccount(
	txn types.Txn,
	account *models.Account,
) error

CreateAccount inserts an Account row directly. See the MetadataStore interface for semantics.

func (*MetadataStoreMysql) CreateDrep added in v0.37.0

func (d *MetadataStoreMysql) CreateDrep(
	txn types.Txn,
	drep *models.Drep,
) error

CreateDrep inserts a Drep row directly. See the MetadataStore interface for semantics.

func (*MetadataStoreMysql) CreateUtxo added in v0.37.0

func (d *MetadataStoreMysql) CreateUtxo(
	txn types.Txn,
	utxo *models.Utxo,
) error

CreateUtxo inserts a Utxo row directly. See the MetadataStore interface for semantics.

func (*MetadataStoreMysql) DB

func (d *MetadataStoreMysql) DB() *gorm.DB

DB returns the database handle

func (*MetadataStoreMysql) DeleteAccountRewardsAfterSlot added in v0.37.0

func (d *MetadataStoreMysql) DeleteAccountRewardsAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeleteAccountRewardsAfterSlot reverts account reward credits recorded after the given slot and deletes their journal rows.

func (*MetadataStoreMysql) DeleteAddressTransactionsAfterSlot added in v0.22.0

func (d *MetadataStoreMysql) DeleteAddressTransactionsAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeleteAddressTransactionsAfterSlot removes address-transaction mapping records added after the given slot.

func (*MetadataStoreMysql) DeleteBlockNoncesAfterPoint added in v0.38.0

func (d *MetadataStoreMysql) DeleteBlockNoncesAfterPoint(
	point ocommon.Point,
	txn types.Txn,
) error

DeleteBlockNoncesAfterPoint deletes block_nonce rows that are no longer on the active chain after a rollback. The rollback point's exact row is kept; same-slot rows with a different hash are removed.

func (*MetadataStoreMysql) DeleteBlockNoncesBeforeSlot

func (d *MetadataStoreMysql) DeleteBlockNoncesBeforeSlot(
	slotNumber uint64,
	txn types.Txn,
) error

DeleteBlockNoncesBeforeSlot deletes block_nonce records with slot less than the specified value

func (*MetadataStoreMysql) DeleteBlockNoncesBeforeSlotWithoutCheckpoints

func (d *MetadataStoreMysql) DeleteBlockNoncesBeforeSlotWithoutCheckpoints(
	slotNumber uint64,
	txn types.Txn,
) error

DeleteBlockNoncesBeforeSlotWithoutCheckpoints deletes block_nonce records with slot < given value AND is_checkpoint = false

func (*MetadataStoreMysql) DeleteCertificatesAfterSlot

func (d *MetadataStoreMysql) DeleteCertificatesAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeleteCertificatesAfterSlot removes all certificate records added after the given slot. This is used during chain rollbacks to undo certificate state changes. All deletions are performed atomically within a transaction to ensure consistency.

func (*MetadataStoreMysql) DeleteCommitteeMembersAfterSlot added in v0.22.0

func (d *MetadataStoreMysql) DeleteCommitteeMembersAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeleteCommitteeMembersAfterSlot removes committee state added after the given slot and clears deleted_slot for any members soft-deleted after that slot.

func (*MetadataStoreMysql) DeleteConstitutionsAfterSlot added in v0.22.0

func (d *MetadataStoreMysql) DeleteConstitutionsAfterSlot(
	slot uint64,
	txn types.Txn,
) error

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 (*MetadataStoreMysql) DeleteEpochSummariesAfterEpoch added in v0.22.0

func (d *MetadataStoreMysql) DeleteEpochSummariesAfterEpoch(
	epoch uint64,
	txn types.Txn,
) error

DeleteEpochSummariesAfterEpoch deletes all epoch summaries after a given epoch. This is used during chain rollbacks.

func (*MetadataStoreMysql) DeleteEpochSummariesBeforeEpoch added in v0.22.0

func (d *MetadataStoreMysql) DeleteEpochSummariesBeforeEpoch(
	epoch uint64,
	txn types.Txn,
) error

DeleteEpochSummariesBeforeEpoch deletes all epoch summaries before a given epoch.

func (*MetadataStoreMysql) DeleteEpochsAfterSlot added in v0.22.0

func (d *MetadataStoreMysql) DeleteEpochsAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeleteEpochsAfterSlot removes all epoch entries whose start slot is after the given slot.

func (*MetadataStoreMysql) DeleteGovernanceProposalsAfterSlot added in v0.22.0

func (d *MetadataStoreMysql) DeleteGovernanceProposalsAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeleteGovernanceProposalsAfterSlot removes proposals added after the given slot, clears deleted_slot for any that were soft-deleted after that slot, and reverts status changes (ratified/enacted) that occurred after the rollback slot. This is used during chain rollbacks.

func (*MetadataStoreMysql) DeleteGovernanceVotesAfterSlot added in v0.22.0

func (d *MetadataStoreMysql) DeleteGovernanceVotesAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeleteGovernanceVotesAfterSlot removes 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.

NOTE: Vote changes (when a voter changes their vote) are tracked via vote_updated_slot. If a vote was changed after the rollback slot but originally cast before it, we cannot restore the previous vote value with the current upsert model. For full rollback support of vote changes, votes should be append-only. Currently, we delete any vote whose update occurred after the rollback slot to avoid having stale vote values persist.

func (*MetadataStoreMysql) DeleteNetworkStateAfterSlot added in v0.22.0

func (d *MetadataStoreMysql) DeleteNetworkStateAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeleteNetworkStateAfterSlot removes network state records added after the given slot.

func (*MetadataStoreMysql) DeletePParamUpdatesAfterSlot

func (d *MetadataStoreMysql) DeletePParamUpdatesAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeletePParamUpdatesAfterSlot removes protocol parameter update records added after the given slot.

func (*MetadataStoreMysql) DeletePParamsAfterSlot

func (d *MetadataStoreMysql) DeletePParamsAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeletePParamsAfterSlot removes protocol parameter records added after the given slot.

func (*MetadataStoreMysql) DeletePoolStakeSnapshotsAfterEpoch added in v0.22.0

func (d *MetadataStoreMysql) DeletePoolStakeSnapshotsAfterEpoch(
	epoch uint64,
	txn types.Txn,
) error

DeletePoolStakeSnapshotsAfterEpoch deletes all pool stake snapshots after a given epoch. This is used during chain rollbacks.

func (*MetadataStoreMysql) DeletePoolStakeSnapshotsBeforeEpoch added in v0.22.0

func (d *MetadataStoreMysql) DeletePoolStakeSnapshotsBeforeEpoch(
	epoch uint64,
	txn types.Txn,
) error

DeletePoolStakeSnapshotsBeforeEpoch deletes all pool stake snapshots before a given epoch.

func (*MetadataStoreMysql) DeletePoolStakeSnapshotsForEpoch added in v0.22.0

func (d *MetadataStoreMysql) DeletePoolStakeSnapshotsForEpoch(
	epoch uint64,
	snapshotType string,
	txn types.Txn,
) error

DeletePoolStakeSnapshotsForEpoch deletes all pool stake snapshots for a specific epoch

func (*MetadataStoreMysql) DeleteSyncState added in v0.22.0

func (d *MetadataStoreMysql) DeleteSyncState(
	key string,
	txn types.Txn,
) error

DeleteSyncState removes a sync state key.

func (*MetadataStoreMysql) DeleteTransactionMetadataLabelsAfterSlot added in v0.28.0

func (d *MetadataStoreMysql) DeleteTransactionMetadataLabelsAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeleteTransactionMetadataLabelsAfterSlot removes transaction metadata label index records added after the given slot.

func (*MetadataStoreMysql) DeleteTransactionsAfterSlot

func (d *MetadataStoreMysql) DeleteTransactionsAfterSlot(
	slot uint64,
	txn types.Txn,
) error

DeleteTransactionsAfterSlot removes transaction records added after the given slot. This also clears UTXO references (spent_at_tx_id, collateral_by_tx_id, referenced_by_tx_id) to transactions being deleted, effectively restoring UTXOs to their unspent state. UTXO hash-based foreign keys are NULLed out before deleting transactions to prevent orphaned references.

func (*MetadataStoreMysql) DeleteUtxo

func (d *MetadataStoreMysql) DeleteUtxo(
	utxoId models.UtxoId,
	txn types.Txn,
) error

func (*MetadataStoreMysql) DeleteUtxos

func (d *MetadataStoreMysql) DeleteUtxos(
	utxos []models.UtxoId,
	txn types.Txn,
) error

func (*MetadataStoreMysql) DeleteUtxosAfterSlot

func (d *MetadataStoreMysql) DeleteUtxosAfterSlot(
	slot uint64,
	txn types.Txn,
) error

func (*MetadataStoreMysql) DiskSize added in v0.29.0

func (d *MetadataStoreMysql) DiskSize() (int64, error)

DiskSize returns 0 for remote database stores.

func (*MetadataStoreMysql) First

func (d *MetadataStoreMysql) First(args any) *gorm.DB

First returns the first DB entry

func (*MetadataStoreMysql) FlushBatch added in v0.37.0

func (d *MetadataStoreMysql) FlushBatch(
	batch *BatchAccumulator,
	txn types.Txn,
) error

FlushBatch writes all accumulated records in a deterministic order.

func (*MetadataStoreMysql) GetAccount

func (d *MetadataStoreMysql) GetAccount(
	stakeKey []byte,
	includeInactive bool,
	txn types.Txn,
) (*models.Account, error)

GetAccount gets an account

func (*MetadataStoreMysql) GetActiveCommitteeMembers added in v0.22.0

func (d *MetadataStoreMysql) GetActiveCommitteeMembers(
	txn types.Txn,
) ([]*models.AuthCommitteeHot, error)

GetActiveCommitteeMembers retrieves all active committee members. Returns only the latest authorization per cold key, and excludes members whose latest resignation is after their latest authorization.

func (*MetadataStoreMysql) GetActiveDreps added in v0.22.0

func (d *MetadataStoreMysql) GetActiveDreps(
	txn types.Txn,
) ([]*models.Drep, error)

GetActiveDreps retrieves all active DReps.

func (*MetadataStoreMysql) GetActiveGovernanceProposals added in v0.22.0

func (d *MetadataStoreMysql) GetActiveGovernanceProposals(
	epoch uint64,
	txn types.Txn,
) ([]*models.GovernanceProposal, error)

GetActiveGovernanceProposals retrieves all governance proposals that are still in the active pool: not expired past the given epoch, not enacted, not marked expired, not soft-deleted.

func (*MetadataStoreMysql) GetActivePoolKeyHashes added in v0.22.0

func (d *MetadataStoreMysql) GetActivePoolKeyHashes(
	txn types.Txn,
) ([][]byte, error)

GetActivePoolKeyHashes retrieves the key hashes of all currently active pools. A pool is active if it has a registration and either no retirement or the retirement epoch is in the future.

This delegates to GetActivePoolKeyHashesAtSlot using the current tip's slot, ensuring consistent same-slot certificate handling via block_index and cert_index ordering (ORDER BY added_slot DESC, block_index DESC, cert_index DESC).

func (*MetadataStoreMysql) GetActivePoolKeyHashesAtSlot added in v0.22.0

func (d *MetadataStoreMysql) GetActivePoolKeyHashesAtSlot(
	slot uint64,
	txn types.Txn,
) ([][]byte, error)

GetActivePoolKeyHashesAtSlot retrieves the key hashes of pools that were active at the given slot. A pool was active at a slot if:

  1. It had a registration with added_slot <= slot
  2. Either no retirement with added_slot <= slot, OR the retirement was for an epoch that hadn't started by the given slot

This implementation uses window functions (ROW_NUMBER) to fetch only the latest registration and retirement per pool directly in the database, avoiding loading all pools and their certificates into memory. Properly handles same-slot certificates by comparing block_index and cert_index.

func (*MetadataStoreMysql) GetActivePoolRelays

func (d *MetadataStoreMysql) GetActivePoolRelays(
	txn types.Txn,
) ([]models.PoolRegistrationRelay, error)

GetActivePoolRelays returns all relays from currently active pools. A pool is considered active if it has a registration and either: - No retirement, or - The retirement epoch is in the future

Implementation note: This function loads all registrations and retirements per pool and filters in Go rather than using complex SQL JOINs. This approach is necessary because:

  1. GORM's Preload with Limit(1) applies the limit globally, not per-parent
  2. Determining the "latest" registration/retirement requires comparing added_slot values which is cumbersome in a single query
  3. The filtering logic (retirement epoch vs current epoch) is clearer in Go

Same-slot certificates are disambiguated by fetching cert_index from the certs table when needed.

For networks with thousands of pools, this may use significant memory. Future optimization could use raw SQL with window functions (ROW_NUMBER) or batch processing if memory becomes a concern.

func (*MetadataStoreMysql) GetAddressesByStakingKey added in v0.22.0

func (d *MetadataStoreMysql) GetAddressesByStakingKey(
	stakingKey []byte,
	limit int,
	offset int,
	txn types.Txn,
) ([]models.AddressTransaction, error)

GetAddressesByStakingKey returns distinct addresses mapped to a staking key.

func (*MetadataStoreMysql) GetAssetByPolicyAndName

func (d *MetadataStoreMysql) GetAssetByPolicyAndName(
	policyId lcommon.Blake2b224,
	assetName []byte,
	txn types.Txn,
) (models.Asset, error)

GetAssetByPolicyAndName returns an asset by policy ID and asset name

func (*MetadataStoreMysql) GetAssetQuantityByPolicyAndName added in v0.36.0

func (d *MetadataStoreMysql) GetAssetQuantityByPolicyAndName(
	policyId lcommon.Blake2b224,
	assetName []byte,
	txn types.Txn,
) (uint64, error)

GetAssetQuantityByPolicyAndName returns the total live quantity for an asset across all matching UTxOs.

func (*MetadataStoreMysql) GetAssetsByPolicy

func (d *MetadataStoreMysql) GetAssetsByPolicy(
	policyId lcommon.Blake2b224,
	txn types.Txn,
) ([]models.Asset, error)

GetAssetsByPolicy returns all assets for a given policy ID

func (*MetadataStoreMysql) GetAssetsByUTxO

func (d *MetadataStoreMysql) GetAssetsByUTxO(
	txId []byte,
	idx uint32,
	txn types.Txn,
) ([]models.Asset, error)

GetAssetsByUTxO returns all assets for a given UTxO using transaction ID and output index

func (*MetadataStoreMysql) GetBackfillCheckpoint added in v0.22.0

func (d *MetadataStoreMysql) GetBackfillCheckpoint(
	phase string,
	txn types.Txn,
) (*models.BackfillCheckpoint, error)

GetBackfillCheckpoint retrieves a backfill checkpoint by phase. Returns nil (not error) if no checkpoint exists for the phase.

func (*MetadataStoreMysql) GetBlockNonce

func (d *MetadataStoreMysql) GetBlockNonce(
	point ocommon.Point,
	txn types.Txn,
) ([]byte, error)

GetBlockNonce retrieves the block nonce for a specific block

func (*MetadataStoreMysql) GetBlockNoncesInSlotRange added in v0.22.0

func (d *MetadataStoreMysql) GetBlockNoncesInSlotRange(
	startSlot uint64,
	endSlot uint64,
	txn types.Txn,
) ([]models.BlockNonce, error)

GetBlockNoncesInSlotRange retrieves all block nonces where slot >= startSlot and slot < endSlot.

func (*MetadataStoreMysql) GetCommitTimestamp

func (d *MetadataStoreMysql) GetCommitTimestamp() (int64, error)

func (*MetadataStoreMysql) GetCommitteeActiveCount added in v0.22.0

func (d *MetadataStoreMysql) GetCommitteeActiveCount(
	txn types.Txn,
) (int, error)

GetCommitteeActiveCount returns the number of active (non-resigned) committee members.

func (*MetadataStoreMysql) GetCommitteeMember added in v0.22.0

func (d *MetadataStoreMysql) GetCommitteeMember(
	coldKey []byte,
	txn types.Txn,
) (*models.AuthCommitteeHot, error)

GetCommitteeMember retrieves a committee member by cold key. Returns the latest authorization (ordered by added_slot DESC).

func (*MetadataStoreMysql) GetCommitteeMembers added in v0.22.0

func (d *MetadataStoreMysql) GetCommitteeMembers(
	txn types.Txn,
) ([]*models.CommitteeMember, error)

GetCommitteeMembers retrieves all active (non-deleted) snapshot-imported committee members.

func (*MetadataStoreMysql) GetCommitteeMembersIncludeDeleted added in v0.37.0

func (d *MetadataStoreMysql) GetCommitteeMembersIncludeDeleted(
	txn types.Txn,
) ([]*models.CommitteeMember, error)

GetCommitteeMembersIncludeDeleted returns every committee member row including soft-deleted ones. See sqlite variant for rationale.

func (*MetadataStoreMysql) GetCommitteeQuorum added in v0.37.0

func (d *MetadataStoreMysql) GetCommitteeQuorum(
	txn types.Txn,
) (*types.Rat, error)

GetCommitteeQuorum retrieves the latest enacted committee quorum. A most-recent marker row with a non-positive quorum represents a NoConfidence-driven clear and is reported as "no quorum enacted".

func (*MetadataStoreMysql) GetConstitution added in v0.22.0

func (d *MetadataStoreMysql) GetConstitution(
	txn types.Txn,
) (*models.Constitution, error)

GetConstitution retrieves the current constitution. Returns nil if the constitution has been soft-deleted.

func (*MetadataStoreMysql) GetDRepVotingPower added in v0.22.0

func (d *MetadataStoreMysql) GetDRepVotingPower(
	drepCredential []byte,
	txn types.Txn,
) (uint64, error)

GetDRepVotingPower calculates the voting power for a DRep by summing the current stake of all accounts delegated to it, including live UTxO balance plus reward-account balance.

TODO: This implementation uses current live balances as an approximation. A future implementation should accept an epoch parameter and use epoch-based stake snapshots for accurate voting power at a specific point in time.

func (*MetadataStoreMysql) GetDRepVotingPowerBatch added in v0.37.0

func (d *MetadataStoreMysql) GetDRepVotingPowerBatch(
	drepCredentials [][]byte,
	txn types.Txn,
) (map[string]uint64, error)

GetDRepVotingPowerBatch returns voting power for each DRep credential in a single query. See sqlite/drep.go for the documented contract.

func (*MetadataStoreMysql) GetDRepVotingPowerByType added in v0.37.0

func (d *MetadataStoreMysql) GetDRepVotingPowerByType(
	drepTypes []uint64,
	txn types.Txn,
) (map[uint64]uint64, error)

GetDRepVotingPowerByType returns voting power grouped by DRep delegation type. It is used for predefined DRep options, which carry no credential.

func (*MetadataStoreMysql) GetDatum

func (d *MetadataStoreMysql) GetDatum(
	hash lcommon.Blake2b256,
	txn types.Txn,
) (*models.Datum, error)

GetDatum returns a datum by its hash

func (*MetadataStoreMysql) GetDrep

func (d *MetadataStoreMysql) GetDrep(
	cred []byte,
	includeInactive bool,
	txn types.Txn,
) (*models.Drep, error)

GetDrep gets a drep

func (*MetadataStoreMysql) GetEpoch added in v0.22.0

func (d *MetadataStoreMysql) GetEpoch(
	epochId uint64,
	txn types.Txn,
) (*models.Epoch, error)

GetEpoch returns a single epoch by its ID, or nil if not found.

func (*MetadataStoreMysql) GetEpochBySlot added in v0.37.0

func (d *MetadataStoreMysql) GetEpochBySlot(
	slot uint64,
	txn types.Txn,
) (*models.Epoch, error)

GetEpochBySlot returns the epoch containing the given slot, or nil if not found.

func (*MetadataStoreMysql) GetEpochSummary

func (d *MetadataStoreMysql) GetEpochSummary(
	epoch uint64,
	txn types.Txn,
) (*models.EpochSummary, error)

GetEpochSummary retrieves an epoch summary by epoch number

func (*MetadataStoreMysql) GetEpochs

func (d *MetadataStoreMysql) GetEpochs(
	txn types.Txn,
) ([]models.Epoch, error)

GetEpochs returns the list of epochs

func (*MetadataStoreMysql) GetEpochsByEra

func (d *MetadataStoreMysql) GetEpochsByEra(
	eraId uint,
	txn types.Txn,
) ([]models.Epoch, error)

GetEpochsByEra returns the list of epochs by era

func (*MetadataStoreMysql) GetExpiredDReps added in v0.22.0

func (d *MetadataStoreMysql) GetExpiredDReps(
	epoch uint64,
	txn types.Txn,
) ([]*models.Drep, error)

GetExpiredDReps retrieves all active DReps whose expiry epoch is at or before the given epoch.

func (*MetadataStoreMysql) GetExpiringGovernanceProposals added in v0.37.0

func (d *MetadataStoreMysql) GetExpiringGovernanceProposals(
	epoch uint64,
	txn types.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 (*MetadataStoreMysql) GetGovernanceProposal added in v0.22.0

func (d *MetadataStoreMysql) GetGovernanceProposal(
	txHash []byte,
	actionIndex uint32,
	txn types.Txn,
) (*models.GovernanceProposal, error)

GetGovernanceProposal retrieves a governance proposal by transaction hash and action index. Returns nil if the proposal has been soft-deleted.

func (*MetadataStoreMysql) GetGovernanceVotes added in v0.22.0

func (d *MetadataStoreMysql) GetGovernanceVotes(
	proposalID uint,
	txn types.Txn,
) ([]*models.GovernanceVote, error)

GetGovernanceVotes retrieves all votes for a governance proposal.

func (*MetadataStoreMysql) GetImportCheckpoint added in v0.22.0

func (d *MetadataStoreMysql) GetImportCheckpoint(
	importKey string,
	txn types.Txn,
) (*models.ImportCheckpoint, error)

GetImportCheckpoint retrieves the checkpoint for a given import key. Returns nil if no checkpoint exists.

func (*MetadataStoreMysql) GetLastBlockNonceInRange added in v0.35.1

func (d *MetadataStoreMysql) GetLastBlockNonceInRange(
	startSlot uint64,
	endSlot uint64,
	txn types.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 (*MetadataStoreMysql) GetLastEnactedGovernanceProposal added in v0.37.0

func (d *MetadataStoreMysql) GetLastEnactedGovernanceProposal(
	actionTypes []uint8,
	txn types.Txn,
) (*models.GovernanceProposal, error)

GetLastEnactedGovernanceProposal returns the most recently enacted proposal whose action_type is in actionTypes, or nil if none exist. See the sqlite variant for the per-purpose grouping rationale.

func (*MetadataStoreMysql) GetLatestEpochSummary

func (d *MetadataStoreMysql) GetLatestEpochSummary(
	txn types.Txn,
) (*models.EpochSummary, error)

GetLatestEpochSummary retrieves the most recent epoch summary

func (*MetadataStoreMysql) GetLiveUtxosBySlot added in v0.37.0

func (d *MetadataStoreMysql) GetLiveUtxosBySlot(
	slot uint64,
	txn types.Txn,
) ([]models.UtxoId, error)

GetLiveUtxosBySlot returns the references of all live UTxOs (deleted_slot = 0) created at the given slot. Only TxId and OutputIdx are populated.

func (*MetadataStoreMysql) GetNetworkState added in v0.22.0

func (d *MetadataStoreMysql) GetNetworkState(
	txn types.Txn,
) (*models.NetworkState, error)

GetNetworkState retrieves the most recent network state.

func (*MetadataStoreMysql) GetNodeSettings added in v0.31.0

func (d *MetadataStoreMysql) GetNodeSettings() (*types.NodeSettings, error)

GetNodeSettings returns the persisted node settings, or nil if the database has never been initialised.

func (*MetadataStoreMysql) GetPParamUpdates

func (d *MetadataStoreMysql) GetPParamUpdates(
	epoch uint64,
	txn types.Txn,
) ([]models.PParamUpdate, error)

GetPParamUpdates returns a list of protocol parameter updates for a given epoch

func (*MetadataStoreMysql) GetPParams

func (d *MetadataStoreMysql) GetPParams(
	epoch uint64,
	eraId uint,
	txn types.Txn,
) ([]models.PParams, error)

GetPParams returns the latest protocol-parameters row at epoch <= the supplied epoch whose era_id matches the supplied era.

func (*MetadataStoreMysql) GetPool

func (d *MetadataStoreMysql) GetPool(
	pkh lcommon.PoolKeyHash,
	includeInactive bool,
	txn types.Txn,
) (*models.Pool, error)

GetPool gets a pool

func (*MetadataStoreMysql) GetPoolByVrfKeyHash added in v0.22.0

func (d *MetadataStoreMysql) GetPoolByVrfKeyHash(
	vrfKeyHash []byte,
	txn types.Txn,
) (*models.Pool, error)

GetPoolByVrfKeyHash retrieves an active pool by its VRF key hash. Returns nil if no active pool uses this VRF key.

func (*MetadataStoreMysql) GetPoolRegistrations

func (d *MetadataStoreMysql) GetPoolRegistrations(
	pkh lcommon.PoolKeyHash,
	txn types.Txn,
) ([]lcommon.PoolRegistrationCertificate, error)

GetPoolRegistrations returns pool registration certificates

func (*MetadataStoreMysql) GetPoolStakeSnapshot

func (d *MetadataStoreMysql) GetPoolStakeSnapshot(
	epoch uint64,
	snapshotType string,
	poolKeyHash []byte,
	txn types.Txn,
) (*models.PoolStakeSnapshot, error)

GetPoolStakeSnapshot retrieves a specific pool's stake snapshot

func (*MetadataStoreMysql) GetPoolStakeSnapshotsByEpoch

func (d *MetadataStoreMysql) GetPoolStakeSnapshotsByEpoch(
	epoch uint64,
	snapshotType string,
	txn types.Txn,
) ([]*models.PoolStakeSnapshot, error)

GetPoolStakeSnapshotsByEpoch retrieves all pool stake snapshots for an epoch

func (*MetadataStoreMysql) GetPools added in v0.30.0

func (d *MetadataStoreMysql) GetPools(
	pkhs []lcommon.PoolKeyHash,
	txn types.Txn,
) ([]models.Pool, error)

GetPools gets pools by key hash.

func (*MetadataStoreMysql) GetRatifiedGovernanceProposals added in v0.37.0

func (d *MetadataStoreMysql) GetRatifiedGovernanceProposals(
	txn types.Txn,
) ([]*models.GovernanceProposal, error)

GetRatifiedGovernanceProposals returns proposals that have been ratified but not yet enacted.

func (*MetadataStoreMysql) GetResignedCommitteeMembers added in v0.37.0

func (d *MetadataStoreMysql) GetResignedCommitteeMembers(
	coldKeys [][]byte,
	txn types.Txn,
) (map[string]bool, error)

GetResignedCommitteeMembers returns cold credentials whose latest resignation is after their latest authorization.

func (*MetadataStoreMysql) GetScript

func (d *MetadataStoreMysql) GetScript(
	hash lcommon.ScriptHash,
	txn types.Txn,
) (*models.Script, error)

GetScript returns the script content by its hash

func (*MetadataStoreMysql) GetStakeByPool added in v0.22.0

func (d *MetadataStoreMysql) GetStakeByPool(
	poolKeyHash []byte,
	txn types.Txn,
) (uint64, uint64, error)

GetStakeByPool returns the total delegated stake and delegator count for a pool.

func (*MetadataStoreMysql) GetStakeByPools added in v0.22.0

func (d *MetadataStoreMysql) GetStakeByPools(
	poolKeyHashes [][]byte,
	txn types.Txn,
) (map[string]uint64, map[string]uint64, error)

GetStakeByPools returns delegated stake for multiple pools in a single query. Stake is computed by joining active accounts with their live UTxOs (deleted_slot = 0) and summing the UTxO amounts per pool.

func (*MetadataStoreMysql) GetStakeRegistrations

func (d *MetadataStoreMysql) GetStakeRegistrations(
	stakingKey []byte,
	txn types.Txn,
) ([]lcommon.StakeRegistrationCertificate, error)

GetStakeRegistrations returns stake registration certificates

func (*MetadataStoreMysql) GetSyncState added in v0.22.0

func (d *MetadataStoreMysql) GetSyncState(
	key string,
	txn types.Txn,
) (string, error)

GetSyncState retrieves a sync state value by key.

func (*MetadataStoreMysql) GetTip

func (d *MetadataStoreMysql) GetTip(
	txn types.Txn,
) (ocommon.Tip, error)

GetTip returns the current metadata Tip as ocommon.Tip

func (*MetadataStoreMysql) GetTotalActiveStake

func (d *MetadataStoreMysql) GetTotalActiveStake(
	epoch uint64,
	snapshotType string,
	txn types.Txn,
) (uint64, error)

GetTotalActiveStake returns the total active stake for an epoch. It uses the pre-calculated total from EpochSummary when available, falling back to summing individual pool snapshots.

func (*MetadataStoreMysql) GetTransactionByHash

func (d *MetadataStoreMysql) GetTransactionByHash(
	hash []byte,
	txn types.Txn,
) (*models.Transaction, error)

GetTransactionByHash returns a transaction by its hash

func (*MetadataStoreMysql) GetTransactionHashesAfterSlot added in v0.22.0

func (d *MetadataStoreMysql) GetTransactionHashesAfterSlot(
	slot uint64,
	txn types.Txn,
) ([][]byte, error)

GetTransactionHashesAfterSlot returns transaction hashes for transactions added after the given slot. This is used for blob cleanup during rollback/truncation.

func (*MetadataStoreMysql) GetTransactionIDByHash added in v0.37.0

func (d *MetadataStoreMysql) GetTransactionIDByHash(
	hash []byte,
	txn types.Txn,
) (uint, bool, error)

GetTransactionIDByHash returns the primary-key ID of the transaction with the given hash without preloading any related rows. Returns (0, false, nil) when no such transaction exists.

func (*MetadataStoreMysql) GetTransactionSlotByHash added in v0.37.0

func (d *MetadataStoreMysql) GetTransactionSlotByHash(
	hash []byte,
	txn types.Txn,
) (uint64, bool, error)

GetTransactionSlotByHash returns the slot of the transaction with the given hash without preloading any related rows. Returns (0, false, nil) when no such transaction exists.

func (*MetadataStoreMysql) GetTransactionsByAddress added in v0.22.0

func (d *MetadataStoreMysql) GetTransactionsByAddress(
	paymentKey []byte,
	stakingKey []byte,
	limit int,
	offset int,
	order string,
	txn types.Txn,
) ([]models.Transaction, error)

GetTransactionsByAddress returns transactions that involve the given payment/staking key with pagination support.

func (*MetadataStoreMysql) GetTransactionsByBlockHash added in v0.22.0

func (d *MetadataStoreMysql) GetTransactionsByBlockHash(
	blockHash []byte,
	txn types.Txn,
) ([]models.Transaction, error)

GetTransactionsByBlockHash returns all transactions in a block, ordered by index

func (*MetadataStoreMysql) GetTransactionsByHashes added in v0.33.0

func (d *MetadataStoreMysql) GetTransactionsByHashes(
	hashes [][]byte,
	txn types.Txn,
) ([]models.Transaction, error)

GetTransactionsByHashes returns transactions for the provided hashes.

func (*MetadataStoreMysql) GetTransactionsByMetadataLabel added in v0.28.0

func (d *MetadataStoreMysql) GetTransactionsByMetadataLabel(
	label uint64,
	limit int,
	offset int,
	descending bool,
	txn types.Txn,
) ([]models.Transaction, error)

GetTransactionsByMetadataLabel returns transactions containing a metadata entry for the requested label.

func (*MetadataStoreMysql) GetUtxo

func (d *MetadataStoreMysql) GetUtxo(
	txId []byte,
	idx uint32,
	txn types.Txn,
) (*models.Utxo, error)

GetUtxo returns a Utxo by reference

func (*MetadataStoreMysql) GetUtxoIncludingSpent added in v0.22.0

func (d *MetadataStoreMysql) GetUtxoIncludingSpent(
	txId []byte,
	idx uint32,
	txn types.Txn,
) (*models.Utxo, error)

GetUtxoIncludingSpent returns a Utxo by reference, including spent UTxOs

func (*MetadataStoreMysql) GetUtxosAddedAfterSlot

func (d *MetadataStoreMysql) GetUtxosAddedAfterSlot(
	slot uint64,
	txn types.Txn,
) ([]models.Utxo, error)

GetUtxosAddedAfterSlot returns a list of Utxos added after a given slot

func (*MetadataStoreMysql) GetUtxosByAddress

func (d *MetadataStoreMysql) GetUtxosByAddress(
	addr ledger.Address,
	txn types.Txn,
) ([]models.Utxo, error)

GetUtxosByAddress returns a list of Utxos

func (*MetadataStoreMysql) GetUtxosByAddressAtSlot added in v0.22.0

func (d *MetadataStoreMysql) GetUtxosByAddressAtSlot(
	addr lcommon.Address,
	slot uint64,
	txn types.Txn,
) ([]models.Utxo, error)

GetUtxosByAddressAtSlot returns UTxOs for an address that existed at a specific slot.

func (*MetadataStoreMysql) GetUtxosByAddressWithOrdering added in v0.27.5

func (d *MetadataStoreMysql) GetUtxosByAddressWithOrdering(
	q *models.UtxoWithOrderingQuery,
	txn types.Txn,
) ([]models.UtxoWithOrdering, error)

GetUtxosByAddressWithOrdering returns UTxOs matching q (OR of addresses, optional asset).

func (*MetadataStoreMysql) GetUtxosByAssets

func (d *MetadataStoreMysql) GetUtxosByAssets(
	policyId []byte,
	assetName []byte,
	txn types.Txn,
) ([]models.Utxo, error)

GetUtxosByAssets returns a list of 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 (*MetadataStoreMysql) GetUtxosDeletedBeforeSlot

func (d *MetadataStoreMysql) GetUtxosDeletedBeforeSlot(
	slot uint64,
	limit int,
	txn types.Txn,
) ([]models.Utxo, error)

GetUtxosDeletedBeforeSlot returns a list of Utxos marked as deleted before a given slot

func (*MetadataStoreMysql) ImportAccount added in v0.22.0

func (d *MetadataStoreMysql) ImportAccount(
	account *models.Account,
	txn types.Txn,
) error

ImportAccount upserts an account (insert or update delegation fields on conflict).

func (*MetadataStoreMysql) ImportDrep added in v0.22.0

func (d *MetadataStoreMysql) ImportDrep(
	drep *models.Drep,
	reg *models.RegistrationDrep,
	txn types.Txn,
) error

ImportDrep upserts a DRep and creates a registration record.

func (*MetadataStoreMysql) ImportPool added in v0.22.0

func (d *MetadataStoreMysql) ImportPool(
	pool *models.Pool,
	reg *models.PoolRegistration,
	txn types.Txn,
) error

ImportPool upserts a pool and creates a registration record.

func (*MetadataStoreMysql) ImportUtxos added in v0.22.0

func (d *MetadataStoreMysql) ImportUtxos(
	utxos []models.Utxo,
	txn types.Txn,
) error

ImportUtxos inserts UTxOs in bulk, ignoring duplicates. Assets are inserted in a second pass to avoid cascading the associated Assets into the same bulk INSERT, which can push the packet size over MySQL limits.

func (*MetadataStoreMysql) InsertDrepIfAbsent added in v0.37.0

func (d *MetadataStoreMysql) InsertDrepIfAbsent(
	cred []byte,
	slot uint64,
	url string,
	hash []byte,
	active bool,
	txn types.Txn,
) error

InsertDrepIfAbsent inserts a DRep row only when no record exists for the given credential. Existing rows are left untouched so the repair path cannot clobber real registration metadata.

func (*MetadataStoreMysql) IsCommitteeMemberResigned added in v0.22.0

func (d *MetadataStoreMysql) IsCommitteeMemberResigned(
	coldKey []byte,
	txn types.Txn,
) (bool, error)

IsCommitteeMemberResigned checks if a committee member has resigned. Returns true only if the latest resignation is after the latest authorization (handles resign-then-rejoin scenarios). Uses (added_slot, certificate_id) for deterministic ordering based on global certificate order.

func (*MetadataStoreMysql) IterateLiveUtxos added in v0.37.0

func (d *MetadataStoreMysql) IterateLiveUtxos(
	txn types.Txn,
	fn func(*models.Utxo) error,
) error

IterateLiveUtxos invokes fn for every live UTxO row in unspecified order, paging through the table to avoid loading the full set at once. See the MetadataStore interface for semantics.

func (*MetadataStoreMysql) MarkUtxosDeletedAtSlot added in v0.37.0

func (d *MetadataStoreMysql) MarkUtxosDeletedAtSlot(
	txn types.Txn,
	refs []types.UtxoKey,
	atSlot uint64,
) error

MarkUtxosDeletedAtSlot marks every live UTxO row matching one of refs as deleted at atSlot. See the MetadataStore interface for semantics.

func (*MetadataStoreMysql) Order

func (d *MetadataStoreMysql) Order(args any) *gorm.DB

Order orders a DB query

func (*MetadataStoreMysql) ReadTransaction added in v0.22.0

func (d *MetadataStoreMysql) ReadTransaction() types.Txn

ReadTransaction creates a read-only transaction.

func (*MetadataStoreMysql) RestoreAccountStateAtSlot

func (d *MetadataStoreMysql) RestoreAccountStateAtSlot(
	slot uint64,
	txn types.Txn,
) error

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 marks them inactive if they were registered after that slot.

This implementation uses batch fetching to avoid N+1 query patterns: instead of querying certificates per-account, it fetches all relevant certificates for all affected accounts upfront (one query per table), then processes them in memory.

func (*MetadataStoreMysql) RestoreDrepStateAtSlot

func (d *MetadataStoreMysql) RestoreDrepStateAtSlot(
	slot uint64,
	txn types.Txn,
) error

RestoreDrepStateAtSlot reverts DRep state to the given slot. DReps that have no registrations at or before the given slot are deleted. DReps that have prior registrations have their Active status and anchor data restored based on the most recent certificate at or before the slot.

This implementation uses batch fetching to avoid N+1 query patterns: instead of querying certificates per-DRep, it fetches all relevant certificates for all affected DReps upfront (one query per table), then processes them in memory.

func (*MetadataStoreMysql) RestoreNormalPragmas added in v0.22.0

func (d *MetadataStoreMysql) RestoreNormalPragmas() error

RestoreNormalPragmas restores MySQL session settings to defaults and restores the connection pool size.

func (*MetadataStoreMysql) RestorePoolStateAtSlot

func (d *MetadataStoreMysql) RestorePoolStateAtSlot(
	slot uint64,
	txn types.Txn,
) error

RestorePoolStateAtSlot reverts pool state to the given slot. Pools that have no registrations at or before the given slot are deleted. Pools that have registrations at or before the given slot have their denormalized fields (pledge, cost, margin, etc.) restored from the most recent registration at or before the slot.

This implementation uses batch fetching to avoid N+1 query patterns: instead of querying certificates per-pool, it fetches all relevant registrations for all affected pools upfront in one query with a JOIN to the certs table to get cert_index for deterministic same-slot ordering.

func (*MetadataStoreMysql) SaveEpochSummary

func (d *MetadataStoreMysql) SaveEpochSummary(
	summary *models.EpochSummary,
	txn types.Txn,
) error

SaveEpochSummary saves an epoch summary

func (*MetadataStoreMysql) SavePoolStakeSnapshot

func (d *MetadataStoreMysql) SavePoolStakeSnapshot(
	snapshot *models.PoolStakeSnapshot,
	txn types.Txn,
) error

SavePoolStakeSnapshot saves a pool stake snapshot

func (*MetadataStoreMysql) SavePoolStakeSnapshots

func (d *MetadataStoreMysql) SavePoolStakeSnapshots(
	snapshots []*models.PoolStakeSnapshot,
	txn types.Txn,
) error

SavePoolStakeSnapshots saves multiple pool stake snapshots in batch

func (*MetadataStoreMysql) SetAccount

func (d *MetadataStoreMysql) SetAccount(
	stakeKey, pkh, drep []byte,
	slot uint64,
	active bool,
	txn types.Txn,
) error

SetAccount saves an account

func (*MetadataStoreMysql) SetBackfillCheckpoint added in v0.22.0

func (d *MetadataStoreMysql) SetBackfillCheckpoint(
	checkpoint *models.BackfillCheckpoint,
	txn types.Txn,
) error

SetBackfillCheckpoint creates or updates a backfill checkpoint, upserting on the Phase column.

func (*MetadataStoreMysql) SetBlockNonce

func (d *MetadataStoreMysql) SetBlockNonce(
	blockHash []byte,
	slotNumber uint64,
	nonce []byte,
	isCheckpoint bool,
	txn types.Txn,
) error

SetBlockNonce inserts or updates a block nonce. The (hash, slot) uniqueIndex makes this safe to call repeatedly for the same block, which happens when the metadata backfill resumes from a checkpoint that pre-dates a previously-written nonce row.

func (*MetadataStoreMysql) SetBulkLoadPragmas added in v0.22.0

func (d *MetadataStoreMysql) SetBulkLoadPragmas() error

SetBulkLoadPragmas configures MySQL session settings for high-throughput bulk inserts. It pins the connection pool to a single connection so SET statements apply to all queries.

func (*MetadataStoreMysql) SetCommitTimestamp

func (d *MetadataStoreMysql) SetCommitTimestamp(
	timestamp int64,
	txn types.Txn,
) error

func (*MetadataStoreMysql) SetCommitteeMembers added in v0.22.0

func (d *MetadataStoreMysql) SetCommitteeMembers(
	members []*models.CommitteeMember,
	txn types.Txn,
) error

SetCommitteeMembers upserts committee members imported from a Mithril snapshot.

func (*MetadataStoreMysql) SetCommitteeQuorum added in v0.37.0

func (d *MetadataStoreMysql) SetCommitteeQuorum(
	quorum *types.Rat,
	slot uint64,
	txn types.Txn,
) error

SetCommitteeQuorum stores the quorum threshold enacted with a committee. Invariant: at most one committee-quorum mutation per slot (added_slot is uniquely indexed). Governance ratifies at most one committee-purpose action per epoch tick, so SetCommitteeQuorum and ClearCommitteeQuorum cannot race at the same slot under normal operation; the upsert's overwrite semantics exist to keep import/replay idempotent.

func (*MetadataStoreMysql) SetConstitution added in v0.22.0

func (d *MetadataStoreMysql) SetConstitution(
	constitution *models.Constitution,
	txn types.Txn,
) error

SetConstitution sets the constitution.

func (*MetadataStoreMysql) SetDatum

func (d *MetadataStoreMysql) SetDatum(
	hash lcommon.Blake2b256,
	rawDatum []byte,
	addedSlot uint64,
	txn types.Txn,
) error

SetDatum saves a datum

func (*MetadataStoreMysql) SetDrep

func (d *MetadataStoreMysql) SetDrep(
	cred []byte,
	slot uint64,
	url string,
	hash []byte,
	active bool,
	txn types.Txn,
) error

SetDrep saves a drep

func (*MetadataStoreMysql) SetEpoch

func (d *MetadataStoreMysql) SetEpoch(
	slot, epoch uint64,
	nonce, evolvingNonce, candidateNonce, lastEpochBlockNonce []byte,
	era, slotLength, lengthInSlots uint,
	txn types.Txn,
) error

SetEpoch saves an epoch

func (*MetadataStoreMysql) SetGapBlockTransaction added in v0.22.0

func (d *MetadataStoreMysql) SetGapBlockTransaction(
	tx lcommon.Transaction,
	point ocommon.Point,
	idx uint32,
	txn types.Txn,
) error

SetGapBlockTransaction stores a transaction record and its produced outputs without looking up or consuming input UTxOs. Gap blocks from mithril sync have their UTxO state already reflected in the snapshot, so input processing must be skipped entirely.

func (*MetadataStoreMysql) SetGenesisStaking added in v0.22.0

func (d *MetadataStoreMysql) SetGenesisStaking(
	_ map[string]lcommon.PoolRegistrationCertificate,
	_ map[string]string,
	_ []byte,
	_ types.Txn,
) error

SetGenesisStaking is not implemented for the MySQL metadata plugin.

func (*MetadataStoreMysql) SetGenesisTransaction added in v0.22.0

func (d *MetadataStoreMysql) SetGenesisTransaction(
	hash []byte,
	blockHash []byte,
	outputs []models.Utxo,
	txn types.Txn,
) error

SetGenesisTransaction stores a genesis transaction record. Genesis transactions have no inputs, witnesses, or fees - just outputs.

func (*MetadataStoreMysql) SetGovernanceProposal added in v0.22.0

func (d *MetadataStoreMysql) SetGovernanceProposal(
	proposal *models.GovernanceProposal,
	txn types.Txn,
) error

SetGovernanceProposal creates or updates a governance proposal.

func (*MetadataStoreMysql) SetGovernanceVote added in v0.22.0

func (d *MetadataStoreMysql) SetGovernanceVote(
	vote *models.GovernanceVote,
	txn types.Txn,
) error

SetGovernanceVote records a vote on a governance proposal.

func (*MetadataStoreMysql) SetImportCheckpoint added in v0.22.0

func (d *MetadataStoreMysql) SetImportCheckpoint(
	checkpoint *models.ImportCheckpoint,
	txn types.Txn,
) error

SetImportCheckpoint creates or updates a checkpoint.

func (*MetadataStoreMysql) SetNetworkState added in v0.22.0

func (d *MetadataStoreMysql) SetNetworkState(
	treasury, reserves uint64,
	slot uint64,
	txn types.Txn,
) error

SetNetworkState stores the treasury and reserves balances.

func (*MetadataStoreMysql) SetNodeSettings added in v0.31.0

func (d *MetadataStoreMysql) SetNodeSettings(
	s *types.NodeSettings,
) error

SetNodeSettings persists the immutable node settings, inserting the singleton row if it does not already exist.

func (*MetadataStoreMysql) SetPParamUpdate

func (d *MetadataStoreMysql) SetPParamUpdate(
	genesis, update []byte,
	slot, epoch uint64,
	txn types.Txn,
) error

SetPParamUpdate saves a protocol parameter update

func (*MetadataStoreMysql) SetPParams

func (d *MetadataStoreMysql) SetPParams(
	params []byte,
	slot, epoch uint64,
	eraId uint,
	txn types.Txn,
) error

SetPParams saves protocol parameters

func (*MetadataStoreMysql) SetSyncState added in v0.22.0

func (d *MetadataStoreMysql) SetSyncState(
	key, value string,
	txn types.Txn,
) error

SetSyncState stores or updates a sync state value.

func (*MetadataStoreMysql) SetTip

func (d *MetadataStoreMysql) SetTip(
	tip ochainsync.Tip,
	txn types.Txn,
) error

SetTip saves a tip

func (*MetadataStoreMysql) SetTransaction

func (d *MetadataStoreMysql) SetTransaction(
	tx lcommon.Transaction,
	point ocommon.Point,
	idx uint32,
	certDeposits map[int]uint64,
	txn types.Txn,
) error

SetTransaction adds a new transaction to the database and processes all certificates

func (*MetadataStoreMysql) SetUtxoDeletedAtSlot

func (d *MetadataStoreMysql) SetUtxoDeletedAtSlot(
	utxoId ledger.TransactionInput,
	slot uint64,
	spenderTxHash []byte,
	txn types.Txn,
) error

SetUtxoDeletedAtSlot marks a UTxO as deleted at a given slot and records the hash of the transaction that consumed it. The update uses the same optimistic-locking predicate as the normal consume path and also repairs same-slot rows that are still missing spent_at_tx_id.

func (*MetadataStoreMysql) SetUtxosNotDeletedAfterSlot

func (d *MetadataStoreMysql) SetUtxosNotDeletedAfterSlot(
	slot uint64,
	txn types.Txn,
) error

SetUtxosNotDeletedAfterSlot marks a list of Utxos as not deleted after a given slot. Both deleted_slot and spent_at_tx_id must be cleared so the restored row satisfies the spend predicate (deleted_slot = 0 AND spent_at_tx_id IS NULL); otherwise the UTxO appears live but cannot be re-spent.

func (*MetadataStoreMysql) SoftDeleteAllCommitteeMembers added in v0.37.0

func (d *MetadataStoreMysql) SoftDeleteAllCommitteeMembers(
	slot uint64,
	txn types.Txn,
) error

SoftDeleteAllCommitteeMembers marks all active committee members as removed. Used by governance enactment for NoConfidence actions.

func (*MetadataStoreMysql) SoftDeleteCommitteeMembers added in v0.37.0

func (d *MetadataStoreMysql) SoftDeleteCommitteeMembers(
	coldCredHashes [][]byte,
	slot uint64,
	txn types.Txn,
) error

SoftDeleteCommitteeMembers marks the given cold credential hashes as removed by setting deleted_slot. Used by governance enactment to remove members listed in an UpdateCommittee action.

func (*MetadataStoreMysql) Start

func (d *MetadataStoreMysql) Start() error

Start implements the plugin.Plugin interface

func (*MetadataStoreMysql) Stop

func (d *MetadataStoreMysql) Stop() error

Stop implements the plugin.Plugin interface

func (*MetadataStoreMysql) Transaction

func (d *MetadataStoreMysql) Transaction() types.Txn

Transaction creates a gorm transaction

func (*MetadataStoreMysql) UpdateDRepActivity added in v0.22.0

func (d *MetadataStoreMysql) UpdateDRepActivity(
	drepCredential []byte,
	activityEpoch uint64,
	inactivityPeriod uint64,
	txn types.Txn,
) error

UpdateDRepActivity updates the DRep's last activity epoch and recalculates the expiry epoch. Returns ErrDrepActivityNotUpdated if no matching DRep record was found.

MySQL's RowsAffected returns changed rows (not matched rows) by default. If a DRep votes twice in the same epoch, the second update sets identical values and RowsAffected returns 0. To distinguish "not found" from "no change", we add a WHERE clause that checks the current values differ, then fall back to an existence check when RowsAffected is 0.

func (*MetadataStoreMysql) Where

func (d *MetadataStoreMysql) Where(
	query any,
	args ...any,
) *gorm.DB

Where constrains a DB query

type MysqlOptionFunc

type MysqlOptionFunc func(*MetadataStoreMysql)

func WithDSN

func WithDSN(dsn string) MysqlOptionFunc

WithDSN specifies a full MySQL DSN string and takes precedence over individual connection options.

func WithDatabase

func WithDatabase(database string) MysqlOptionFunc

WithDatabase specifies the MySQL database name

func WithHost

func WithHost(host string) MysqlOptionFunc

WithHost specifies the MySQL host

func WithLogger

func WithLogger(logger *slog.Logger) MysqlOptionFunc

WithLogger specifies the logger object to use for logging messages

func WithPassword

func WithPassword(password string) MysqlOptionFunc

WithPassword specifies the MySQL password

func WithPort

func WithPort(port uint) MysqlOptionFunc

WithPort specifies the MySQL port

func WithPromRegistry

func WithPromRegistry(
	registry prometheus.Registerer,
) MysqlOptionFunc

WithPromRegistry specifies the prometheus registry to use for metrics

func WithSSLMode

func WithSSLMode(sslMode string) MysqlOptionFunc

WithSSLMode specifies the MySQL TLS option (mapped to tls= in the DSN)

func WithStorageMode added in v0.22.0

func WithStorageMode(mode string) MysqlOptionFunc

WithStorageMode specifies the storage tier. "core" = consensus only, "api" = full tx metadata.

func WithTimeZone

func WithTimeZone(timeZone string) MysqlOptionFunc

WithTimeZone specifies the MySQL time zone location

func WithUser

func WithUser(user string) MysqlOptionFunc

WithUser specifies the MySQL user

type NodeSettings added in v0.31.0

type NodeSettings struct {
	ID          uint   `gorm:"primarykey"`
	StorageMode string `gorm:"size:16;not null"`
	Network     string `gorm:"size:64;not null"`
}

NodeSettings persists immutable node configuration so that storage mode and network cannot be changed after the database has been initialised.

func (NodeSettings) TableName added in v0.31.0

func (NodeSettings) TableName() string

Jump to

Keyboard shortcuts

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