Documentation ¶
Overview ¶
Package monitor wraps an Ethereum connection and tries to reconnect on error
Index ¶
- type Config
- type ConnectionInfo
- type GethConnection
- type MonitorInfo
- type MonitorWebserver
- type ReorgMonitor
- func (mon *ReorgMonitor) AddBlock(block *analysis.Block) bool
- func (mon *ReorgMonitor) AnalyzeTree(maxBlocks, distanceToLastBlockHeight uint64) (*analysis.TreeAnalysis, error)
- func (mon *ReorgMonitor) CheckBlockForReferences(block *analysis.Block) error
- func (mon *ReorgMonitor) ConnectClients() (connectedClients int)
- func (mon *ReorgMonitor) EnsureBlock(blockHash common.Hash, origin analysis.BlockOrigin, nodeUri string) (block *analysis.Block, alreadyExisted bool, err error)
- func (mon *ReorgMonitor) String() string
- func (mon *ReorgMonitor) SubscribeAndListen()
- func (mon *ReorgMonitor) TrimCache()
- type StatusResponse
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 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 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 (*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
Click to show internal directories.
Click to hide internal directories.