blocks

package
v0.0.0-...-b400eb5 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockMonitor

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

BlockMonitor watches a HeaderGetter (probably an ethclient)for new blocks, publishing new blocks to a Publisher. In the event of a chain reorganization, it will emit any blocks from the new chain, so long as the common ancestor is in its block ring buffer. If the HeaderGetter does not yet have the next block, the BlockMonitor will poll every queryInterval. Finally, a BlockRecorder is used to track the last recorded block number, so that the BlockMonitor can resume where it left off in the event of a restart.

func NewBlockMonitor

func NewBlockMonitor(headerGetter HeaderGetter, publisher channels.Publisher, interval time.Duration, blockRecorder BlockRecorder, brbSize int) *BlockMonitor

NewBlockMonitor creates an BlockMonitor with the provided HeaderGetter, Publisher, and BlockRecorder. When blocks are unavailable, it will sleep for `interval` between polling, and it will keep `brbSize` historic block headers to deal with chain reorganizations.

func NewRPCBlockMonitor

func NewRPCBlockMonitor(rpcURL string, publisher channels.Publisher, interval time.Duration, blockRecorder BlockRecorder, brbSize int) (*BlockMonitor, error)

NewRPCBlockMonitor creates a BlockMonitor using an ehtclient to the specified rpcURL for a HeaderGetter. Other parameters match NewBlockMonitor.

func (*BlockMonitor) Process

func (bm *BlockMonitor) Process() error

Process watches for new blocks, publishing each block on the provided publisher.

func (*BlockMonitor) Stop

func (bm *BlockMonitor) Stop()

Stop sends the signal to stop processing.

type BlockRecorder

type BlockRecorder interface {
	Record(*big.Int) error
	Get() (*big.Int, error)
}

BlockRecorder keeps track of the last recorded block, primarily so that the block monitor can resume where it left off in the event that it restarts.

func NewMockBlockRecorder

func NewMockBlockRecorder() BlockRecorder

func NewRedisBlockRecorder

func NewRedisBlockRecorder(redisClient *redis.Client, key string) BlockRecorder

type HeaderGetter

type HeaderGetter interface {
	HeaderByNumber(context.Context, *big.Int) (*types.Header, error)
	HeaderByHash(context.Context, common.Hash) (*types.Header, error)
}

HeaderGetter returns block headers by hash or number. The ethclient provides this interface, but for test purposes we want a simpler interface.

type MiniBlock

type MiniBlock struct {
	Hash   common.Hash `json:"hash"`
	Number *big.Int    `json:"number"`
	Bloom  types.Bloom `json:"bloom"`
}

MiniBlock is a subset of the Ethereum block header that has the subset of fields we need to monitor for events. The hash is tracked to identify specific blocks in the event of a reorg. The block number is tracked to make it easy to guess what block should come next (though reorgs can alter this). The bloom filter is tracked so that downstream tasks can efficiently determine if they need to take action on this block.

type MockHeaderGetter

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

func NewMockHeaderGetter

func NewMockHeaderGetter(headers []*types.Header) *MockHeaderGetter

func (*MockHeaderGetter) AddHeader

func (hg *MockHeaderGetter) AddHeader(header *types.Header)

func (*MockHeaderGetter) HeaderByHash

func (hg *MockHeaderGetter) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error)

func (*MockHeaderGetter) HeaderByNumber

func (hg *MockHeaderGetter) HeaderByNumber(ctx context.Context, bigIdx *big.Int) (*types.Header, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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