eventfeed

package
v1.0.1-beta-3 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: MIT, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RunSQL is a RunSQL event fired by the SC.
	RunSQL EventType = "RunSQL"
	// CreateTable is a CreateTable event fired by the SC.
	CreateTable = "CreateTable"
	// SetController is a SetController event fired by the SC.
	SetController = "SetController"
	// TransferTable is a TransferTable event fired by the SC.
	TransferTable = "TransferTable"
)

Variables

SupportedEvents contains a map from **all** EventType values to the corresponding struct that will be used for unmarshaling. Note that tbleth.Contract*** is automatically generated by `make ethereum`, so keeping this mapping is easy since these structs are generated from the contract ABI.

IMPORTANT: we should *always* have a mapping for all EventType values.

Functions

This section is empty.

Types

type BlockEvents

type BlockEvents struct {
	BlockNumber int64
	Txns        []TxnEvents
}

BlockEvents contains a set of events for a particular block height.

type ChainClient

type ChainClient interface {
	FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)
	HeaderByNumber(ctx context.Context, block *big.Int) (*types.Header, error)
}

ChainClient provides basic apis for an EventFeed.

type Config

type Config struct {
	MinBlockChainDepth  int
	ChainAPIBackoff     time.Duration
	NewHeadPollFreq     time.Duration
	PersistEvents       bool
	FetchExtraBlockInfo bool
}

Config contains configuration parameters for an event feed.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration.

type EventFeed

type EventFeed interface {
	Start(ctx context.Context, fromHeight int64, ch chan<- BlockEvents, filterEventTypes []EventType) error
}

EventFeed provides a stream of on-chain events from a smart contract.

type EventType

type EventType string

EventType is an event type.

type Option

type Option func(*Config) error

Option modifies a configuration attribute.

func WithChainAPIBackoff

func WithChainAPIBackoff(backoff time.Duration) Option

WithChainAPIBackoff provides a sleep duration between failed node api calls to retry.

func WithEventPersistence

func WithEventPersistence(enabled bool) Option

WithEventPersistence indicates that all events should be persisted.

func WithFetchExtraBlockInformation

func WithFetchExtraBlockInformation(enabled bool) Option

WithFetchExtraBlockInformation indicates that we'll persist extra block information from persisted events.

func WithMinBlockDepth

func WithMinBlockDepth(depth int) Option

WithMinBlockDepth provides the confidence interval of block depth from which the event feed can safely assume block finality.

func WithNewHeadPollFreq

func WithNewHeadPollFreq(pollFreq time.Duration) Option

WithNewHeadPollFreq is the rate at which we poll the chain to detect new blocks. This should be configured close to the expected block time of the chain.

If set to lower, the validator is more reactive to new blocks as soon as they get miner paying an efficiency cost. For example, Ethereum has an expected block time of 12s. If we set this value to 6s, on average half of the polls will detect a new block.

If set to greater, the validator will have some delay to execute new events on new blocks. But, it would be more efficient in Ethereum node APIs usage, since the next detected block might be N (N>1) blocks further than the last detected one, making the `eth_getLogs(...)` query block range wider. This means that with less Ethereum node APIs we would detect more events on average (again, paying the cost of having a bit more delay on event execution).

Tunning this setting has a direct impact on potential Ethereum node API as a service cost, since bigger values have a direct impact in total API calls per day. Operators can also use this configuration to adjust to their budget.

type TxnEvents

type TxnEvents struct {
	TxnHash common.Hash
	Events  []interface{}
}

TxnEvents contains all events in a transaction.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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