orm

package
v0.10.14 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorNotFound is returned when finding a single value fails.
	ErrorNotFound = gorm.ErrRecordNotFound
	// ErrNoAdvisoryLock is returned when an advisory lock can't be acquired.
	ErrNoAdvisoryLock = errors.New("can't acquire advisory lock")
	// ErrReleaseLockFailed  is returned when releasing the advisory lock fails.
	ErrReleaseLockFailed = errors.New("advisory lock release failed")
	// ErrOptimisticUpdateConflict is returned when a record update failed
	// because another update occurred while the model was in memory and the
	// differences must be reconciled.
	ErrOptimisticUpdateConflict = errors.New("conflict while updating record")
)

Functions

func NewOrmLogWrapper added in v0.10.11

func NewOrmLogWrapper(logger *logger.Logger, logAllQueries bool, slowThreshold time.Duration) *ormLogWrapper

FIXME: This is a GORM log wrapper, not a ORM log wrapper so it probably belongs in a different package

Types

type ConfigReader added in v0.6.6

type ConfigReader interface {
	AllowOrigins() string
	BlockBackfillDepth() uint64
	BridgeResponseURL() *url.URL
	CertFile() string
	ChainID() *big.Int
	ClientNodeURL() string
	CreateProductionLogger() *logger.Logger
	DatabaseMaximumTxDuration() time.Duration
	DatabaseTimeout() models.Duration
	DatabaseURL() url.URL
	DefaultHTTPAllowUnrestrictedNetworkAccess() bool
	DefaultHTTPLimit() int64
	DefaultHTTPTimeout() models.Duration
	DefaultMaxHTTPAttempts() uint
	Dev() bool
	EnableExperimentalAdapters() bool
	EthBalanceMonitorBlockDelay() uint16
	EthFinalityDepth() uint
	EthGasBumpPercent() uint16
	EthGasBumpThreshold() uint64
	EthGasBumpTxDepth() uint16
	EthGasBumpWei() *big.Int
	EthGasLimitDefault() uint64
	EthGasLimitMultiplier() float32
	EthGasPriceDefault() *big.Int
	EthHeadTrackerHistoryDepth() uint
	EthHeadTrackerMaxBufferSize() uint
	EthLogBackfillBatchSize() uint32
	EthMaxGasPriceWei() *big.Int
	EthNonceAutoSync() bool
	EthRPCDefaultBatchSize() uint32
	EthTxReaperInterval() time.Duration
	EthTxReaperThreshold() time.Duration
	EthTxResendAfterThreshold() time.Duration
	EthereumSecondaryURLs() []url.URL
	EthereumURL() string
	ExplorerAccessKey() string
	ExplorerSecret() string
	ExplorerURL() *url.URL
	FeatureExternalInitiators() bool
	FeatureFluxMonitor() bool
	FeatureOffchainReporting() bool
	BlockHistoryEstimatorBlockDelay() uint16
	BlockHistoryEstimatorBlockHistorySize() uint16
	BlockHistoryEstimatorTransactionPercentile() uint16
	InsecureSkipVerify() bool
	JSONConsole() bool
	KeeperDefaultTransactionQueueDepth() uint32
	KeeperRegistryCheckGasOverhead() uint64
	KeeperRegistryPerformGasOverhead() uint64
	KeeperRegistrySyncInterval() time.Duration
	KeeperMinimumRequiredConfirmations() uint64
	KeeperMaximumGracePeriod() int64
	KeyFile() string
	LinkContractAddress() string
	LogLevel() config.LogLevel
	LogSQLStatements() bool
	LogToDisk() bool
	MaximumServiceDuration() models.Duration
	MigrateDatabase() bool
	MinIncomingConfirmations() uint32
	MinRequiredOutgoingConfirmations() uint64
	MinimumContractPayment() *assets.Link
	MinimumRequestExpiration() uint64
	MinimumServiceDuration() models.Duration
	OCRTraceLogging() bool
	OperatorContractAddress() common.Address
	Port() uint16
	ReaperExpiration() models.Duration
	RootDir() string
	SecureCookies() bool
	SessionOptions() sessions.Options
	SessionSecret() ([]byte, error)
	SessionTimeout() models.Duration
	SetEthGasPriceDefault(value *big.Int) error
	TLSCertPath() string
	TLSDir() string
	TLSHost() string
	TLSKeyPath() string
	TLSPort() uint16
	TLSRedirect() bool
	TriggerFallbackDBPollInterval() time.Duration
}

ConfigReader represents just the read side of the config

type Connection added in v0.8.5

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

Connection manages all of the possible database connection setup and config.

func NewConnection added in v0.8.5

func NewConnection(dialect dialects.DialectName, uri string, advisoryLockID int64, lockRetryInterval time.Duration, maxOpenConns, maxIdleConns int) (Connection, error)

NewConnection returns a Connection which holds all of the configuration necessary for managing the database connection.

type LockingStrategy

type LockingStrategy interface {
	Lock(timeout models.Duration) error
	Unlock(timeout models.Duration) error
}

LockingStrategy employs the locking and unlocking of an underlying resource for exclusive access, usually a file or database.

func NewLockingStrategy

func NewLockingStrategy(ct Connection) (LockingStrategy, error)

NewLockingStrategy returns the locking strategy for a particular dialect to ensure exlusive access to the orm.

func NewPostgresLockingStrategy

func NewPostgresLockingStrategy(ct Connection) (LockingStrategy, error)

NewPostgresLockingStrategy returns a new instance of the PostgresLockingStrategy.

type ORM

type ORM struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

ORM contains the database object used by Chainlink.

func NewORM

func NewORM(uri string, timeout models.Duration, shutdownSignal gracefulpanic.Signal, dialect dialects.DialectName, advisoryLockID int64, lockRetryInterval time.Duration, maxOpenConns, maxIdleConns int) (*ORM, error)

NewORM initializes the orm with the configured uri

func (*ORM) AnyJobWithType

func (orm *ORM) AnyJobWithType(taskTypeName string) (bool, error)

AnyJobWithType returns true if there is at least one job associated with the type name specified and false otherwise

func (*ORM) ArchiveJob

func (orm *ORM) ArchiveJob(ID models.JobID) error

ArchiveJob soft deletes the job, job_runs and its initiator. It is idempotent, subsequent runs will do nothing and return no error

func (*ORM) AuthorizedUserWithSession

func (orm *ORM) AuthorizedUserWithSession(sessionID string, sessionDuration time.Duration) (models.User, error)

AuthorizedUserWithSession will return the one API user if the Session ID exists and hasn't expired, and update session's LastUsed field.

func (*ORM) BridgeTypes

func (orm *ORM) BridgeTypes(offset int, limit int) ([]models.BridgeType, int, error)

BridgeTypes returns bridge types ordered by name filtered limited by the passed params.

func (*ORM) ClearNonCurrentSessions

func (orm *ORM) ClearNonCurrentSessions(sessionID string) error

ClearNonCurrentSessions removes all sessions but the id passed in.

func (*ORM) Close

func (orm *ORM) Close() error

Close closes the underlying database connection.

func (*ORM) CountOf added in v0.8.2

func (orm *ORM) CountOf(t interface{}) (int, error)

func (*ORM) CreateBridgeType

func (orm *ORM) CreateBridgeType(bt *models.BridgeType) error

CreateBridgeType saves the bridge type.

func (*ORM) CreateExternalInitiator

func (orm *ORM) CreateExternalInitiator(externalInitiator *models.ExternalInitiator) error

CreateExternalInitiator inserts a new external initiator

func (*ORM) CreateInitiator

func (orm *ORM) CreateInitiator(initr *models.Initiator) error

CreateInitiator saves the initiator.

func (*ORM) CreateJob

func (orm *ORM) CreateJob(job *models.JobSpec) error

CreateJob saves a job to the database and adds IDs to associated tables.

func (*ORM) CreateJobRun

func (orm *ORM) CreateJobRun(run *models.JobRun) error

CreateJobRun inserts a new JobRun

func (*ORM) CreateServiceAgreement

func (orm *ORM) CreateServiceAgreement(sa *models.ServiceAgreement) error

CreateServiceAgreement saves a Service Agreement, its JobSpec and its associations to the database.

func (*ORM) CreateSession

func (orm *ORM) CreateSession(sr models.SessionRequest) (string, error)

CreateSession will check the password in the SessionRequest against the hashed API User password in the db.

func (*ORM) DeleteBridgeType

func (orm *ORM) DeleteBridgeType(bt *models.BridgeType) error

DeleteBridgeType removes the bridge type

func (*ORM) DeleteExternalInitiator

func (orm *ORM) DeleteExternalInitiator(name string) error

DeleteExternalInitiator removes an external initiator

func (*ORM) DeleteFluxMonitorRoundsBackThrough added in v0.8.7

func (orm *ORM) DeleteFluxMonitorRoundsBackThrough(aggregator common.Address, roundID uint32) error

DeleteFluxMonitorRoundsBackThrough deletes all the RoundStat records for a given oracle address starting from the most recent round back through the given round

func (*ORM) DeleteJobSpecError added in v0.8.9

func (orm *ORM) DeleteJobSpecError(ID int64) error

DeleteJobSpecError removes a JobSpecError

func (*ORM) DeleteUser

func (orm *ORM) DeleteUser() error

DeleteUser will delete the API User in the db.

func (*ORM) DeleteUserSession

func (orm *ORM) DeleteUserSession(sessionID string) error

DeleteUserSession will erase the session ID for the sole API User.

func (*ORM) EthTransactionsWithAttempts added in v0.9.6

func (orm *ORM) EthTransactionsWithAttempts(offset, limit int) ([]bulletprooftxmanager.EthTx, int, error)

EthTransactionsWithAttempts returns all eth transactions with at least one attempt limited by passed parameters. Attempts are sorted by created_at.

func (*ORM) EthTxAttempts added in v0.9.6

func (orm *ORM) EthTxAttempts(offset, limit int) ([]bulletprooftxmanager.EthTxAttempt, int, error)

EthTxAttempts returns the last tx attempts sorted by created_at descending.

func (*ORM) ExternalInitiatorsSorted added in v0.10.11

func (orm *ORM) ExternalInitiatorsSorted(offset int, limit int) ([]models.ExternalInitiator, int, error)

ExternalInitiatorsSorted returns many ExternalInitiators sorted by Name from the store adhering to the passed parameters.

func (*ORM) FindBridge

func (orm *ORM) FindBridge(name models.TaskType) (bt models.BridgeType, err error)

FindBridge looks up a Bridge by its Name.

func (*ORM) FindBridgesByNames added in v0.8.2

func (orm *ORM) FindBridgesByNames(names []string) ([]models.BridgeType, error)

FindBridgesByNames finds multiple bridges by their names.

func (*ORM) FindEthTaskRunTxByTaskRunID added in v0.8.7

func (orm *ORM) FindEthTaskRunTxByTaskRunID(taskRunID uuid.UUID) (*bulletprooftxmanager.EthTaskRunTx, error)

FindEthTaskRunTxByTaskRunID finds the EthTaskRunTx with its EthTxes and EthTxAttempts preloaded

func (*ORM) FindEthTxAttempt added in v0.9.6

func (orm *ORM) FindEthTxAttempt(hash common.Hash) (*bulletprooftxmanager.EthTxAttempt, error)

FindEthTxAttempt returns an individual EthTxAttempt

func (*ORM) FindExternalInitiator

func (orm *ORM) FindExternalInitiator(
	eia *auth.Token,
) (*models.ExternalInitiator, error)

FindExternalInitiator finds an external initiator given an authentication request

func (*ORM) FindExternalInitiatorByName added in v0.6.6

func (orm *ORM) FindExternalInitiatorByName(iname string) (exi models.ExternalInitiator, err error)

FindExternalInitiatorByName finds an external initiator given an authentication request

func (*ORM) FindInitiator

func (orm *ORM) FindInitiator(ID int64) (initr models.Initiator, err error)

FindInitiator returns the single initiator defined by the passed ID.

func (*ORM) FindJobIDsWithBridge added in v0.10.3

func (orm *ORM) FindJobIDsWithBridge(bridgeName string) ([]models.JobID, error)

func (*ORM) FindJobRun

func (orm *ORM) FindJobRun(id uuid.UUID) (jr models.JobRun, err error)

FindJobRun looks up a JobRun by its ID.

func (*ORM) FindJobRunIncludingArchived added in v0.10.0

func (orm *ORM) FindJobRunIncludingArchived(id uuid.UUID) (jr models.JobRun, err error)

func (*ORM) FindJobSpec added in v0.9.7

func (orm *ORM) FindJobSpec(id models.JobID) (job models.JobSpec, err error)

FindJob looks up a JobSpec by its ID.

func (*ORM) FindJobSpecError added in v0.8.9

func (orm *ORM) FindJobSpecError(jobID models.JobID, description string) (*models.JobSpecError, error)

FindJobSpecError looks for a JobSpecError record with the given jobID and description

func (*ORM) FindJobSpecUnscoped added in v0.10.0

func (orm *ORM) FindJobSpecUnscoped(id models.JobID) (job models.JobSpec, err error)

func (*ORM) FindJobWithErrors added in v0.8.9

func (orm *ORM) FindJobWithErrors(id models.JobID) (models.JobSpec, error)

FindJobWithErrors looks up a Job by its ID and preloads JobSpecErrors.

func (*ORM) FindLatestNodeVersion added in v0.10.4

func (orm *ORM) FindLatestNodeVersion() (*models.NodeVersion, error)

FindLatestNodeVersion looks up the latest node version

func (*ORM) FindOrCreateFluxMonitorRoundStats added in v0.8.7

func (orm *ORM) FindOrCreateFluxMonitorRoundStats(aggregator common.Address, roundID uint32) (stats models.FluxMonitorRoundStats, err error)

FindOrCreateFluxMonitorRoundStats find the round stats record for a given oracle on a given round, or creates it if no record exists

func (*ORM) FindServiceAgreement

func (orm *ORM) FindServiceAgreement(id string) (sa models.ServiceAgreement, err error)

FindServiceAgreement looks up a ServiceAgreement by its ID.

func (*ORM) FindUser

func (orm *ORM) FindUser() (models.User, error)

FindUser will return the one API user, or an error.

func (*ORM) IdempotentInsertEthTaskRunTx added in v0.8.7

func (orm *ORM) IdempotentInsertEthTaskRunTx(meta models.EthTxMeta, fromAddress common.Address, toAddress common.Address, encodedPayload []byte, gasLimit uint64) error

IdempotentInsertEthTaskRunTx creates both eth_task_run_transaction and eth_tx in one hit It can be called multiple times without error as long as the outcome would have resulted in the same database state

func (*ORM) JobRunsCountFor

func (orm *ORM) JobRunsCountFor(jobSpecID models.JobID) (int, error)

JobRunsCountFor returns the current number of runs for the job

func (*ORM) JobRunsCountForGivenStatus added in v0.10.5

func (orm *ORM) JobRunsCountForGivenStatus(jobSpecID models.JobID, status string) (int, error)

func (*ORM) JobRunsFor

func (orm *ORM) JobRunsFor(jobSpecID models.JobID, limit ...int) ([]models.JobRun, error)

JobRunsFor fetches all JobRuns with a given Job ID, sorted by their created at time.

func (*ORM) JobRunsSorted

func (orm *ORM) JobRunsSorted(sort SortType, offset int, limit int) ([]models.JobRun, int, error)

JobRunsSorted returns job runs ordered and filtered by the passed params.

func (*ORM) JobRunsSortedFor

func (orm *ORM) JobRunsSortedFor(id models.JobID, order SortType, offset int, limit int) ([]models.JobRun, int, int, int, error)

JobRunsSortedFor returns job runs for a specific job spec ordered and filtered by the passed params.

func (*ORM) Jobs

func (orm *ORM) Jobs(cb func(*models.JobSpec) bool, initrTypes ...string) error

Jobs fetches all jobs.

func (*ORM) JobsSorted

func (orm *ORM) JobsSorted(sort SortType, offset int, limit int) ([]models.JobSpec, int, error)

JobsSorted returns many JobSpecs sorted by CreatedAt from the store adhering to the passed parameters.

func (*ORM) LinkEarnedFor added in v0.6.6

func (orm *ORM) LinkEarnedFor(spec *models.JobSpec) (*assets.Link, error)

LinkEarnedFor shows the total link earnings for a job

func (*ORM) MarkRan

func (orm *ORM) MarkRan(i models.Initiator, ran bool) error

MarkRan will set Ran to true for a given initiator

func (*ORM) MostRecentFluxMonitorRoundID added in v0.8.7

func (orm *ORM) MostRecentFluxMonitorRoundID(aggregator common.Address) (uint32, error)

MostRecentFluxMonitorRoundID finds roundID of the most recent round that the provided oracle address submitted to

func (*ORM) MustEnsureAdvisoryLock added in v0.8.2

func (orm *ORM) MustEnsureAdvisoryLock() error

MustEnsureAdvisoryLock sends a shutdown signal to the ORM if it an advisory lock cannot be acquired.

func (*ORM) MustSQLDB added in v0.10.0

func (orm *ORM) MustSQLDB() *sql.DB

func (*ORM) PendingBridgeType

func (orm *ORM) PendingBridgeType(jr models.JobRun) (bt models.BridgeType, err error)

PendingBridgeType returns the bridge type of the current pending task, or error if not pending bridge.

func (*ORM) RawDBWithAdvisoryLock added in v0.10.3

func (orm *ORM) RawDBWithAdvisoryLock(fn func(*gorm.DB) error) error

func (*ORM) RemoveUnstartedTransactions added in v0.9.3

func (orm *ORM) RemoveUnstartedTransactions() error

func (*ORM) SaveJobRun

func (orm *ORM) SaveJobRun(run *models.JobRun) error

SaveJobRun updates UpdatedAt for a JobRun and updates its status, finished at and run results. It auto-inserts run results if none are existing already for the given jobrun/taskruns.

func (*ORM) SaveUser

func (orm *ORM) SaveUser(user *models.User) error

SaveUser saves the user.

func (*ORM) SetLogging added in v0.6.1

func (orm *ORM) SetLogging(enabled bool)

SetLogging turns on SQL statement logging

func (*ORM) Transaction added in v0.8.7

func (orm *ORM) Transaction(fc func(tx *gorm.DB) error) (err error)

func (*ORM) Unscoped

func (orm *ORM) Unscoped() *ORM

Unscoped returns a new instance of this ORM that includes soft deleted items.

func (*ORM) UnscopedJobRunsWithStatus

func (orm *ORM) UnscopedJobRunsWithStatus(cb func(*models.JobRun), statuses ...models.RunStatus) error

UnscopedJobRunsWithStatus passes all JobRuns to a callback, one by one, including those that were soft deleted.

func (*ORM) UpdateBridgeType

func (orm *ORM) UpdateBridgeType(bt *models.BridgeType, btr *models.BridgeTypeRequest) error

UpdateBridgeType updates the bridge type.

func (*ORM) UpdateFluxMonitorRoundStats added in v0.8.13

func (orm *ORM) UpdateFluxMonitorRoundStats(aggregator common.Address, roundID uint32, jobRunID uuid.UUID) error

UpdateFluxMonitorRoundStats trys to create a RoundStat record for the given oracle at the given round. If one already exists, it increments the num_submissions column.

func (*ORM) UpsertErrorFor added in v0.8.9

func (orm *ORM) UpsertErrorFor(jobID models.JobID, description string)

UpsertErrorFor upserts a JobSpecError record, incrementing the occurrences counter by 1 if the record is found

func (*ORM) UpsertNodeVersion added in v0.10.4

func (orm *ORM) UpsertNodeVersion(version models.NodeVersion) error

UpsertNodeVersion inserts a new NodeVersion

type PostgresLockingStrategy

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

PostgresLockingStrategy uses a postgres advisory lock to ensure exclusive access.

func (*PostgresLockingStrategy) Lock

func (s *PostgresLockingStrategy) Lock(timeout models.Duration) error

Lock uses a blocking postgres advisory lock that times out at the passed timeout.

func (*PostgresLockingStrategy) Unlock

func (s *PostgresLockingStrategy) Unlock(timeout models.Duration) error

Unlock unlocks the locked postgres advisory lock.

type SortType

type SortType int

SortType defines the different sort orders available.

const (
	// Ascending is the sort order going up, i.e. 1,2,3.
	Ascending SortType = iota
	// Descending is the sort order going down, i.e. 3,2,1.
	Descending
)

func (SortType) String

func (s SortType) String() string

Jump to

Keyboard shortcuts

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