monitor

package
v0.0.0-...-cb3ca1d Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

README

Monitor

Monitor performs Log collecting periodically.

Several most recent blocks on the blockchain are considered unreliable (the relevant setting is eth.min.confirmations).

Let:

  • A = last processed block number
  • Z = most recent block number on the blockchain
  • C = the min confirmations setting
  • F = the fresh offerings setting

Thus the range of interest for agent and client logs Ri = [A + 1, Z - C], and for offering it is:

    if F > 0 Ro = Ri ∩ [Z - C - F, +inf)
    else Ro = Ri

These are the rules for filtering logs on the blockchain:

  1. Events for Agent
  • From: A + 1
  • To: Z - C
  • Topics[0]: any
  • Topics[1]: one of accounts with in_use = true
  1. Events for Client
  • From: A + 1
  • To: Z - C
  • Topics[0]: one of these hashes
    • LogChannelCreated
    • LogChannelToppedUp
    • LogChannelCloseRequested
    • LogCooperativeChannelClose
    • LogUnCooperativeChannelClose
    • Topics[2]: one of the accounts with in_use = true
  1. Offering events
  • From: max(A + 1, Z - C - F) if F > 0
  • From: A + 1 if F == 0
  • To: Z - C
  • Topics[0]: one of these hashes
    • LogOfferingCreated
    • LogOfferingDeleted
    • LogOfferingPopedUp
  • Topics[1]: not one of the accounts with in_use = true
  • Topics[2]: one of the accounts with in_use = true

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInput = fmt.Errorf("one or more input parameters is wrong")
)

Blockchain monitor errors.

Functions

This section is empty.

Types

type Client

type Client interface {
	FilterLogs(ctx context.Context,
		q ethereum.FilterQuery) ([]ethtypes.Log, error)
	HeaderByNumber(ctx context.Context,
		number *big.Int) (*ethtypes.Header, error)
}

Client defines typed wrappers for the Ethereum RPC API.

type Config

type Config struct {
	CollectPause  int64 // pause between collect iterations
	SchedulePause int64 // pause between schedule iterations
	Timeout       int64 // maximum time of one operation
}

Config for blockchain monitor.

func NewConfig

func NewConfig() *Config

NewConfig creates a default blockchain monitor configuration.

type Monitor

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

Monitor implements blockchain monitor which fetches logs from the blockchain and creates jobs accordingly.

func NewMonitor

func NewMonitor(cfg *Config, logger *util.Logger, db *reform.DB,
	queue Queue, eth Client, pscAddr common.Address,
	ptcAddr common.Address) (*Monitor, error)

NewMonitor creates a Monitor with specified settings.

func (*Monitor) Start

func (m *Monitor) Start() error

Start starts the monitor. It will continue collecting logs and scheduling jobs until it is stopped with Stop.

func (*Monitor) Stop

func (m *Monitor) Stop() error

Stop makes the monitor stop.

type Queue

type Queue interface {
	Add(j *data.Job) error
}

Queue is a job processing queue.

Jump to

Keyboard shortcuts

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