Documentation
¶
Index ¶
- Variables
- func DBConfigFromEnv() (uri, user, password, dbName string)
- func NewEphemeralSQLiteConnection(name string) gorm.Dialector
- func NewMySQLConnection(user, password, addr, dbName string) gorm.Dialector
- func NewSQLLogger(l *zap.Logger, config *LoggerConfig) logger.Interface
- func NewSQLiteConnection(path string) gorm.Dialector
- type ContractCommon
- type EphemeralAutopilotStore
- type EphemeralWalletStore
- func (s *EphemeralWalletStore) Balance() (sc types.Currency)
- func (s *EphemeralWalletStore) ProcessConsensusChange(cc modules.ConsensusChange)
- func (s *EphemeralWalletStore) Transactions(since time.Time, max int) ([]wallet.Transaction, error)
- func (s *EphemeralWalletStore) UnspentSiacoinElements() ([]wallet.SiacoinElement, error)
- type JSONAutopilotStore
- type JSONWalletStore
- type LoggerConfig
- type Model
- type SQLStore
- func (s *SQLStore) Accounts(ctx context.Context) ([]api.Account, error)
- func (s *SQLStore) ActiveContracts(ctx context.Context) ([]api.ContractMetadata, error)
- func (s *SQLStore) AddContract(ctx context.Context, c rhpv2.ContractRevision, totalCost types.Currency, ...) (_ api.ContractMetadata, err error)
- func (s *SQLStore) AddRenewedContract(ctx context.Context, c rhpv2.ContractRevision, totalCost types.Currency, ...) (api.ContractMetadata, error)
- func (s *SQLStore) AncestorContracts(ctx context.Context, id types.FileContractID, startHeight uint64) ([]api.ArchivedContract, error)
- func (s *SQLStore) Close() error
- func (s *SQLStore) Contract(ctx context.Context, id types.FileContractID) (api.ContractMetadata, error)
- func (s *SQLStore) ContractSets(ctx context.Context) ([]string, error)
- func (s *SQLStore) Contracts(ctx context.Context, set string) ([]api.ContractMetadata, error)
- func (s *SQLStore) DeleteContractSet(ctx context.Context, name string) error
- func (s *SQLStore) DeleteSetting(ctx context.Context, key string) error
- func (ss *SQLStore) Host(ctx context.Context, hostKey types.PublicKey) (hostdb.HostInfo, error)
- func (ss *SQLStore) HostAllowlist(ctx context.Context) (allowlist []types.PublicKey, err error)
- func (ss *SQLStore) HostBlocklist(ctx context.Context) (blocklist []string, err error)
- func (ss *SQLStore) Hosts(ctx context.Context, offset, limit int) ([]hostdb.Host, error)
- func (ss *SQLStore) HostsForScanning(ctx context.Context, maxLastScan time.Time, offset, limit int) ([]hostdb.HostAddress, error)
- func (s *SQLStore) Object(ctx context.Context, key string) (object.Object, error)
- func (s *SQLStore) ObjectEntries(ctx context.Context, path, prefix string, offset, limit int) ([]string, error)
- func (s *SQLStore) ObjectsStats(ctx context.Context) (api.ObjectsStats, error)
- func (ss *SQLStore) ProcessConsensusChange(cc modules.ConsensusChange)
- func (s *SQLStore) RecordContractSpending(ctx context.Context, records []api.ContractSpendingRecord) error
- func (ss *SQLStore) RecordInteractions(ctx context.Context, interactions []hostdb.Interaction) error
- func (s *SQLStore) RemoveContract(ctx context.Context, id types.FileContractID) error
- func (s *SQLStore) RemoveContracts(ctx context.Context) error
- func (s *SQLStore) RemoveObject(ctx context.Context, key string) error
- func (ss *SQLStore) RemoveOfflineHosts(ctx context.Context, minRecentFailures uint64, maxDowntime time.Duration) (removed uint64, err error)
- func (s *SQLStore) SaveAccounts(ctx context.Context, accounts []api.Account) error
- func (ss *SQLStore) SearchHosts(ctx context.Context, filterMode, addressContains string, ...) ([]hostdb.Host, error)
- func (s *SQLStore) SearchObjects(ctx context.Context, substring string, offset, limit int) ([]string, error)
- func (s *SQLStore) SetContractSet(ctx context.Context, name string, contractIds []types.FileContractID) error
- func (s *SQLStore) Setting(ctx context.Context, key string) (string, error)
- func (s *SQLStore) Settings(ctx context.Context) ([]string, error)
- func (s *SQLStore) UnhealthySlabs(ctx context.Context, healthCutoff float64, set string, limit int) ([]object.Slab, error)
- func (ss *SQLStore) UpdateHostAllowlistEntries(ctx context.Context, add, remove []types.PublicKey, clear bool) (err error)
- func (ss *SQLStore) UpdateHostBlocklistEntries(ctx context.Context, add, remove []string, clear bool) (err error)
- func (s *SQLStore) UpdateObject(ctx context.Context, key string, o object.Object, ...) error
- func (s *SQLStore) UpdateSetting(ctx context.Context, key, value string) error
- func (ss *SQLStore) UpdateSlab(ctx context.Context, s object.Slab, ...) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrHostNotFound = errors.New("host doesn't exist in hostdb") ErrNegativeOffset = errors.New("offset can not be negative") )
var ( // ErrSlabNotFound is returned if get is unable to retrieve a slab from the // database. ErrSlabNotFound = errors.New("slab not found in database") // ErrContractNotFound is returned when a contract can't be retrieved from // the database. ErrContractNotFound = errors.New("couldn't find contract") // ErrContractSetNotFound is returned when a contract can't be retrieved // from the database. ErrContractSetNotFound = errors.New("couldn't find contract set") )
Functions ¶
func DBConfigFromEnv ¶
func DBConfigFromEnv() (uri, user, password, dbName string)
func NewEphemeralSQLiteConnection ¶
NewEphemeralSQLiteConnection creates a connection to an in-memory SQLite DB. NOTE: Use simple names such as a random hex identifier or the filepath.Base of a test's name. Certain symbols will break the cfg string and cause a file to be created on disk.
mode: set to memory for in-memory database cache: set to shared which is required for in-memory databases _foreign_keys: enforce foreign_key relations
func NewMySQLConnection ¶
NewMySQLConnection creates a connection to a MySQL database.
func NewSQLLogger ¶
func NewSQLLogger(l *zap.Logger, config *LoggerConfig) logger.Interface
func NewSQLiteConnection ¶
NewSQLiteConnection opens a sqlite db at the given path.
_busy_timeout: set to prevent concurrent transactions from failing and instead have them block _foreign_keys: enforce foreign_key relations _journal_mode: set to WAL instead of delete since it's usually the fastest. Only downside is that the db won't work on network drives. In that case this should be made configurable and set to TRUNCATE or any of the other options. For reference see https://github.com/mattn/go-sqlite3#connection-string.
Types ¶
type ContractCommon ¶
type ContractCommon struct { FCID fileContractID `gorm:"unique;index;NOT NULL;column:fcid;size:32"` RenewedFrom fileContractID `gorm:"index;size:32"` TotalCost currency ProofHeight uint64 `gorm:"index;default:0"` RevisionHeight uint64 `gorm:"index;default:0"` RevisionNumber string `gorm:"NOT NULL;default:'0'"` // string since db can't store math.MaxUint64 StartHeight uint64 `gorm:"index;NOT NULL"` WindowStart uint64 `gorm:"index;NOT NULL;default:0"` WindowEnd uint64 `gorm:"index;NOT NULL;default:0"` // spending fields UploadSpending currency DownloadSpending currency FundAccountSpending currency }
type EphemeralAutopilotStore ¶
type EphemeralAutopilotStore struct {
// contains filtered or unexported fields
}
EphemeralAutopilotStore implements autopilot.Store in memory.
func NewEphemeralAutopilotStore ¶
func NewEphemeralAutopilotStore() *EphemeralAutopilotStore
NewEphemeralAutopilotStore returns a new EphemeralAutopilotStore.
func (*EphemeralAutopilotStore) Config ¶
func (s *EphemeralAutopilotStore) Config() api.AutopilotConfig
Config implements autopilot.Store.
func (*EphemeralAutopilotStore) ProcessConsensusChange ¶
func (s *EphemeralAutopilotStore) ProcessConsensusChange(cc modules.ConsensusChange)
ProcessConsensusChange implements chain.Subscriber.
func (*EphemeralAutopilotStore) SetConfig ¶
func (s *EphemeralAutopilotStore) SetConfig(c api.AutopilotConfig) error
SetConfig implements autopilot.Store.
type EphemeralWalletStore ¶
type EphemeralWalletStore struct {
// contains filtered or unexported fields
}
EphemeralWalletStore implements wallet.SingleAddressStore in memory.
func NewEphemeralWalletStore ¶
func NewEphemeralWalletStore(addr types.Address) *EphemeralWalletStore
NewEphemeralWalletStore returns a new EphemeralWalletStore.
func (*EphemeralWalletStore) Balance ¶
func (s *EphemeralWalletStore) Balance() (sc types.Currency)
Balance implements wallet.SingleAddressStore.
func (*EphemeralWalletStore) ProcessConsensusChange ¶
func (s *EphemeralWalletStore) ProcessConsensusChange(cc modules.ConsensusChange)
ProcessConsensusChange implements modules.ConsensusSetSubscriber.
func (*EphemeralWalletStore) Transactions ¶
func (s *EphemeralWalletStore) Transactions(since time.Time, max int) ([]wallet.Transaction, error)
Transactions implements wallet.SingleAddressStore.
func (*EphemeralWalletStore) UnspentSiacoinElements ¶
func (s *EphemeralWalletStore) UnspentSiacoinElements() ([]wallet.SiacoinElement, error)
UnspentSiacoinElements implements wallet.SingleAddressStore.
type JSONAutopilotStore ¶
type JSONAutopilotStore struct { *EphemeralAutopilotStore // contains filtered or unexported fields }
JSONAutopilotStore implements autopilot.Store in memory, backed by a JSON file.
func NewJSONAutopilotStore ¶
func NewJSONAutopilotStore(dir string) (*JSONAutopilotStore, error)
NewJSONAutopilotStore returns a new JSONAutopilotStore.
func (*JSONAutopilotStore) SetConfig ¶
func (s *JSONAutopilotStore) SetConfig(c api.AutopilotConfig) error
SetConfig implements autopilot.Store.
type JSONWalletStore ¶
type JSONWalletStore struct { *EphemeralWalletStore // contains filtered or unexported fields }
JSONWalletStore implements wallet.SingleAddressStore in memory, backed by a JSON file.
func NewJSONWalletStore ¶
func NewJSONWalletStore(dir string, addr types.Address) (*JSONWalletStore, modules.ConsensusChangeID, error)
NewJSONWalletStore returns a new JSONWalletStore.
func (*JSONWalletStore) ProcessConsensusChange ¶
func (s *JSONWalletStore) ProcessConsensusChange(cc modules.ConsensusChange)
ProcessConsensusChange implements chain.Subscriber.
type LoggerConfig ¶
type Model ¶
Model defines the common fields of every table. Same as Model but excludes soft deletion since it breaks cascading deletes.
type SQLStore ¶
type SQLStore struct {
// contains filtered or unexported fields
}
SQLStore is a helper type for interacting with a SQL-based backend.
func NewSQLStore ¶
func NewSQLStore(conn gorm.Dialector, migrate bool, persistInterval time.Duration, logger glogger.Interface) (*SQLStore, modules.ConsensusChangeID, error)
NewSQLStore uses a given Dialector to connect to a SQL database. NOTE: Only pass migrate=true for the first instance of SQLHostDB if you connect via the same Dialector multiple times.
func (*SQLStore) ActiveContracts ¶
func (*SQLStore) AddContract ¶
func (*SQLStore) AddRenewedContract ¶
func (s *SQLStore) AddRenewedContract(ctx context.Context, c rhpv2.ContractRevision, totalCost types.Currency, startHeight uint64, renewedFrom types.FileContractID) (api.ContractMetadata, error)
AddRenewedContract adds a new contract which was created as the result of a renewal to the store. The old contract specified as 'renewedFrom' will be deleted from the active contracts and moved to the archive. Both new and old contract will be linked to each other through the RenewedFrom and RenewedTo fields respectively.
func (*SQLStore) AncestorContracts ¶
func (s *SQLStore) AncestorContracts(ctx context.Context, id types.FileContractID, startHeight uint64) ([]api.ArchivedContract, error)
func (*SQLStore) Contract ¶
func (s *SQLStore) Contract(ctx context.Context, id types.FileContractID) (api.ContractMetadata, error)
func (*SQLStore) ContractSets ¶
func (*SQLStore) DeleteContractSet ¶
func (*SQLStore) DeleteSetting ¶
DeleteSetting implements the bus.SettingStore interface.
func (*SQLStore) HostAllowlist ¶
func (*SQLStore) HostBlocklist ¶
func (*SQLStore) HostsForScanning ¶
func (ss *SQLStore) HostsForScanning(ctx context.Context, maxLastScan time.Time, offset, limit int) ([]hostdb.HostAddress, error)
HostsForScanning returns the address of hosts for scanning.
func (*SQLStore) ObjectEntries ¶
func (*SQLStore) ObjectsStats ¶
ObjectsStats returns some info related to the objects stored in the store. To reduce locking and make sure all results are consistent, everything is done within a single transaction.
func (*SQLStore) ProcessConsensusChange ¶
func (ss *SQLStore) ProcessConsensusChange(cc modules.ConsensusChange)
ProcessConsensusChange implements consensus.Subscriber.
func (*SQLStore) RecordContractSpending ¶
func (*SQLStore) RecordInteractions ¶
func (ss *SQLStore) RecordInteractions(ctx context.Context, interactions []hostdb.Interaction) error
RecordHostInteraction records an interaction with a host. If the host is not in the store, a new entry is created for it.
func (*SQLStore) RemoveContract ¶
func (*SQLStore) RemoveObject ¶
func (*SQLStore) RemoveOfflineHosts ¶
func (*SQLStore) SaveAccounts ¶
SaveAccounts saves the given accounts in the db, overwriting any existing ones.
func (*SQLStore) SearchHosts ¶
func (*SQLStore) SearchObjects ¶
func (*SQLStore) SetContractSet ¶
func (*SQLStore) UnhealthySlabs ¶
func (s *SQLStore) UnhealthySlabs(ctx context.Context, healthCutoff float64, set string, limit int) ([]object.Slab, error)
UnhealthySlabs returns up to 'limit' slabs that do not reach full redundancy in the given contract set. These slabs need to be migrated to good contracts so they are restored to full health.
func (*SQLStore) UpdateHostAllowlistEntries ¶
func (*SQLStore) UpdateHostBlocklistEntries ¶
func (*SQLStore) UpdateObject ¶
func (*SQLStore) UpdateSetting ¶
UpdateSetting implements the bus.SettingStore interface.