ethtxmanager

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 25 Imported by: 6

Documentation

Overview

Package ethtxmanager handles ethereum transactions: It makes calls to send and to aggregate batch, checks possible errors, like wrong nonce or gas limit too low and make correct adjustments to request according to it. Also, it tracks transaction receipt and status of tx in case tx is rejected and send signals to sequencer/aggregator to resend sequence/batch

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound when the object is not found
	ErrNotFound = errors.New("not found")
	// ErrAlreadyExists when the object already exists
	ErrAlreadyExists = errors.New("already exists")

	// ErrExecutionReverted returned when trying to get the revert message
	// but the call fails without revealing the revert reason
	ErrExecutionReverted = errors.New("execution reverted")
)

Functions

func CreateLogger

func CreateLogger(monitoredTxId common.Hash, from common.Address, to *common.Address) *log.Logger

CreateLogger creates an instance of logger with all the important fields already set for a types.MonitoredTx without requiring an instance of types.MonitoredTx, this should be use in for callers before calling the ADD method

func CreateMonitoredTxResultLogger

func CreateMonitoredTxResultLogger(mTxResult types.MonitoredTxResult) *log.Logger

CreateMonitoredTxResultLogger creates an instance of logger with all the important fields already set for a types.MonitoredTxResult

Types

type BatchCall

type BatchCall struct {
	Method     string
	Parameters []interface{}
}

BatchCall used in batch requests to send multiple methods and parameters at once

type Client

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

Client for eth tx manager

func New

func New(cfg Config) (*Client, error)

New creates new eth tx manager

func (*Client) Add

func (c *Client) Add(ctx context.Context, to *common.Address, value *big.Int,
	data []byte, gasOffset uint64, sidecar *ethTypes.BlobTxSidecar) (common.Hash, error)

Add a transaction to be sent and monitored

func (*Client) AddWithGas

func (c *Client) AddWithGas(ctx context.Context, to *common.Address,
	value *big.Int, data []byte, gasOffset uint64, sidecar *ethTypes.BlobTxSidecar, gas uint64) (common.Hash, error)

AddWithGas adds a transaction to be sent and monitored with a defined gas to be used so it's not estimated

func (*Client) EncodeBlobData

func (c *Client) EncodeBlobData(data []byte) (kzg4844.Blob, error)

EncodeBlobData encodes data into blob data type

func (*Client) MakeBlobSidecar

func (c *Client) MakeBlobSidecar(blobs []kzg4844.Blob) *ethTypes.BlobTxSidecar

MakeBlobSidecar constructs a blob tx sidecar

func (*Client) ProcessPendingMonitoredTxs

func (c *Client) ProcessPendingMonitoredTxs(ctx context.Context, resultHandler ResultHandler)

ProcessPendingMonitoredTxs will check all monitored txs and wait until all of them are either confirmed or failed before continuing

for the confirmed and failed ones, the resultHandler will be triggered

func (*Client) Remove

func (c *Client) Remove(ctx context.Context, id common.Hash) error

Remove a transaction from the monitored txs

func (*Client) RemoveAll

func (c *Client) RemoveAll(ctx context.Context) error

RemoveAll removes all the monitored txs

func (*Client) Result

func (c *Client) Result(ctx context.Context, id common.Hash) (types.MonitoredTxResult, error)

Result returns the current result of the transaction execution with all the details

func (*Client) ResultsByStatus

func (c *Client) ResultsByStatus(ctx context.Context,
	statuses []types.MonitoredTxStatus) ([]types.MonitoredTxResult, error)

ResultsByStatus returns all the results for all the monitored txs matching the provided statuses if the statuses are empty, all the statuses are considered.

func (*Client) Start

func (c *Client) Start()

Start will start the tx management, reading txs from storage, send then to the blockchain and keep monitoring them until they get mined

func (*Client) Stop

func (c *Client) Stop()

Stop stops the monitored tx management

type Config

type Config struct {
	// FrequencyToMonitorTxs frequency of the resending failed txs
	FrequencyToMonitorTxs types.Duration `mapstructure:"FrequencyToMonitorTxs"`

	// WaitTxToBeMined time to wait after transaction was sent to the ethereum
	WaitTxToBeMined types.Duration `mapstructure:"WaitTxToBeMined"`

	// GetReceiptMaxTime is the max time to wait to get the receipt of the mined transaction
	GetReceiptMaxTime types.Duration `mapstructure:"WaitReceiptMaxTime"`

	// GetReceiptWaitInterval is the time to sleep before trying to get the receipt of the mined transaction
	GetReceiptWaitInterval types.Duration `mapstructure:"WaitReceiptCheckInterval"`

	// PrivateKeys defines all the key store files that are going
	// to be read in order to provide the private keys to sign the L1 txs
	PrivateKeys []types.KeystoreFileConfig `mapstructure:"PrivateKeys"`

	// ForcedGas is the amount of gas to be forced in case of gas estimation error
	ForcedGas uint64 `mapstructure:"ForcedGas"`

	// GasPriceMarginFactor is used to multiply the suggested gas price provided by the network
	// in order to allow a different gas price to be set for all the transactions and making it
	// easier to have the txs prioritized in the pool, default value is 1.
	//
	// ex:
	// suggested gas price: 100
	// GasPriceMarginFactor: 1
	// gas price = 100
	//
	// suggested gas price: 100
	// GasPriceMarginFactor: 1.1
	// gas price = 110
	GasPriceMarginFactor float64 `mapstructure:"GasPriceMarginFactor"`

	// MaxGasPriceLimit helps avoiding transactions to be sent over an specified
	// gas price amount, default value is 0, which means no limit.
	// If the gas price provided by the network and adjusted by the GasPriceMarginFactor
	// is greater than this configuration, transaction will have its gas price set to
	// the value configured in this config as the limit.
	//
	// ex:
	//
	// suggested gas price: 100
	// gas price margin factor: 20%
	// max gas price limit: 150
	// tx gas price = 120
	//
	// suggested gas price: 100
	// gas price margin factor: 20%
	// max gas price limit: 110
	// tx gas price = 110
	MaxGasPriceLimit uint64 `mapstructure:"MaxGasPriceLimit"`

	// StoragePath is the path of the internal storage
	StoragePath string `mapstructure:"StoragePath"`

	// ReadPendingL1Txs is a flag to enable the reading of pending L1 txs
	// It can only be enabled if DBPath is empty
	ReadPendingL1Txs bool `mapstructure:"ReadPendingL1Txs"`

	// Etherman configuration
	Etherman etherman.Config `mapstructure:"Etherman"`

	// Log configuration
	Log log.Config `mapstructure:"Log"`

	// SafeStatusL1NumberOfBlocks overwrites the number of blocks to consider a tx as safe
	// overwriting the default value provided by the network
	// 0 means that the default value will be used
	SafeStatusL1NumberOfBlocks uint64 `mapstructure:"SafeStatusL1NumberOfBlocks"`

	// FinalizedStatusL1NumberOfBlocks overwrites the number of blocks to consider a tx as finalized
	// overwriting the default value provided by the network
	// 0 means that the default value will be used
	FinalizedStatusL1NumberOfBlocks uint64 `mapstructure:"FinalizedStatusL1NumberOfBlocks"`
}

Config is configuration for ethereum transaction manager

type RPCClient

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

RPCClient is a client to interact with the Ethereum JSON RPC Server

func NewRPCClient

func NewRPCClient(url string) *RPCClient

NewRPCClient creates an instance of client

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

Request is a jsonrpc request

type Response

type Response struct {
	JSONRPC string
	ID      interface{}
	Result  json.RawMessage
}

Response is a jsonrpc success response

func JSONRPCBatchCall

func JSONRPCBatchCall(url string, httpHeaders map[string]string, calls ...BatchCall) ([]Response, error)

JSONRPCBatchCall executes a 2.0 JSON RPC HTTP Post Batch Request to the provided URL with the provided method and parameters groups, which is compatible with the Ethereum JSON RPC Server.

func JSONRPCCall

func JSONRPCCall(url, method string, httpHeaders map[string]string, parameters ...interface{}) (Response, error)

JSONRPCCall executes a 2.0 JSON RPC HTTP Post Request to the provided URL with the provided method and parameters, which is compatible with the Ethereum JSON RPC Server.

type ResultHandler

type ResultHandler func(types.MonitoredTxResult)

ResultHandler used by the caller to handle results when processing monitored txs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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