sync

package
v1.10.3-0...-ec03cfc Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2021 License: LGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GetBlockHashesAmountCap is the cap of GetBlockHashes request
	GetBlockHashesAmountCap = 50

	// GetBlocksByNumAmountCap is the cap of request of a single GetBlocksByNum request.
	// This number has an effect on maxMsgBytes as 20MB defined in github.com/harmony-one/harmony/p2p/stream/types.
	// Since we have an assumption that rlp encoded block size is smaller than 2MB (p2p.node.MaxMessageSize),
	// so the max size of a stream message is capped at 2MB * 10 = 20MB.
	GetBlocksByNumAmountCap = 10

	// GetBlocksByHashesAmountCap is the cap of request of single GetBlocksByHashes request
	// This number has an effect on maxMsgBytes as 20MB defined in github.com/harmony-one/harmony/p2p/stream/types.
	// See comments for GetBlocksByNumAmountCap.
	GetBlocksByHashesAmountCap = 10
)

Variables

View Source
var (

	// MyVersion is the version of sync protocol of the local node
	MyVersion = version100

	// MinVersion is the minimum version for matching function
	MinVersion = version100
)
View Source
var (
	// WithHighPriority instruct the request manager to do the request with high
	// priority
	WithHighPriority = requestmanager.WithHighPriority
	// WithBlacklist instruct the request manager not to assign the request to the
	// given streamID
	WithBlacklist = requestmanager.WithBlacklist
	// WithWhitelist instruct the request manager only to assign the request to the
	// given streamID
	WithWhitelist = requestmanager.WithWhitelist
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Chain     engine.ChainReader
	Host      libp2p_host.Host
	Discovery discovery.Discovery
	ShardID   nodeconfig.ShardID
	Network   nodeconfig.NetworkType

	// stream manager config
	SmSoftLowCap int
	SmHardLowCap int
	SmHiCap      int
	DiscBatch    int
}

Config is the sync protocol config

type Option

Option is the additional option to do requests. Currently, two options are supported:

  1. WithHighPriority - do the request in high priority.
  2. WithBlacklist - do the request without the given stream ids as blacklist
  3. WithWhitelist - do the request only with the given stream ids

type Protocol

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

Protocol is the protocol for sync streaming

func NewProtocol

func NewProtocol(config Config) *Protocol

NewProtocol creates a new sync protocol

func (*Protocol) Close

func (p *Protocol) Close()

Close close the protocol

func (*Protocol) GetBlockHashes

func (p *Protocol) GetBlockHashes(ctx context.Context, bns []uint64, opts ...Option) (hashes []common.Hash, stid sttypes.StreamID, err error)

GetBlockHashes do getBlockHashesRequest through sync stream protocol. Return the hash of the given block number. If a block is unknown, the hash will be emptyHash.

func (*Protocol) GetBlocksByHashes

func (p *Protocol) GetBlocksByHashes(ctx context.Context, hs []common.Hash, opts ...Option) (blocks []*types.Block, stid sttypes.StreamID, err error)

GetBlocksByHashes do getBlocksByHashesRequest through sync stream protocol.

func (*Protocol) GetBlocksByNumber

func (p *Protocol) GetBlocksByNumber(ctx context.Context, bns []uint64, opts ...Option) (blocks []*types.Block, stid sttypes.StreamID, err error)

GetBlocksByNumber do getBlocksByNumberRequest through sync stream protocol. Return the block as result, target stream id, and error

func (*Protocol) GetCurrentBlockNumber

func (p *Protocol) GetCurrentBlockNumber(ctx context.Context, opts ...Option) (bn uint64, stid sttypes.StreamID, err error)

GetCurrentBlockNumber get the current block number from remote node

func (*Protocol) GetStreamManager

func (p *Protocol) GetStreamManager() streammanager.StreamManager

GetStreamManager get the underlying stream manager for upper level stream operations

func (*Protocol) HandleStream

func (p *Protocol) HandleStream(raw libp2p_network.Stream)

HandleStream is the stream handle function being registered to libp2p.

func (*Protocol) Match

func (p *Protocol) Match(targetID string) bool

Match checks the compatibility to the target protocol ID.

func (*Protocol) NumStreams

func (p *Protocol) NumStreams() int

NumStreams return the streams with minimum version. Note: nodes with sync version smaller than minVersion is not counted.

func (*Protocol) ProtoID

func (p *Protocol) ProtoID() sttypes.ProtoID

ProtoID return the ProtoID of the sync protocol

func (*Protocol) RemoveStream

func (p *Protocol) RemoveStream(stID sttypes.StreamID)

RemoveStream removes the stream of the given stream ID

func (*Protocol) Specifier

func (p *Protocol) Specifier() string

Specifier return the specifier for the protocol

func (*Protocol) Start

func (p *Protocol) Start()

Start starts the sync protocol

func (*Protocol) SubscribeAddStreamEvent

func (p *Protocol) SubscribeAddStreamEvent(ch chan<- streammanager.EvtStreamAdded) event.Subscription

SubscribeAddStreamEvent subscribe the stream add event

func (*Protocol) Version

func (p *Protocol) Version() *version.Version

Version returns the sync protocol version

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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