iotex-core: Index | Files

package blocksync

import ""


Package Files

blocksync.go buffer.go slidingwindow.go util.go worker.go


const (
    // Open indicates an open state
    Open = iota
    // Closing indicates a closing state
    Closing = Open + 1
    // Closed indicates a closed state
    Closed = Closing + 1


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

WindowSize defines the bufferSize of window

type BlockDAO Uses

type BlockDAO interface {
    GetBlockByHeight(uint64) (*block.Block, error)

BlockDAO represents the block data access object

type BlockSync Uses

type BlockSync interface {

    TargetHeight() uint64
    ProcessSyncRequest(ctx context.Context, peer peerstore.PeerInfo, sync *iotexrpc.BlockSync) error
    ProcessBlock(ctx context.Context, blk *block.Block) error
    ProcessBlockSync(ctx context.Context, blk *block.Block) error

BlockSync defines the interface of blocksyncer

func NewBlockSyncer Uses

func NewBlockSyncer(
    cfg config.Config,
    chain blockchain.Blockchain,
    dao BlockDAO,
    ap actpool.ActPool,
    cs consensus.Consensus,
    opts ...Option,
) (BlockSync, error)

NewBlockSyncer returns a new block syncer instance

type Config Uses

type Config struct {
    // contains filtered or unexported fields

Config represents the config to setup blocksync

type Neighbors Uses

type Neighbors func(ctx context.Context) ([]peerstore.PeerInfo, error)

Neighbors returns the neighbors' addresses

type Option Uses

type Option func(cfg *Config) error

Option is the option to override the blocksync config

func WithNeighbors Uses

func WithNeighbors(neighborsHandler Neighbors) Option

WithNeighbors is the option to set the neighbors callback

func WithUnicastOutBound Uses

func WithUnicastOutBound(unicastHandler UnicastOutbound) Option

WithUnicastOutBound is the option to set the unicast callback

type SlidingWindow Uses

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

SlidingWindow implements a sliding window

func NewSlidingWindow Uses

func NewSlidingWindow() *SlidingWindow

NewSlidingWindow returns a SlidingWindow instance

func (*SlidingWindow) Next Uses

func (sw *SlidingWindow) Next() uint64

Next returns the next close value of the sliding window

func (*SlidingWindow) SetRange Uses

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

SetRange set the initial range for sliding window

func (*SlidingWindow) TurnClose Uses

func (sw *SlidingWindow) TurnClose() bool

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

func (*SlidingWindow) TurnOpen Uses

func (sw *SlidingWindow) TurnOpen() bool

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

func (*SlidingWindow) Update Uses

func (sw *SlidingWindow) Update(value uint64)

Update updates the window [close, open]

type UnicastOutbound Uses

type UnicastOutbound func(ctx context.Context, peer peerstore.PeerInfo, msg proto.Message) error

UnicastOutbound sends a unicast message to the given address

Package blocksync imports 19 packages (graph) and is imported by 1 packages. Updated 2020-03-29. Refresh now. Tools for package owners.