bulletprooftxmanager

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EthTxUnstarted               = EthTxState("unstarted")
	EthTxInProgress              = EthTxState("in_progress")
	EthTxFatalError              = EthTxState("fatal_error")
	EthTxUnconfirmed             = EthTxState("unconfirmed")
	EthTxConfirmed               = EthTxState("confirmed")
	EthTxConfirmedMissingReceipt = EthTxState("confirmed_missing_receipt")

	EthTxAttemptInProgress      = EthTxAttemptState("in_progress")
	EthTxAttemptInsufficientEth = EthTxAttemptState("insufficient_eth")
	EthTxAttemptBroadcast       = EthTxAttemptState("broadcast")
)
View Source
const InFlightTransactionRecheckInterval = 1 * time.Second

InFlightTransactionRecheckInterval controls how often the EthBroadcaster will poll the unconfirmed queue to see if it is allowed to send another transaction

View Source
const SimulationTimeout = 2 * time.Second

SimulationTimeout must be short since simulation adds latency to broadcasting a tx which can negatively affect response time

Variables

View Source
var (
	// ErrCouldNotGetReceipt is the error string we save if we reach our finality depth for a confirmed transaction without ever getting a receipt
	// This most likely happened because an external wallet used the account for this nonce
	ErrCouldNotGetReceipt = "could not get receipt"
)
View Source
var Max256BitUInt = big.NewInt(0).Exp(big.NewInt(2), big.NewInt(256), nil)

Functions

func CheckEthTxQueueCapacity added in v0.10.8

func CheckEthTxQueueCapacity(q pg.Queryer, fromAddress common.Address, maxQueuedTransactions uint64, chainID big.Int) (err error)

CheckEthTxQueueCapacity returns an error if inserting this transaction would exceed the maximum queue size.

func CountUnconfirmedTransactions added in v0.10.8

func CountUnconfirmedTransactions(q pg.Q, fromAddress common.Address, chainID big.Int) (count uint32, err error)

CountUnconfirmedTransactions returns the number of unconfirmed transactions

func CountUnstartedTransactions added in v0.10.11

func CountUnstartedTransactions(q pg.Q, fromAddress common.Address, chainID big.Int) (count uint32, err error)

CountUnstartedTransactions returns the number of unconfirmed transactions

func GetNextNonce

func GetNextNonce(q pg.Q, address gethCommon.Address, chainID *big.Int) (nonce int64, err error)

GetNextNonce returns keys.next_nonce for the given address

func IncrementNextNonce

func IncrementNextNonce(q pg.Queryer, address gethCommon.Address, chainID *big.Int, currentNonce int64) error

IncrementNextNonce increments keys.next_nonce by 1

Types

type BulletproofTxManager added in v0.10.8

type BulletproofTxManager struct {
	utils.StartStopOnce
	// contains filtered or unexported fields
}

func NewBulletproofTxManager added in v0.10.8

func NewBulletproofTxManager(db *sqlx.DB, ethClient eth.Client, config Config, keyStore KeyStore, eventBroadcaster pg.EventBroadcaster, lggr logger.Logger) *BulletproofTxManager

func (*BulletproofTxManager) Close added in v0.10.8

func (b *BulletproofTxManager) Close() (merr error)

func (*BulletproofTxManager) CreateEthTransaction added in v0.10.8

func (b *BulletproofTxManager) CreateEthTransaction(newTx NewTx, qs ...pg.QOpt) (etx EthTx, err error)

CreateEthTransaction inserts a new transaction

func (*BulletproofTxManager) GetGasEstimator added in v0.10.10

func (b *BulletproofTxManager) GetGasEstimator() gas.Estimator

GetGasEstimator returns the gas estimator, mostly useful for tests

func (*BulletproofTxManager) OnNewLongestChain added in v0.10.8

func (b *BulletproofTxManager) OnNewLongestChain(ctx context.Context, head *eth.Head)

OnNewLongestChain conforms to HeadTrackable

func (*BulletproofTxManager) RegisterResumeCallback added in v1.0.0

func (b *BulletproofTxManager) RegisterResumeCallback(fn ResumeCallback)

func (*BulletproofTxManager) Start added in v0.10.8

func (b *BulletproofTxManager) Start() (merr error)

func (*BulletproofTxManager) Trigger added in v0.10.8

func (b *BulletproofTxManager) Trigger(addr common.Address)

Trigger forces the EthBroadcaster to check early for the given address

type ChainKeyStore added in v1.1.0

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

func NewChainKeyStore added in v1.1.0

func NewChainKeyStore(chainID big.Int, config Config, keystore KeyStore) ChainKeyStore

func (*ChainKeyStore) NewDynamicFeeAttempt added in v1.1.0

func (c *ChainKeyStore) NewDynamicFeeAttempt(etx EthTx, fee gas.DynamicFee, gasLimit uint64) (attempt EthTxAttempt, err error)

func (*ChainKeyStore) NewLegacyAttempt added in v1.1.0

func (c *ChainKeyStore) NewLegacyAttempt(etx EthTx, gasPrice *big.Int, gasLimit uint64) (attempt EthTxAttempt, err error)

func (*ChainKeyStore) SignTx added in v1.1.0

func (c *ChainKeyStore) SignTx(address common.Address, tx *gethTypes.Transaction) (common.Hash, []byte, error)

type Config added in v0.10.8

type Config interface {
	gas.Config
	EthTxReaperInterval() time.Duration
	EthTxReaperThreshold() time.Duration
	EthTxResendAfterThreshold() time.Duration
	EvmGasBumpThreshold() uint64
	EvmGasBumpTxDepth() uint16
	EvmGasLimitDefault() uint64
	EvmMaxInFlightTransactions() uint32
	EvmMaxQueuedTransactions() uint64
	EvmNonceAutoSync() bool
	EvmRPCDefaultBatchSize() uint32
	KeySpecificMaxGasPriceWei(addr common.Address) *big.Int
	TriggerFallbackDBPollInterval() time.Duration
	LogSQL() bool
}

Config encompasses config used by bulletprooftxmanager package Unless otherwise specified, these should support changing at runtime

type DropOldestStrategy added in v0.10.9

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

DropOldestStrategy will send the newest N transactions, older ones will be removed from the queue

func NewDropOldestStrategy added in v0.10.9

func NewDropOldestStrategy(subject uuid.UUID, queueSize uint32, simulate bool) DropOldestStrategy

func (DropOldestStrategy) PruneQueue added in v0.10.9

func (s DropOldestStrategy) PruneQueue(q pg.Queryer) (n int64, err error)

func (DropOldestStrategy) Simulate added in v1.1.0

func (s DropOldestStrategy) Simulate() bool

func (DropOldestStrategy) Subject added in v0.10.9

func (s DropOldestStrategy) Subject() uuid.NullUUID

type EthBroadcaster

type EthBroadcaster struct {
	ChainKeyStore

	utils.StartStopOnce
	// contains filtered or unexported fields
}

EthBroadcaster monitors eth_txes for transactions that need to be broadcast, assigns nonces and ensures that at least one eth node somewhere has received the transaction successfully.

This does not guarantee delivery! A whole host of other things can subsequently go wrong such as transactions being evicted from the mempool, eth nodes going offline etc. Responsibility for ensuring eventual inclusion into the chain falls on the shoulders of the ethConfirmer.

What EthBroadcaster does guarantee is: - a monotonic series of increasing nonces for eth_txes that can all eventually be confirmed if you retry enough times - transition of eth_txes out of unstarted into either fatal_error or unconfirmed - existence of a saved eth_tx_attempt

func NewEthBroadcaster

func NewEthBroadcaster(db *sqlx.DB, ethClient eth.Client, config Config, keystore KeyStore,
	eventBroadcaster pg.EventBroadcaster,
	keyStates []ethkey.State, estimator gas.Estimator, resumeCallback ResumeCallback,
	logger logger.Logger) *EthBroadcaster

NewEthBroadcaster returns a new concrete EthBroadcaster

func (*EthBroadcaster) Close added in v0.10.3

func (eb *EthBroadcaster) Close() error

func (*EthBroadcaster) ProcessUnstartedEthTxs

func (eb *EthBroadcaster) ProcessUnstartedEthTxs(ctx context.Context, keyState ethkey.State) error

func (*EthBroadcaster) Start

func (eb *EthBroadcaster) Start() error

func (*EthBroadcaster) Trigger

func (eb *EthBroadcaster) Trigger(addr gethCommon.Address)

Trigger forces the monitor for a particular address to recheck for new eth_txes Logs error and does nothing if address was not registered on startup

type EthConfirmer

type EthConfirmer struct {
	utils.StartStopOnce

	ChainKeyStore
	// contains filtered or unexported fields
}

EthConfirmer is a broad service which performs four different tasks in sequence on every new longest chain Step 1: Mark that all currently pending transaction attempts were broadcast before this block Step 2: Check pending transactions for receipts Step 3: See if any transactions have exceeded the gas bumping block threshold and, if so, bump them Step 4: Check confirmed transactions to make sure they are still in the longest chain (reorg protection)

func NewEthConfirmer

func NewEthConfirmer(db *sqlx.DB, ethClient eth.Client, config Config, keystore KeyStore,
	keyStates []ethkey.State, estimator gas.Estimator, resumeCallback ResumeCallback, lggr logger.Logger) *EthConfirmer

NewEthConfirmer instantiates a new eth confirmer

func (*EthConfirmer) CheckForReceipts added in v0.10.8

func (ec *EthConfirmer) CheckForReceipts(ctx context.Context, blockNum int64) error

CheckForReceipts finds attempts that are still pending and checks to see if a receipt is present for the given block number

func (*EthConfirmer) Close added in v0.10.8

func (ec *EthConfirmer) Close() error

Close is a comment to appease the linter

func (*EthConfirmer) EnsureConfirmedTransactionsInLongestChain added in v0.10.8

func (ec *EthConfirmer) EnsureConfirmedTransactionsInLongestChain(ctx context.Context, head *eth.Head) error

EnsureConfirmedTransactionsInLongestChain finds all confirmed eth_txes up to the depth of the given chain and ensures that every one has a receipt with a block hash that is in the given chain.

If any of the confirmed transactions does not have a receipt in the chain, it has been re-org'd out and will be rebroadcast.

func (*EthConfirmer) ForceRebroadcast added in v0.10.8

func (ec *EthConfirmer) ForceRebroadcast(beginningNonce uint, endingNonce uint, gasPriceWei uint64, address gethCommon.Address, overrideGasLimit uint64) error

ForceRebroadcast sends a transaction for every nonce in the given nonce range at the given gas price. If an eth_tx exists for this nonce, we re-send the existing eth_tx with the supplied parameters. If an eth_tx doesn't exist for this nonce, we send a zero transaction. This operates completely orthogonal to the normal EthConfirmer and can result in untracked attempts! Only for emergency usage. This is in case of some unforeseen scenario where the node is refusing to release the lock. KISS.

func (*EthConfirmer) ProcessHead added in v0.10.8

func (ec *EthConfirmer) ProcessHead(ctx context.Context, head *eth.Head) error

ProcessHead takes all required transactions for the confirmer on a new head

func (*EthConfirmer) RebroadcastWhereNecessary added in v0.10.8

func (ec *EthConfirmer) RebroadcastWhereNecessary(ctx context.Context, blockHeight int64) error

RebroadcastWhereNecessary bumps gas or resends transactions that were previously out-of-eth

func (*EthConfirmer) ResumePendingTaskRuns added in v1.0.0

func (ec *EthConfirmer) ResumePendingTaskRuns(ctx context.Context, head *eth.Head) error

ResumePendingTaskRuns issues callbacks to task runs that are pending waiting for receipts

func (*EthConfirmer) SetBroadcastBeforeBlockNum added in v0.10.8

func (ec *EthConfirmer) SetBroadcastBeforeBlockNum(blockNum int64) error

SetBroadcastBeforeBlockNum updates already broadcast attempts with the current block number. This is safe no matter how old the head is because if the attempt is already broadcast it _must_ have been before this head.

func (*EthConfirmer) Start added in v0.10.8

func (ec *EthConfirmer) Start() error

Start is a comment to appease the linter

type EthReceipt added in v0.10.10

type EthReceipt struct {
	ID               int64
	TxHash           common.Hash
	BlockHash        common.Hash
	BlockNumber      int64
	TransactionIndex uint
	Receipt          []byte
	CreatedAt        time.Time
}

type EthResender added in v0.10.4

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

EthResender periodically picks up transactions that have been languishing unconfirmed for a configured amount of time without being sent, and sends their highest priced attempt again. This helps to defend against geth/parity silently dropping txes, or txes being ejected from the mempool.

Previously we relied on the bumper to do this for us implicitly but there can occasionally be problems with this (e.g. abnormally long block times, or if gas bumping is disabled)

func NewEthResender added in v0.10.4

func NewEthResender(lggr logger.Logger, db *sqlx.DB, ethClient eth.Client, pollInterval time.Duration, config Config) *EthResender

NewEthResender creates a new concrete EthResender

func (*EthResender) Start added in v0.10.4

func (er *EthResender) Start()

Start is a comment which satisfies the linter

func (*EthResender) Stop added in v0.10.4

func (er *EthResender) Stop()

Stop is a comment which satisfies the linter

type EthTx added in v0.10.10

type EthTx struct {
	ID             int64
	Nonce          *int64
	FromAddress    common.Address
	ToAddress      common.Address
	EncodedPayload []byte
	Value          assets.Eth
	// GasLimit on the EthTx is always the conceptual gas limit, which is not
	// necessarily the same as the on-chain encoded value (i.e. Optimism)
	GasLimit uint64
	Error    null.String
	// BroadcastAt is updated every time an attempt for this eth_tx is re-sent
	// In almost all cases it will be within a second or so of the actual send time.
	BroadcastAt   *time.Time
	CreatedAt     time.Time
	State         EthTxState
	EthTxAttempts []EthTxAttempt `json:"-"`
	// Marshalled EthTxMeta
	// Used for additional context around transactions which you want to log
	// at send time.
	Meta       *datatypes.JSON
	Subject    uuid.NullUUID
	EVMChainID utils.Big

	PipelineTaskRunID uuid.NullUUID
	MinConfirmations  cnull.Uint32

	// AccessList is optional and only has an effect on DynamicFee transactions
	// on chains that support it (e.g. Ethereum Mainnet after London hard fork)
	AccessList NullableEIP2930AccessList

	// Simulate if set to true will cause this eth_tx to be simulated before
	// initial send and aborted on revert
	Simulate bool
}

func FindEthTxsRequiringGasBump added in v0.10.0

func FindEthTxsRequiringGasBump(ctx context.Context, q pg.Q, lggr logger.Logger, address gethCommon.Address, blockNum, gasBumpThreshold, depth int64, chainID big.Int) (etxs []*EthTx, err error)

FindEthTxsRequiringGasBump returns transactions that have all attempts which are unconfirmed for at least gasBumpThreshold blocks, limited by limit pending transactions

It also returns eth_txes that are unconfirmed with no eth_tx_attempts

func FindEthTxsRequiringRebroadcast added in v0.10.0

func FindEthTxsRequiringRebroadcast(ctx context.Context, q pg.Q, lggr logger.Logger, address gethCommon.Address, blockNum, gasBumpThreshold, bumpDepth int64, maxInFlightTransactions uint32, chainID big.Int) (etxs []*EthTx, err error)

FindEthTxsRequiringRebroadcast returns attempts that hit insufficient eth, and attempts that need bumping, in nonce ASC order

func FindEthTxsRequiringResubmissionDueToInsufficientEth added in v0.10.0

func FindEthTxsRequiringResubmissionDueToInsufficientEth(ctx context.Context, q pg.Q, lggr logger.Logger, address gethCommon.Address, chainID big.Int) (etxs []*EthTx, err error)

FindEthTxsRequiringResubmissionDueToInsufficientEth returns transactions that need to be re-sent because they hit an out-of-eth error on a previous block

func SendEther added in v0.8.8

func SendEther(q pg.Q, chainID *big.Int, from, to common.Address, value assets.Eth, gasLimit uint64) (etx EthTx, err error)

SendEther creates a transaction that transfers the given value of ether TODO: Make this a method on the bulletprooftxmanager

func (EthTx) GetError added in v0.10.10

func (e EthTx) GetError() error

func (EthTx) GetID added in v0.10.10

func (e EthTx) GetID() string

GetID allows EthTx to be used as jsonapi.MarshalIdentifier

type EthTxAttempt added in v0.10.10

type EthTxAttempt struct {
	ID      int64
	EthTxID int64
	EthTx   EthTx
	// GasPrice applies to LegacyTx
	GasPrice *utils.Big
	// GasTipCap and GasFeeCap are used instead for DynamicFeeTx
	GasTipCap *utils.Big
	GasFeeCap *utils.Big
	// ChainSpecificGasLimit on the EthTxAttempt is always the same as the on-chain encoded value for gas limit
	ChainSpecificGasLimit   uint64
	SignedRawTx             []byte
	Hash                    common.Hash
	CreatedAt               time.Time
	BroadcastBeforeBlockNum *int64
	State                   EthTxAttemptState
	EthReceipts             []EthReceipt `json:"-"`
	TxType                  int
}

func FindEthTxesRequiringResend added in v0.10.4

func FindEthTxesRequiringResend(db *sqlx.DB, olderThan time.Time, maxInFlightTransactions uint32, chainID big.Int) (attempts []EthTxAttempt, err error)

FindEthTxesRequiringResend returns the highest priced attempt for each eth_tx that was last sent before or at the given time (up to limit)

func (EthTxAttempt) DynamicFee added in v1.1.0

func (a EthTxAttempt) DynamicFee() gas.DynamicFee

func (EthTxAttempt) GetSignedTx added in v0.10.10

func (a EthTxAttempt) GetSignedTx() (*types.Transaction, error)

GetSignedTx decodes the SignedRawTx into a types.Transaction struct

type EthTxAttemptState added in v0.10.10

type EthTxAttemptState string

type EthTxMeta added in v1.0.0

type EthTxMeta struct {
	JobID         int32
	RequestID     common.Hash
	RequestTxHash common.Hash
	// Used for the VRFv2 - max link this tx will bill
	// should it get bumped
	MaxLink string
	// Used for the VRFv2 - the subscription ID of the
	// requester of the VRF.
	SubID uint64 `json:"SubId"`
}

type EthTxState added in v0.10.10

type EthTxState string

type KeyStore added in v0.10.8

type KeyStore interface {
	GetStatesForChain(chainID *big.Int) ([]ethkey.State, error)
	SignTx(fromAddress common.Address, tx *gethTypes.Transaction, chainID *big.Int) (*gethTypes.Transaction, error)
	SubscribeToKeyChanges() (ch chan struct{}, unsub func())
}

KeyStore encompasses the subset of keystore used by bulletprooftxmanager

type Log added in v0.10.0

type Log struct {
	Address     common.Address `json:"address"`
	Topics      []common.Hash  `json:"topics"`
	Data        []byte         `json:"data"`
	BlockNumber uint64         `json:"blockNumber"`
	TxHash      common.Hash    `json:"transactionHash"`
	TxIndex     uint           `json:"transactionIndex"`
	BlockHash   common.Hash    `json:"blockHash"`
	Index       uint           `json:"logIndex"`
	Removed     bool           `json:"removed"`
}

Log represents a contract log event.

Copied from go-ethereum: https://github.com/ethereum/go-ethereum/blob/ce9a289fa48e0d2593c4aaa7e207c8a5dd3eaa8a/core/types/log.go

We use our own version because Geth's version specifies various gencodec:"required" fields which cause unhelpful errors when unmarshalling from an empty JSON object which can happen in the batch fetcher.

func FromGethLog added in v0.10.0

func FromGethLog(gl *gethTypes.Log) *Log

FromGethLog converts a gethTypes.Log to a Log

func (Log) MarshalJSON added in v0.10.0

func (l Log) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Log) UnmarshalJSON added in v0.10.0

func (l *Log) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type NSinserttx added in v0.10.4

type NSinserttx struct {
	Etx     EthTx
	Attempt EthTxAttempt
}

NSinserttx represents an EthTx and Attempt to be inserted together

type NewTx added in v1.0.0

type NewTx struct {
	FromAddress    common.Address
	ToAddress      common.Address
	EncodedPayload []byte
	GasLimit       uint64
	Meta           *EthTxMeta

	MinConfirmations  null.Uint32
	PipelineTaskRunID *uuid.UUID

	Strategy TxStrategy
}

type NonceSyncer added in v0.10.4

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

NonceSyncer manages the delicate task of syncing the local nonce with the chain nonce in case of divergence.

On startup, we check each key for the nonce value on chain and compare it to our local value.

Usually the on-chain nonce will be the same as (or lower than) the next_nonce in the DB, in which case we do nothing.

If we are restoring from a backup however, or another wallet has used the account, the chain nonce might be higher than our local one. In this scenario, we must fastforward the local nonce to match the chain nonce.

The problem with doing this is that now Chainlink does not have any ownership or control over potentially pending transactions with nonces between our local highest nonce and the chain nonce. If one of those transactions is pushed out of the mempool or re-org'd out of the chain, we run the risk of being stuck with a gap in the nonce sequence that will never be filled.

The solution is to query the chain for our own transactions and take ownership of them by writing them to the database and letting the EthConfirmer handle them as it would any other transaction.

This is not quite as straightforward as one might expect. We cannot query transactions from our account to infinite depth (geth does not support this). The best we can do is to query for all transactions sent within the past ETH_FINALITY_DEPTH blocks and find the ones sent by our address(es).

This gives us re-org protection up to ETH_FINALITY_DEPTH deep in the worst case, which is in line with our other guarantees.

func NewNonceSyncer added in v0.10.4

func NewNonceSyncer(db *sqlx.DB, lggr logger.Logger, cfg pg.LogConfig, ethClient eth.Client) *NonceSyncer

NewNonceSyncer returns a new syncer

func (NonceSyncer) SyncAll added in v0.10.4

func (s NonceSyncer) SyncAll(ctx context.Context, keyStates []ethkey.State) (merr error)

SyncAll syncs nonces for all keys in parallel

This should only be called once, before the EthBroadcaster has started. Calling it later is not safe and could lead to races.

type NullTxManager added in v0.10.8

type NullTxManager struct {
	ErrMsg string
}

func (*NullTxManager) Close added in v0.10.8

func (n *NullTxManager) Close() error

func (*NullTxManager) CreateEthTransaction added in v0.10.8

func (n *NullTxManager) CreateEthTransaction(NewTx, ...pg.QOpt) (etx EthTx, err error)

func (*NullTxManager) GetGasEstimator added in v0.10.10

func (n *NullTxManager) GetGasEstimator() gas.Estimator

func (*NullTxManager) Healthy added in v0.10.8

func (n *NullTxManager) Healthy() error

func (*NullTxManager) OnNewLongestChain added in v0.10.8

func (n *NullTxManager) OnNewLongestChain(context.Context, *eth.Head)

func (*NullTxManager) Ready added in v0.10.8

func (n *NullTxManager) Ready() error

func (*NullTxManager) RegisterResumeCallback added in v1.0.0

func (n *NullTxManager) RegisterResumeCallback(fn ResumeCallback)

func (*NullTxManager) Start added in v0.10.8

func (n *NullTxManager) Start() error

func (*NullTxManager) Trigger added in v0.10.8

func (n *NullTxManager) Trigger(common.Address)

type NullableEIP2930AccessList added in v1.1.0

type NullableEIP2930AccessList struct {
	AccessList types.AccessList
	Valid      bool
}

func NullableEIP2930AccessListFrom added in v1.1.0

func NullableEIP2930AccessListFrom(al types.AccessList) (n NullableEIP2930AccessList)

func (NullableEIP2930AccessList) MarshalJSON added in v1.1.0

func (e NullableEIP2930AccessList) MarshalJSON() ([]byte, error)

func (*NullableEIP2930AccessList) Scan added in v1.1.0

func (e *NullableEIP2930AccessList) Scan(value interface{}) error

Scan returns the selector from its serialization in the database

func (*NullableEIP2930AccessList) UnmarshalJSON added in v1.1.0

func (e *NullableEIP2930AccessList) UnmarshalJSON(input []byte) error

func (NullableEIP2930AccessList) Value added in v1.1.0

Value returns this instance serialized for database storage

type ORM added in v1.1.0

type ORM interface {
	EthTransactionsWithAttempts(offset, limit int) ([]EthTx, int, error)
	EthTxAttempts(offset, limit int) ([]EthTxAttempt, int, error)
	FindEthTxAttempt(hash common.Hash) (*EthTxAttempt, error)
	InsertEthTxAttempt(attempt *EthTxAttempt) error
	InsertEthTx(etx *EthTx) error
	InsertEthReceipt(receipt *EthReceipt) error
	FindEthTxWithAttempts(etxID int64) (etx EthTx, err error)
}

func NewORM added in v1.1.0

func NewORM(db *sqlx.DB, lggr logger.Logger, cfg pg.LogConfig) ORM

type Reaper added in v0.10.7

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

Reaper handles periodic database cleanup for BPTXM

func NewReaper added in v0.10.7

func NewReaper(lggr logger.Logger, db *sqlx.DB, config ReaperConfig, chainID big.Int) *Reaper

NewReaper instantiates a new reaper object

func (*Reaper) ReapEthTxes added in v0.10.7

func (r *Reaper) ReapEthTxes(headNum int64) error

ReapEthTxes deletes old eth_txes

func (*Reaper) SetLatestBlockNum added in v0.10.7

func (r *Reaper) SetLatestBlockNum(latestBlockNum int64)

SetLatestBlockNum should be called on every new highest block number

func (*Reaper) Start added in v0.10.7

func (r *Reaper) Start()

Start the reaper. Should only be called once.

func (*Reaper) Stop added in v0.10.7

func (r *Reaper) Stop()

Stop the reaper. Should only be called once.

type ReaperConfig added in v0.10.7

type ReaperConfig interface {
	EthTxReaperInterval() time.Duration
	EthTxReaperThreshold() time.Duration
	EvmFinalityDepth() uint32
}

ReaperConfig is the config subset used by the reaper

type Receipt added in v0.10.0

type Receipt struct {
	PostState         []byte          `json:"root"`
	Status            uint64          `json:"status"`
	CumulativeGasUsed uint64          `json:"cumulativeGasUsed"`
	Bloom             gethTypes.Bloom `json:"logsBloom"`
	Logs              []*Log          `json:"logs"`
	TxHash            common.Hash     `json:"transactionHash"`
	ContractAddress   common.Address  `json:"contractAddress"`
	GasUsed           uint64          `json:"gasUsed"`
	BlockHash         common.Hash     `json:"blockHash,omitempty"`
	BlockNumber       *big.Int        `json:"blockNumber,omitempty"`
	TransactionIndex  uint            `json:"transactionIndex"`
}

Receipt represents an ethereum receipt.

Copied from go-ethereum: https://github.com/ethereum/go-ethereum/blob/ce9a289fa48e0d2593c4aaa7e207c8a5dd3eaa8a/core/types/receipt.go#L50

We use our own version because Geth's version specifies various gencodec:"required" fields which cause unhelpful errors when unmarshalling from an empty JSON object which can happen in the batch fetcher.

func FromGethReceipt added in v0.10.0

func FromGethReceipt(gr *gethTypes.Receipt) *Receipt

FromGethReceipt converts a gethTypes.Receipt to a Receipt

func (Receipt) IsUnmined added in v0.10.0

func (r Receipt) IsUnmined() bool

IsUnmined returns true if the receipt is for a TX that has not been mined yet. Supposedly according to the spec this should never happen, but Parity does it anyway.

func (Receipt) IsZero added in v0.10.0

func (r Receipt) IsZero() bool

IsZero returns true if receipt is the zero receipt Batch calls to the RPC will return a pointer to an empty Receipt struct Easiest way to check if the receipt was missing is to see if the hash is 0x0 Real receipts will always have the TxHash set

func (Receipt) MarshalJSON added in v0.10.0

func (r Receipt) MarshalJSON() ([]byte, error)

MarshalJSON marshals Receipt as JSON. Copied from: https://github.com/ethereum/go-ethereum/blob/ce9a289fa48e0d2593c4aaa7e207c8a5dd3eaa8a/core/types/gen_receipt_json.go

func (*Receipt) UnmarshalJSON added in v0.10.0

func (r *Receipt) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type ResumeCallback added in v1.1.0

type ResumeCallback func(id uuid.UUID, result interface{}, err error) error

ResumeCallback is assumed to be idempotent

type SendEveryStrategy added in v0.10.9

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

SendEveryStrategy will always send the tx

func (SendEveryStrategy) PruneQueue added in v0.10.9

func (SendEveryStrategy) PruneQueue(pg.Queryer) (int64, error)

func (SendEveryStrategy) Simulate added in v1.1.0

func (s SendEveryStrategy) Simulate() bool

func (SendEveryStrategy) Subject added in v0.10.9

func (SendEveryStrategy) Subject() uuid.NullUUID

type TxManager added in v0.10.8

type TxManager interface {
	httypes.HeadTrackable
	service.Service
	Trigger(addr common.Address)
	CreateEthTransaction(newTx NewTx, qopts ...pg.QOpt) (etx EthTx, err error)
	GetGasEstimator() gas.Estimator
	RegisterResumeCallback(fn ResumeCallback)
}

type TxStrategy added in v0.10.9

type TxStrategy interface {
	// Subject will be saved to eth_txes.subject if not null
	Subject() uuid.NullUUID
	// PruneQueue is called after eth_tx insertion
	PruneQueue(q pg.Queryer) (n int64, err error)
	// Simulate indicates whether this transaction can be safely simulated using eth_call
	// Simulating transactions before send and aborting on revert can save gas
	// BE CAREFUL - not all transaction types are safe to simulate, e.g. if
	// they can call arbitrary user-specified code, because there could be a case where
	// it would erroneously fail during simulation but would succeed for real
	Simulate() bool
}

TxStrategy controls how txes are queued and sent

func NewQueueingTxStrategy added in v0.10.9

func NewQueueingTxStrategy(subject uuid.UUID, queueSize uint32, simulate bool) (strategy TxStrategy)

func NewSendEveryStrategy added in v1.1.0

func NewSendEveryStrategy(simulate bool) TxStrategy

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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