blocksync

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2018 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// Idle indicates an idle state
	Idle = iota
	// Init indicates the state when first block is received
	Init = Idle + 1
	// Active indicates the state after first block has been processed
	Active = Init + 1
)
View Source
const (
	// Open indicates an open state
	Open = iota
	// Closing indicates a closing state
	Closing = Open + 1
	// Closed indicates a closed state
	Closed = Closing + 1
)

Variables

View Source
var (
	// ErrInvalidRange indicates invalid range.
	ErrInvalidRange = errors.New("invalid open/close values")
)
View Source
var WindowSize uint32 = 8

WindowSize defines the size of window

Functions

func SyncTaskInterval

func SyncTaskInterval(cfg *config.Config) time.Duration

SyncTaskInterval returns the recurring sync task interval, or 0 if this config should not need to run sync task

Types

type BlockSync

type BlockSync interface {
	Start() error
	Stop() error
	P2P() *network.Overlay
	ProcessSyncRequest(sender string, sync *pb.BlockSync) error
	ProcessBlock(blk *bc.Block) error
	ProcessBlockSync(blk *bc.Block) error
}

BlockSync defines the interface of blocksyncer

func NewBlockSyncer

func NewBlockSyncer(cfg *config.Config, chain *bc.Blockchain, tp txpool.TxPool, p2p *network.Overlay, dp delegate.Pool) BlockSync

NewBlockSyncer returns a new block syncer instance

type SlidingWindow

type SlidingWindow struct {
	State int
	// contains filtered or unexported fields
}

SlidingWindow implements a sliding window

func NewSlidingWindow

func NewSlidingWindow() *SlidingWindow

NewSlidingWindow returns a SlidingWindow instance

func (*SlidingWindow) Next

func (sw *SlidingWindow) Next() uint32

Next returns the next close value of the sliding window

func (*SlidingWindow) SetRange

func (sw *SlidingWindow) SetRange(left uint32, right uint32) error

SetRange set the initial range for sliding window

func (*SlidingWindow) TurnClose

func (sw *SlidingWindow) TurnClose() bool

TurnClose returns true if State transitions Open --> Closing/Closed

func (*SlidingWindow) TurnOpen

func (sw *SlidingWindow) TurnOpen() bool

TurnOpen returns true if State transitions Closing/Closed --> Open

func (*SlidingWindow) Update

func (sw *SlidingWindow) Update(value uint32)

Update updates the window [close, open]

Jump to

Keyboard shortcuts

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