bc

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: GPL-3.0 Imports: 20 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).

Number of blocks to filter within one request is used to split total range in sub ranges (the relevant setting is eth.event.blocklimit).

On clients additional backward search is done to get offerings. The number of blocks to see back is used (the relevant setting is eth.event.offeringsfreshblocks).

Forward search range of interest (Agent & Client)

Let:

  • A = last processed block number
  • Z = most recent block number on the blockchain
  • C = the min confirmations setting
  • L = the limit blocks to retrieve setting

Thus the range of interest it is:

if (A + 1) < (A + 1 + min(L, Z-C)) => [A+1, A + 1 + min(L, Z-C) ]
else range of interest is empty

Backward search for offerings (Client only)

Let:

  • A = last block number the last processed range started from
  • Z = most recent block number on the blockchain
  • C = the min confirmations setting
  • L = the limit blocks to retrieve setting
  • F = the offerings fresh block setting

Thus the range of interest for backward offerings earch is:

if (A - L - 1) < (A - 1) => [A - L - 1; A - 1]
else range of interest is empty

Filtering rules

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/bc") = 0xD8D2
	ErrFailedToFetchLogs errors.Error = 0xD8D2<<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) ([]types.Log, error)
	HeaderByNumber(ctx context.Context,
		number *big.Int) (*types.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.
	RateAfter      uint   // Number of ethereum channel close events to initiate rating calculation after.
}

Config is a monitor configuration.

func NewConfig

func NewConfig() *Config

NewConfig creates a default blockchain monitor configuration.

type Monitor

type Monitor struct {
	// RequestTimeout is a timeout for requeting anything using Client.
	RequestTimeout time.Duration
	// Queue is a job queue.
	Queue Queue
	// NextRound returns queries to get ethereum logs at the next round of monitoring.
	NextRound func(latestBlock uint64) ([]ethereum.FilterQuery, func(*reform.TX) error, error)
	// JobsForLog return jobs to create for given ethereum log.
	JobsForLog func(*data.JobEthLog) ([]data.Job, error)
	// RoundsInterval is an interval at which monitoring rounds are run.
	RoundsInterval time.Duration
	// contains filtered or unexported fields
}

Monitor continuously scans blockchain for new ethereum logs and creates jobs for them.

Each round of monitoring consists of adding jobs for ethereum logs filtered by filter queries. Each round start by NextRound and DoneRound.

func NewMonitor

func NewMonitor(config *Config, client Client, queue Queue,
	db *reform.DB, logger log.Logger, pscAddr, ptcAddr common.Address, role string) (*Monitor, error)

NewMonitor creates blockchain monitor.

func (*Monitor) Round

func (m *Monitor) Round() error

Round is one round of monitoring.

func (*Monitor) Start

func (m *Monitor) Start()

Start starts monitoring rounds.

func (*Monitor) Stop

func (m *Monitor) Stop()

Stop stops monitoring.

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