sync

package
v0.0.0-...-8aa4d74 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SyncPoolSize             uint64 = 300
	FetchTimeout                    = 1 * time.Minute
	RetryInterval                   = 10 * time.Second
	CheckBlockHeightInterval        = 30 * time.Second
	CheckPrevBlockInterval          = 30 * time.Second
	WatchInterval                   = 5 * time.Second
)
View Source
const MaxRetries = 10

Variables

View Source
var ErrFinished = errors.New("Add: Pool is finished")

Functions

func SetLogging

func SetLogging(level logging.Lvl, handler logging.Handler)

func Try

func Try(maxRetries int, fn TryFunc) error

func TryForever

func TryForever(fn TryFunc) error

Types

type AfterFunc

type AfterFunc = func(time.Duration) <-chan time.Time

type BlockFetcher

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

func NewBlockFetcher

func NewBlockFetcher(
	cm network.ConnectionManager,
	client Doer,
	st *storage.LevelDBBackend,
	localNode *node.LocalNode,
	opts ...BlockFetcherOption) *BlockFetcher

func (*BlockFetcher) Fetch

func (f *BlockFetcher) Fetch(ctx context.Context, syncInfo *SyncInfo) (*SyncInfo, error)

type BlockFetcherOption

type BlockFetcherOption = func(f *BlockFetcher)

type BlockValidator

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

func (*BlockValidator) Validate

func (v *BlockValidator) Validate(ctx context.Context, syncInfo *SyncInfo) error

type BlockValidatorOption

type BlockValidatorOption func(*BlockValidator)

type Config

type Config struct {
	SyncPoolSize             uint64
	FetchTimeout             time.Duration
	RetryInterval            time.Duration
	CheckBlockHeightInterval time.Duration
	CheckPrevBlockInterval   time.Duration
	WatchInterval            time.Duration
	// contains filtered or unexported fields
}

func (*Config) LoggingConfig

func (c *Config) LoggingConfig()

func (*Config) NewFetcher

func (c *Config) NewFetcher() Fetcher

func (*Config) NewHTTP2Client

func (c *Config) NewHTTP2Client() *common.HTTP2Client

func (*Config) NewSyncer

func (c *Config) NewSyncer() *Syncer

func (*Config) NewValidator

func (c *Config) NewValidator() Validator

func (*Config) NewWatcher

func (c *Config) NewWatcher(s SyncController) *Watcher

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

type Fetcher

type Fetcher interface {
	Fetch(ctx context.Context, syncInfo *SyncInfo) (*SyncInfo, error)
}

type NodeList

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

func (*NodeList) NodeAddrs

func (l *NodeList) NodeAddrs() []string

func (*NodeList) SetLatestNodeAddrs

func (l *NodeList) SetLatestNodeAddrs(addrs []string)

type Pool

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

func NewPool

func NewPool(n uint64) *Pool

func (*Pool) Add

func (p *Pool) Add(ctx context.Context, f func()) error

func (*Pool) Finish

func (p *Pool) Finish()

func (*Pool) TryAdd

func (p *Pool) TryAdd(ctx context.Context, f func()) bool

type SyncController

type SyncController interface {
	SetSyncTargetBlock(ctx context.Context, height uint64, nodeAddressList []string) error
}

type SyncInfo

type SyncInfo struct {
	Height uint64
	Block  *block.Block
	Bts    []*block.BlockTransaction
	Ptx    *ballot.ProposerTransaction

	// Fetching target node addresses, NodeList is  the validators which
	// participated and confirmed the consensus of latest ballot.
	NodeList *NodeList
}

func (*SyncInfo) NodeAddrs

func (s *SyncInfo) NodeAddrs() []string

type SyncProgress

type SyncProgress struct {
	StartingBlock uint64 // Block number where sync began
	CurrentBlock  uint64 // Current block number where sync is at
	HighestBlock  uint64 // Highest alleged block number in the chain
}

type Syncer

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

func NewSyncer

func NewSyncer(
	f Fetcher,
	v Validator,
	st *storage.LevelDBBackend,
	opts ...SyncerOption) *Syncer

func (*Syncer) SetSyncTargetBlock

func (s *Syncer) SetSyncTargetBlock(ctx context.Context, height uint64, nodeAddrs []string) error

func (*Syncer) Start

func (s *Syncer) Start() error

func (*Syncer) Stop

func (s *Syncer) Stop() error

func (*Syncer) SyncProgress

func (s *Syncer) SyncProgress(ctx context.Context) (*SyncProgress, error)

type SyncerOption

type SyncerOption func(s *Syncer)

type TryFunc

type TryFunc func(attempt int) (retry bool, err error)

type Validator

type Validator interface {
	Validate(context.Context, *SyncInfo) error
}

type Watcher

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

func NewWatcher

func NewWatcher(
	syncer SyncController,
	client Doer,
	cm network.ConnectionManager,
	st *storage.LevelDBBackend,
	ln *node.LocalNode,
	opts ...WatcherOption) *Watcher

func (*Watcher) SetLogger

func (w *Watcher) SetLogger(l log15.Logger)

func (*Watcher) Start

func (w *Watcher) Start() error

func (*Watcher) Stop

func (w *Watcher) Stop() error

type WatcherOption

type WatcherOption func(*Watcher)

Jump to

Keyboard shortcuts

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