sqlite

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 29 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

A Store is a persistent store that uses a SQL database as its backend.

func OpenDatabase

func OpenDatabase(fp string, log *zap.Logger) (*Store, error)

OpenDatabase creates a new SQLite store and initializes the database. If the database does not exist, it is created.

func (*Store) AccountBalance

func (s *Store) AccountBalance(accountID rhpv3.Account) (balance types.Currency, err error)

AccountBalance returns the balance of the account with the given ID.

func (*Store) AddContract

func (s *Store) AddContract(revision contracts.SignedRevision, formationSet []types.Transaction, lockedCollateral types.Currency, initialUsage contracts.Usage, negotationHeight uint64) error

AddContract adds a new contract to the database.

func (*Store) AddEntries

func (s *Store) AddEntries(entries []logging.Entry) error

AddEntries adds the entries to the database

func (*Store) AddTemporarySectors

func (s *Store) AddTemporarySectors(sectors []storage.TempSector) error

AddTemporarySectors adds the roots of sectors that are temporarily stored on the host. The sectors will be deleted after the expiration height.

func (*Store) AddVolume

func (s *Store) AddVolume(localPath string, readOnly bool) (volumeID int, err error)

AddVolume initializes a new storage volume and adds it to the volume store. GrowVolume must be called afterwards to initialize the volume to its desired size.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database.

func (*Store) Contract

func (s *Store) Contract(id types.FileContractID) (contracts.Contract, error)

Contract returns the contract with the given ID.

func (*Store) ContractAction

func (s *Store) ContractAction(height uint64, contractFn func(types.FileContractID, uint64, string)) error

ContractAction calls contractFn on every contract in the store that needs a lifecycle action performed.

func (*Store) ContractFormationSet

func (s *Store) ContractFormationSet(id types.FileContractID) ([]types.Transaction, error)

ContractFormationSet returns the set of transactions that were created during contract formation.

func (*Store) Contracts

func (s *Store) Contracts(filter contracts.ContractFilter) (contracts []contracts.Contract, count int, err error)

Contracts returns a paginated list of contracts.

func (*Store) CreditAccount

func (s *Store) CreditAccount(accountID rhpv3.Account, amount types.Currency, expiration time.Time) (balance types.Currency, err error)

CreditAccount adds the specified amount to the account with the given ID.

func (*Store) DebitAccount

func (s *Store) DebitAccount(accountID rhpv3.Account, amount types.Currency) (balance types.Currency, err error)

DebitAccount subtracts the specified amount from the account with the given ID. Returns the remaining balance of the account.

func (*Store) ExpireContractSectors

func (s *Store) ExpireContractSectors(height uint64) error

ExpireContractSectors expires all sectors that are no longer covered by an active contract.

func (*Store) ExpireTempSectors

func (s *Store) ExpireTempSectors(height uint64) error

ExpireTempSectors deletes the roots of sectors that are no longer temporarily stored on the host.

func (*Store) GetRegistryValue

func (s *Store) GetRegistryValue(key rhpv3.RegistryKey) (entry rhpv3.RegistryValue, _ error)

GetRegistryValue returns the registry value for the given key. If the key is not found should return ErrEntryNotFound.

func (*Store) GrowVolume

func (s *Store) GrowVolume(id int, maxSectors uint64) error

GrowVolume grows a storage volume's metadata by n sectors.

func (*Store) HostKey

func (s *Store) HostKey() (pk types.PrivateKey)

HostKey returns the host's private key.

func (*Store) IncrementRHP2DataUsage

func (s *Store) IncrementRHP2DataUsage(ingress, egress uint64) error

IncrementRHP2DataUsage increments the RHP2 ingress and egress metrics.

func (*Store) IncrementRHP3DataUsage

func (s *Store) IncrementRHP3DataUsage(ingress, egress uint64) error

IncrementRHP3DataUsage increments the RHP3 ingress and egress metrics.

func (*Store) IncrementRegistryAccess

func (s *Store) IncrementRegistryAccess(read, write uint64) error

IncrementRegistryAccess increments the registry read and write metrics.

func (*Store) IncrementSectorStats

func (s *Store) IncrementSectorStats(reads, writes, cacheHit, cacheMiss uint64) error

IncrementSectorStats increments the sector read, write and cache metrics.

func (*Store) LastContractChange

func (s *Store) LastContractChange() (id modules.ConsensusChangeID, err error)

LastContractChange gets the last consensus change processed by the contractor.

func (*Store) LastWalletChange

func (s *Store) LastWalletChange() (id modules.ConsensusChangeID, height uint64, err error)

LastWalletChange gets the last consensus change processed by the wallet.

func (*Store) LogEntries

func (s *Store) LogEntries(filter logging.Filter) (entries []logging.Entry, count int, err error)

LogEntries returns all log entries matching the given filter.

func (*Store) Metrics

func (s *Store) Metrics(timestamp time.Time) (m metrics.Metrics, err error)

Metrics returns aggregate metrics for the host as of the timestamp.

func (*Store) MigrateSectors

func (s *Store) MigrateSectors(volumeID int, startIndex uint64, migrateFn func(locations []storage.SectorLocation) error) error

MigrateSectors migrates each occupied sector of a volume starting at startIndex. The sector data should be copied to the new location and synced to disk during migrateFn. Sectors are migrated in batches of 256.

func (*Store) PeriodMetrics

func (s *Store) PeriodMetrics(start time.Time, n int, interval metrics.Interval) ([]metrics.Metrics, error)

PeriodMetrics returns aggregate metrics for n periods starting at start

func (*Store) Prune

func (s *Store) Prune(min time.Time) error

Prune deletes all log entries older than the given time.

func (*Store) PruneAccounts

func (s *Store) PruneAccounts(height uint64) error

PruneAccounts removes all accounts that have expired

func (*Store) PruneSectors

func (s *Store) PruneSectors() (int, error)

PruneSectors removes the metadata of any sectors that are not locked or referenced by a contract.

func (*Store) RegistryEntries

func (s *Store) RegistryEntries() (count, max uint64, err error)

RegistryEntries returns the current number of entries as well as the maximum number of entries the registry can hold.

func (*Store) RemoveSector

func (s *Store) RemoveSector(root types.Hash256) (err error)

RemoveSector removes the metadata of a sector and returns its location in the volume.

func (*Store) RemoveVolume

func (s *Store) RemoveVolume(id int, force bool) error

RemoveVolume removes a storage volume from the volume store. If there are used sectors in the volume, ErrVolumeNotEmpty is returned. If force is true, the volume is removed regardless of whether it is empty.

func (*Store) RenewContract

func (s *Store) RenewContract(renewal contracts.SignedRevision, clearing contracts.SignedRevision, renewalTxnSet []types.Transaction, lockedCollateral types.Currency, clearingUsage, renewalUsage contracts.Usage, negotationHeight uint64) error

RenewContract adds a new contract to the database and sets the old contract's renewed_from field. The old contract's sector roots are copied to the new contract.

func (*Store) ResetWallet

func (s *Store) ResetWallet() error

ResetWallet resets the wallet to its initial state. This is used when a consensus subscription error occurs.

func (*Store) ReviseContract

func (s *Store) ReviseContract(revision contracts.SignedRevision, usage contracts.Usage, oldSectors uint64, sectorChanges []contracts.SectorChange) error

ReviseContract atomically updates a contract's revision and sectors

func (*Store) SectorLocation

func (s *Store) SectorLocation(root types.Hash256) (storage.SectorLocation, func() error, error)

SectorLocation returns the location of a sector or an error if the sector is not found. The location is locked until release is called.

func (*Store) SectorRoots

func (s *Store) SectorRoots(contractID types.FileContractID, offset, limit uint64) ([]types.Hash256, error)

SectorRoots returns the sector roots for a contract. If limit is 0, all roots are returned.

func (*Store) SetAvailable

func (s *Store) SetAvailable(volumeID int, available bool) error

SetAvailable sets the available flag on a volume.

func (*Store) SetContractStatus

func (s *Store) SetContractStatus(id types.FileContractID, status contracts.ContractStatus) error

SetContractStatus sets the contract's status.

func (*Store) SetLogger

func (s *Store) SetLogger(log *zap.Logger)

SetLogger sets the logger used by the store.

func (*Store) SetReadOnly

func (s *Store) SetReadOnly(volumeID int, readOnly bool) error

SetReadOnly sets the read-only flag on a volume.

func (*Store) SetRegistryValue

func (s *Store) SetRegistryValue(entry rhpv3.RegistryEntry, expiration uint64) error

SetRegistryValue sets the registry value for the given key.

func (*Store) Settings

func (s *Store) Settings() (config settings.Settings, err error)

Settings returns the current host settings.

func (*Store) ShrinkVolume

func (s *Store) ShrinkVolume(id int, maxSectors uint64) error

ShrinkVolume shrinks a storage volume's metadata to maxSectors. If there are used sectors outside of the new maximum, ErrVolumeNotEmpty is returned.

func (*Store) StorageUsage

func (s *Store) StorageUsage() (usedSectors, totalSectors uint64, err error)

StorageUsage returns the number of sectors stored and the total number of sectors available in the storage pool.

func (*Store) StoreSector

func (s *Store) StoreSector(root types.Hash256, fn func(loc storage.SectorLocation, exists bool) error) (func() error, error)

StoreSector calls fn with an empty location in a writable volume. If the sector root already exists, fn is called with the existing location and exists is true. Unless exists is true, The sector must be written to disk within fn. If fn returns an error, the metadata is rolled back. If no space is available, ErrNotEnoughStorage is returned. The location is locked until release is called.

The sector should be referenced by either a contract or temp store before release is called to prevent Prune() from removing it.

func (*Store) TransactionCount

func (s *Store) TransactionCount() (count uint64, err error)

TransactionCount returns the total number of transactions in the wallet.

func (*Store) Transactions

func (s *Store) Transactions(limit, offset int) (txns []wallet.Transaction, err error)

Transactions returns a paginated list of transactions ordered by block height descending. If no transactions are found, (nil, nil) is returned.

func (*Store) UnspentSiacoinElements

func (s *Store) UnspentSiacoinElements() (utxos []wallet.SiacoinElement, err error)

UnspentSiacoinElements returns the spendable siacoin outputs in the wallet.

func (*Store) UpdateContractState

func (s *Store) UpdateContractState(ccID modules.ConsensusChangeID, height uint64, fn func(contracts.UpdateStateTransaction) error) error

UpdateContractState atomically updates the contractor's state.

func (*Store) UpdateSettings

func (s *Store) UpdateSettings(settings settings.Settings) error

UpdateSettings updates the host's stored settings.

func (*Store) UpdateWallet

func (s *Store) UpdateWallet(ccID modules.ConsensusChangeID, height uint64, fn func(wallet.UpdateTransaction) error) error

UpdateWallet begins an update transaction on the wallet store.

func (*Store) VerifyWalletKey

func (s *Store) VerifyWalletKey(seedHash types.Hash256) error

VerifyWalletKey checks that the wallet seed matches the seed hash. This detects if the user's recovery phrase has changed and the wallet needs to rescan.

func (*Store) Volume

func (s *Store) Volume(id int) (storage.Volume, error)

Volume returns a volume by its ID.

func (*Store) Volumes

func (s *Store) Volumes() ([]storage.Volume, error)

Volumes returns a list of all volumes.

Jump to

Keyboard shortcuts

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