Documentation
¶
Index ¶
- func Backup(ctx context.Context, srcPath, destPath string) (err error)
- func ForeignKeyCheck(ctx context.Context, fp string, log *zap.Logger) error
- func IntegrityCheck(ctx context.Context, fp string, log *zap.Logger) error
- func NewPeerStore(s *Store) (syncer.PeerStore, error)
- type PeerStore
- func (ps *PeerStore) AddPeer(peer string) error
- func (ps *PeerStore) Ban(peer string, duration time.Duration, reason string) error
- func (ps *PeerStore) Banned(peer string) (bool, error)
- func (ps *PeerStore) PeerInfo(peer string) (syncer.PeerInfo, error)
- func (ps *PeerStore) Peers() ([]syncer.PeerInfo, error)
- func (ps *PeerStore) UpdatePeerInfo(peer string, fn func(*syncer.PeerInfo)) error
- type Store
- func (s *Store) AccountBalance(accountID rhp3.Account) (balance types.Currency, err error)
- func (s *Store) AccountFunding(account rhp3.Account) (srcs []accounts.FundingSource, err error)
- func (s *Store) Accounts(limit, offset int) (acc []accounts.Account, err error)
- func (s *Store) AddContract(revision contracts.SignedRevision, formationSet []types.Transaction, ...) error
- func (s *Store) AddPeer(peer string) error
- func (s *Store) AddTempSector(root types.Hash256, expiration uint64) error
- func (s *Store) AddTemporarySectors(sectors []storage.TempSector) errordeprecated
- func (s *Store) AddV2Contract(contract contracts.V2Contract, formationSet rhp4.TransactionSet) error
- func (s *Store) AddVolume(localPath string, readOnly bool) (volumeID int64, err error)
- func (s *Store) Backup(ctx context.Context, destPath string) error
- func (s *Store) Ban(peer string, duration time.Duration, reason string) error
- func (s *Store) Banned(peer string) (banned bool, _ error)
- func (s *Store) CheckContractAccountFunding() error
- func (s *Store) Close() error
- func (s *Store) Contract(id types.FileContractID) (contract contracts.Contract, err error)
- func (s *Store) ContractActions(index types.ChainIndex, revisionBroadcastHeight uint64) (actions contracts.LifecycleActions, err error)
- func (s *Store) ContractChainIndexElement(index types.ChainIndex) (element types.ChainIndexElement, err error)
- func (s *Store) Contracts(filter contracts.ContractFilter) (contracts []contracts.Contract, count int, err error)
- func (s *Store) CreditAccountWithContract(fund accounts.FundAccountWithContract) error
- func (s *Store) DebitAccount(accountID rhp3.Account, usage accounts.Usage) error
- func (s *Store) ExpireContractSectors(height uint64) error
- func (s *Store) ExpireTempSectors(height uint64) error
- func (s *Store) ExpireV2ContractSectors(height uint64) error
- func (s *Store) GetRegistryValue(key rhp3.RegistryKey) (entry rhp3.RegistryValue, err error)
- func (s *Store) GrowVolume(id int64, maxSectors uint64) error
- func (s *Store) HasSector(root types.Hash256) (exists bool, err error)
- func (s *Store) HostKey() (pk types.PrivateKey)
- func (s *Store) IncrementRHPDataUsage(ingress, egress uint64) error
- func (s *Store) IncrementRegistryAccess(read, write uint64) error
- func (s *Store) IncrementSectorStats(reads, writes, cacheHit, cacheMiss uint64) error
- func (s *Store) LastAnnouncement() (ann settings.Announcement, err error)
- func (s *Store) LastV2AnnouncementHash() (h types.Hash256, index types.ChainIndex, err error)
- func (s *Store) Metrics(timestamp time.Time) (m metrics.Metrics, err error)
- func (s *Store) MigrateSectors(ctx context.Context, volumeID int64, startIndex uint64, ...) (migrated, failed int, err error)
- func (s *Store) Peers() (peers []syncer.PeerInfo, _ error)
- func (s *Store) PeriodMetrics(start time.Time, n int, interval metrics.Interval) ([]metrics.Metrics, error)
- func (s *Store) PinnedSettings(context.Context) (pinned pin.PinnedSettings, err error)
- func (s *Store) PruneAccounts(height uint64) error
- func (s *Store) PruneSectors(ctx context.Context, lastAccess time.Time) error
- func (s *Store) RHP4AccountBalance(account proto4.Account) (balance types.Currency, err error)
- func (s *Store) RHP4AccountBalances(accounts []proto4.Account) (balances []types.Currency, err error)
- func (s *Store) RHP4CreditAccounts(deposits []proto4.AccountDeposit, contractID types.FileContractID, ...) (balances []types.Currency, err error)
- func (s *Store) RHP4DebitAccount(account proto4.Account, usage proto4.Usage) error
- func (s *Store) RebroadcastFormationSets(minNegotiationheight uint64) (rebroadcast [][]types.Transaction, err error)
- func (s *Store) RecalcContractAccountFunding() error
- func (s *Store) RegisterWebhook(url, secret string, scopes []string) (id int64, err error)
- func (s *Store) RegistryEntries() (count, limit uint64, err error)
- func (s *Store) RemoveSector(root types.Hash256) (err error)
- func (s *Store) RemoveVolume(id int64, force bool) error
- func (s *Store) RemoveWebhook(id int64) error
- func (s *Store) RenewContract(renewal contracts.SignedRevision, clearing contracts.SignedRevision, ...) error
- func (s *Store) RenewV2Contract(renewal contracts.V2Contract, renewalSet rhp4.TransactionSet, ...) error
- func (s *Store) ResetChainState() error
- func (s *Store) RevertLastAnnouncement() error
- func (s *Store) ReviseContract(revision contracts.SignedRevision, roots []types.Hash256, ...) error
- func (s *Store) ReviseV2Contract(id types.FileContractID, revision types.V2FileContract, ...) error
- func (s *Store) SectorLocation(root types.Hash256) (location storage.SectorLocation, err error)
- func (s *Store) SectorReferences(root types.Hash256) (refs storage.SectorReference, err error)
- func (s *Store) SectorRoots() (roots map[types.FileContractID][]types.Hash256, err error)
- func (s *Store) SetAvailable(volumeID int64, available bool) error
- func (s *Store) SetReadOnly(volumeID int64, readOnly bool) error
- func (s *Store) SetRegistryValue(entry rhp3.RegistryEntry, expiration uint64) error
- func (s *Store) Settings() (config settings.Settings, err error)
- func (s *Store) ShrinkVolume(id int64, maxSectors uint64) error
- func (s *Store) StorageUsage() (usedSectors, totalSectors uint64, err error)
- func (s *Store) StoreSector(root types.Hash256, fn storage.StoreFunc) error
- func (s *Store) Tip() (index types.ChainIndex, err error)
- func (s *Store) UnspentSiacoinElements() (utxos []types.SiacoinElement, err error)
- func (s *Store) UpdateChainState(fn func(index.UpdateTx) error) error
- func (s *Store) UpdateLastAnnouncement(ann settings.Announcement) error
- func (s *Store) UpdatePinnedSettings(_ context.Context, p pin.PinnedSettings) error
- func (s *Store) UpdateSettings(settings settings.Settings) error
- func (s *Store) UpdateWebhook(id int64, url string, scopes []string) error
- func (s *Store) V2Contract(id types.FileContractID) (contract contracts.V2Contract, err error)
- func (s *Store) V2ContractElement(contractID types.FileContractID) (basis types.ChainIndex, ele types.V2FileContractElement, err error)
- func (s *Store) V2Contracts(filter contracts.V2ContractFilter) (contracts []contracts.V2Contract, count int, err error)
- func (s *Store) V2SectorRoots() (roots map[types.FileContractID][]types.Hash256, err error)
- func (s *Store) Vacuum() error
- func (s *Store) VerifyWalletKey(seedHash types.Hash256) error
- func (s *Store) Volume(id int64) (vol storage.Volume, err error)
- func (s *Store) Volumes() (volumes []storage.Volume, err error)
- func (s *Store) WalletEventCount() (count uint64, err error)
- func (s *Store) WalletEvents(offset, limit int) (events []wallet.Event, err error)
- func (s *Store) Webhooks() (hooks []webhooks.Webhook, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Backup ¶
Backup creates a backup of the database at the specified path. The backup is created using the SQLite backup API, which is safe to use with a live database.
This function should be used if the database is not already open in the current process. If the database is already open, use Store.Backup.
func ForeignKeyCheck ¶
ForeignKeyCheck runs a PRAGMA foreign_key_check on the database and logs any foreign key constraint violations. If any violations are found, an error is returned.
func IntegrityCheck ¶
IntegrityCheck runs a PRAGMA integrity_check on the database and logs any integrity errors. If any errors are found, an error is returned.
Types ¶
type PeerStore ¶
type PeerStore struct {
// contains filtered or unexported fields
}
A PeerStore stores information about peers.
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 ¶
OpenDatabase creates a new SQLite store and initializes the database. If the database does not exist, it is created.
func (*Store) AccountBalance ¶
AccountBalance returns the balance of the account with the given ID.
func (*Store) AccountFunding ¶
AccountFunding returns all contracts that were used to fund the account.
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) AddTempSector ¶
AddTempSector adds a sector to temporary storage. The sectors will be deleted after the expiration height
func (*Store) AddTemporarySectors
deprecated
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.
Deprecated: use AddTempSector
func (*Store) AddV2Contract ¶
func (s *Store) AddV2Contract(contract contracts.V2Contract, formationSet rhp4.TransactionSet) error
AddV2Contract adds a new contract to the database.
func (*Store) AddVolume ¶
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) Backup ¶
Backup creates a backup of the database at the specified path. The backup is created using the SQLite backup API, which is safe to use with a live database.
This function should be used if the database is already open in the current process. If the database is not already open, use Backup.
func (*Store) Ban ¶
Ban 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).
func (*Store) CheckContractAccountFunding ¶
CheckContractAccountFunding checks that the contract account funding table is correct.
func (*Store) ContractActions ¶
func (s *Store) ContractActions(index types.ChainIndex, revisionBroadcastHeight uint64) (actions contracts.LifecycleActions, err error)
ContractActions returns the contract lifecycle actions for the given index.
func (*Store) ContractChainIndexElement ¶
func (s *Store) ContractChainIndexElement(index types.ChainIndex) (element types.ChainIndexElement, err error)
ContractChainIndexElement returns the chain index element for the given height.
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) CreditAccountWithContract ¶
func (s *Store) CreditAccountWithContract(fund accounts.FundAccountWithContract) error
CreditAccountWithContract adds the specified amount to the account with the given ID.
func (*Store) DebitAccount ¶
DebitAccount subtracts the specified amount from the account with the given ID. Returns the remaining balance of the account.
func (*Store) ExpireContractSectors ¶
ExpireContractSectors expires all sectors that are no longer covered by an active contract.
func (*Store) ExpireTempSectors ¶
ExpireTempSectors deletes the roots of sectors that are no longer temporarily stored on the host.
func (*Store) ExpireV2ContractSectors ¶
ExpireV2ContractSectors expires all sectors that are no longer covered by an active contract.
func (*Store) GetRegistryValue ¶
func (s *Store) GetRegistryValue(key rhp3.RegistryKey) (entry rhp3.RegistryValue, err error)
GetRegistryValue returns the registry value for the given key. If the key is not found should return ErrEntryNotFound.
func (*Store) GrowVolume ¶
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) IncrementRHPDataUsage ¶
IncrementRHPDataUsage increments the RHP3 ingress and egress metrics.
func (*Store) IncrementRegistryAccess ¶
IncrementRegistryAccess increments the registry read and write metrics.
func (*Store) IncrementSectorStats ¶
IncrementSectorStats increments the sector read, write and cache metrics.
func (*Store) LastAnnouncement ¶
func (s *Store) LastAnnouncement() (ann settings.Announcement, err error)
LastAnnouncement returns the last announcement.
func (*Store) LastV2AnnouncementHash ¶
LastV2AnnouncementHash returns the hash of the last v2 announcement and the chain index it was confirmed in.
func (*Store) MigrateSectors ¶
func (s *Store) MigrateSectors(ctx context.Context, volumeID int64, startIndex uint64, migrateFn storage.MigrateFunc) (migrated, failed int, err error)
MigrateSectors migrates each occupied sector of a volume starting at startIndex. migrateFn will be called for each sector that needs to be migrated. The sector data should be copied to the new location and synced to disk immediately. If migrateFn returns an error, that sector will be considered failed and the migration will continue. If the context is canceled, the migration will stop and the error will be returned. If the host runs out of writable storage, migration will stop and ErrNotEnoughStorage will be returned. The number of sectors migrated and failed will always be returned, even if an error occurs.
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) PinnedSettings ¶
PinnedSettings returns the host's pinned settings.
func (*Store) PruneAccounts ¶
PruneAccounts removes all accounts that have expired
func (*Store) PruneSectors ¶
PruneSectors removes volume references for sectors that have not been accessed since the provided timestamp and are no longer referenced by a contract or temp storage.
func (*Store) RHP4AccountBalance ¶
RHP4AccountBalance returns the balance of the account with the given ID.
func (*Store) RHP4AccountBalances ¶
func (s *Store) RHP4AccountBalances(accounts []proto4.Account) (balances []types.Currency, err error)
RHP4AccountBalances returns the balances of the accounts with the given IDs. The balances are returned in the same order as the input accounts. If an account does not exist, the balance at that index will be types.ZeroCurrency.
func (*Store) RHP4CreditAccounts ¶
func (s *Store) RHP4CreditAccounts(deposits []proto4.AccountDeposit, contractID types.FileContractID, revision types.V2FileContract, usage proto4.Usage) (balances []types.Currency, err error)
RHP4CreditAccounts credits the accounts with the given deposits and revises the contract.
func (*Store) RHP4DebitAccount ¶
RHP4DebitAccount debits the account with the given ID.
func (*Store) RebroadcastFormationSets ¶
func (s *Store) RebroadcastFormationSets(minNegotiationheight uint64) (rebroadcast [][]types.Transaction, err error)
RebroadcastFormationSets returns formation sets that should be rebroadcast
func (*Store) RecalcContractAccountFunding ¶
RecalcContractAccountFunding recalculates the contract account funding table.
func (*Store) RegisterWebhook ¶
RegisterWebhook registers a new webhook.
func (*Store) RegistryEntries ¶
RegistryEntries returns the current number of entries as well as the maximum number of entries the registry can hold.
func (*Store) RemoveSector ¶
RemoveSector removes the metadata of a sector and returns its location in the volume.
func (*Store) RemoveVolume ¶
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) RemoveWebhook ¶
RemoveWebhook removes a webhook.
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) RenewV2Contract ¶
func (s *Store) RenewV2Contract(renewal contracts.V2Contract, renewalSet rhp4.TransactionSet, renewedID types.FileContractID, roots []types.Hash256) error
RenewV2Contract adds a new v2 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. The status of the old contract should continue to be active until the renewal is confirmed
func (*Store) ResetChainState ¶
ResetChainState resets the consensus state of the store. This should only occur if the user has reset their consensus database to sync from scratch.
func (*Store) RevertLastAnnouncement ¶
RevertLastAnnouncement reverts the last announcement.
func (*Store) ReviseContract ¶
func (s *Store) ReviseContract(revision contracts.SignedRevision, roots []types.Hash256, usage contracts.Usage, sectorChanges []contracts.SectorChange) error
ReviseContract atomically updates a contract's revision and sectors
func (*Store) ReviseV2Contract ¶
func (s *Store) ReviseV2Contract(id types.FileContractID, revision types.V2FileContract, oldRoots, newRoots []types.Hash256, usage proto4.Usage) error
ReviseV2Contract atomically updates a contract's revision and sectors
func (*Store) SectorLocation ¶
SectorLocation returns the location of a sector or an error if the sector is not found.
func (*Store) SectorReferences ¶
SectorReferences returns the references, if any of a sector root
func (*Store) SectorRoots ¶
SectorRoots returns the sector roots for all contracts.
func (*Store) SetAvailable ¶
SetAvailable sets the available flag on a volume.
func (*Store) SetReadOnly ¶
SetReadOnly sets the read-only flag on a volume.
func (*Store) SetRegistryValue ¶
func (s *Store) SetRegistryValue(entry rhp3.RegistryEntry, expiration uint64) error
SetRegistryValue sets the registry value for the given key.
func (*Store) ShrinkVolume ¶
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 ¶
StorageUsage returns the number of sectors stored and the total number of sectors available in the storage pool.
func (*Store) StoreSector ¶
StoreSector calls fn with an empty location in a writable volume. If the sector root already exists, nil is returned. The sector should be written to disk within fn. If fn returns an error, the metadata is rolled back and the error is returned. If no space is available, ErrNotEnoughStorage is returned.
func (*Store) Tip ¶
func (s *Store) Tip() (index types.ChainIndex, err error)
Tip returns the last scanned chain index.
func (*Store) UnspentSiacoinElements ¶
func (s *Store) UnspentSiacoinElements() (utxos []types.SiacoinElement, err error)
UnspentSiacoinElements returns the spendable siacoin outputs in the wallet.
func (*Store) UpdateChainState ¶
UpdateChainState updates the chain state with the given updates.
func (*Store) UpdateLastAnnouncement ¶
func (s *Store) UpdateLastAnnouncement(ann settings.Announcement) error
UpdateLastAnnouncement updates the last announcement.
func (*Store) UpdatePinnedSettings ¶
UpdatePinnedSettings updates the host's pinned settings.
func (*Store) UpdateSettings ¶
UpdateSettings updates the host's stored settings.
func (*Store) UpdateWebhook ¶
UpdateWebhook updates a webhook.
func (*Store) V2Contract ¶
func (s *Store) V2Contract(id types.FileContractID) (contract contracts.V2Contract, err error)
V2Contract returns the contract with the given ID.
func (*Store) V2ContractElement ¶
func (s *Store) V2ContractElement(contractID types.FileContractID) (basis types.ChainIndex, ele types.V2FileContractElement, err error)
V2ContractElement returns the latest v2 state element with the given ID.
func (*Store) V2Contracts ¶
func (s *Store) V2Contracts(filter contracts.V2ContractFilter) (contracts []contracts.V2Contract, count int, err error)
V2Contracts returns a paginated list of v2 contracts.
func (*Store) V2SectorRoots ¶
V2SectorRoots returns the sector roots for all v2 contracts.
func (*Store) VerifyWalletKey ¶
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) WalletEventCount ¶
WalletEventCount returns the total number of events relevant to the wallet.
func (*Store) WalletEvents ¶
WalletEvents returns a paginated list of transactions ordered by maturity height, descending. If no more transactions are available, (nil, nil) should be returned.