database

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockInitialIndex uint64 = 1
)

Variables

View Source
var DefaultConfig = &Config{
	BlobCacheSize:  1073741824,
	BlobPlugin:     "badger",
	DataDir:        ".dingo",
	MetadataPlugin: "sqlite",
}
View Source
var ErrBlockNotFound = errors.New("block not found")

Functions

func BlockBlobIndexKey added in v0.4.5

func BlockBlobIndexKey(blockNumber uint64) []byte

func BlockBlobKey added in v0.4.2

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

func BlockBlobKeyHashHex added in v0.4.2

func BlockBlobKeyHashHex(slot uint64, hashHex string) ([]byte, error)

func BlockBlobMetadataKey added in v0.4.2

func BlockBlobMetadataKey(baseKey []byte) []byte

func BlockDeleteTxn added in v0.4.2

func BlockDeleteTxn(txn *Txn, block Block) error

func UtxoBlobKey added in v0.4.2

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

Types

type Account added in v0.6.0

type Account struct {
	ID         uint   `gorm:"primarykey"`
	StakingKey []byte `gorm:"uniqueIndex"`
	Pool       []byte `gorm:"index"`
	Drep       []byte `gorm:"index"`
	AddedSlot  uint64
	Active     bool
}

func (*Account) TableName added in v0.6.0

func (a *Account) TableName() string

type Block added in v0.4.2

type Block struct {
	ID       uint64
	Slot     uint64
	Number   uint64
	Hash     []byte
	Type     uint
	PrevHash []byte
	Cbor     []byte
}

func BlockBeforeSlot added in v0.4.2

func BlockBeforeSlot(db *Database, slotNumber uint64) (Block, error)

func BlockBeforeSlotTxn added in v0.4.2

func BlockBeforeSlotTxn(txn *Txn, slotNumber uint64) (Block, error)

func BlockByPoint added in v0.4.2

func BlockByPoint(db *Database, point ocommon.Point) (Block, error)

func BlockByPointTxn added in v0.4.2

func BlockByPointTxn(txn *Txn, point ocommon.Point) (Block, error)

func BlocksAfterSlotTxn added in v0.4.2

func BlocksAfterSlotTxn(txn *Txn, slotNumber uint64) ([]Block, error)

func BlocksRecent added in v0.4.2

func BlocksRecent(db *Database, count int) ([]Block, error)

func BlocksRecentTxn added in v0.4.2

func BlocksRecentTxn(txn *Txn, count int) ([]Block, error)

func (Block) Decode added in v0.4.2

func (b Block) Decode() (ledger.Block, error)

type BlockBlobMetadata added in v0.4.2

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

type BlockNonce added in v0.11.0

type BlockNonce struct {
	ID           uint `gorm:"primarykey"`
	Hash         []byte
	Slot         uint64
	Nonce        []byte
	IsCheckpoint bool
}

func (BlockNonce) TableName added in v0.11.0

func (BlockNonce) TableName() string

type CommitTimestampError

type CommitTimestampError struct {
	MetadataTimestamp int64
	BlobTimestamp     int64
}

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 {
	BlobCacheSize  int64
	BlobPlugin     string
	DataDir        string
	MetadataPlugin string
	Logger         *slog.Logger
	PromRegistry   prometheus.Registerer
}

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

func New(
	config *Config,
) (*Database, error)

New creates a new database instance with optional persistence using the provided data directory

func (*Database) AddUtxos added in v0.8.0

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

func (*Database) ApplyPParamUpdates added in v0.4.4

func (d *Database) ApplyPParamUpdates(
	slot, epoch uint64,
	era uint,
	currentPParams *lcommon.ProtocolParameters,
	decodeFunc func([]byte) (any, error),
	updateFunc func(lcommon.ProtocolParameters, any) (lcommon.ProtocolParameters, error),
	txn *Txn,
) error

func (*Database) Blob

func (d *Database) Blob() blob.BlobStore

Blob returns the underling blob store instance

func (*Database) BlobTxn added in v0.4.3

func (d *Database) BlobTxn(readWrite bool) *Txn

BlobTxn starts a new blob-only database transaction and returns a handle to it

func (*Database) BlockByIndex added in v0.4.5

func (d *Database) BlockByIndex(blockIndex uint64, txn *Txn) (Block, error)

func (*Database) BlockCreate added in v0.4.5

func (d *Database) BlockCreate(block Block, txn *Txn) error

func (*Database) Close

func (d *Database) Close() error

Close cleans up the database connections

func (*Database) Config added in v0.12.1

func (d *Database) Config() *Config

Config returns the config object used for the database instance

func (*Database) DataDir added in v0.4.3

func (d *Database) DataDir() string

DataDir returns the path to the data directory used for storage

func (*Database) DeleteBlockNoncesBeforeSlot added in v0.11.0

func (d *Database) DeleteBlockNoncesBeforeSlot(
	slotNumber uint64,
	txn *Txn,
) error

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) GetAccount added in v0.6.0

func (d *Database) GetAccount(
	stakeKey []byte,
	txn *Txn,
) (Account, error)

GetAccount returns an account by staking key

func (*Database) GetBlockNonce added in v0.11.0

func (d *Database) GetBlockNonce(
	blockHash []byte,
	slotNumber uint64,
	txn *Txn,
) ([]byte, error)

func (*Database) GetDatumByHash added in v0.9.0

func (d *Database) GetDatumByHash(
	hash lcommon.Blake2b256,
	txn *Txn,
) ([]byte, error)

GetDatum returns the datum for a given Blake2b256 hash

func (*Database) GetEpochLatest added in v0.4.3

func (d *Database) GetEpochLatest(txn *Txn) (Epoch, error)

func (*Database) GetEpochs added in v0.6.0

func (d *Database) GetEpochs(txn *Txn) ([]Epoch, error)

func (*Database) GetEpochsByEra added in v0.4.3

func (d *Database) GetEpochsByEra(eraId uint, txn *Txn) ([]Epoch, error)

func (*Database) GetPParams added in v0.4.4

func (d *Database) GetPParams(
	epoch uint64,
	decodeFunc func([]byte) (lcommon.ProtocolParameters, error),
	txn *Txn,
) (lcommon.ProtocolParameters, error)

func (*Database) GetPool added in v0.17.0

func (d *Database) GetPool(
	pkh []byte,
	txn *Txn,
) (Pool, error)

GetPool returns a pool by its key hash

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) GetStakeRegistrations added in v0.4.3

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

GetStakeRegistrations returns a list of stake registration certificates

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) Logger added in v0.4.3

func (d *Database) Logger() *slog.Logger

Logger returns the logger instance

func (*Database) Metadata

func (d *Database) Metadata() metadata.MetadataStore

Metadata returns the underlying metadata store instance

func (*Database) MetadataTxn added in v0.4.3

func (d *Database) MetadataTxn(readWrite bool) *Txn

MetadataTxn starts a new metadata-only database transaction and returns a handle to it

func (*Database) NewUtxo added in v0.4.4

func (d *Database) NewUtxo(
	txId []byte,
	outputIdx uint32,
	slot uint64,
	paymentKey, stakeKey, cbor []byte,
	amt uint64,
	txn *Txn,
) error

func (*Database) SetAccount added in v0.6.0

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

SetAccount saves an account

func (*Database) SetBlockNonce added in v0.11.0

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

func (*Database) SetDatum added in v0.9.0

func (d *Database) SetDatum(
	rawDatum []byte,
	addedSlot uint64,
	txn *Txn,
) error

SetDatum saves the raw datum into the database by computing the hash before inserting.

func (*Database) SetDeregistration added in v0.6.0

func (d *Database) SetDeregistration(
	cert *lcommon.DeregistrationCertificate,
	slot uint64,
	txn *Txn,
) error

SetDeregistration saves a deregistration certificate

func (*Database) SetDeregistrationDrep added in v0.7.0

func (d *Database) SetDeregistrationDrep(
	cert *lcommon.DeregistrationDrepCertificate,
	slot, deposit uint64,
	txn *Txn,
) error

SetDeregistrationDrep saves a deregistration drep certificate

func (*Database) SetEpoch added in v0.4.3

func (d *Database) SetEpoch(
	slot, epoch uint64,
	nonce []byte,
	era, slotLength, lengthInSlots uint,
	txn *Txn,
) error

func (*Database) SetPParamUpdate added in v0.4.4

func (d *Database) SetPParamUpdate(
	genesis, params []byte,
	slot, epoch uint64,
	txn *Txn,
) error

func (*Database) SetPParams added in v0.4.4

func (d *Database) SetPParams(
	params []byte,
	slot, epoch uint64,
	era uint,
	txn *Txn,
) error

func (*Database) SetPoolRegistration added in v0.4.3

func (d *Database) SetPoolRegistration(
	cert *lcommon.PoolRegistrationCertificate,
	slot, deposit uint64,
	txn *Txn,
) error

SetPoolRegistration saves a pool registration certificate

func (*Database) SetPoolRetirement added in v0.4.3

func (d *Database) SetPoolRetirement(
	cert *lcommon.PoolRetirementCertificate,
	slot uint64,
	txn *Txn,
) error

SetPoolRetirement saves a pool retirement certificate

func (*Database) SetRegistration added in v0.5.0

func (d *Database) SetRegistration(
	cert *lcommon.RegistrationCertificate,
	slot, deposit uint64,
	txn *Txn,
) error

SetRegistration saves a registration certificate

func (*Database) SetRegistrationDrep added in v0.7.0

func (d *Database) SetRegistrationDrep(
	cert *lcommon.RegistrationDrepCertificate,
	slot, deposit uint64,
	txn *Txn,
) error

SetRegistrationDrep saves a registration drep certificate

func (*Database) SetStakeDelegation added in v0.4.3

func (d *Database) SetStakeDelegation(
	cert *lcommon.StakeDelegationCertificate,
	slot uint64,
	txn *Txn,
) error

SetStakeDelegation saves a stake delegation certificate

func (*Database) SetStakeDeregistration added in v0.4.3

func (d *Database) SetStakeDeregistration(
	cert *lcommon.StakeDeregistrationCertificate,
	slot uint64,
	txn *Txn,
) error

SetStakeDeregistration saves a stake deregistration certificate

func (*Database) SetStakeRegistration added in v0.4.3

func (d *Database) SetStakeRegistration(
	cert *lcommon.StakeRegistrationCertificate,
	slot, deposit uint64,
	txn *Txn,
) error

SetStakeRegistration saves a stake registration certificate

func (*Database) SetStakeRegistrationDelegation added in v0.7.0

func (d *Database) SetStakeRegistrationDelegation(
	cert *lcommon.StakeRegistrationDelegationCertificate,
	slot, deposit uint64,
	txn *Txn,
) error

SetStakeRegistrationDelegation saves a stake registration delegation certificate

func (*Database) SetStakeVoteDelegation added in v0.10.0

func (d *Database) SetStakeVoteDelegation(
	cert *lcommon.StakeVoteDelegationCertificate,
	slot uint64,
	txn *Txn,
) error

SetStakeVoteDelegation saves a stake vote delegation certificate

func (*Database) SetStakeVoteRegistrationDelegation added in v0.7.0

func (d *Database) SetStakeVoteRegistrationDelegation(
	cert *lcommon.StakeVoteRegistrationDelegationCertificate,
	slot, deposit uint64,
	txn *Txn,
) error

SetStakeVoteRegistrationDelegation saves a stake vote registration delegation certificate

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) SetUpdateDrep added in v0.10.0

func (d *Database) SetUpdateDrep(
	cert *lcommon.UpdateDrepCertificate,
	slot uint64,
	txn *Txn,
) error

SetUpdateDrep saves an update drep certificate

func (*Database) SetVoteDelegation added in v0.10.0

func (d *Database) SetVoteDelegation(
	cert *lcommon.VoteDelegationCertificate,
	slot uint64,
	txn *Txn,
) error

SetVoteDelegation saves a vote delegation certificate

func (*Database) SetVoteRegistrationDelegation added in v0.7.0

func (d *Database) SetVoteRegistrationDelegation(
	cert *lcommon.VoteRegistrationDelegationCertificate,
	slot, deposit uint64,
	txn *Txn,
) error

SetVoteRegistrationDelegation saves a vote registration delegation certificate

func (*Database) Transaction

func (d *Database) Transaction(readWrite bool) *Txn

Transaction starts a new database transaction and returns a handle to it

func (*Database) UtxoByRef added in v0.4.3

func (d *Database) UtxoByRef(
	txId []byte,
	outputIdx uint32,
	txn *Txn,
) (Utxo, error)

func (*Database) UtxoConsume added in v0.4.4

func (d *Database) UtxoConsume(
	utxoId ledger.TransactionInput,
	slot uint64,
	txn *Txn,
) error

func (*Database) UtxosByAddress added in v0.4.3

func (d *Database) UtxosByAddress(
	addr ledger.Address,
	txn *Txn,
) ([]Utxo, error)

func (*Database) UtxosDeleteConsumed added in v0.4.4

func (d *Database) UtxosDeleteConsumed(
	slot uint64,
	limit int,
	txn *Txn,
) (int, error)

func (*Database) UtxosDeleteRolledback added in v0.4.3

func (d *Database) UtxosDeleteRolledback(
	slot uint64,
	txn *Txn,
) error

func (*Database) UtxosUnspend added in v0.4.3

func (d *Database) UtxosUnspend(
	slot uint64,
	txn *Txn,
) error

type Datum added in v0.17.0

type Datum struct {
	ID        uint   `gorm:"primarykey"`
	Hash      []byte `gorm:"index;not null;unique"`
	RawDatum  []byte `gorm:"not null"`
	AddedSlot uint64 `gorm:"not null"`
}

type Epoch added in v0.4.3

type Epoch struct {
	ID uint `gorm:"primarykey"`
	// NOTE: we would normally use this as the primary key, but GORM doesn't
	// like a primary key value of 0
	EpochId       uint64 `gorm:"uniqueIndex"`
	StartSlot     uint64
	Nonce         []byte
	EraId         uint
	SlotLength    uint
	LengthInSlots uint
}

func (Epoch) TableName added in v0.4.3

func (Epoch) TableName() string

type Pool added in v0.17.0

type Pool struct {
	PoolKeyHash   []byte
	VrfKeyHash    []byte
	Pledge        types.Uint64
	Cost          types.Uint64
	Margin        *types.Rat
	RewardAccount []byte
	Owners        []PoolRegistrationOwner
	Relays        []PoolRegistrationRelay
	Registration  []PoolRegistration
	Retirement    []PoolRetirement
}

Pool contains the current pool state plus historical registration/retirement entries

type PoolRegistration added in v0.17.0

type PoolRegistration struct {
	MetadataUrl  string
	MetadataHash []byte
	AddedSlot    uint64
}

type PoolRegistrationOwner added in v0.17.0

type PoolRegistrationOwner struct {
	KeyHash []byte
}

type PoolRegistrationRelay added in v0.17.0

type PoolRegistrationRelay struct {
	Port     uint
	Ipv4     *net.IP
	Ipv6     *net.IP
	Hostname string
}

type PoolRetirement added in v0.17.0

type PoolRetirement struct {
	Epoch uint64
}

type Txn

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

Txn is a wrapper around the transaction objects for the underlying DB engines

func NewBlobOnlyTxn added in v0.4.3

func NewBlobOnlyTxn(db *Database, readWrite bool) *Txn

func NewMetadataOnlyTxn added in v0.4.3

func NewMetadataOnlyTxn(db *Database, readWrite bool) *Txn

func NewTxn

func NewTxn(db *Database, readWrite bool) *Txn

func (*Txn) Blob

func (t *Txn) Blob() *badger.Txn

func (*Txn) Commit

func (t *Txn) Commit() error

func (*Txn) DB added in v0.4.2

func (t *Txn) DB() *Database

func (*Txn) Do

func (t *Txn) Do(fn func(*Txn) error) error

Do executes the specified function in the context of the transaction. Any errors returned will result in the transaction being rolled back

func (*Txn) Metadata

func (t *Txn) Metadata() *gorm.DB

func (*Txn) Rollback

func (t *Txn) Rollback() error

type Utxo added in v0.4.2

type Utxo struct {
	ID          uint   `gorm:"primarykey"`
	TxId        []byte `gorm:"index:tx_id_output_idx"`
	OutputIdx   uint32 `gorm:"index:tx_id_output_idx"`
	AddedSlot   uint64 `gorm:"index"`
	DeletedSlot uint64 `gorm:"index"`
	PaymentKey  []byte `gorm:"index"`
	StakingKey  []byte `gorm:"index"`
	Amount      uint64 `gorm:"index"`
	Cbor        []byte `gorm:"-"` // This is not represented in the metadata DB
}

func (*Utxo) Decode added in v0.4.2

func (u *Utxo) Decode() (ledger.TransactionOutput, error)

func (*Utxo) TableName added in v0.4.2

func (u *Utxo) TableName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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