chainlink: github.com/smartcontractkit/chainlink/core/store Index | Files | Directories

package store

import "github.com/smartcontractkit/chainlink/core/store"

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

Config

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

CallerSubscriberClient

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

go-ethereum/rpc/client.go

KeyStore

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

go-ethereum/accounts/keystore/keystore.go

Store

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.

Index

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

Constants

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: https://github.com/ethereum/go-ethereum/issues/3731

Variables

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

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
    Unconfirmed
    // Confirmed means that a transaction has had at least one confirmation, but
    // not enough to satisfy the minimum number of confirmations configuration
    // option
    Confirmed
    // Safe has the required number of confirmations or more
    Safe
)

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 {
    eth.Client
    // 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 *KeyStore, 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

BumpGasByIncrement returns a new gas price increased by the larger of: - A configured percentage bump (ETH_GAS_BUMP_PERCENT) - A configured fixed amount of Wei (ETH_GAS_PRICE_WEI)

func (*EthTxManager) BumpGasUntilSafe Uses

func (txm *EthTxManager) BumpGasUntilSafe(hash common.Hash) (*eth.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) (*eth.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) OnNewHead Uses

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

OnNewHead 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) (string, error)

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

func (txm *EthTxManager) WithdrawLINK(wr models.WithdrawalRequest) (common.Hash, error)

WithdrawLINK withdraws the given amount of LINK from the contract to the configured withdrawal address. If wr.ContractAddress is empty (zero address), funds are withdrawn from configured OracleContractAddress.

type HeadTrackable Uses

type HeadTrackable interface {
    Connect(*models.Head) error
    Disconnect()
    OnNewHead(*models.Head)
}

HeadTrackable represents any object that wishes to respond to ethereum events, after being attached to HeadTracker.

type InMemoryKeyStore Uses

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

type KeyStore Uses

type KeyStore struct {
    *keystore.KeyStore
}

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) 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 ManagedAccount Uses

type ManagedAccount struct {
    accounts.Account
    // 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 Store Uses

type Store struct {
    *orm.ORM
    Config      *orm.Config
    Clock       utils.AfterNower
    KeyStore    *KeyStore
    VRFKeyStore *VRFKeyStore
    TxManager   TxManager
    // 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 NewStoreWithDialer Uses

func NewStoreWithDialer(config *orm.Config, dialer Dialer, shutdownSignal gracefulpanic.Signal) *Store

NewStoreWithDialer creates a new store with the given config and 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 {
    HeadTrackable
    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) (*eth.TxReceipt, AttemptState, error)

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

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

    SignedRawTxWithBumpedGas(originalTx models.Tx, gasLimit uint64, gasPrice big.Int) (string, error)

    eth.Client
}

TxManager represents an interface for interacting with the blockchain

type VRFKeyStore Uses

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

VRFKeyStore tracks auxillary 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.EncryptedSecretKey, 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, seed *big.Int) (
    vrf.MarshaledProof, error)

GenerateProof(k, seed) is marshaled randomness proof given public key k and VRF input seed.

k 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.EncryptedSecretKey, error)

Get retrieves all EncryptedSecretKey'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.EncryptedSecretKey, 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)

ListKey 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.

Directories

PathSynopsis
dbutil
migrations
migrations/migration0
migrations/migration1559081901
migrations/migration1559767166
migrations/migration1560433987
migrations/migration1560791143
migrations/migration1560881846
migrations/migration1560881855
migrations/migration1560886530
migrations/migration1560924400
migrations/migration1564007745
migrations/migration1565139192
migrations/migration1565210496
migrations/migration1565291711
migrations/migration1565877314
migrations/migration1566498796
migrations/migration1566915476
migrations/migration1567029116
migrations/migration1568280052
migrations/migration1568390387
migrations/migration1568833756
migrations/migration1570087128
migrations/migration1570675883
migrations/migration1573667511
migrations/migration1573812490
migrations/migration1574659987
migrations/migration1575036327
migrations/migration1576022702
migrations/migration1579700934
migrations/migration1580904019
migrations/migration1581240419
migrations/migration1584377646
migrations/migration1585918589
modelsPackage models contain the key job components used by the Chainlink application.
models/vrfkeyPackage vrfkey tracks the secret keys associated with VRF proofs.
orm
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). Updated 2020-04-07. Refresh now. Tools for package owners.

The go get command cannot install this package because of the following issues: