chainlink: Index | Files | Directories

package store

import ""

Package store is used to keep application events in sync between the database on the node and the blockchain.


Config contains the local configuration options that the application will adhere to.


This makes use of Go-Ethereum's functions to interact with the blockchain. The underlying functions can be viewed here:



KeyStore also utilizes Go-Ethereum's functions to store encrypted keys on the local file system. The underlying functions can be viewed here:



The Store is the persistence layer for the application. It saves the the application state and most interaction with the node needs to occur through the store.

Tx Manager

The transaction manager is used to syncronize interactions on the Ethereum blockchain with the application and database.


Package Files

doc.go key_store.go prometheus.go store.go tx_manager.go types.go version.go vrf_key_store.go vrf_key_store_db.go


const (
    // AutoMigrate is a flag that automatically migrates the DB when passed to initializeORM
    AutoMigrate = "auto_migrate"
const EthereumMessageHashPrefix = "\x19Ethereum Signed Message:\n32"

EthereumMessageHashPrefix is a Geth-originating message prefix that seeks to prevent arbitrary message data to be representable as a valid Ethereum transaction For more information, see:


var AttemptToDeleteNonExistentKeyFromDB = errors.New("key is not present in DB")

AttemptToDeleteNonExistentKeyFromDB is returned when Delete is asked to delete a key it can't find in the DB.

var (
    // ErrPendingConnection is the error returned if TxManager is not connected.
    ErrPendingConnection = errors.New("Cannot talk to chain, pending connection")
var MatchingVRFKeyError = errors.New(
    `key with matching public key already stored in DB`)

MatchingVRFKeyError is returned when Import attempts to import key with a PublicKey matching one already in the database

var Sha = "unset"

Sha string "unset"

var Version = "unset"

Version the version of application

func BumpGas Uses

func BumpGas(config orm.ConfigReader, originalGasPrice *big.Int) *big.Int

BumpGas computes the next gas price to attempt as the largest of: - A configured percentage bump (ETH_GAS_BUMP_PERCENT) on top of the baseline price. - A configured fixed amount of Wei (ETH_GAS_PRICE_WEI) on top of the baseline price. The baseline price is the maximum of the previous gas price attempt and the node's current gas price.

func PromUpdateEthBalance Uses

func PromUpdateEthBalance(balance *assets.Eth, from common.Address)

type AttemptState Uses

type AttemptState int

AttemptState enumerates the possible states of a transaction attempt as it gets accepted and confirmed by the blockchain

const (
    // Unknown is returned when the state of a transaction could not be
    // determined because of an error
    Unknown AttemptState = iota
    // Unconfirmed means that a transaction has had no confirmations at all
    // Confirmed means that a transaction has had at least one confirmation, but
    // not enough to satisfy the minimum number of confirmations configuration
    // option
    // Safe has the required number of confirmations or more

func (AttemptState) String Uses

func (a AttemptState) String() string

String conforms to the Stringer interface for AttemptState

type Dialer Uses

type Dialer interface {
    Dial(string) (eth.CallerSubscriber, error)

Dialer implements Dial which is a function that creates a client for that url

type EthDialer Uses

type EthDialer struct {
    // contains filtered or unexported fields

EthDialer is Dialer which accesses rpc urls

func NewEthDialer Uses

func NewEthDialer(rateLimit uint64) *EthDialer

NewEthDialer returns an eth dialer with the specified rate limit

func (*EthDialer) Dial Uses

func (ed *EthDialer) Dial(urlString string) (eth.CallerSubscriber, error)

Dial will dial the given url and return a CallerSubscriber

type EthTxManager Uses

type EthTxManager struct {
    // contains filtered or unexported fields

EthTxManager contains fields for the Ethereum client, the KeyStore, the local Config for the application, and the database.

func NewEthTxManager Uses

func NewEthTxManager(client eth.Client, config orm.ConfigReader, keyStore KeyStoreInterface, orm *orm.ORM) *EthTxManager

NewEthTxManager constructs an EthTxManager using the passed variables and initializing internal variables.

func (*EthTxManager) BumpGasByIncrement Uses

func (txm *EthTxManager) BumpGasByIncrement(originalGasPrice *big.Int) *big.Int

func (*EthTxManager) BumpGasUntilSafe Uses

func (txm *EthTxManager) BumpGasUntilSafe(hash common.Hash) (*models.TxReceipt, AttemptState, error)

BumpGasUntilSafe process a collection of related TxAttempts, trying to get at least one TxAttempt into a safe state, bumping gas if needed

func (*EthTxManager) CheckAttempt Uses

func (txm *EthTxManager) CheckAttempt(txAttempt *models.TxAttempt, blockHeight uint64) (*models.TxReceipt, AttemptState, error)

CheckAttempt retrieves a receipt for a TxAttempt, and check if it meets the minimum number of confirmations

func (*EthTxManager) Connect Uses

func (txm *EthTxManager) Connect(bn *models.Head) error

Connect iterates over the available accounts to retrieve their nonce for client side management.

func (*EthTxManager) Connected Uses

func (txm *EthTxManager) Connected() bool

Connected returns a bool indicating whether or not it is connected.

func (*EthTxManager) ContractLINKBalance Uses

func (txm *EthTxManager) ContractLINKBalance(wr models.WithdrawalRequest) (assets.Link, error)

ContractLINKBalance returns the balance for the contract associated with this withdrawal request, or any errors

func (*EthTxManager) CreateTx Uses

func (txm *EthTxManager) CreateTx(to common.Address, data []byte) (*models.Tx, error)

CreateTx signs and sends a transaction to the Ethereum blockchain.

func (*EthTxManager) CreateTxWithEth Uses

func (txm *EthTxManager) CreateTxWithEth(from, to common.Address, value *assets.Eth) (*models.Tx, error)

CreateTxWithEth signs and sends a transaction with some ETH to transfer.

func (*EthTxManager) CreateTxWithGas Uses

func (txm *EthTxManager) CreateTxWithGas(surrogateID null.String, to common.Address, data []byte, gasPriceWei *big.Int, gasLimit uint64) (*models.Tx, error)

CreateTxWithGas signs and sends a transaction to the Ethereum blockchain.

func (*EthTxManager) Disconnect Uses

func (txm *EthTxManager) Disconnect()

Disconnect marks this instance as disconnected.

func (*EthTxManager) GetAvailableAccount Uses

func (txm *EthTxManager) GetAvailableAccount(from common.Address) *ManagedAccount

GetAvailableAccount retrieves a managed account if it one matches the address given.

func (*EthTxManager) GetLINKBalance Uses

func (txm *EthTxManager) GetLINKBalance(address common.Address) (*assets.Link, error)

GetLINKBalance returns the balance of LINK at the given address

func (*EthTxManager) NextActiveAccount Uses

func (txm *EthTxManager) NextActiveAccount() *ManagedAccount

NextActiveAccount uses round robin to select a managed account from the list of available accounts as defined in Register(...)

func (*EthTxManager) OnNewLongestChain Uses

func (txm *EthTxManager) OnNewLongestChain(head models.Head)

OnNewLongestChain does nothing; exists to comply with interface.

func (*EthTxManager) Register Uses

func (txm *EthTxManager) Register(accts []accounts.Account)

Register activates accounts for outgoing transactions and client side nonce management.

func (*EthTxManager) SignedRawTxWithBumpedGas Uses

func (txm *EthTxManager) SignedRawTxWithBumpedGas(originalTx models.Tx, gasLimit uint64, gasPrice big.Int) ([]byte, error)

SignedRawTxWithBumpedGas takes a transaction and generates a new signed TX from it with the provided params

type GethClientWrapper Uses

type GethClientWrapper interface {
    GethClient(func(gethClient eth.GethClient) error) error
    RPCClient(func(rpcClient eth.RPCClient) error) error

type HeadTrackable Uses

type HeadTrackable interface {
    Connect(*models.Head) error
    OnNewLongestChain(head models.Head)

HeadTrackable represents any object that wishes to respond to ethereum events, after being attached to HeadTracker. go:generate mockery --name HeadTrackable --output ../internal/mocks/ --case=underscore

type InMemoryKeyStore Uses

type InMemoryKeyStore = map[vrfkey.PublicKey]vrfkey.PrivateKey

type KeyStore Uses

type KeyStore struct {

KeyStore manages a key storage directory on disk.

func NewInsecureKeyStore Uses

func NewInsecureKeyStore(keyDir string) *KeyStore

NewInsecureKeyStore creates an *INSECURE* keystore for the given directory. NOTE: Should only be used for testing!

func NewKeyStore Uses

func NewKeyStore(keyDir string) *KeyStore

NewKeyStore creates a keystore for the given directory.

func (*KeyStore) GetAccountByAddress Uses

func (ks *KeyStore) GetAccountByAddress(address common.Address) (accounts.Account, error)

GetAccountByAddress returns the account matching the address provided, or an error if it is missing

func (*KeyStore) GetAccounts Uses

func (ks *KeyStore) GetAccounts() []accounts.Account

GetAccounts returns all accounts

func (*KeyStore) GetFirstAccount Uses

func (ks *KeyStore) GetFirstAccount() (accounts.Account, error)

GetFirstAccount returns the unlocked account in the KeyStore object. The client ensures that an account exists during authentication.

func (*KeyStore) HasAccounts Uses

func (ks *KeyStore) HasAccounts() bool

HasAccounts returns true if there are accounts located at the keystore directory.

func (*KeyStore) NewAccount Uses

func (ks *KeyStore) NewAccount(passphrase string) (accounts.Account, error)

NewAccount adds an account to the keystore

func (*KeyStore) SignHash Uses

func (ks *KeyStore) SignHash(hash common.Hash) (models.Signature, error)

SignHash signs a precomputed digest, using the first account's private key This method adds an ethereum message prefix to the message before signing it, invalidating any would-be valid Ethereum transactions

func (*KeyStore) SignTx Uses

func (ks *KeyStore) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)

SignTx uses the unlocked account to sign the given transaction.

func (*KeyStore) Unlock Uses

func (ks *KeyStore) Unlock(phrase string) error

Unlock uses the given password to try to unlock accounts located in the keystore directory.

type KeyStoreInterface Uses

type KeyStoreInterface interface {
    Accounts() []accounts.Account
    Wallets() []accounts.Wallet
    GetFirstAccount() (accounts.Account, error)
    HasAccounts() bool
    Unlock(phrase string) error
    NewAccount(passphrase string) (accounts.Account, error)
    SignHash(hash common.Hash) (models.Signature, error)
    Import(keyJSON []byte, passphrase, newPassphrase string) (accounts.Account, error)
    GetAccounts() []accounts.Account
    GetAccountByAddress(common.Address) (accounts.Account, error)

    SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)

go:generate mockery --name KeyStoreInterface --output ../internal/mocks/ --case=underscore

type ManagedAccount Uses

type ManagedAccount struct {
    // contains filtered or unexported fields

ManagedAccount holds the account information alongside a client managed nonce to coordinate outgoing transactions.

func NewManagedAccount Uses

func NewManagedAccount(a accounts.Account, nonce uint64) *ManagedAccount

NewManagedAccount creates a managed account that handles nonce increments locally.

func (*ManagedAccount) GetAndIncrementNonce Uses

func (a *ManagedAccount) GetAndIncrementNonce(callback func(uint64) error) error

GetAndIncrementNonce will Yield the current nonce to a callback function and increment it once the callback has finished executing

func (*ManagedAccount) Nonce Uses

func (a *ManagedAccount) Nonce() uint64

Nonce returns the client side managed nonce.

func (*ManagedAccount) ReloadNonce Uses

func (a *ManagedAccount) ReloadNonce(txm *EthTxManager) error

ReloadNonce fetch and update the current nonce via eth_getTransactionCount

type NotifyNewEthTx Uses

type NotifyNewEthTx interface {

NotifyNewEthTx allows to notify the ethBroadcaster of a new transaction go:generate mockery --name NotifyNewEthTx --output ../internal/mocks/ --case=underscore

type Store Uses

type Store struct {
    Config            *orm.Config
    Clock             utils.AfterNower
    KeyStore          KeyStoreInterface
    VRFKeyStore       *VRFKeyStore
    TxManager         TxManager
    GethClientWrapper GethClientWrapper
    NotifyNewEthTx    NotifyNewEthTx
    // contains filtered or unexported fields

Store contains fields for the database, Config, KeyStore, and TxManager for keeping the application state in sync with the database.

func NewInsecureStore Uses

func NewInsecureStore(config *orm.Config, shutdownSignal gracefulpanic.Signal) *Store

NewInsecureStore creates a new store with the given config and dialer, using an insecure keystore. NOTE: Should only be used for testing!

func NewStore Uses

func NewStore(config *orm.Config, shutdownSignal gracefulpanic.Signal) *Store

NewStore will create a new store using the Eth dialer

func (*Store) AuthorizedUserWithSession Uses

func (s *Store) AuthorizedUserWithSession(sessionID string) (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 (*Store) Close Uses

func (s *Store) Close() error

Close shuts down all of the working parts of the store.

func (*Store) Start Uses

func (s *Store) Start() error

Start initiates all of Store's dependencies including the TxManager.

func (*Store) SyncDiskKeyStoreToDB Uses

func (s *Store) SyncDiskKeyStoreToDB() error

SyncDiskKeyStoreToDB writes all keys in the keys directory to the underlying orm.

func (*Store) Unscoped Uses

func (s *Store) Unscoped() *Store

Unscoped returns a shallow copy of the store, with an unscoped ORM allowing one to work with soft deleted records.

type TxManager Uses

type TxManager interface {
    Connected() bool
    Register(accounts []accounts.Account)

    CreateTx(to common.Address, data []byte) (*models.Tx, error)
    CreateTxWithGas(surrogateID null.String, to common.Address, data []byte, gasPriceWei *big.Int, gasLimit uint64) (*models.Tx, error)
    CreateTxWithEth(from, to common.Address, value *assets.Eth) (*models.Tx, error)
    CheckAttempt(txAttempt *models.TxAttempt, blockHeight uint64) (*models.TxReceipt, AttemptState, error)

    BumpGasUntilSafe(hash common.Hash) (*models.TxReceipt, AttemptState, error)

    ContractLINKBalance(wr models.WithdrawalRequest) (assets.Link, error)
    GetLINKBalance(address common.Address) (*assets.Link, error)
    NextActiveAccount() *ManagedAccount

    SignedRawTxWithBumpedGas(originalTx models.Tx, gasLimit uint64, gasPrice big.Int) ([]byte, error)


TxManager represents an interface for interacting with the blockchain

type VRFKeyStore Uses

type VRFKeyStore struct {
    // contains filtered or unexported fields

VRFKeyStore tracks auxiliary VRF secret keys, and generates their VRF proofs

VRF proofs need access to the actual secret key, which geth does not expose. Similar to the way geth's KeyStore exposes signing capability, VRFKeyStore exposes VRF proof generation without the caller needing explicit knowledge of the secret key.

func NewVRFKeyStore Uses

func NewVRFKeyStore(store *Store) *VRFKeyStore

NewVRFKeyStore returns an empty VRFKeyStore

func (*VRFKeyStore) CreateKey Uses

func (ks *VRFKeyStore) CreateKey(phrase string, p ...vrfkey.ScryptParams,
) (vrfkey.PublicKey, error)

CreateKey returns a public key which is immediately unlocked in memory, and saved in DB encrypted with phrase. If p is given, its parameters are used for key derivation from the phrase.

func (*VRFKeyStore) CreateWeakInMemoryEncryptedKeyXXXTestingOnly Uses

func (ks *VRFKeyStore) CreateWeakInMemoryEncryptedKeyXXXTestingOnly(
    phrase string) (*vrfkey.EncryptedVRFKey, error)

CreateWeakInMemoryEncryptedKeyXXXTestingOnly is for testing only! It returns an encrypted key which is fast to unlock, but correspondingly easy to brute force. It is not persisted to the DB, because no one should be keeping such keys lying around.

func (*VRFKeyStore) Delete Uses

func (ks *VRFKeyStore) Delete(key vrfkey.PublicKey) (err error)

Delete removes keys with this public key from the keystore and the DB, if present.

func (*VRFKeyStore) Forget Uses

func (ks *VRFKeyStore) Forget(k vrfkey.PublicKey) error

func (*VRFKeyStore) GenerateProof Uses

func (ks *VRFKeyStore) GenerateProof(k vrfkey.PublicKey, i vrf.PreSeedData) (
    vrf.MarshaledOnChainResponse, error)

GenerateProof is marshaled randomness proof given k and VRF input seed computed from the SeedData

Key must have already been unlocked in ks, as constructing the VRF proof requires the secret key.

func (*VRFKeyStore) Get Uses

func (ks *VRFKeyStore) Get(k ...vrfkey.PublicKey) ([]*vrfkey.EncryptedVRFKey, error)

Get retrieves all EncryptedVRFKey's associated with k, or all encrypted keys if k is nil, or errors

func (*VRFKeyStore) GetSpecificKey Uses

func (ks *VRFKeyStore) GetSpecificKey(
    k vrfkey.PublicKey) (*vrfkey.EncryptedVRFKey, error)

func (*VRFKeyStore) Import Uses

func (ks *VRFKeyStore) Import(keyjson []byte, auth string) error

Import adds this encrypted key to the DB and unlocks it in in-memory store with passphrase auth, and returns any resulting errors

func (*VRFKeyStore) ListKeys Uses

func (ks *VRFKeyStore) ListKeys() (publicKeys []*vrfkey.PublicKey, err error)

ListKeys lists the public keys contained in the db

func (*VRFKeyStore) Store Uses

func (ks *VRFKeyStore) Store(key *vrfkey.PrivateKey, phrase string,
    p ...vrfkey.ScryptParams) error

Store saves key to ks (in memory), and to the DB, encrypted with phrase

func (*VRFKeyStore) StoreInMemoryXXXTestingOnly Uses

func (ks *VRFKeyStore) StoreInMemoryXXXTestingOnly(key *vrfkey.PrivateKey)

StoreInMemoryXXXTestingOnly memorizes key, only in in-memory store.

func (*VRFKeyStore) Unlock Uses

func (ks *VRFKeyStore) Unlock(phrase string) (keysUnlocked []vrfkey.PublicKey,
    merr error)

Unlock tries to unlock each vrf key in the db, using the given pass phrase, and returns any keys it manages to unlock, and any errors which result.


modelsPackage models contain the key job components used by the Chainlink application.
models/vrfkeyPackage vrfkey tracks the secret keys associated with VRF proofs.
presentersPackage presenters allow for the specification and result of a Job, its associated TaskSpecs, and every JobRun and TaskRun to be returned in a user friendly human readable format.

Package store imports 37 packages (graph) and is imported by 9 packages. Updated 2020-08-05. Refresh now. Tools for package owners.