sql

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNegativeOffset = errors.New("offset can not be negative")
View Source
var (
	ZeroCurrency = Currency(types.ZeroCurrency)
)

Functions

func AbortMultipartUpload

func AbortMultipartUpload(ctx context.Context, tx sql.Tx, bucket, key string, uploadID string) error

func Accounts

func Accounts(ctx context.Context, tx sql.Tx, owner string) ([]api.Account, error)

func AncestorContracts

func AncestorContracts(ctx context.Context, tx sql.Tx, fcid types.FileContractID, startHeight uint64) ([]api.ArchivedContract, error)

func ArchiveContract

func ArchiveContract(ctx context.Context, tx sql.Tx, fcid types.FileContractID, reason string) error

func Autopilot

func Autopilot(ctx context.Context, tx sql.Tx, id string) (api.Autopilot, error)

func Autopilots

func Autopilots(ctx context.Context, tx sql.Tx) ([]api.Autopilot, error)

func Bucket

func Bucket(ctx context.Context, tx sql.Tx, bucket string) (api.Bucket, error)

func Contract added in v1.1.0

func Contract(ctx context.Context, tx sql.Tx, fcid types.FileContractID) (api.ContractMetadata, error)

func ContractMetrics

func ContractMetrics(ctx context.Context, tx sql.Tx, start time.Time, n uint64, interval time.Duration, opts ContractMetricsQueryOpts) ([]api.ContractMetric, error)

func ContractPruneMetrics

func ContractPruneMetrics(ctx context.Context, tx sql.Tx, start time.Time, n uint64, interval time.Duration, opts api.ContractPruneMetricsQueryOpts) ([]api.ContractPruneMetric, error)

func ContractRoots

func ContractRoots(ctx context.Context, tx sql.Tx, fcid types.FileContractID) ([]types.Hash256, error)

func ContractSetChurnMetrics

func ContractSetChurnMetrics(ctx context.Context, tx sql.Tx, start time.Time, n uint64, interval time.Duration, opts api.ContractSetChurnMetricsQueryOpts) ([]api.ContractSetChurnMetric, error)

func ContractSetID added in v1.1.0

func ContractSetID(ctx context.Context, tx sql.Tx, contractSet string) (int64, error)

func ContractSetMetrics

func ContractSetMetrics(ctx context.Context, tx sql.Tx, start time.Time, n uint64, interval time.Duration, opts api.ContractSetMetricsQueryOpts) ([]api.ContractSetMetric, error)

func ContractSets

func ContractSets(ctx context.Context, tx sql.Tx) ([]string, error)

func ContractSize

func ContractSize(ctx context.Context, tx sql.Tx, id types.FileContractID) (api.ContractSize, error)

func ContractSizes

func ContractSizes(ctx context.Context, tx sql.Tx) (map[types.FileContractID]api.ContractSize, error)

func Contracts

func Contracts(ctx context.Context, tx sql.Tx, opts api.ContractsOpts) ([]api.ContractMetadata, error)

func CopyObject

func CopyObject(ctx context.Context, tx sql.Tx, srcBucket, dstBucket, srcKey, dstKey, mimeType string, metadata api.ObjectUserMetadata) (api.ObjectMetadata, error)

func DeleteBucket

func DeleteBucket(ctx context.Context, tx sql.Tx, bucket string) error

func DeleteHostSector

func DeleteHostSector(ctx context.Context, tx sql.Tx, hk types.PublicKey, root types.Hash256) (int, error)

func DeleteMetadata

func DeleteMetadata(ctx context.Context, tx sql.Tx, objID int64) error

func DeleteSettings

func DeleteSettings(ctx context.Context, tx sql.Tx, key string) error

func DeleteWebhook

func DeleteWebhook(ctx context.Context, tx sql.Tx, wh webhooks.Webhook) error

func FetchUsedContracts

func FetchUsedContracts(ctx context.Context, tx sql.Tx, fcids []types.FileContractID) (map[types.FileContractID]UsedContract, error)

func GetContractState added in v1.1.0

func GetContractState(ctx context.Context, tx sql.Tx, fcid types.FileContractID) (api.ContractState, error)

func HostAllowlist

func HostAllowlist(ctx context.Context, tx sql.Tx) ([]types.PublicKey, error)

func HostBlocklist

func HostBlocklist(ctx context.Context, tx sql.Tx) ([]string, error)

func HostsForScanning

func HostsForScanning(ctx context.Context, tx sql.Tx, maxLastScan time.Time, offset, limit int) ([]api.HostAddress, error)

func InsertBufferedSlab

func InsertBufferedSlab(ctx context.Context, tx sql.Tx, fileName string, contractSetID int64, ec object.EncryptionKey, minShards, totalShards uint8) (int64, error)

func InsertContract added in v1.1.0

func InsertContract(ctx context.Context, tx sql.Tx, rev rhpv2.ContractRevision, contractPrice, totalCost types.Currency, startHeight uint64, renewedFrom types.FileContractID, state string) (api.ContractMetadata, error)

func InsertMetadata

func InsertMetadata(ctx context.Context, tx sql.Tx, objID, muID *int64, md api.ObjectUserMetadata) error

func InsertMultipartUpload

func InsertMultipartUpload(ctx context.Context, tx sql.Tx, bucket, key string, ec object.EncryptionKey, mimeType string, metadata api.ObjectUserMetadata) (string, error)

func InsertObject

func InsertObject(ctx context.Context, tx sql.Tx, key string, bucketID, size int64, ec object.EncryptionKey, mimeType, eTag string) (int64, error)

func ListBuckets

func ListBuckets(ctx context.Context, tx sql.Tx) ([]api.Bucket, error)

func ListObjects

func ListObjects(ctx context.Context, tx Tx, bucket, prefix, sortBy, sortDir, marker string, limit int) (api.ObjectsListResponse, error)

func MarkPackedSlabUploaded added in v1.1.0

func MarkPackedSlabUploaded(ctx context.Context, tx Tx, slab api.UploadedPackedSlab) (string, error)

func MultipartUpload

func MultipartUpload(ctx context.Context, tx sql.Tx, uploadID string) (api.MultipartUpload, error)

func MultipartUploadForCompletion

func MultipartUploadForCompletion(ctx context.Context, tx sql.Tx, bucket, key, uploadID string, parts []api.MultipartCompletedPart) (multipartUpload, []multipartUploadPart, int64, string, error)

func MultipartUploadParts

func MultipartUploadParts(ctx context.Context, tx sql.Tx, bucket, key, uploadID string, marker int, limit int64) (api.MultipartListPartsResponse, error)

func MultipartUploads

func MultipartUploads(ctx context.Context, tx sql.Tx, bucket, prefix, keyMarker, uploadIDMarker string, limit int) (api.MultipartListUploadsResponse, error)

func NormalizePeer added in v1.1.0

func NormalizePeer(peer string) (string, error)

func Object added in v1.1.0

func Object(ctx context.Context, tx Tx, bucket, key string) (api.Object, error)

func ObjectEntries added in v1.1.0

func ObjectEntries(ctx context.Context, tx Tx, bucket, path, prefix, sortBy, sortDir, marker string, offset, limit int) ([]api.ObjectMetadata, bool, error)

func ObjectMetadata added in v1.1.0

func ObjectMetadata(ctx context.Context, tx Tx, bucket, key string) (api.Object, error)

func ObjectsBySlabKey added in v1.1.0

func ObjectsBySlabKey(ctx context.Context, tx Tx, bucket string, slabKey object.EncryptionKey) ([]api.ObjectMetadata, error)

func PeerBanned added in v1.1.0

func PeerBanned(ctx context.Context, tx sql.Tx, addr string) (bool, error)

func PeerInfo added in v1.1.0

func PeerInfo(ctx context.Context, tx sql.Tx, addr string) (syncer.PeerInfo, error)

func Peers added in v1.1.0

func Peers(ctx context.Context, tx sql.Tx) ([]syncer.PeerInfo, error)

func PrepareSlabHealth

func PrepareSlabHealth(ctx context.Context, tx sql.Tx, limit int64, now time.Time) error

func PruneMetrics

func PruneMetrics(ctx context.Context, tx sql.Tx, metric string, cutoff time.Time) error

func QueryContracts

func QueryContracts(ctx context.Context, tx sql.Tx, whereExprs []string, whereArgs []any) ([]api.ContractMetadata, error)

func RecordContractMetric

func RecordContractMetric(ctx context.Context, tx sql.Tx, metrics ...api.ContractMetric) error

func RecordContractPruneMetric

func RecordContractPruneMetric(ctx context.Context, tx sql.Tx, metrics ...api.ContractPruneMetric) error

func RecordContractSetChurnMetric

func RecordContractSetChurnMetric(ctx context.Context, tx sql.Tx, metrics ...api.ContractSetChurnMetric) error

func RecordContractSetMetric

func RecordContractSetMetric(ctx context.Context, tx sql.Tx, metrics ...api.ContractSetMetric) error

func RecordContractSpending added in v1.1.0

func RecordContractSpending(ctx context.Context, tx Tx, fcid types.FileContractID, revisionNumber, size uint64, newSpending api.ContractSpending) error

func RecordHostScans

func RecordHostScans(ctx context.Context, tx sql.Tx, scans []api.HostScan) error

func RecordPriceTables

func RecordPriceTables(ctx context.Context, tx sql.Tx, priceTableUpdates []api.HostPriceTableUpdate) error

func RecordWalletMetric

func RecordWalletMetric(ctx context.Context, tx sql.Tx, metrics ...api.WalletMetric) error

func RemoveContractSet

func RemoveContractSet(ctx context.Context, tx sql.Tx, contractSet string) error

func RemoveOfflineHosts

func RemoveOfflineHosts(ctx context.Context, tx sql.Tx, minRecentFailures uint64, maxDownTime time.Duration) (int64, error)

func RenewContract added in v1.1.0

func RenewContract(ctx context.Context, tx sql.Tx, rev rhpv2.ContractRevision, contractPrice, totalCost types.Currency, startHeight uint64, renewedFrom types.FileContractID, state string) (api.ContractMetadata, error)

func RenewedContract

func RenewedContract(ctx context.Context, tx sql.Tx, renewedFrom types.FileContractID) (api.ContractMetadata, error)

func ResetChainState added in v1.1.0

func ResetChainState(ctx context.Context, tx sql.Tx) error

func ResetLostSectors

func ResetLostSectors(ctx context.Context, tx sql.Tx, hk types.PublicKey) error

func SearchHosts

func SearchHosts(ctx context.Context, tx sql.Tx, autopilot, filterMode, usabilityMode, addressContains string, keyIn []types.PublicKey, offset, limit int) ([]api.Host, error)

func SearchObjects added in v1.1.0

func SearchObjects(ctx context.Context, tx Tx, bucket, substring string, offset, limit int) ([]api.ObjectMetadata, error)

func Setting

func Setting(ctx context.Context, tx sql.Tx, key string) (string, error)

func Settings

func Settings(ctx context.Context, tx sql.Tx) ([]string, error)

func Slab added in v1.1.0

func Slab(ctx context.Context, tx sql.Tx, key object.EncryptionKey) (object.Slab, error)

func SlabBuffers

func SlabBuffers(ctx context.Context, tx sql.Tx) (map[string]string, error)

func Tip added in v1.1.0

func Tip(ctx context.Context, tx sql.Tx) (types.ChainIndex, error)

func UnhealthySlabs added in v1.1.0

func UnhealthySlabs(ctx context.Context, tx sql.Tx, healthCutoff float64, set string, limit int) ([]api.UnhealthySlab, error)

func UnmarshalEventData added in v1.1.0

func UnmarshalEventData(b []byte, t string) (dst wallet.EventData, err error)

func UnspentSiacoinElements added in v1.1.0

func UnspentSiacoinElements(ctx context.Context, tx sql.Tx) (elements []types.SiacoinElement, err error)

func UpdateBucketPolicy

func UpdateBucketPolicy(ctx context.Context, tx sql.Tx, bucket string, bp api.BucketPolicy) error

func UpdateChainIndex added in v1.1.0

func UpdateChainIndex(ctx context.Context, tx sql.Tx, index types.ChainIndex, l *zap.SugaredLogger) error

func UpdateContract added in v1.1.0

func UpdateContract(ctx context.Context, tx sql.Tx, fcid types.FileContractID, revisionHeight, revisionNumber, size uint64, l *zap.SugaredLogger) error

func UpdateContractProofHeight added in v1.1.0

func UpdateContractProofHeight(ctx context.Context, tx sql.Tx, fcid types.FileContractID, proofHeight uint64, l *zap.SugaredLogger) error

func UpdateContractState added in v1.1.0

func UpdateContractState(ctx context.Context, tx sql.Tx, fcid types.FileContractID, state api.ContractState, l *zap.SugaredLogger) error

func UpdateFailedContracts added in v1.1.0

func UpdateFailedContracts(ctx context.Context, tx sql.Tx, blockHeight uint64, l *zap.SugaredLogger) error

func UpdateMetadata

func UpdateMetadata(ctx context.Context, tx sql.Tx, objID int64, md api.ObjectUserMetadata) error

func UpdatePeerInfo added in v1.1.0

func UpdatePeerInfo(ctx context.Context, tx sql.Tx, addr string, fn func(*syncer.PeerInfo)) error

func UpdateWalletSiacoinElementProofs added in v1.1.0

func UpdateWalletSiacoinElementProofs(ctx context.Context, tx sql.Tx, updater wallet.ProofUpdater) error

func WalletEventCount added in v1.1.0

func WalletEventCount(ctx context.Context, tx sql.Tx) (count uint64, err error)

func WalletEvents added in v1.1.0

func WalletEvents(ctx context.Context, tx sql.Tx, offset, limit int) (events []wallet.Event, _ error)

func WalletMetrics

func WalletMetrics(ctx context.Context, tx sql.Tx, start time.Time, n uint64, interval time.Duration, opts api.WalletMetricsQueryOpts) ([]api.WalletMetric, error)

func Webhooks

func Webhooks(ctx context.Context, tx sql.Tx) ([]webhooks.Webhook, error)

Types

type AutopilotConfig

type AutopilotConfig api.AutopilotConfig

func (*AutopilotConfig) Scan

func (cfg *AutopilotConfig) Scan(value interface{}) error

Scan scan value into AutopilotConfig, implements sql.Scanner interface.

func (AutopilotConfig) Value

func (cfg AutopilotConfig) Value() (driver.Value, error)

Value returns a AutopilotConfig value, implements driver.Valuer interface.

type BCurrency added in v1.1.0

type BCurrency types.Currency

func (*BCurrency) Scan added in v1.1.0

func (sc *BCurrency) Scan(src any) error

Scan implements the sql.Scanner interface.

func (BCurrency) Value added in v1.1.0

func (sc BCurrency) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type BigInt

type BigInt big.Int

func (*BigInt) Scan

func (b *BigInt) Scan(value interface{}) error

Scan scan value into BigInt, implements sql.Scanner interface.

func (BigInt) Value

func (b BigInt) Value() (driver.Value, error)

Value returns a BigInt value, implements driver.Valuer interface.

type BusSetting

type BusSetting string

func (*BusSetting) Scan

func (s *BusSetting) Scan(value interface{}) error

Scan scans value into the BusSetting

func (BusSetting) String

func (s BusSetting) String() string

String implements fmt.Stringer to prevent "s3authentication" settings from getting leaked.

func (BusSetting) Value

func (s BusSetting) Value() (driver.Value, error)

Value returns a BusSetting value, implements driver.Valuer interface.

type ChainUpdateTx added in v1.1.0

type ChainUpdateTx interface {
	ContractState(fcid types.FileContractID) (api.ContractState, error)
	UpdateChainIndex(index types.ChainIndex) error
	UpdateContract(fcid types.FileContractID, revisionHeight, revisionNumber, size uint64) error
	UpdateContractState(fcid types.FileContractID, state api.ContractState) error
	UpdateContractProofHeight(fcid types.FileContractID, proofHeight uint64) error
	UpdateFailedContracts(blockHeight uint64) error
	UpdateHost(hk types.PublicKey, ha chain.HostAnnouncement, bh uint64, blockID types.BlockID, ts time.Time) error

	wallet.UpdateTx
}

The database interfaces define all methods that a SQL database must implement to be used by the SQLStore.

type ContractMetricsQueryOpts

type ContractMetricsQueryOpts struct {
	api.ContractMetricsQueryOpts
	IndexHint string
}

type ContractRow

type ContractRow struct {
	FCID        FileContractID
	RenewedFrom FileContractID

	ContractPrice  Currency
	State          ContractState
	TotalCost      Currency
	ProofHeight    uint64
	RevisionHeight uint64
	RevisionNumber uint64
	Size           uint64
	StartHeight    uint64
	WindowStart    uint64
	WindowEnd      uint64

	// spending fields
	UploadSpending      Currency
	DownloadSpending    Currency
	FundAccountSpending Currency
	DeleteSpending      Currency
	ListSpending        Currency

	ContractSet string
	NetAddress  string
	PublicKey   PublicKey
	SiamuxPort  string
}

func (*ContractRow) ContractMetadata

func (r *ContractRow) ContractMetadata() api.ContractMetadata

func (*ContractRow) Scan

func (r *ContractRow) Scan(s Scanner) error

type ContractState

type ContractState uint8

func ContractStateFromString added in v1.1.0

func ContractStateFromString(state string) ContractState

func (*ContractState) LoadString

func (s *ContractState) LoadString(state string) error

func (ContractState) String

func (s ContractState) String() string

type Currency

type Currency types.Currency

func (*Currency) Scan

func (c *Currency) Scan(value interface{}) error

Scan scan value into Currency, implements sql.Scanner interface.

func (Currency) Value

func (c Currency) Value() (driver.Value, error)

Value returns a publicKey value, implements driver.Valuer interface.

type Database

type Database interface {
	io.Closer

	// LoadSlabBuffers loads the slab buffers from the database.
	LoadSlabBuffers(ctx context.Context) ([]LoadedSlabBuffer, []string, error)

	// Migrate runs all missing migrations on the database.
	Migrate(ctx context.Context) error

	// Transaction starts a new transaction.
	Transaction(ctx context.Context, fn func(DatabaseTx) error) error

	// Version returns the database version and name.
	Version(ctx context.Context) (string, string, error)
}

The database interfaces define all methods that a SQL database must implement to be used by the SQLStore.

type DatabaseTx

type DatabaseTx interface {
	// AbortMultipartUpload aborts a multipart upload and deletes it from
	// the database.
	AbortMultipartUpload(ctx context.Context, bucket, key string, uploadID string) error

	// Accounts returns all accounts from the db.
	Accounts(ctx context.Context, owner string) ([]api.Account, error)

	// AddMultipartPart adds a part to an unfinished multipart upload.
	AddMultipartPart(ctx context.Context, bucket, key, contractSet, eTag, uploadID string, partNumber int, slices object.SlabSlices) error

	// AddPeer adds a peer to the store.
	AddPeer(ctx context.Context, addr string) error

	// AddWebhook adds a new webhook to the database. If the webhook already
	// exists, it is updated.
	AddWebhook(ctx context.Context, wh webhooks.Webhook) error

	// AncestorContracts returns all ancestor contracts of the contract up
	// until the given start height.
	AncestorContracts(ctx context.Context, id types.FileContractID, startHeight uint64) ([]api.ArchivedContract, error)

	// ArchiveContract moves a contract from the regular contracts to the
	// archived ones.
	ArchiveContract(ctx context.Context, fcid types.FileContractID, reason string) error

	// Autopilot returns the autopilot with the given ID. Returns
	// api.ErrAutopilotNotFound if the autopilot doesn't exist.
	Autopilot(ctx context.Context, id string) (api.Autopilot, error)

	// Autopilots returns all autopilots.
	Autopilots(ctx context.Context) ([]api.Autopilot, error)

	// BanPeer temporarily bans one or more IPs. The addr should either be a
	// single IP with port (e.g. 1.2.3.4:5678) or a CIDR subnet (e.g.
	// 1.2.3.4/16).
	BanPeer(ctx context.Context, addr string, duration time.Duration, reason string) error

	// Bucket returns the bucket with the given name. If the bucket doesn't
	// exist, it returns api.ErrBucketNotFound.
	Bucket(ctx context.Context, bucket string) (api.Bucket, error)

	// CompleteMultipartUpload completes a multipart upload by combining the
	// provided parts into an object in bucket 'bucket' with key 'key'. The
	// parts need to be provided in ascending partNumber order without
	// duplicates but can contain gaps.
	CompleteMultipartUpload(ctx context.Context, bucket, key, uploadID string, parts []api.MultipartCompletedPart, opts api.CompleteMultipartOptions) (string, error)

	// Contract returns the metadata of the contract with the given ID or
	// ErrContractNotFound.
	Contract(ctx context.Context, id types.FileContractID) (cm api.ContractMetadata, err error)

	// ContractRoots returns the roots of the contract with the given ID.
	ContractRoots(ctx context.Context, fcid types.FileContractID) ([]types.Hash256, error)

	// Contracts returns contract metadata for all active contracts. The
	// opts argument can be used to filter the result.
	Contracts(ctx context.Context, opts api.ContractsOpts) ([]api.ContractMetadata, error)

	// ContractSetID returns the ID of the contract set with the given name.
	// NOTE: Our locking strategy requires that the contract set ID is
	// unique. So even after a contract set was deleted, the ID must not be
	// reused.
	ContractSetID(ctx context.Context, contractSet string) (int64, error)

	// ContractSets returns the names of all contract sets.
	ContractSets(ctx context.Context) ([]string, error)

	// ContractSize returns the size of the contract with the given ID as
	// well as the estimated number of bytes that can be pruned from it.
	ContractSize(ctx context.Context, id types.FileContractID) (api.ContractSize, error)

	// ContractSizes returns the sizes of all contracts in the database as
	// well as the estimated number of bytes that can be pruned from them.
	ContractSizes(ctx context.Context) (map[types.FileContractID]api.ContractSize, error)

	// CopyObject copies an object from one bucket and key to another. If
	// source and destination are the same, only the metadata and mimeType
	// are overwritten with the provided ones.
	CopyObject(ctx context.Context, srcBucket, dstBucket, srcKey, dstKey, mimeType string, metadata api.ObjectUserMetadata) (api.ObjectMetadata, error)

	// CreateBucket creates a new bucket with the given name and policy. If
	// the bucket already exists, api.ErrBucketExists is returned.
	CreateBucket(ctx context.Context, bucket string, policy api.BucketPolicy) error

	// DeleteBucket deletes a bucket. If the bucket isn't empty, it returns
	// api.ErrBucketNotEmpty. If the bucket doesn't exist, it returns
	// api.ErrBucketNotFound.
	DeleteBucket(ctx context.Context, bucket string) error

	// DeleteHostSector deletes all contract sector links that a host has
	// with the given root incrementing the lost sector count in the
	// process. If another contract with a different host exists that
	// contains the root, latest_host is updated to that host.
	DeleteHostSector(ctx context.Context, hk types.PublicKey, root types.Hash256) (int, error)

	// DeleteObject deletes an object from the database and returns true if
	// the requested object was actually deleted.
	DeleteObject(ctx context.Context, bucket, key string) (bool, error)

	// DeleteObjects deletes a batch of objects starting with the given
	// prefix and returns 'true' if any object was deleted.
	DeleteObjects(ctx context.Context, bucket, prefix string, limit int64) (bool, error)

	// DeleteSettings deletes the settings with the given key.
	DeleteSettings(ctx context.Context, key string) error

	// DeleteWebhook deletes the webhook with the matching module, event and
	// URL of the provided webhook. If the webhook doesn't exist,
	// webhooks.ErrWebhookNotFound is returned.
	DeleteWebhook(ctx context.Context, wh webhooks.Webhook) error

	// InsertBufferedSlab inserts a buffered slab into the database. This
	// includes the creation of a buffered slab as well as the corresponding
	// regular slab it is linked to. It returns the ID of the buffered slab
	// that was created.
	InsertBufferedSlab(ctx context.Context, fileName string, contractSetID int64, ec object.EncryptionKey, minShards, totalShards uint8) (int64, error)

	// InsertContract inserts a new contract into the database.
	InsertContract(ctx context.Context, rev rhpv2.ContractRevision, contractPrice, totalCost types.Currency, startHeight uint64, renewedFrom types.FileContractID, state string) (api.ContractMetadata, error)

	// InsertMultipartUpload creates a new multipart upload and returns a
	// unique upload ID.
	InsertMultipartUpload(ctx context.Context, bucket, path string, ec object.EncryptionKey, mimeType string, metadata api.ObjectUserMetadata) (string, error)

	// InvalidateSlabHealthByFCID invalidates the health of all slabs that
	// are associated with any of the provided contracts.
	InvalidateSlabHealthByFCID(ctx context.Context, fcids []types.FileContractID, limit int64) (int64, error)

	// HostAllowlist returns the list of public keys of hosts on the
	// allowlist.
	HostAllowlist(ctx context.Context) ([]types.PublicKey, error)

	// HostBlocklist returns the list of host addresses on the blocklist.
	HostBlocklist(ctx context.Context) ([]string, error)

	// InsertObject inserts a new object into the database.
	InsertObject(ctx context.Context, bucket, key, contractSet string, o object.Object, mimeType, eTag string, md api.ObjectUserMetadata) error

	// HostsForScanning returns a list of hosts to scan which haven't been
	// scanned since at least maxLastScan.
	HostsForScanning(ctx context.Context, maxLastScan time.Time, offset, limit int) ([]api.HostAddress, error)

	// ListBuckets returns a list of all buckets in the database.
	ListBuckets(ctx context.Context) ([]api.Bucket, error)

	// ListObjects returns a list of objects from the given bucket.
	ListObjects(ctx context.Context, bucket, prefix, sortBy, sortDir, marker string, limit int) (api.ObjectsListResponse, error)

	// MakeDirsForPathDeprecated creates all directories for a given
	// object's path. This method is deprecated and should not be used, it's
	// used by migration 00008_directories and should be removed when that
	// migration is squashed.
	MakeDirsForPathDeprecated(ctx context.Context, path string) (int64, error)

	// MarkPackedSlabUploaded marks the packed slab as uploaded in the
	// database, causing the provided shards to be associated with the slab.
	// The returned string contains the filename of the slab buffer on disk.
	MarkPackedSlabUploaded(ctx context.Context, slab api.UploadedPackedSlab) (string, error)

	// MultipartUpload returns the multipart upload with the given ID or
	// api.ErrMultipartUploadNotFound if the upload doesn't exist.
	MultipartUpload(ctx context.Context, uploadID string) (api.MultipartUpload, error)

	// MultipartUploadParts returns a list of all parts for a given
	// multipart upload
	MultipartUploadParts(ctx context.Context, bucket, key, uploadID string, marker int, limit int64) (api.MultipartListPartsResponse, error)

	// MultipartUploads returns a list of all multipart uploads.
	MultipartUploads(ctx context.Context, bucket, prefix, keyMarker, uploadIDMarker string, limit int) (api.MultipartListUploadsResponse, error)

	// Object returns an object from the database.
	Object(ctx context.Context, bucket, key string) (api.Object, error)

	// ObjectEntries queries the database for objects in a given dir.
	ObjectEntries(ctx context.Context, bucket, key, prefix, sortBy, sortDir, marker string, offset, limit int) ([]api.ObjectMetadata, bool, error)

	// ObjectMetadata returns an object's metadata.
	ObjectMetadata(ctx context.Context, bucket, key string) (api.Object, error)

	// ObjectsBySlabKey returns all objects that contain a reference to the
	// slab with the given slabKey.
	ObjectsBySlabKey(ctx context.Context, bucket string, slabKey object.EncryptionKey) (metadata []api.ObjectMetadata, err error)

	// ObjectsStats returns overall stats about stored objects
	ObjectsStats(ctx context.Context, opts api.ObjectsStatsOpts) (api.ObjectsStatsResponse, error)

	// PeerBanned returns true if the peer is banned.
	PeerBanned(ctx context.Context, addr string) (bool, error)

	// PeerInfo returns the metadata for the specified peer or
	// ErrPeerNotFound if the peer wasn't found in the store.
	PeerInfo(ctx context.Context, addr string) (syncer.PeerInfo, error)

	// Peers returns the set of known peers.
	Peers(ctx context.Context) ([]syncer.PeerInfo, error)

	// ProcessChainUpdate applies the given chain update to the database.
	ProcessChainUpdate(ctx context.Context, applyFn func(ChainUpdateTx) error) error

	// PrunableContractRoots returns the indices of roots that are not in
	// the contract.
	PrunableContractRoots(ctx context.Context, fcid types.FileContractID, roots []types.Hash256) (indices []uint64, err error)

	// PruneSlabs deletes slabs that are no longer referenced by any slice
	// or slab buffer.
	PruneSlabs(ctx context.Context, limit int64) (int64, error)

	// RecordContractSpending records new spending for a contract
	RecordContractSpending(ctx context.Context, fcid types.FileContractID, revisionNumber, size uint64, newSpending api.ContractSpending) error

	// RecordHostScans records the results of host scans in the database
	// such as recording the settings and price table of a host in case of
	// success and updating the uptime and downtime of a host.
	// NOTE: The price table is only updated if the known price table is
	// expired since price tables from scans are not paid for and are
	// therefore only useful for gouging checks.
	RecordHostScans(ctx context.Context, scans []api.HostScan) error

	// RecordPriceTables records price tables for hosts in the database
	// increasing the successful/failed interactions accordingly.
	RecordPriceTables(ctx context.Context, priceTableUpdate []api.HostPriceTableUpdate) error

	// RemoveContractSet removes the contract set with the given name from
	// the database.
	RemoveContractSet(ctx context.Context, contractSet string) error

	// RemoveOfflineHosts removes all hosts that have been offline for
	// longer than maxDownTime and been scanned at least minRecentFailures
	// times. The contracts of those hosts are also removed.
	RemoveOfflineHosts(ctx context.Context, minRecentFailures uint64, maxDownTime time.Duration) (int64, error)

	// RenameObject renames an object in the database from keyOld to keyNew
	// and the new directory dirID. returns api.ErrObjectExists if the an
	// object already exists at the target location or api.ErrObjectNotFound
	// if the object at keyOld doesn't exist. If force is true, the instead
	// of returning api.ErrObjectExists, the existing object will be
	// deleted.
	RenameObject(ctx context.Context, bucket, keyOld, keyNew string, force bool) error

	// RenameObjects renames all objects in the database with the given
	// prefix to the new prefix. If 'force' is true, it will overwrite any
	// existing objects with the new prefix. If no object can be renamed,
	// `api.ErrOBjectNotFound` is returned. If 'force' is false and an
	// object already exists with the new prefix, `api.ErrObjectExists` is
	// returned.
	RenameObjects(ctx context.Context, bucket, prefixOld, prefixNew string, force bool) error

	// RenewContract renews the contract in the database. That means the
	// contract with the ID of 'renewedFrom' will be moved to the archived
	// contracts and the new contract will overwrite the existing one,
	// inheriting its sectors.
	RenewContract(ctx context.Context, rev rhpv2.ContractRevision, contractPrice, totalCost types.Currency, startHeight uint64, renewedFrom types.FileContractID, state string) (api.ContractMetadata, error)

	// RenewedContract returns the metadata of the contract that was renewed
	// from the specified contract or ErrContractNotFound otherwise.
	RenewedContract(ctx context.Context, renewedFrom types.FileContractID) (api.ContractMetadata, error)

	// ResetChainState deletes all chain data in the database.
	ResetChainState(ctx context.Context) error

	// ResetLostSectors resets the lost sector count for the given host.
	ResetLostSectors(ctx context.Context, hk types.PublicKey) error

	// SaveAccounts saves the given accounts in the db, overwriting any
	// existing ones.
	SaveAccounts(ctx context.Context, accounts []api.Account) error

	// SearchHosts returns a list of hosts that match the provided filters
	SearchHosts(ctx context.Context, autopilotID, filterMode, usabilityMode, addressContains string, keyIn []types.PublicKey, offset, limit int) ([]api.Host, error)

	// SearchObjects returns a list of objects that contain the provided
	// substring.
	SearchObjects(ctx context.Context, bucket, substring string, offset, limit int) ([]api.ObjectMetadata, error)

	// UpdateContractSet adds/removes the provided contract ids to/from
	// the contract set. The contract set is created in the process if
	// it doesn't exist already.
	UpdateContractSet(ctx context.Context, name string, toAdd, toRemove []types.FileContractID) error

	// Setting returns the setting with the given key from the database.
	Setting(ctx context.Context, key string) (string, error)

	// Settings returns all available settings from the database.
	Settings(ctx context.Context) ([]string, error)

	// Slab returns the slab with the given ID or api.ErrSlabNotFound.
	Slab(ctx context.Context, key object.EncryptionKey) (object.Slab, error)

	// SlabBuffers returns the filenames and associated contract sets of all
	// slab buffers.
	SlabBuffers(ctx context.Context) (map[string]string, error)

	// Tip returns the sync height.
	Tip(ctx context.Context) (types.ChainIndex, error)

	// UnhealthySlabs returns up to 'limit' slabs belonging to the contract
	// set 'set' with a health smaller than or equal to 'healthCutoff'
	UnhealthySlabs(ctx context.Context, healthCutoff float64, set string, limit int) ([]api.UnhealthySlab, error)

	// UnspentSiacoinElements returns all wallet outputs in the database.
	UnspentSiacoinElements(ctx context.Context) ([]types.SiacoinElement, error)

	// UpdateAutopilot updates the autopilot with the provided one or
	// creates a new one if it doesn't exist yet.
	UpdateAutopilot(ctx context.Context, ap api.Autopilot) error

	// UpdateBucketPolicy updates the policy of the bucket with the provided
	// one, fully overwriting the existing policy.
	UpdateBucketPolicy(ctx context.Context, bucket string, policy api.BucketPolicy) error

	// UpdateHostAllowlistEntries updates the allowlist in the database
	UpdateHostAllowlistEntries(ctx context.Context, add, remove []types.PublicKey, clear bool) error

	// UpdateHostBlocklistEntries updates the blocklist in the database
	UpdateHostBlocklistEntries(ctx context.Context, add, remove []string, clear bool) error

	// UpdateHostCheck updates the host check for the given host.
	UpdateHostCheck(ctx context.Context, autopilot string, hk types.PublicKey, hc api.HostCheck) error

	// UpdatePeerInfo updates the metadata for the specified peer.
	UpdatePeerInfo(ctx context.Context, addr string, fn func(*syncer.PeerInfo)) error

	// UpdateSetting updates the setting with the given key to the given
	// value.
	UpdateSetting(ctx context.Context, key, value string) error

	// UpdateSlab updates the slab in the database. That includes the following:
	// - Optimistically set health to 100%
	// - Invalidate health_valid_until
	// - Update LatestHost for every shard
	// The operation is not allowed to update the number of shards
	// associated with a slab or the root/slabIndex of any shard.
	UpdateSlab(ctx context.Context, s object.Slab, contractSet string, usedContracts []types.FileContractID) error

	// UpdateSlabHealth updates the health of up to 'limit' slab in the
	// database if their health is not valid anymore. A random interval
	// between 'minValidity' and 'maxValidity' is used to determine the time
	// the health of the updated slabs becomes invalid
	UpdateSlabHealth(ctx context.Context, limit int64, minValidity, maxValidity time.Duration) (int64, error)

	// WalletEvents returns all wallet events in the database.
	WalletEvents(ctx context.Context, offset, limit int) ([]wallet.Event, error)

	// WalletEventCount returns the total number of events in the database.
	WalletEventCount(ctx context.Context) (uint64, error)

	// Webhooks returns all registered webhooks.
	Webhooks(ctx context.Context) ([]webhooks.Webhook, error)
}

The database interfaces define all methods that a SQL database must implement to be used by the SQLStore.

type DurationMS added in v1.1.0

type DurationMS time.Duration

func (*DurationMS) Scan added in v1.1.0

func (d *DurationMS) Scan(value interface{}) error

Scan scan value into DurationMS, implements sql.Scanner interface.

func (DurationMS) Value added in v1.1.0

func (d DurationMS) Value() (driver.Value, error)

Value returns a int64 value representing a duration in milliseconds, implements driver.Valuer interface.

type EncryptionKey added in v1.1.0

type EncryptionKey object.EncryptionKey

func (*EncryptionKey) Scan added in v1.1.0

func (k *EncryptionKey) Scan(value interface{}) error

Scan scans value into key, implements sql.Scanner interface.

func (EncryptionKey) String added in v1.1.0

func (k EncryptionKey) String() string

String implements fmt.Stringer to prevent the key from getting leaked in logs.

func (EncryptionKey) Value added in v1.1.0

func (k EncryptionKey) Value() (driver.Value, error)

Value returns an key value, implements driver.Valuer interface.

type FileContractID

type FileContractID types.FileContractID

func (*FileContractID) Scan

func (fcid *FileContractID) Scan(value interface{}) error

Scan scan value into fileContractID, implements sql.Scanner interface.

func (FileContractID) Value

func (fcid FileContractID) Value() (driver.Value, error)

Value returns a fileContractID value, implements driver.Valuer interface.

type Hash256

type Hash256 types.Hash256

func (*Hash256) Scan

func (h *Hash256) Scan(value interface{}) error

Scan scan value into address, implements sql.Scanner interface.

func (Hash256) Value

func (h Hash256) Value() (driver.Value, error)

Value returns an addr value, implements driver.Valuer interface.

type HostSettings

type HostSettings rhpv2.HostSettings

func (*HostSettings) Scan

func (hs *HostSettings) Scan(value interface{}) error

Scan scan value into HostSettings, implements sql.Scanner interface.

func (HostSettings) Value

func (hs HostSettings) Value() (driver.Value, error)

Value returns a HostSettings value, implements driver.Valuer interface.

type LoadedSlabBuffer

type LoadedSlabBuffer struct {
	ID            int64
	ContractSetID int64
	Filename      string
	Key           object.EncryptionKey
	MinShards     uint8
	Size          int64
	TotalShards   uint8
}

The database interfaces define all methods that a SQL database must implement to be used by the SQLStore.

func LoadSlabBuffers

func LoadSlabBuffers(ctx context.Context, db *sql.DB) (bufferedSlabs []LoadedSlabBuffer, orphanedBuffers []string, err error)

type MerkleProof added in v1.1.0

type MerkleProof struct{ Hashes []types.Hash256 }

func (*MerkleProof) Scan added in v1.1.0

func (mp *MerkleProof) Scan(value interface{}) error

Scan scans value into a MerkleProof, implements sql.Scanner interface.

func (MerkleProof) Value added in v1.1.0

func (mp MerkleProof) Value() (driver.Value, error)

Value returns a MerkleProof value, implements driver.Valuer interface.

type MetricsDatabase

type MetricsDatabase interface {
	io.Closer

	// Migrate runs all missing migrations on the database.
	Migrate(ctx context.Context) error

	// Transaction starts a new transaction.
	Transaction(ctx context.Context, fn func(MetricsDatabaseTx) error) error

	// Version returns the database version and name.
	Version(ctx context.Context) (string, string, error)
}

The database interfaces define all methods that a SQL database must implement to be used by the SQLStore.

type MetricsDatabaseTx

type MetricsDatabaseTx interface {
	// ContractMetrics returns contract metrics  for the given time range
	// and options.
	ContractMetrics(ctx context.Context, start time.Time, n uint64, interval time.Duration, opts api.ContractMetricsQueryOpts) ([]api.ContractMetric, error)

	// ContractPruneMetrics returns the contract prune metrics for the given
	// time range and options.
	ContractPruneMetrics(ctx context.Context, start time.Time, n uint64, interval time.Duration, opts api.ContractPruneMetricsQueryOpts) ([]api.ContractPruneMetric, error)

	// ContractSetChurnMetrics returns the contract set churn metrics for
	// the given time range and options.
	ContractSetChurnMetrics(ctx context.Context, start time.Time, n uint64, interval time.Duration, opts api.ContractSetChurnMetricsQueryOpts) ([]api.ContractSetChurnMetric, error)

	// ContractSetMetrics returns the contract set metrics for the given
	// time range and options.
	ContractSetMetrics(ctx context.Context, start time.Time, n uint64, interval time.Duration, opts api.ContractSetMetricsQueryOpts) ([]api.ContractSetMetric, error)

	// PruneMetrics deletes metrics of a certain type older than the given
	// cutoff time.
	PruneMetrics(ctx context.Context, metric string, cutoff time.Time) error

	// RecordContractMetric records contract metrics.
	RecordContractMetric(ctx context.Context, metrics ...api.ContractMetric) error

	// RecordContractPruneMetric records contract prune metrics.
	RecordContractPruneMetric(ctx context.Context, metrics ...api.ContractPruneMetric) error

	// RecordContractSetChurnMetric records contract set churn metrics.
	RecordContractSetChurnMetric(ctx context.Context, metrics ...api.ContractSetChurnMetric) error

	// RecordContractSetMetric records contract set metrics.
	RecordContractSetMetric(ctx context.Context, metrics ...api.ContractSetMetric) error

	// RecordWalletMetric records wallet metrics.
	RecordWalletMetric(ctx context.Context, metrics ...api.WalletMetric) error

	// WalletMetrics returns wallet metrics for the given time range
	WalletMetrics(ctx context.Context, start time.Time, n uint64, interval time.Duration, opts api.WalletMetricsQueryOpts) ([]api.WalletMetric, error)
}

The database interfaces define all methods that a SQL database must implement to be used by the SQLStore.

type PriceTable

type PriceTable rhpv3.HostPriceTable

func (*PriceTable) Scan

func (pt *PriceTable) Scan(value interface{}) error

Scan scan value into PriceTable, implements sql.Scanner interface.

func (PriceTable) Value

func (pt PriceTable) Value() (driver.Value, error)

Value returns a PriceTable value, implements driver.Valuer interface.

type PublicKey

type PublicKey types.PublicKey

func (*PublicKey) Scan

func (pk *PublicKey) Scan(value interface{}) error

Scan scan value into publicKey, implements sql.Scanner interface.

func (PublicKey) Value

func (pk PublicKey) Value() (driver.Value, error)

Value returns a publicKey value, implements driver.Valuer interface.

type Scanner added in v1.1.0

type Scanner interface {
	Scan(dest ...any) error
}

type Tx added in v1.1.0

type Tx interface {
	sql.Tx

	CharLengthExpr() string

	// ScanObjectMetadata scans the object metadata from the given scanner.
	// The columns required to scan the metadata are returned by the
	// SelectObjectMetadataExpr helper method. Additional fields can be
	// selected and scanned by passing them to the method as 'others'.
	ScanObjectMetadata(s Scanner, others ...any) (md api.ObjectMetadata, err error)
	SelectObjectMetadataExpr() string
}

Tx is an interface that allows for injecting custom methods into helpers to avoid duplicating code.

type Uint64Str added in v1.1.0

type Uint64Str uint64

func (*Uint64Str) Scan added in v1.1.0

func (u *Uint64Str) Scan(value interface{}) error

Scan scan value into Uint64, implements sql.Scanner interface.

func (Uint64Str) Value added in v1.1.0

func (u Uint64Str) Value() (driver.Value, error)

Value returns a Uint64 value, implements driver.Valuer interface.

type UnixTimeMS

type UnixTimeMS time.Time

func (*UnixTimeMS) Scan

func (u *UnixTimeMS) Scan(value interface{}) error

Scan scan value into unixTimeMS, implements sql.Scanner interface.

func (UnixTimeMS) Value

func (u UnixTimeMS) Value() (driver.Value, error)

Value returns a int64 value representing a unix timestamp in milliseconds, implements driver.Valuer interface.

type Unsigned64

type Unsigned64 uint64

func (*Unsigned64) Scan

func (u *Unsigned64) Scan(value interface{}) error

Scan scan value into Unsigned64, implements sql.Scanner interface.

func (Unsigned64) Value

func (u Unsigned64) Value() (driver.Value, error)

Value returns an Unsigned64 value, implements driver.Valuer interface.

type UsedContract

type UsedContract struct {
	ID          int64
	FCID        FileContractID
	RenewedFrom FileContractID
}

The database interfaces define all methods that a SQL database must implement to be used by the SQLStore.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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