observer

package
v0.0.0-...-1929ff6 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 44 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

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,
	chain chains.Chain,
	evmClient interfaces.EVMRPCClient,
	evmJSONRPC interfaces.EVMJSONRPCClient,
	chainParams observertypes.ChainParams,
	zetacoreClient interfaces.ZetacoreClient,
	tss interfaces.TSSSigner,
	database *db.DB,
	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) FilterTSSOutbound

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

FilterTSSOutbound filters the outbounds from TSS address to supplement outbound trackers

func (*Observer) FilterTSSOutboundInBlock

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

FilterTSSOutboundInBlock filters the outbounds in a single block to supplement outbound trackers

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) GetERC20CustodyV2Contract

func (ob *Observer) GetERC20CustodyV2Contract() (ethcommon.Address, *erc20custodyv2.ERC20Custody, error)

GetERC20CustodyV2Contract returns ERC20CustodyV2 contract address and binder NOTE: we use the same address as gateway v1 this simplify the migration process v1 will be completely removed in the future currently the ABI for withdraw is identical, therefore both contract instances can be used

func (*Observer) GetGatewayContract

func (ob *Observer) GetGatewayContract() (ethcommon.Address, *gatewayevm.GatewayEVM, error)

GetGatewayContract returns the gateway contract address and binder

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) IsTxConfirmed

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

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

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) ObserveGatewayCall

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

ObserveGatewayCall queries the gateway contract for call events returns the last block successfully scanned TODO: there are lot of similarities between this function and ObserveGatewayDeposit logic should be factorized using interfaces and generics https://github.com/zeta-chain/node/issues/2493

func (*Observer) ObserveGatewayDeposit

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

ObserveGatewayDeposit queries the gateway contract for deposit events 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.

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) ProcessOutboundTrackers

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

ProcessOutboundTrackers processes outbound trackers

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) 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) VoteOutboundIfConfirmed

func (ob *Observer) VoteOutboundIfConfirmed(
	ctx context.Context,
	cctx *crosschaintypes.CrossChainTx,
) (bool, error)

VoteOutboundIfConfirmed checks outbound status and returns (continueKeysign, error)

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 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

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