db

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package db provides a lightweight GORM-based SQLite wrapper for persisting state required by the Push Universal Validator (UV), with per-chain database isolation.

Package db provides a lightweight GORM-based SQLite wrapper for persisting state required by the Push Universal Validator (UV), such as block tracking, processed cross-chain messages, and transaction receipts.

Index

Constants

View Source
const (
	// InMemorySQLiteDSN is a special DSN to create an ephemeral in-memory SQLite database.
	InMemorySQLiteDSN = ":memory:"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainDBManager

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

ChainDBManager manages per-chain database instances for traffic isolation

func NewChainDBManager

func NewChainDBManager(baseDir string, logger zerolog.Logger, cfg *config.Config) *ChainDBManager

NewChainDBManager creates a new manager for per-chain databases

func NewInMemoryChainDBManager

func NewInMemoryChainDBManager(logger zerolog.Logger, cfg *config.Config) *ChainDBManager

NewInMemoryChainDBManager creates a manager with in-memory databases (for testing)

func (*ChainDBManager) CloseAll

func (m *ChainDBManager) CloseAll() error

CloseAll closes all database connections

func (*ChainDBManager) CloseChainDB

func (m *ChainDBManager) CloseChainDB(chainID string) error

CloseChainDB closes and removes a specific chain's database from the manager

func (*ChainDBManager) GetAllDatabases

func (m *ChainDBManager) GetAllDatabases() map[string]*DB

GetAllDatabases returns all active database instances

func (*ChainDBManager) GetChainDB

func (m *ChainDBManager) GetChainDB(chainID string) (*DB, error)

GetChainDB returns a database instance for a specific chain Creates the database lazily if it doesn't exist

func (*ChainDBManager) GetDatabaseStats

func (m *ChainDBManager) GetDatabaseStats() map[string]interface{}

GetDatabaseStats returns statistics about managed databases

type DB

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

DB wraps a GORM client and provides simplified DB lifecycle management.

func OpenFileDB

func OpenFileDB(dir, filename string, migrateSchema bool) (*DB, error)

OpenFileDB opens (or creates) a file-backed SQLite database located in the given directory. If `migrateSchema` is true, all defined schema models are automatically migrated.

func OpenInMemoryDB

func OpenInMemoryDB(migrateSchema bool) (*DB, error)

OpenInMemoryDB opens a non-persistent SQLite database in memory. This is useful for testing or ephemeral state.

func (*DB) Client

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

Client returns the internal *gorm.DB instance for direct usage in queries.

func (*DB) Close

func (d *DB) Close() error

Close safely closes the underlying database connection.

func (*DB) DeleteOldConfirmedTransactions

func (d *DB) DeleteOldConfirmedTransactions(retentionPeriod time.Duration) (int64, error)

DeleteOldConfirmedTransactions removes confirmed gateway transactions older than the specified retention period. Only transactions with status "confirmed" that were last updated before the cutoff time are deleted. Returns the number of deleted records and any error encountered.

func (*DB) SetupDBForTesting

func (d *DB) SetupDBForTesting(client *gorm.DB)

SetupDBForTesting sets the internal GORM client for testing purposes. This should only be used in test files.

type PerChainTransactionCleaner

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

PerChainTransactionCleaner handles periodic cleanup of old confirmed transactions with per-chain configuration

func NewPerChainTransactionCleaner

func NewPerChainTransactionCleaner(
	dbManager *ChainDBManager,
	cfg *config.Config,
	logger zerolog.Logger,
) *PerChainTransactionCleaner

NewPerChainTransactionCleaner creates a new per-chain transaction cleaner

func (*PerChainTransactionCleaner) GetCleanerStatus

func (tc *PerChainTransactionCleaner) GetCleanerStatus() map[string]struct {
	CleanupInterval time.Duration
	RetentionPeriod time.Duration
}

GetCleanerStatus returns the status of all chain cleaners

func (*PerChainTransactionCleaner) Start

Start begins the per-chain cleanup process

func (*PerChainTransactionCleaner) Stop

func (tc *PerChainTransactionCleaner) Stop()

Stop gracefully stops all chain cleaners

func (*PerChainTransactionCleaner) UpdateChainConfig

func (tc *PerChainTransactionCleaner) UpdateChainConfig(chainID string)

UpdateChainConfig updates the configuration for a specific chain's cleaner

Jump to

Keyboard shortcuts

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