Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Option
- type Protocol
- func (p *Protocol) Close()
- func (p *Protocol) GetAccountRange(ctx context.Context, root common.Hash, origin common.Hash, limit common.Hash, ...) (accounts []*message.AccountData, proof [][]byte, stid sttypes.StreamID, ...)
- func (p *Protocol) GetBlockHashes(ctx context.Context, bns []uint64, opts ...Option) (hashes []common.Hash, stid sttypes.StreamID, err error)
- func (p *Protocol) GetBlocksByHashes(ctx context.Context, hs []common.Hash, opts ...Option) (blocks []*types.Block, stid sttypes.StreamID, err error)
- func (p *Protocol) GetBlocksByNumber(ctx context.Context, bns []uint64, opts ...Option) (blocks []*types.Block, stid sttypes.StreamID, err error)
- func (p *Protocol) GetByteCodes(ctx context.Context, hs []common.Hash, bytes uint64, opts ...Option) (codes [][]byte, stid sttypes.StreamID, err error)
- func (p *Protocol) GetCurrentBlockNumber(ctx context.Context, opts ...Option) (bn uint64, stid sttypes.StreamID, err error)
- func (p *Protocol) GetNodeData(ctx context.Context, hs []common.Hash, opts ...Option) (data [][]byte, stid sttypes.StreamID, err error)
- func (p *Protocol) GetRawBlocksByNumber(ctx context.Context, bns []uint64, opts ...Option) (blockBytes [][]byte, sigBytes [][]byte, stid sttypes.StreamID, err error)
- func (p *Protocol) GetReceipts(ctx context.Context, hs []common.Hash, opts ...Option) (receipts []types.Receipts, stid sttypes.StreamID, err error)
- func (p *Protocol) GetStorageRanges(ctx context.Context, root common.Hash, accounts []common.Hash, ...) (slots [][]*message.StorageData, proof [][]byte, stid sttypes.StreamID, ...)
- func (p *Protocol) GetStreamManager() streammanager.StreamManager
- func (p *Protocol) GetTrieNodes(ctx context.Context, root common.Hash, paths []*message.TrieNodePathSet, ...) (nodes [][]byte, stid sttypes.StreamID, err error)
- func (p *Protocol) HandleStream(raw libp2p_network.Stream)
- func (p *Protocol) IsBeaconNode() bool
- func (p *Protocol) Match(targetID protocol.ID) bool
- func (p *Protocol) NumStreams() int
- func (p *Protocol) ProtoID() sttypes.ProtoID
- func (p *Protocol) RemoveStream(stID sttypes.StreamID)
- func (p *Protocol) ShardProtoID() sttypes.ProtoID
- func (p *Protocol) Specifier() string
- func (p *Protocol) Start()
- func (p *Protocol) StreamFailed(stID sttypes.StreamID, reason string)
- func (p *Protocol) SubscribeAddStreamEvent(ch chan<- streammanager.EvtStreamAdded) event.Subscription
- func (p *Protocol) Version() *version.Version
Constants ¶
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 ¶
var ( // MyVersion is the version of sync protocol of the local node MyVersion = version100 // MinVersion is the minimum version for matching function MinVersion = version100 )
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 ¶
type Option = requestmanager.RequestOption
Option is the additional option to do requests. Currently, two options are supported:
- WithHighPriority - do the request in high priority.
- WithBlacklist - do the request without the given stream ids as blacklist
- 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 ¶
NewProtocol creates a new sync 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 (*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 ¶
IsBeaconNode returns true if it is a beacon chain node
func (*Protocol) NumStreams ¶
NumStreams return the streams with minimum version. Note: nodes with sync version smaller than minVersion is not counted.
func (*Protocol) RemoveStream ¶
RemoveStream removes the stream of the given stream ID TODO: add reason to parameters
func (*Protocol) ShardProtoID ¶
ShardProtoID returns the ProtoID of the sync protocol for shard nodes
func (*Protocol) StreamFailed ¶
func (*Protocol) SubscribeAddStreamEvent ¶
func (p *Protocol) SubscribeAddStreamEvent(ch chan<- streammanager.EvtStreamAdded) event.Subscription
SubscribeAddStreamEvent subscribe the stream add event