blocksync

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Interval:              30 * time.Second,
	ProcessSyncRequestTTL: 10 * time.Second,
	BufferSize:            200,
	IntervalSize:          20,
	MaxRepeat:             3,
	RepeatDecayStep:       1,
}

DefaultConfig is the default config

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 BlockPeer added in v1.8.2

type BlockPeer func(string)

BlockPeer adds the peer into blacklist in p2p layer

type BlockSync

type BlockSync interface {
	lifecycle.StartStopper
	nodestats.StatsReporter
	// TargetHeight returns the target height to sync to
	TargetHeight() uint64
	// ProcessSyncRequest processes a block sync request
	ProcessSyncRequest(context.Context, peer.AddrInfo, uint64, uint64) error
	// ProcessBlock processes an incoming block
	ProcessBlock(context.Context, string, *block.Block) error
	// SyncStatus report block sync status
	SyncStatus() (startingHeight uint64, currentHeight uint64, targetHeight uint64, syncSpeedDesc string)
}

BlockSync defines the interface of blocksyncer

func NewBlockSyncer

func NewBlockSyncer(
	cfg Config,
	tipHeightHandler TipHeight,
	blockByHeightHandler BlockByHeight,
	commitBlockHandler CommitBlock,
	p2pNeighbor Neighbors,
	uniCastHandler UniCastOutbound,
	blockP2pPeer BlockPeer,
) (BlockSync, error)

NewBlockSyncer returns a new block syncer instance

func NewDummyBlockSyncer added in v1.6.3

func NewDummyBlockSyncer() BlockSync

NewDummyBlockSyncer creates a dummy BlockSync

type CommitBlock added in v1.2.0

type CommitBlock func(*block.Block) error

CommitBlock commits a block to blockchain

type Config added in v0.4.4

type Config struct {
	Interval              time.Duration `yaml:"interval"` // update duration
	ProcessSyncRequestTTL time.Duration `yaml:"processSyncRequestTTL"`
	BufferSize            uint64        `yaml:"bufferSize"`
	IntervalSize          uint64        `yaml:"intervalSize"`
	// MaxRepeat is the maximal number of repeat of a block sync request
	MaxRepeat int `yaml:"maxRepeat"`
	// RepeatDecayStep is the step for repeat number decreasing by 1
	RepeatDecayStep int `yaml:"repeatDecayStep"`
}

Config is the config struct for the BlockSync

type Neighbors added in v0.4.4

type Neighbors func() ([]peer.AddrInfo, error)

Neighbors acquires p2p neighbors in the network

type TipHeight added in v1.2.0

type TipHeight func() uint64

TipHeight returns the tip height of blockchain

type UniCastOutbound added in v1.8.2

type UniCastOutbound func(context.Context, peer.AddrInfo, proto.Message) error

UniCastOutbound sends a unicase message to the peer

Jump to

Keyboard shortcuts

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