observer

package
v0.0.0-...-2da98db Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 39 Imported by: 0

Documentation

Overview

Package observer implements the EVM chain observer

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchConnectorContractEth

func FetchConnectorContractEth(
	addr ethcommon.Address,
	client interfaces.EVMRPCClient,
) (*zetaconnectoreth.ZetaConnectorEth, error)

FetchConnectorContractEth returns the Eth connector address and binder TODO(revamp): move this to a contract package

func FetchZetaTokenContract

func FetchZetaTokenContract(
	addr ethcommon.Address,
	client interfaces.EVMRPCClient,
) (*zeta.ZetaNonEth, error)

FetchZetaTokenContract returns the non-Eth ZETA token binder TODO(revamp): move this to a contract package

func ParseAndCheckWithdrawnEvent

func ParseAndCheckWithdrawnEvent(
	cctx *crosschaintypes.CrossChainTx,
	receipt *ethtypes.Receipt,
	custodyAddr ethcommon.Address,
	custody *erc20custody.ERC20Custody,
) (*erc20custody.ERC20CustodyWithdrawn, error)

ParseAndCheckWithdrawnEvent parses and checks erc20 Withdrawn event from the outbound receipt

func ParseAndCheckZetaEvent

func ParseAndCheckZetaEvent(
	cctx *crosschaintypes.CrossChainTx,
	receipt *ethtypes.Receipt,
	connectorAddr ethcommon.Address,
	connector *zetaconnector.ZetaConnectorNonEth,
) (*zetaconnector.ZetaConnectorNonEthZetaReceived, *zetaconnector.ZetaConnectorNonEthZetaReverted, error)

ParseAndCheckZetaEvent parses and checks ZetaReceived/ZetaReverted event from the outbound receipt It either returns an ZetaReceived or an ZetaReverted event, or an error if no event found

func ParseOutboundReceivedValue

func ParseOutboundReceivedValue(
	cctx *crosschaintypes.CrossChainTx,
	receipt *ethtypes.Receipt,
	transaction *ethtypes.Transaction,
	cointype coin.CoinType,
	connectorAddress ethcommon.Address,
	connector *zetaconnector.ZetaConnectorNonEth,
	custodyAddress ethcommon.Address,
	custody *erc20custody.ERC20Custody,
) (*big.Int, chains.ReceiveStatus, error)

ParseOutboundReceivedValue parses the received value and status from the outbound receipt The receivd value is the amount of Zeta/ERC20/Gas token (released from connector/custody/TSS) sent to the receiver

Types

type Observer

type Observer struct {
	// base.Observer implements the base chain observer
	base.Observer
	// contains filtered or unexported fields
}

Observer is the observer for evm chains

func NewObserver

func NewObserver(
	ctx context.Context,
	evmCfg config.EVMConfig,
	evmClient interfaces.EVMRPCClient,
	chainParams observertypes.ChainParams,
	zetacoreClient interfaces.ZetacoreClient,
	tss interfaces.TSSSigner,
	dbpath string,
	logger base.Logger,
	ts *metrics.TelemetryServer,
) (*Observer, error)

NewObserver returns a new EVM chain observer

func (*Observer) BlockByNumber

func (ob *Observer) BlockByNumber(blockNumber int) (*ethrpc.Block, error)

BlockByNumber query block by number via JSON-RPC

func (*Observer) BuildInboundVoteMsgForDepositedEvent

func (ob *Observer) BuildInboundVoteMsgForDepositedEvent(
	event *erc20custody.ERC20CustodyDeposited,
	sender ethcommon.Address,
) *types.MsgVoteInbound

BuildInboundVoteMsgForDepositedEvent builds a inbound vote message for a Deposited event

func (*Observer) BuildInboundVoteMsgForTokenSentToTSS

func (ob *Observer) BuildInboundVoteMsgForTokenSentToTSS(
	tx *ethrpc.Transaction,
	sender ethcommon.Address,
	blockNumber uint64,
) *types.MsgVoteInbound

BuildInboundVoteMsgForTokenSentToTSS builds a inbound vote message for a token sent to TSS

func (*Observer) BuildInboundVoteMsgForZetaSentEvent

func (ob *Observer) BuildInboundVoteMsgForZetaSentEvent(
	appContext *zctx.AppContext,
	event *zetaconnector.ZetaConnectorNonEthZetaSent,
) *types.MsgVoteInbound

BuildInboundVoteMsgForZetaSentEvent builds a inbound vote message for a ZetaSent event

func (*Observer) CheckAndVoteInboundTokenERC20

func (ob *Observer) CheckAndVoteInboundTokenERC20(
	ctx context.Context,
	tx *ethrpc.Transaction,
	receipt *ethtypes.Receipt,
	vote bool,
) (string, error)

CheckAndVoteInboundTokenERC20 checks and votes on the given inbound ERC20 token

func (*Observer) CheckAndVoteInboundTokenGas

func (ob *Observer) CheckAndVoteInboundTokenGas(
	ctx context.Context,
	tx *ethrpc.Transaction,
	receipt *ethtypes.Receipt,
	vote bool,
) (string, error)

CheckAndVoteInboundTokenGas checks and votes on the given inbound gas token

func (*Observer) CheckAndVoteInboundTokenZeta

func (ob *Observer) CheckAndVoteInboundTokenZeta(
	ctx context.Context,
	tx *ethrpc.Transaction,
	receipt *ethtypes.Receipt,
	vote bool,
) (string, error)

CheckAndVoteInboundTokenZeta checks and votes on the given inbound Zeta token

func (*Observer) CheckTxInclusion

func (ob *Observer) CheckTxInclusion(tx *ethtypes.Transaction, receipt *ethtypes.Receipt) error

CheckTxInclusion returns nil only if tx is included at the position indicated by the receipt ([block, index])

func (*Observer) GetBlockByNumberCached

func (ob *Observer) GetBlockByNumberCached(blockNumber uint64) (*ethrpc.Block, error)

GetBlockByNumberCached get block by number from cache returns block, ethrpc.Block, isFallback, isSkip, error

func (*Observer) GetBlockHeaderCached

func (ob *Observer) GetBlockHeaderCached(ctx context.Context, blockNumber uint64) (*ethtypes.Header, error)

GetBlockHeaderCached get block header by number from cache

func (*Observer) GetChainParams

func (ob *Observer) GetChainParams() observertypes.ChainParams

GetChainParams returns the chain params for the observer Note: chain params is accessed concurrently

func (*Observer) GetConnectorContract

func (ob *Observer) GetConnectorContract() (ethcommon.Address, *zetaconnector.ZetaConnectorNonEth, error)

GetConnectorContract returns the non-Eth connector address and binder

func (*Observer) GetConnectorContractEth

func (ob *Observer) GetConnectorContractEth() (ethcommon.Address, *zetaconnectoreth.ZetaConnectorEth, error)

GetConnectorContractEth returns the Eth connector address and binder

func (*Observer) GetERC20CustodyContract

func (ob *Observer) GetERC20CustodyContract() (ethcommon.Address, *erc20custody.ERC20Custody, error)

GetERC20CustodyContract returns ERC20Custody contract address and binder

func (*Observer) GetPendingTx

func (ob *Observer) GetPendingTx(nonce uint64) *ethtypes.Transaction

GetPendingTx gets the pending transaction from memory

func (*Observer) GetTxID

func (ob *Observer) GetTxID(nonce uint64) string

GetTxID returns a unique id for outbound tx

func (*Observer) GetTxNReceipt

func (ob *Observer) GetTxNReceipt(nonce uint64) (*ethtypes.Receipt, *ethtypes.Transaction)

GetTxNReceipt gets the receipt and transaction from memory

func (*Observer) HasEnoughConfirmations

func (ob *Observer) HasEnoughConfirmations(receipt *ethtypes.Receipt, lastHeight uint64) bool

HasEnoughConfirmations checks if the given receipt has enough confirmations

func (*Observer) IsOutboundProcessed

func (ob *Observer) IsOutboundProcessed(
	ctx context.Context,
	cctx *crosschaintypes.CrossChainTx,
	logger zerolog.Logger,
) (bool, bool, error)

IsOutboundProcessed checks outbound status and returns (isIncluded, isConfirmed, error) It also posts vote to zetacore if the tx is confirmed TODO(revamp): rename as it also vote the outbound

func (*Observer) IsTxConfirmed

func (ob *Observer) IsTxConfirmed(nonce uint64) bool

IsTxConfirmed returns true if there is a confirmed tx for 'nonce'

func (*Observer) LoadDB

func (ob *Observer) LoadDB(ctx context.Context, dbPath string) error

LoadDB open sql database and load data into EVM observer TODO(revamp): move to a db file

func (*Observer) LoadLastBlockScanned

func (ob *Observer) LoadLastBlockScanned(ctx context.Context) error

LoadLastBlockScanned loads the last scanned block from the database TODO(revamp): move to a db file

func (*Observer) ObserveERC20Deposited

func (ob *Observer) ObserveERC20Deposited(ctx context.Context, startBlock, toBlock uint64) uint64

ObserveERC20Deposited queries the ERC20CustodyDeposited event from the ERC20Custody contract and posts to zetacore returns the last block successfully scanned

func (*Observer) ObserveInbound

func (ob *Observer) ObserveInbound(ctx context.Context, sampledLogger zerolog.Logger) error

ObserveInbound observes the evm chain for inbounds and posts votes to zetacore

func (*Observer) ObserveTSSReceiveInBlock

func (ob *Observer) ObserveTSSReceiveInBlock(ctx context.Context, blockNumber uint64) error

ObserveTSSReceiveInBlock queries the incoming gas asset to TSS address in a single block and posts votes

func (*Observer) ObserveZetaSent

func (ob *Observer) ObserveZetaSent(ctx context.Context, startBlock, toBlock uint64) (uint64, error)

ObserveZetaSent queries the ZetaSent event from the connector contract and posts to zetacore returns the last block successfully scanned

func (*Observer) ObserverTSSReceive

func (ob *Observer) ObserverTSSReceive(ctx context.Context, startBlock, toBlock uint64) (uint64, error)

ObserverTSSReceive queries the incoming gas asset to TSS address and posts to zetacore returns the last block successfully scanned

func (*Observer) PostGasPrice

func (ob *Observer) PostGasPrice(ctx context.Context) error

PostGasPrice posts gas price to zetacore TODO(revamp): move to gas price file

func (*Observer) PostVoteInbound

func (ob *Observer) PostVoteInbound(
	ctx context.Context,
	msg *types.MsgVoteInbound,
	coinType coin.CoinType,
	retryGasLimit uint64,
) (string, error)

PostVoteInbound posts a vote for the given vote message

func (*Observer) PostVoteOutbound

func (ob *Observer) PostVoteOutbound(
	ctx context.Context,
	cctxIndex string,
	receipt *ethtypes.Receipt,
	transaction *ethtypes.Transaction,
	receiveValue *big.Int,
	receiveStatus chains.ReceiveStatus,
	nonce uint64,
	coinType coin.CoinType,
	logger zerolog.Logger,
)

PostVoteOutbound posts vote to zetacore for the confirmed outbound

func (*Observer) ProcessInboundTrackers

func (ob *Observer) ProcessInboundTrackers(ctx context.Context) error

ProcessInboundTrackers processes inbound trackers from zetacore TODO(revamp): move inbound tracker function to a separate file

func (*Observer) RemoveCachedBlock

func (ob *Observer) RemoveCachedBlock(blockNumber uint64)

RemoveCachedBlock remove block from cache

func (*Observer) SetChainParams

func (ob *Observer) SetChainParams(params observertypes.ChainParams)

SetChainParams sets the chain params for the observer Note: chain params is accessed concurrently

func (*Observer) SetPendingTx

func (ob *Observer) SetPendingTx(nonce uint64, transaction *ethtypes.Transaction)

SetPendingTx sets the pending transaction in memory

func (*Observer) SetTxNReceipt

func (ob *Observer) SetTxNReceipt(nonce uint64, receipt *ethtypes.Receipt, transaction *ethtypes.Transaction)

SetTxNReceipt sets the receipt and transaction in memory

func (*Observer) Start

func (ob *Observer) Start(ctx context.Context)

Start all observation routines for the evm chain

func (*Observer) TransactionByHash

func (ob *Observer) TransactionByHash(txHash string) (*ethrpc.Transaction, bool, error)

TransactionByHash query transaction by hash via JSON-RPC TODO(revamp): update this method as a pure RPC method that takes two parameters (jsonRPC, and txHash) and move to upper package to file rpc.go

func (*Observer) WatchGasPrice

func (ob *Observer) WatchGasPrice(ctx context.Context) error

WatchGasPrice watches evm chain for gas prices and post to zetacore TODO(revamp): move ticker to ticker file TODO(revamp): move inner logic to a separate function

func (*Observer) WatchInbound

func (ob *Observer) WatchInbound(ctx context.Context) error

WatchInbound watches evm chain for incoming txs and post votes to zetacore TODO(revamp): move ticker function to a separate file

func (*Observer) WatchInboundTracker

func (ob *Observer) WatchInboundTracker(ctx context.Context) error

WatchInboundTracker gets a list of Inbound tracker suggestions from zeta-core at each tick and tries to check if the in-tx was confirmed. If it was, it tries to broadcast the confirmation vote. If this zeta client has previously broadcast the vote, the tx would be rejected TODO(revamp): move inbound tracker function to a separate file

func (*Observer) WatchOutbound

func (ob *Observer) WatchOutbound(ctx context.Context) error

WatchOutbound watches evm chain for outgoing txs status TODO(revamp): move ticker function to ticker file TODO(revamp): move inner logic to a separate function

func (*Observer) WatchRPCStatus

func (ob *Observer) WatchRPCStatus(ctx context.Context) error

WatchRPCStatus watches the RPC status of the evm chain TODO(revamp): move ticker to ticker file TODO(revamp): move inner logic to a separate function

func (*Observer) WithEvmClient

func (ob *Observer) WithEvmClient(client interfaces.EVMRPCClient)

WithEvmClient attaches a new evm client to the observer

func (*Observer) WithEvmJSONRPC

func (ob *Observer) WithEvmJSONRPC(client interfaces.EVMJSONRPCClient)

WithEvmJSONRPC attaches a new evm json rpc client to the observer

Jump to

Keyboard shortcuts

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