Documentation ¶
Overview ¶
Package fetch contains mechanism to fetch Data from remote peers
nolint
nolint
Index ¶
- type Config
- type DataHandlers
- type Fetch
- func (f *Fetch) AddPeersFromHash(fromHash types.Hash32, toHashes []types.Hash32)
- func (f *Fetch) GetEpochATXIDs(ctx context.Context, eid types.EpochID, okCB func([]byte, p2p.Peer), ...) error
- func (f *Fetch) GetHash(hash types.Hash32, h datastore.Hint, validateHash bool) chan ftypes.HashDataPromiseResult
- func (f *Fetch) GetHashes(hashes []types.Hash32, hint datastore.Hint, validateHash bool) map[types.Hash32]chan ftypes.HashDataPromiseResult
- func (f *Fetch) GetLayerData(ctx context.Context, lid types.LayerID, okCB func([]byte, p2p.Peer, int), ...) error
- func (f *Fetch) GetLayerOpinions(ctx context.Context, lid types.LayerID, okCB func([]byte, p2p.Peer, int), ...) error
- func (f *Fetch) RegisterPeerHashes(peer p2p.Peer, hashes []types.Hash32)
- func (f *Fetch) Start()
- func (f *Fetch) Stop()
- type HashPeers
- type HashPeersCache
- func (hpc *HashPeersCache) Add(hash types.Hash32, peer p2p.Peer)
- func (hpc *HashPeersCache) AddPeersFromHash(fromHash types.Hash32, toHashes []types.Hash32)
- func (hpc *HashPeersCache) GetRandom(hash types.Hash32, hint datastore.Hint, rng *rand.Rand) (p2p.Peer, bool)
- func (hpc *HashPeersCache) RegisterPeerHashes(peer p2p.Peer, hashes []types.Hash32)
- type LayerData
- type LayerOpinion
- func (t *LayerOpinion) DecodeScale(dec *scale.Decoder) (total int, err error)
- func (t *LayerOpinion) EncodeScale(enc *scale.Encoder) (total int, err error)
- func (lo *LayerOpinion) MarshalLogObject(encoder log.ObjectEncoder) error
- func (lo *LayerOpinion) Peer() p2p.Peer
- func (lo *LayerOpinion) SetPeer(p p2p.Peer)
- type LayerPromiseData
- type LayerPromiseOpinions
- type Logic
- func (l *Logic) AddPeersFromHash(fromHash types.Hash32, toHashes []types.Hash32)
- func (l *Logic) Close()
- func (l *Logic) GetAtxs(ctx context.Context, ids []types.ATXID) error
- func (l *Logic) GetBallots(ctx context.Context, ids []types.BallotID) error
- func (l *Logic) GetBlockTxs(ctx context.Context, ids []types.TransactionID) error
- func (l *Logic) GetBlocks(ctx context.Context, ids []types.BlockID) error
- func (l *Logic) GetEpochATXs(ctx context.Context, eid types.EpochID) error
- func (l *Logic) GetPoetProof(ctx context.Context, id types.Hash32) error
- func (l *Logic) GetProposalTxs(ctx context.Context, ids []types.TransactionID) error
- func (l *Logic) GetProposals(ctx context.Context, ids []types.ProposalID) error
- func (l *Logic) PollLayerData(ctx context.Context, layerID types.LayerID) chan LayerPromiseData
- func (l *Logic) PollLayerOpinions(ctx context.Context, layerID types.LayerID) chan LayerPromiseOpinions
- func (l *Logic) RegisterPeerHashes(peer p2p.Peer, hashes []types.Hash32)
- func (l *Logic) Start()
- type RequestBatch
- type RequestMessage
- type ResponseBatch
- type ResponseMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { BatchTimeout int // in milliseconds MaxRetriesForPeer int BatchSize int RequestTimeout int // in seconds MaxRetriesForRequest int }
Config is the configuration file of the Fetch component.
func DefaultConfig ¶ added in v1.0.0
func DefaultConfig() Config
DefaultConfig is the default config for the fetch component.
type DataHandlers ¶
type DataHandlers struct { ATX atxHandler Ballot ballotHandler Block blockHandler Proposal proposalHandler TX txHandler Poet poetHandler }
DataHandlers collects handlers for different data type.
type Fetch ¶
type Fetch struct {
// contains filtered or unexported fields
}
Fetch is the main struct that contains network peers and logic to batch and dispatch hash fetch requests.
func (*Fetch) AddPeersFromHash ¶
AddPeersFromHash adds peers from one hash to others.
func (*Fetch) GetEpochATXIDs ¶
func (f *Fetch) GetEpochATXIDs(ctx context.Context, eid types.EpochID, okCB func([]byte, p2p.Peer), errFunc func(error)) error
GetEpochATXIDs get all ATXIDs targeted for a specified epoch from peers.
func (*Fetch) GetHash ¶
func (f *Fetch) GetHash(hash types.Hash32, h datastore.Hint, validateHash bool) chan ftypes.HashDataPromiseResult
GetHash is the regular buffered call to get a specific hash, using provided hash, h as hint the receiving end will know where to look for the hash, this function returns HashDataPromiseResult channel that will hold Data received or error.
func (*Fetch) GetHashes ¶
func (f *Fetch) GetHashes(hashes []types.Hash32, hint datastore.Hint, validateHash bool) map[types.Hash32]chan ftypes.HashDataPromiseResult
GetHashes gets a list of hashes to be fetched and will return a map of hashes and their respective promise channels.
func (*Fetch) GetLayerData ¶ added in v1.0.0
func (f *Fetch) GetLayerData(ctx context.Context, lid types.LayerID, okCB func([]byte, p2p.Peer, int), errCB func(error, p2p.Peer, int)) error
GetLayerData get layer data from peers.
func (*Fetch) GetLayerOpinions ¶ added in v1.0.0
func (f *Fetch) GetLayerOpinions(ctx context.Context, lid types.LayerID, okCB func([]byte, p2p.Peer, int), errCB func(error, p2p.Peer, int)) error
GetLayerOpinions get opinions on data in the specified layer from peers.
func (*Fetch) RegisterPeerHashes ¶ added in v1.0.0
RegisterPeerHashes registers provided peer for a list of hashes.
type HashPeersCache ¶ added in v1.0.0
HashPeersCache holds lru cache of peers to pull hash from.
func NewHashPeersCache ¶ added in v1.0.0
func NewHashPeersCache(size int) *HashPeersCache
NewHashPeersCache creates a new hash-to-peers cache.
func (*HashPeersCache) Add ¶ added in v1.0.0
func (hpc *HashPeersCache) Add(hash types.Hash32, peer p2p.Peer)
Add is a thread-safe version of add.
func (*HashPeersCache) AddPeersFromHash ¶
func (hpc *HashPeersCache) AddPeersFromHash(fromHash types.Hash32, toHashes []types.Hash32)
AddPeersFromHash adds peers from one hash to others.
func (*HashPeersCache) GetRandom ¶ added in v1.0.0
func (hpc *HashPeersCache) GetRandom(hash types.Hash32, hint datastore.Hint, rng *rand.Rand) (p2p.Peer, bool)
GetRandom returns a random peer for a given hash.
func (*HashPeersCache) RegisterPeerHashes ¶ added in v1.0.0
func (hpc *HashPeersCache) RegisterPeerHashes(peer p2p.Peer, hashes []types.Hash32)
RegisterPeerHashes registers provided peer for a list of hashes.
type LayerData ¶ added in v1.0.0
LayerData is the data response for a given layer ID.
func (*LayerData) DecodeScale ¶ added in v1.0.0
func (*LayerData) EncodeScale ¶ added in v1.0.0
type LayerOpinion ¶ added in v1.0.0
type LayerOpinion struct { EpochWeight uint64 PrevAggHash types.Hash32 Verified types.LayerID Valid, Invalid []types.BlockID Cert *types.Certificate // contains filtered or unexported fields }
LayerOpinion is the response for opinion for a given layer.
func (*LayerOpinion) DecodeScale ¶ added in v1.0.0
func (t *LayerOpinion) DecodeScale(dec *scale.Decoder) (total int, err error)
func (*LayerOpinion) EncodeScale ¶ added in v1.0.0
func (t *LayerOpinion) EncodeScale(enc *scale.Encoder) (total int, err error)
func (*LayerOpinion) MarshalLogObject ¶ added in v1.0.0
func (lo *LayerOpinion) MarshalLogObject(encoder log.ObjectEncoder) error
MarshalLogObject implements logging encoder for LayerOpinion.
func (*LayerOpinion) SetPeer ¶ added in v1.0.0
func (lo *LayerOpinion) SetPeer(p p2p.Peer)
SetPeer ...
type LayerPromiseData ¶
LayerPromiseData is the result of trying to fetch data for an entire layer.
type LayerPromiseOpinions ¶
type LayerPromiseOpinions struct { Err error Layer types.LayerID Opinions []*LayerOpinion }
LayerPromiseOpinions is the result of trying to fetch opinions for a layer.
type Logic ¶
type Logic struct {
// contains filtered or unexported fields
}
Logic is the struct containing components needed to follow layer fetching logic.
func NewLogic ¶
func NewLogic(cfg Config, cdb *datastore.CachedDB, msh meshProvider, host *p2p.Host, handlers DataHandlers, log log.Log) *Logic
NewLogic creates a new instance of layer fetching logic.
func (*Logic) AddPeersFromHash ¶
AddPeersFromHash is a wrapper around fetcher's AddPeersFromHash.
func (*Logic) GetAtxs ¶
GetAtxs gets the data for given atx IDs and validates them. returns an error if at least one ATX cannot be fetched.
func (*Logic) GetBallots ¶
GetBallots gets data for the specified BallotIDs and validates them.
func (*Logic) GetBlockTxs ¶
GetBlockTxs fetches the txs provided as IDs and saves them, they will be validated before block is applied.
func (*Logic) GetEpochATXs ¶
GetEpochATXs fetches all atxs received by peer for given layer.
func (*Logic) GetPoetProof ¶
GetPoetProof gets poet proof from remote peer.
func (*Logic) GetProposalTxs ¶
GetProposalTxs fetches the txs provided as IDs and validates them, returns an error if one TX failed to be fetched.
func (*Logic) GetProposals ¶
GetProposals gets the data for given proposal IDs from peers.
func (*Logic) PollLayerData ¶
PollLayerData polls peers for the data in the specified layer. it returns a channel for the caller to be notified when responses are received from all peers.
func (*Logic) PollLayerOpinions ¶
func (l *Logic) PollLayerOpinions(ctx context.Context, layerID types.LayerID) chan LayerPromiseOpinions
PollLayerOpinions polls peers for the opinions on blocks in the specified layer. it returns a channel for the caller to be notified when responses are received from all peers.
func (*Logic) RegisterPeerHashes ¶
RegisterPeerHashes is a wrapper around fetcher's RegisterPeerHashes.
type RequestBatch ¶ added in v1.0.0
type RequestBatch struct { ID types.Hash32 Requests []RequestMessage }
RequestBatch is a batch of requests and a hash of all requests as ID.
func (*RequestBatch) DecodeScale ¶ added in v1.0.0
func (t *RequestBatch) DecodeScale(dec *scale.Decoder) (total int, err error)
func (*RequestBatch) EncodeScale ¶ added in v1.0.0
func (t *RequestBatch) EncodeScale(enc *scale.Encoder) (total int, err error)
type RequestMessage ¶ added in v1.0.0
RequestMessage is sent to the peer for hash query.
func (*RequestMessage) DecodeScale ¶ added in v1.0.0
func (t *RequestMessage) DecodeScale(dec *scale.Decoder) (total int, err error)
func (*RequestMessage) EncodeScale ¶ added in v1.0.0
func (t *RequestMessage) EncodeScale(enc *scale.Encoder) (total int, err error)
type ResponseBatch ¶ added in v1.0.0
type ResponseBatch struct { ID types.Hash32 Responses []ResponseMessage }
ResponseBatch is the response struct send for a RequestBatch. the ResponseBatch ID must be the same as stated in RequestBatch even if not all Data is present.
func (*ResponseBatch) DecodeScale ¶ added in v1.0.0
func (t *ResponseBatch) DecodeScale(dec *scale.Decoder) (total int, err error)
func (*ResponseBatch) EncodeScale ¶ added in v1.0.0
func (t *ResponseBatch) EncodeScale(enc *scale.Encoder) (total int, err error)
type ResponseMessage ¶ added in v1.0.0
ResponseMessage is sent to the node as a response.
func (*ResponseMessage) DecodeScale ¶ added in v1.0.0
func (t *ResponseMessage) DecodeScale(dec *scale.Decoder) (total int, err error)
func (*ResponseMessage) EncodeScale ¶ added in v1.0.0
func (t *ResponseMessage) EncodeScale(enc *scale.Encoder) (total int, err error)