ethereum

package
v0.77.0-preview.10 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: AGPL-3.0 Imports: 22 Imported by: 0

README

Ethereum event forwarder

This package contains the specific implementation of the event forwarder for Ethereum blockchain.

It reads the logs of Vega's bridge contracts, filters on specific events, translates them to ChainEvent transactions and use the Event Forwarder engine to forward it to the network.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHeartbeat = errors.New("forwarded heartbeat is invalid")

Functions

This section is empty.

Types

type Assets

type Assets interface {
	GetVegaIDFromEthereumAddress(string) string
}

Assets ...

type Client

type Client interface {
	ethbind.ContractFilterer

	CurrentHeight(context.Context) (uint64, error)
	HeaderByNumber(context.Context, *big.Int) (*ethtypes.Header, error)
}

type Config

type Config struct {
	// Level specifies the logging level of the Ethereum implementation of the
	// Event Forwarder.
	Level                                   encoding.LogLevel `long:"log-level"`
	MaxEthereumBlocks                       uint64            `long:"max-ethereum-blocks"`
	PollEventRetryDuration                  encoding.Duration
	ChainID                                 string
	SkipClientVerification                  bool
	HeartbeatIntervalForTestOnlyDoNotChange encoding.Duration
}

func NewDefaultConfig added in v0.55.0

func NewDefaultConfig() Config

type Contract added in v0.77.0

type Contract struct {
	types.EthereumContract
	// contains filtered or unexported fields
}

Contract wrapper around EthereumContract to keep track of the block heights we've checked.

type Engine

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

func NewEngine

func NewEngine(
	cfg Config,
	log *logging.Logger,
	filterer Filterer,
	forwarder Forwarder,
	stakingDeployment types.EthereumContract,
	vestingDeployment types.EthereumContract,
	multiSigDeployment types.EthereumContract,
	collateralDeployment types.EthereumContract,
	chainID string,
	blockTime time.Duration,
) *Engine

func (*Engine) ReloadConf

func (e *Engine) ReloadConf(cfg Config)

func (*Engine) Start

func (e *Engine) Start()

Start starts the polling of the Ethereum bridges, listens to the events they emit and forward it to the network.

func (*Engine) Stop

func (e *Engine) Stop()

Stop stops the engine, its polling and event forwarding.

func (*Engine) UpdateCollateralStartingBlock added in v0.69.0

func (e *Engine) UpdateCollateralStartingBlock(b uint64)

func (*Engine) UpdateMultiSigControlStartingBlock

func (e *Engine) UpdateMultiSigControlStartingBlock(b uint64)

func (*Engine) UpdateStakingStartingBlock

func (e *Engine) UpdateStakingStartingBlock(b uint64)

func (*Engine) UpdateStartingBlock added in v0.77.0

func (e *Engine) UpdateStartingBlock(address string, block uint64)

UpdateStartingBlock sets the height that we should starting looking for new events from for the given bridge contract address.

func (*Engine) VerifyHeartbeat added in v0.77.0

func (e *Engine) VerifyHeartbeat(ctx context.Context, height uint64, chainID string, address string, blockTime uint64) error

VerifyHeart checks that the block height of the heartbeat exists and contains the correct block time. It also checks that this node has checked the logs of the given contract address up to at least the given height.

type Filterer

type Filterer interface {
	FilterCollateralEvents(ctx context.Context, startAt, stopAt uint64, cb OnEventFound)
	FilterStakingEvents(ctx context.Context, startAt, stopAt uint64, cb OnEventFound)
	FilterVestingEvents(ctx context.Context, startAt, stopAt uint64, cb OnEventFound)
	FilterMultisigControlEvents(ctx context.Context, startAt, stopAt uint64, cb OnEventFound)
	CurrentHeight(context.Context) uint64
	GetEthTime(ctx context.Context, atBlock uint64) (uint64, error)
}

type Forwarder

type Forwarder interface {
	ForwardFromSelf(*commandspb.ChainEvent)
}

type LogFilterer

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

LogFilterer wraps the Ethereum event filterers to return Vega events.

func NewLogFilterer

func NewLogFilterer(
	cfg Config,
	log *logging.Logger,
	ethClient Client,
	collateralBridge types.EthereumContract,
	stakingBridge types.EthereumContract,
	vestingBridge types.EthereumContract,
	multiSigControl types.EthereumContract,
	assets Assets,
	chainID string,
) (*LogFilterer, error)

func (*LogFilterer) CurrentHeight

func (f *LogFilterer) CurrentHeight(ctx context.Context) uint64

func (*LogFilterer) FilterCollateralEvents

func (f *LogFilterer) FilterCollateralEvents(ctx context.Context, startAt, stopAt uint64, cb OnEventFound)

FilterCollateralEvents retrieves the events from the collateral bridge on Ethereum starting at startAt, transform them into ChainEvent, and pass it to the OnEventFound callback. The properties startAt and stopAt are inclusive.

func (*LogFilterer) FilterMultisigControlEvents

func (f *LogFilterer) FilterMultisigControlEvents(ctx context.Context, startAt, stopAt uint64, cb OnEventFound)

func (*LogFilterer) FilterStakingEvents

func (f *LogFilterer) FilterStakingEvents(ctx context.Context, startAt, stopAt uint64, cb OnEventFound)

FilterStakingEvents retrieves the events from the staking bridge on Ethereum starting at startAt, transform them into ChainEvent, and pass it to the OnEventFound callback. The properties startAt and stopAt are inclusive.

func (*LogFilterer) FilterVestingEvents

func (f *LogFilterer) FilterVestingEvents(ctx context.Context, startAt, stopAt uint64, cb OnEventFound)

FilterVestingEvents retrieves the events from the vesting bridge on Ethereum starting at startAt, transform them into ChainEvent, and pass it to the OnEventFound callback. The properties startAt and stopAt are inclusive.

func (*LogFilterer) GetEthTime added in v0.77.0

func (f *LogFilterer) GetEthTime(ctx context.Context, atBlock uint64) (uint64, error)

func (*LogFilterer) VerifyClient added in v0.76.0

func (f *LogFilterer) VerifyClient(ctx context.Context) error

VerifyClient checks that the configured RPC node is able to properly query contract logs.

type OnEventFound

type OnEventFound func(*commandspb.ChainEvent, uint64)

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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