store

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2020 License: MIT Imports: 34 Imported by: 12

Documentation

Overview

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

Constants

View Source
const (
	// AutoMigrate is a flag that automatically migrates the DB when passed to initializeORM
	AutoMigrate = "auto_migrate"
)
View Source
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

View Source
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.

View Source
var (
	// ErrPendingConnection is the error returned if TxManager is not connected.
	ErrPendingConnection = errors.New("Cannot talk to chain, pending connection")
)
View Source
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

View Source
var Sha = "unset"

Sha string "unset"

View Source
var Version = "unset"

Version the version of application

Functions

func BumpGas added in v0.8.7

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

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 added in v0.8.11

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

Types

type AttemptState

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

func (a AttemptState) String() string

String conforms to the Stringer interface for AttemptState

type EthTxManager

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

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 added in v0.8.2

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

func (*EthTxManager) BumpGasUntilSafe

func (txm *EthTxManager) BumpGasUntilSafe(hash common.Hash) (*types.Receipt, 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

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

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

func (*EthTxManager) Connect

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

func (txm *EthTxManager) Connected() bool

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

func (*EthTxManager) CreateTx

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

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

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

func (txm *EthTxManager) Disconnect()

Disconnect marks this instance as disconnected.

func (*EthTxManager) GetAvailableAccount added in v0.6.8

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

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

func (*EthTxManager) GetLINKBalance

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

GetLINKBalance returns the balance of LINK at the given address

func (*EthTxManager) NextActiveAccount

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 added in v0.8.5

func (txm *EthTxManager) OnNewLongestChain(ctx context.Context, head models.Head)

OnNewLongestChain does nothing; exists to comply with interface.

func (*EthTxManager) Register

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

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

func (*EthTxManager) SignedRawTxWithBumpedGas added in v0.8.2

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 HeadTrackable

type HeadTrackable interface {
	Connect(head *models.Head) error
	Disconnect()
	OnNewLongestChain(ctx context.Context, head models.Head)
}

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

type InMemoryKeyStore added in v0.8.2

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

type KeyStore

type KeyStore struct {
	*keystore.KeyStore
}

KeyStore manages a key storage directory on disk.

func NewInsecureKeyStore added in v0.8.2

func NewInsecureKeyStore(keyDir string) *KeyStore

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

func NewKeyStore

func NewKeyStore(keyDir string) *KeyStore

NewKeyStore creates a keystore for the given directory.

func (*KeyStore) GetAccountByAddress added in v0.8.7

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

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

GetAccounts returns all accounts

func (*KeyStore) GetFirstAccount

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

func (ks *KeyStore) HasAccounts() bool

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

func (*KeyStore) NewAccount

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

NewAccount adds an account to the keystore

func (*KeyStore) SignHash added in v0.6.10

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

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

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

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

type KeyStoreInterface added in v0.8.4

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)
	Export(a accounts.Account, passphrase, newPassphrase string) ([]byte, error)
	GetAccounts() []accounts.Account
	GetAccountByAddress(common.Address) (accounts.Account, error)

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

type ManagedAccount

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

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

NewManagedAccount creates a managed account that handles nonce increments locally.

func (*ManagedAccount) GetAndIncrementNonce

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

func (a *ManagedAccount) Nonce() uint64

Nonce returns the client side managed nonce.

func (*ManagedAccount) ReloadNonce

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

ReloadNonce fetch and update the current nonce via eth_getTransactionCount

type NotifyNewEthTx added in v0.8.7

type NotifyNewEthTx interface {
	Trigger()
}

NotifyNewEthTx allows to notify the ethBroadcaster of a new transaction

type Store

type Store struct {
	*orm.ORM
	Config         *orm.Config
	Clock          utils.AfterNower
	KeyStore       KeyStoreInterface
	VRFKeyStore    *VRFKeyStore
	TxManager      TxManager
	EthClient      eth.Client
	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 added in v0.8.2

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

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

func NewStore

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

NewStore will create a new store

func (*Store) AuthorizedUserWithSession

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

func (s *Store) Close() error

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

func (*Store) Start

func (s *Store) Start() error

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

func (*Store) SyncDiskKeyStoreToDB

func (s *Store) SyncDiskKeyStoreToDB() error

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

func (*Store) Unscoped

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

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) (*types.Receipt, AttemptState, error)

	BumpGasUntilSafe(hash common.Hash) (*types.Receipt, AttemptState, error)

	GetLINKBalance(address common.Address) (*assets.Link, error)
	NextActiveAccount() *ManagedAccount

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

	eth.Client
}

TxManager represents an interface for interacting with the blockchain

type VRFKeyStore added in v0.8.2

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 added in v0.8.2

func NewVRFKeyStore(store *Store) *VRFKeyStore

NewVRFKeyStore returns an empty VRFKeyStore

func (*VRFKeyStore) CreateKey added in v0.8.2

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 added in v0.8.2

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 added in v0.8.2

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 added in v0.8.2

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

func (*VRFKeyStore) GenerateProof added in v0.8.2

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 added in v0.8.2

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

func (*VRFKeyStore) GetSpecificKey added in v0.8.2

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

func (*VRFKeyStore) Import added in v0.8.2

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 added in v0.8.2

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

ListKeys lists the public keys contained in the db

func (*VRFKeyStore) Store added in v0.8.2

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 added in v0.8.2

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

StoreInMemoryXXXTestingOnly memorizes key, only in in-memory store.

func (*VRFKeyStore) Unlock added in v0.8.2

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

Path Synopsis
Package models contain the key job components used by the Chainlink application.
Package models contain the key job components used by the Chainlink application.
vrfkey
Package vrfkey tracks the secret keys associated with VRF proofs.
Package vrfkey tracks the secret keys associated with VRF proofs.
Package 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 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.

Jump to

Keyboard shortcuts

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