sync

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: LGPL-3.0 Imports: 36 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/zennittians/intelchain/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/zennittians/intelchain/p2p/stream/types.
	// See comments for GetBlocksByNumAmountCap.
	GetBlocksByHashesAmountCap = 10

	// GetNodeDataCap is the cap of request of single GetNodeData request
	// This number has an effect on maxMsgBytes as 20MB defined in github.com/zennittians/intelchain/p2p/stream/types.
	GetNodeDataCap = 256

	// GetReceiptsCap is the cap of request of single GetReceipts request
	// This number has an effect on maxMsgBytes as 20MB defined in github.com/zennittians/intelchain/p2p/stream/types.
	GetReceiptsCap = 128

	// GetStorageRangesRequestCap is the cap of request of single GetStorageRanges request
	// This number has an effect on maxMsgBytes as 20MB defined in github.com/zennittians/intelchain/p2p/stream/types.
	GetStorageRangesRequestCap = 256

	// GetByteCodesRequestCap is the cap of request of single GetByteCodes request
	// This number has an effect on maxMsgBytes as 20MB defined in github.com/zennittians/intelchain/p2p/stream/types.
	GetByteCodesRequestCap = 128

	// GetTrieNodesRequestCap is the cap of request of single GetTrieNodes request
	// This number has an effect on maxMsgBytes as 20MB defined in github.com/zennittians/intelchain/p2p/stream/types.
	GetTrieNodesRequestCap = 128

	// MaxStreamFailures is the maximum allowed failures before stream gets removed
	MaxStreamFailures = 5

	// FaultRecoveryThreshold is the minimum duration before it resets the previous failures
	// So, if stream hasn't had any issue for a certain amount of time since last failure, we can still trust it
	FaultRecoveryThreshold = 30 * time.Minute
)

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
	BeaconNode           bool
	MaxAdvertiseWaitTime int
	// 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) GetAccountRange

func (p *Protocol) GetAccountRange(ctx context.Context, root common.Hash, origin common.Hash, limit common.Hash, bytes uint64, opts ...Option) (accounts []*message.AccountData, proof [][]byte, stid sttypes.StreamID, err error)

GetAccountRange do getAccountRange through sync stream protocol. returns the accounts along with proofs as result, target stream id, and error

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) GetByteCodes

func (p *Protocol) GetByteCodes(ctx context.Context, hs []common.Hash, bytes uint64, opts ...Option) (codes [][]byte, stid sttypes.StreamID, err error)

GetByteCodes do getByteCodes through sync stream protocol. returns the codes 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) GetNodeData

func (p *Protocol) GetNodeData(ctx context.Context, hs []common.Hash, opts ...Option) (data [][]byte, stid sttypes.StreamID, err error)

GetNodeData do getNodeData through sync stream protocol. Return the state node data as result, target stream id, and error

func (*Protocol) GetRawBlocksByNumber

func (p *Protocol) GetRawBlocksByNumber(ctx context.Context, bns []uint64, opts ...Option) (blockBytes [][]byte, sigBytes [][]byte, stid sttypes.StreamID, err error)

func (*Protocol) GetReceipts

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

GetReceipts do getReceiptsRequest through sync stream protocol. Return the receipts as result, target stream id, and error

func (*Protocol) GetStorageRanges

func (p *Protocol) GetStorageRanges(ctx context.Context, root common.Hash, accounts []common.Hash, origin common.Hash, limit common.Hash, bytes uint64, opts ...Option) (slots [][]*message.StorageData, proof [][]byte, stid sttypes.StreamID, err error)

GetStorageRanges do getStorageRanges through sync stream protocol. returns the slots along with proofs as result, target stream id, and error

func (*Protocol) GetStreamManager

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

GetStreamManager get the underlying stream manager for upper level stream operations

func (*Protocol) GetTrieNodes

func (p *Protocol) GetTrieNodes(ctx context.Context, root common.Hash, paths []*message.TrieNodePathSet, bytes uint64, opts ...Option) (nodes [][]byte, stid sttypes.StreamID, err error)

GetTrieNodes do getTrieNodes through sync stream protocol. returns the nodes as result, target stream id, and error

func (*Protocol) HandleStream

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

HandleStream is the stream handle function being registered to libp2p.

func (*Protocol) IsBeaconNode

func (p *Protocol) IsBeaconNode() bool

IsBeaconNode returns true if it is a beacon chain node

func (*Protocol) Match

func (p *Protocol) Match(targetID protocol.ID) 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 TODO: add reason to parameters

func (*Protocol) ShardProtoID

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

ShardProtoID returns the ProtoID of the sync protocol for shard nodes

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) StreamFailed

func (p *Protocol) StreamFailed(stID sttypes.StreamID, reason string)

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