blocksync

package
v1.2.0-rc0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

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 uint64 = 8

WindowSize defines the bufferSize of window

Functions

This section is empty.

Types

type BlockByHeight added in v1.2.0

type BlockByHeight func(uint64) (*block.Block, error)

BlockByHeight returns the block of a given height

type BlockSync

type BlockSync interface {
	lifecycle.StartStopper

	TargetHeight() uint64
	ProcessSyncRequest(context.Context, uint64, uint64, func(context.Context, *block.Block) error) error
	ProcessBlock(context.Context, *block.Block) error
	SyncStatus() string
}

BlockSync defines the interface of blocksyncer

func NewBlockSyncer

func NewBlockSyncer(
	cfg config.BlockSync,
	tipHeightHandler TipHeight,
	blockByHeightHandler BlockByHeight,
	commitBlockHandler CommitBlock,
	requestBlocksHandler RequestBlocks,
) (BlockSync, error)

NewBlockSyncer returns a new block syncer instance

type CommitBlock added in v1.2.0

type CommitBlock func(*block.Block) error

CommitBlock commits a block to blockchain

type RequestBlocks added in v1.2.0

type RequestBlocks func(ctx context.Context, start uint64, end uint64) error

RequestBlocks send a block request to peers

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() uint64

Next returns the next close value of the sliding window

func (*SlidingWindow) SetRange

func (sw *SlidingWindow) SetRange(left uint64, right uint64) 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 uint64)

Update updates the window [close, open]

type TipHeight added in v1.2.0

type TipHeight func() uint64

TipHeight returns the tip height of blockchain

Jump to

Keyboard shortcuts

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