transaction

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FuncSelectorT = reflect.TypeOf(FuncSelector{})

Functions

This section is empty.

Types

type ErrInvalidMonitorRequest

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

Error in case of a invalid request is sent to the watcher backend.

func (*ErrInvalidMonitorRequest) Error

func (e *ErrInvalidMonitorRequest) Error() string

type ErrInvalidTransactionRequest

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

Error in case of a invalid transaction is sent to the watcher backend.

func (*ErrInvalidTransactionRequest) Error

type ErrRecoverable

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

Error type that is usually recoverable (e.g network issues).

func (*ErrRecoverable) Error

func (e *ErrRecoverable) Error() string

type ErrTransactionStale

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

Specific error in case a transaction becomes stale.

func (*ErrTransactionStale) Error

func (e *ErrTransactionStale) Error() string

type ErrTxNotFound

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

Error in case a transaction is not found in the rpc node.

func (*ErrTxNotFound) Error

func (e *ErrTxNotFound) Error() string

type FrontWatcher

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

FrontWatcher is a struct that has the data necessary by the Transaction FrontWatcher service. The transaction watcher service is responsible for check, retrieve and cache transaction receipts.

func NewWatcher

func NewWatcher(client layer1.Client, txConfirmationBlocks uint64, database *db.Database, statusDisplay bool, txPollingTime time.Duration) *FrontWatcher

NewWatcher creates a new transaction watcher struct.

func WatcherFromNetwork

func WatcherFromNetwork(network layer1.Client, database *db.Database, statusDisplay bool, txPollingTime time.Duration) *FrontWatcher

WatcherFromNetwork creates a transaction Watcher from a given ethereum network.

func (*FrontWatcher) Close

func (f *FrontWatcher) Close()

Close the transaction watcher service.

func (*FrontWatcher) Start

func (f *FrontWatcher) Start() error

Start the transaction watcher service.

func (*FrontWatcher) Subscribe

func (w *FrontWatcher) Subscribe(ctx context.Context, txn *types.Transaction, options *SubscribeOptions) (ReceiptResponse, error)

Subscribe a transaction to be watched by the transaction watcher service. If a transaction was accepted by the watcher service, a response struct is returned. The response struct is where the receipt going to be written once available. The final tx hash in the receipt can be different from the initial txn sent. This can happen if the txn got stale and the watcher did a transaction replace with higher fees.

func (*FrontWatcher) SubscribeAndWait

func (w *FrontWatcher) SubscribeAndWait(ctx context.Context, txn *types.Transaction, options *SubscribeOptions) (*types.Receipt, error)

SubscribeAndWait queues a transaction and wait for its receipt.

func (*FrontWatcher) Wait

func (w *FrontWatcher) Wait(ctx context.Context, receiptResponse ReceiptResponse) (*types.Receipt, error)

Wait is a function that wait for a transaction receipt. This is blocking function that will wait for a receipt to be received.

type FuncSelector

type FuncSelector [4]byte

func ExtractSelector

func ExtractSelector(data []byte) *FuncSelector

ExtractSelector extracts the selector for a layer1 smart contract call (the first 4 bytes in the call data).

func (FuncSelector) MarshalText

func (fs FuncSelector) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a FuncSelector.

func (*FuncSelector) UnmarshalJSON

func (fs *FuncSelector) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*FuncSelector) UnmarshalText

func (fs *FuncSelector) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

type MonitorWorkRequest

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

MonitorWorkRequest is an internal struct used to send work requests to the workers that will retrieve the receipts.

type MonitorWorkResponse

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

MonitorWorkResponse is an internal struct used by the workers to communicate the result from the receipt retrieval work.

type Profile

type Profile struct {
	AverageGas   uint64 `json:"averageGas"`
	MinimumGas   uint64 `json:"minimumGas"`
	MaximumGas   uint64 `json:"maximumGas"`
	TotalGas     uint64 `json:"totalGas"`
	TotalCount   uint64 `json:"totalCount"`
	TotalSuccess uint64 `json:"totalSuccess"`
}

Profile to keep track of gas metrics in the overall system.

type ReceiptResponse

type ReceiptResponse interface {
	IsReady() bool
	GetReceiptBlocking(ctx context.Context) (*types.Receipt, error)
}

ReceiptResponse to be implemented by the returning object from the Watcher.

type SharedReceipt

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

A SharedReceipt retrieved by the watcher.

func (*SharedReceipt) GetReceiptBlocking

func (r *SharedReceipt) GetReceiptBlocking(ctx context.Context) (*types.Receipt, error)

GetReceiptBlocking blocking function to get the receipt from a transaction. This function will block until the receipt is available and sent by the transaction watcher service.

func (*SharedReceipt) IsReady

func (r *SharedReceipt) IsReady() bool

IsReady to check if a receipt is ready.

type SubscribeOptions

type SubscribeOptions struct {
	EnableAutoRetry bool   // if we should disable auto retry of a transaction in case it becomes stale
	MaxStaleBlocks  uint64 // how many blocks we should consider a transaction stale and mark it for retry
}

SubscribeOptions used for the Txn replacement mechanism.

func NewSubscribeOptions

func NewSubscribeOptions(enableAutoRetry bool, maxStaleBlocks uint64) *SubscribeOptions

NewSubscribeOptions for the Txn to be watched.

type SubscribeRequest

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

SubscribeRequest Type to do subscription request against the tx watcher system. SubscribeResponseChannel should be set.

func NewSubscribeRequest

func NewSubscribeRequest(txn *types.Transaction, options *SubscribeOptions) SubscribeRequest

NewSubscribeRequest creates a new subscribe request.

func (SubscribeRequest) Listen

Listen is a blocking function to listen for the response of a subscribe request.

type SubscribeResponse

type SubscribeResponse struct {
	Err      error          // errors that happened when processing the subscription request
	Response *SharedReceipt // struct where the receipt from the tx monitoring will be sent
}

SubscribeResponse is a type that it's going to be used to reply a subscription request.

type SubscribeResponseChannel

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

SubscribeResponseChannel is a response channel is basically a non-blocking channel that can only be written and closed once.

func NewResponseChannel

func NewResponseChannel() *SubscribeResponseChannel

NewResponseChannel creates a new response channel.

type Watcher

type Watcher interface {
	Start() error
	Close()
	Subscribe(ctx context.Context, txn *types.Transaction, options *SubscribeOptions) (ReceiptResponse, error)
	Wait(ctx context.Context, receiptResponse ReceiptResponse) (*types.Receipt, error)
	SubscribeAndWait(ctx context.Context, txn *types.Transaction, options *SubscribeOptions) (*types.Receipt, error)
}

Watcher to be implemented by FrontWatcher.

type WatcherBackend

type WatcherBackend struct {
	MonitoredTxns map[common.Hash]monitored `json:"monitoredTxns"` // Map of transactions whose receipts we're looking for
	ReceiptCache  map[common.Hash]receipt   `json:"receiptCache"`  // Receipts retrieved from transactions. The keys are txGroup hashes
	Aggregates    map[FuncSelector]Profile  `json:"aggregates"`    // Struct to keep track of the gas metrics used by the system
	RetryGroups   map[common.Hash]group     `json:"retryGroups"`   // Map of groups of transactions that were retried

	TxPollingTime time.Duration `json:"-"` // time in seconds which will be polling for transactions receipts
	// contains filtered or unexported fields
}

WatcherBackend is a backend struct used to monitor Ethereum transactions and retrieve their receipts.

func (*WatcherBackend) LoadState

func (wb *WatcherBackend) LoadState() error

LoadState loads the watcher backend state from the database.

func (*WatcherBackend) Loop

func (wb *WatcherBackend) Loop()

Loop is a main loop where do all the backend actions.

func (*WatcherBackend) PersistState

func (wb *WatcherBackend) PersistState() error

PersistState persists the watcher backend state into the database.

type WorkerPool

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

WorkerPool is a Struct that keep track of the state needed by the worker pool service. The WorkerPool spawn multiple go routines (workers) to check and retrieve the receipts.

func NewWorkerPool

func NewWorkerPool(ctx context.Context, client layer1.Client, baseFee, tipCap *big.Int, logger *logrus.Entry, requestWorkChannel <-chan MonitorWorkRequest, responseWorkChannel chan<- MonitorWorkResponse) *WorkerPool

NewWorkerPool creates a new WorkerPool service.

func (*WorkerPool) ExecuteWork

func (w *WorkerPool) ExecuteWork(numWorkers uint64)

ExecuteWork is a function to spawn the workers and wait for the job to be done.

Jump to

Keyboard shortcuts

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