evm

package
v0.0.0-...-a9efee2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: Apache-2.0 Imports: 30 Imported by: 2

Documentation

Index

Constants

View Source
const (
	BTS_MAX_BLOCKS = 10000
)
View Source
const CCQ_BACKFILL_DELAY = 100 * time.Millisecond
View Source
const CCQ_MAX_BATCH_SIZE = int64(1000)
View Source
const CCQ_TIMESTAMP_RANGE_IN_SECONDS = uint64(30 * 60)
View Source
const MaxWaitConfirmations = 60

MaxWaitConfirmations is the maximum number of confirmations to wait before declaring a transaction abandoned.

Variables

View Source
var (
	ErrInvalidEnv = errors.New("invalid environment")
	ErrNotFound   = errors.New("not found")
)
View Source
var (
	// SECURITY: Hardcoded ABI identifier for the LogMessagePublished topic. When using the watcher, we don't need this
	// since the node will only hand us pre-filtered events. In this case, we need to manually verify it
	// since ParseLogMessagePublished will only verify whether it parses.
	LogMessagePublishedTopic = eth_common.HexToHash("0x6eb224fb001ed210e379b335e35efe88672a8ce935d981a6896b27ffdf52a3b2")
)

Functions

func GetEvmChainID

func GetEvmChainID(env common.Environment, chainID vaa.ChainID) (uint64, error)

GetEvmChainID returns the configured EVM chain ID for the specified environment / chain.

func GetFinality

func GetFinality(env common.Environment, chainID vaa.ChainID) (finalized bool, safe bool, err error)

GetFinality returns the finalized and safe flags for the specified environment / chain. These are used to configure the watcher at run time.

func MessageEventsForTransaction

func MessageEventsForTransaction(
	ctx context.Context,
	ethConn connectors.Connector,
	contract eth_common.Address,
	chainId vaa.ChainID,
	tx eth_common.Hash) (uint64, []*common.MessagePublication, error)

MessageEventsForTransaction returns the lockup events for a given transaction. Returns the block number and a list of MessagePublication events.

func PadAddress

func PadAddress(address common.Address) vaa.Address

PadAddress creates 32-byte VAA.Address from 20-byte Ethereum addresses by adding 12 0-bytes at the left

func QueryEvmChainID

func QueryEvmChainID(ctx context.Context, url string) (uint64, error)

QueryEvmChainID queries the specified RPC for the EVM chain ID.

func SupportedInMainnet

func SupportedInMainnet(chainID vaa.ChainID) bool

SupportedInMainnet returns true if the chain is configured in Mainnet.

Types

type Block

type Block struct {
	Timestamp uint64
	BlockNum  uint64
}

func (Block) Cmp

func (lhs Block) Cmp(rhs Block) int

Cmp compares two blocks, returning the usual -1, 0, +1.

type Blocks

type Blocks []Block

func (Blocks) SearchForTimestamp

func (blocks Blocks) SearchForTimestamp(timestamp uint64) int

type BlocksByTimestamp

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

func NewBlocksByTimestamp

func NewBlocksByTimestamp(maxCacheSize int, unsafeDevMode bool) *BlocksByTimestamp

NewBlocksByTimestamp creates an empty cache of blocks by timestamp.

func (*BlocksByTimestamp) AddBatch

func (bts *BlocksByTimestamp) AddBatch(blocks Blocks)

AddBatch adds a batch of blocks to the cache. This is meant to be used for backfilling the cache. It makes sure there are no duplicate blocks and regenerates the cache in the correct order by timestamp.

func (*BlocksByTimestamp) AddLatest

func (bts *BlocksByTimestamp) AddLatest(logger *zap.Logger, timestamp uint64, blockNum uint64)

AddLatest adds a block to the end of the cache. This is meant to be used in the normal scenario when a new latest block is received. If the specified timestamp or block number is less than the latest in the cache (most likely a rollback), the cache will be truncated and the new value inserted.

func (*BlocksByTimestamp) GetRange

func (bts *BlocksByTimestamp) GetRange() (firstBlockNum, firstBlockTime, lastBlockNum, lastBlockTime uint64)

GetRange returns the range covered by the cache for debugging purposes.

func (*BlocksByTimestamp) LookUp

func (bts *BlocksByTimestamp) LookUp(timestamp uint64) (uint64, uint64, bool)

LookUp searches the cache for the specified timestamp and returns the blocks surrounding that timestamp. It also returns true if the results are complete or false if they are not. The following rules apply: - If timestamp is less than the first timestamp in the cache, it returns (0, <theFirstBlockInTheCache>, false) - If timestamp is greater than or equal to the last timestamp in the cache, it returns (<theLastBlockInTheCache>, 0, false) - If timestamp exactly matches one in the cache, it returns (<theLastBlockForThatTimestamp>, <theFirstBlockForTheNextTimestamp>, true) - If timestamp is not in the cache, but there are blocks around it, it returns (<theLastBlockForThePreviousTimestamp>, <theFirstBlockForTheNextTimestamp>, false)

type EnvEntry

type EnvEntry struct {
	// InstantFinality indicates that the chain has instant finality, meaning finalized and safe blocks can be generated along with the latest block.
	// Note that if InstantFinality is set to true, Finalized and Safe are for documentation purposes only.
	InstantFinality bool

	// Finalized indicates if the chain supports querying for finalized blocks.
	Finalized bool

	// Safe indicates if the chain supports querying for safe blocks.
	Safe bool

	// EvmChainID is the expected EVM chain ID (what is returned by the `eth_chainId` RPC call).
	EvmChainID uint64

	// PublicRPC is not actually used by the watcher. It's used to verify that the EvmChainID specified here is correct.
	PublicRPC string
}

EnvEntry specifies the config data for a given chain / environment.

type EnvMap

type EnvMap map[vaa.ChainID]EnvEntry

EnvMap defines the config data for a given environment (mainet or testnet).

func GetChainConfigMap

func GetChainConfigMap(env common.Environment) (EnvMap, error)

GetChainConfigMap is a helper that returns the configuration for the specified environment. This is public so the chain verify utility can use it.

type EthCallDataIntf

type EthCallDataIntf interface {
	CallDataList() []*query.EthCallData
}

type EvmCallData

type EvmCallData struct {
	To         eth_common.Address
	Data       string
	CallResult *eth_hexutil.Bytes
	// contains filtered or unexported fields
}

EvmCallData contains the details of a single call in the batch.

func (EvmCallData) String

func (ecd EvmCallData) String() string

type Watcher

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

func NewEthWatcher

func NewEthWatcher(
	url string,
	contract eth_common.Address,
	networkName string,
	chainID vaa.ChainID,
	msgC chan<- *common.MessagePublication,
	setC chan<- *common.GuardianSet,
	obsvReqC <-chan *gossipv1.ObservationRequest,
	queryReqC <-chan *query.PerChainQueryInternal,
	queryResponseC chan<- *query.PerChainQueryResponseInternal,
	env common.Environment,
	ccqBackfillCache bool,
) *Watcher

func (*Watcher) GetLatestFinalizedBlockNumber

func (w *Watcher) GetLatestFinalizedBlockNumber() uint64

GetLatestFinalizedBlockNumber() implements the L1Finalizer interface and allows other watchers to get the latest finalized block number from this watcher.

func (*Watcher) QueryHandler

func (w *Watcher) QueryHandler(ctx context.Context, queryRequest *query.PerChainQueryInternal)

QueryHandler is the top-level query handler. It breaks out the requests based on the type and calls the appropriate handler.

func (*Watcher) Reobserve

func (w *Watcher) Reobserve(ctx context.Context, chainID vaa.ChainID, txID []byte, customEndpoint string) (uint32, error)

Reobserve is the interface for reobserving using a custom URL. It opens a connection to that URL and does the reobservation on it.

func (*Watcher) Run

func (w *Watcher) Run(parentCtx context.Context) error

func (*Watcher) SetL1Finalizer

func (w *Watcher) SetL1Finalizer(l1Finalizer interfaces.L1Finalizer)

SetL1Finalizer is used to set the layer one finalizer.

type WatcherConfig

type WatcherConfig struct {
	NetworkID              watchers.NetworkID // human readable name
	ChainID                vaa.ChainID        // ChainID
	Rpc                    string             // RPC URL
	Contract               string             // hex representation of the contract address
	GuardianSetUpdateChain bool               // if `true`, we will retrieve the GuardianSet from this chain and watch this chain for GuardianSet updates
	L1FinalizerRequired    watchers.NetworkID // (optional)

	CcqBackfillCache bool
	// contains filtered or unexported fields
}

func (*WatcherConfig) Create

func (*WatcherConfig) GetChainID

func (wc *WatcherConfig) GetChainID() vaa.ChainID

func (*WatcherConfig) GetNetworkID

func (wc *WatcherConfig) GetNetworkID() watchers.NetworkID

func (*WatcherConfig) RequiredL1Finalizer

func (wc *WatcherConfig) RequiredL1Finalizer() watchers.NetworkID

func (*WatcherConfig) SetL1Finalizer

func (wc *WatcherConfig) SetL1Finalizer(l1finalizer interfaces.L1Finalizer)

Directories

Path Synopsis
finalizers

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳