monitor

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 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 blocks setting
  • L = the limit blocks to retrieve setting

Thus the range of interest it is:

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

and:

    if L > 0 & (Z - C) > (A + 1) & (Z - C) - (A + 1) > L Ri = A + 1 + L
    else Ri = Z - C

These are the rules for filtering logs on the blockchain:

For Agents:

  1. all events with agent account address as topic[1]
  • Topics[0]: any
  • Topics[1]: one of accounts with in_use = true
  1. all incoming transfers
  • Topics[0]: Transfer
  • Topics[2]: one of accounts with in_use = true

For Clients: 1.

  • Topics[0]: one of these hashes
    • Transfer
    • LogChannelToppedUp
    • LogChannelCloseRequested
  • Topics[2]: one of the accounts with in_use = true
  • Topics[0]: one of these hashes
    • Tranfer
    • Approval
  • Topics[1]: one of the accounts with in_use = true
  • Topics[0]: one of these hashes
    • LogChannelCreated
    • LogOfferingCreated
    • LogOfferingDeleted
    • LogOfferingPopedUp
    • LogCooperativeChannelClose
    • LogUnCooperativeChannelClose

Documentation

Index

Constants

View Source
const (
	// CRC16("github.com/privatix/dappctrl/monitor") = 0xE464
	ErrFailedToFetchLogs errors.Error = 0xE464<<8 + iota
	ErrFailedToGetActiveAccounts
	ErrFailedToScanRows
	ErrFailedToTraverseAddresses
	ErrFailedToGetHeaderByNumber
	ErrFailedToParseABI
	ErrFailedToUnpack
	ErrWrongNumberOfEventArgs
	ErrWrongBlockArgumentType
	ErrUnsupportedTopic
	ErrInternal
)

Errors.

Variables

This section is empty.

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 {
	EthCallTimeout uint   // In milliseconds.
	InitialBlocks  uint64 // In Ethereum blocks.
	QueryPause     uint   // In milliseconds.
}

Config is a monitor configuration.

func NewConfig

func NewConfig() *Config

NewConfig creates a default blockchain monitor configuration.

type JobsProducers

type JobsProducers map[common.Hash]func(*data.JobEthLog, []data.Job) ([]data.Job, error)

JobsProducers used to bind methods as jobs builder for specific event. First argument is log to proccess. Second argument is jobs produced but not yet created in db. It is used to produce jobs that might have relateds in current produced set.

type Monitor

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

Monitor is a blockchain monitor.

func NewMonitor

func NewMonitor(conf *Config, c Client, db *reform.DB, l log.Logger, psc,
	ptc common.Address, role string, q Queue) (*Monitor, error)

NewMonitor creates new blockchain monitor.

func (*Monitor) Start

func (m *Monitor) Start()

Start starts scanning blockchain for events.

func (*Monitor) Stop

func (m *Monitor) Stop()

Stop stops the monitor.

type Queue

type Queue interface {
	Add(*reform.TX, *data.Job) error
}

Queue is a job queue.

Jump to

Keyboard shortcuts

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