monitor

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package monitor wraps an Ethereum connection and tries to reconnect on error

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	EthereumJsonRpcURIs []string `mapstructure:"ethereum-jsonrpc-uris"`
	PostgresDSN         string   `mapstructure:"postgres-dsn"`
	ListenAddress       string   `mapstructure:"listen-address"`
	SimulateBlocks      bool     `mapstructure:"simulate-blocks"`
	MevGethURI          string   `mapstructure:"mev-geth-uri"`
	MaxBlocks           int      `mapstructure:"max-blocks"`
	EnableDebug         bool     `mapstructure:"debug"`
}

Config defines attributes used by reorg monitor server and used for reading in environment variables and CLI flags.

type ConnectionInfo

type ConnectionInfo struct {
	NodeUri         string
	IsConnected     bool
	IsSubscribed    bool
	NumBlocks       uint64
	NumReconnects   int64
	NumResubscribes int64
	NextTimeout     int64
}

type GethConnection

type GethConnection struct {
	NodeUri      string
	Client       *ethclient.Client
	NewBlockChan chan<- *analysis.Block

	IsConnected         bool
	IsSubscribed        bool
	NextRetryTimeoutSec int64 // Wait time before retry. Starts at 5 seconds and doubles after each unsuccessful retry (max: 3 min).

	NumResubscribes int64
	NumReconnects   int64
	NumBlocks       uint64
}

func NewGethConnection

func NewGethConnection(nodeUri string, newBlockChan chan<- *analysis.Block) (*GethConnection, error)

func (*GethConnection) Connect

func (conn *GethConnection) Connect() (err error)

func (*GethConnection) ResubscribeAfterTimeout

func (conn *GethConnection) ResubscribeAfterTimeout()

func (*GethConnection) Subscribe

func (conn *GethConnection) Subscribe() error

type MonitorInfo

type MonitorInfo struct {
	Id                  string
	NumBlocks           int
	EarliestBlockNumber uint64
	LatestBlockNumber   uint64
	TimeStarted         string
}

type MonitorWebserver

type MonitorWebserver struct {
	Monitor     *ReorgMonitor
	Addr        string
	TimeStarted time.Time
}

func NewMonitorWebserver

func NewMonitorWebserver(monitor *ReorgMonitor, listenAddr string) *MonitorWebserver

func (*MonitorWebserver) HandleStatusRequest

func (ws *MonitorWebserver) HandleStatusRequest(w http.ResponseWriter, r *http.Request)

func (*MonitorWebserver) ListenAndServe

func (ws *MonitorWebserver) ListenAndServe() error

type ReorgMonitor

type ReorgMonitor struct {
	NewBlockChan chan *analysis.Block
	NewReorgChan chan<- *analysis.Reorg

	BlockByHash    map[common.Hash]*analysis.Block
	BlocksByHeight map[uint64]map[common.Hash]*analysis.Block

	EarliestBlockNumber uint64
	LatestBlockNumber   uint64

	KnownReorgs map[string]uint64 // key: reorgId, value: endBlockNumber
	// contains filtered or unexported fields
}

func NewReorgMonitor

func NewReorgMonitor(gethNodeUris []string, reorgChan chan<- *analysis.Reorg, verbose bool, maxBlocks int) *ReorgMonitor

func (*ReorgMonitor) AddBlock

func (mon *ReorgMonitor) AddBlock(block *analysis.Block) bool

AddBlock adds a block to history if it hasn't been seen before, and download unknown referenced blocks (parent, uncles).

func (*ReorgMonitor) AnalyzeTree

func (mon *ReorgMonitor) AnalyzeTree(maxBlocks, distanceToLastBlockHeight uint64) (*analysis.TreeAnalysis, error)

func (*ReorgMonitor) CheckBlockForReferences

func (mon *ReorgMonitor) CheckBlockForReferences(block *analysis.Block) error

func (*ReorgMonitor) ConnectClients

func (mon *ReorgMonitor) ConnectClients() (connectedClients int)

func (*ReorgMonitor) EnsureBlock

func (mon *ReorgMonitor) EnsureBlock(blockHash common.Hash, origin analysis.BlockOrigin, nodeUri string) (block *analysis.Block, alreadyExisted bool, err error)

func (*ReorgMonitor) String

func (mon *ReorgMonitor) String() string

func (*ReorgMonitor) SubscribeAndListen

func (mon *ReorgMonitor) SubscribeAndListen()

SubscribeAndListen is the main monitor loop: subscribes to new blocks from all geth connections, and waits for new blocks to process. After adding a new block, a reorg check takes place. If a new completed reorg is detected, it is sent to the channel.

func (*ReorgMonitor) TrimCache

func (mon *ReorgMonitor) TrimCache()

type StatusResponse

type StatusResponse struct {
	Monitor     MonitorInfo
	Connections []ConnectionInfo
}

API response

Jump to

Keyboard shortcuts

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