fetch

package
v0.2.18-beta.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: MIT Imports: 23 Imported by: 1

Documentation

Overview

Package fetch contains mechanism to fetch Data from remote peers

nolint

nolint

Index

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

func (f *Fetch) AddPeersFromHash(fromHash types.Hash32, toHashes []types.Hash32)

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

func (f *Fetch) RegisterPeerHashes(peer p2p.Peer, hashes []types.Hash32)

RegisterPeerHashes registers provided peer for a list of hashes.

func (*Fetch) Start

func (f *Fetch) Start()

Start starts handling fetch requests.

func (*Fetch) Stop

func (f *Fetch) Stop()

Stop stops handling fetch requests.

type HashPeers added in v1.0.0

type HashPeers map[p2p.Peer]struct{}

HashPeers holds registered peers for a hash.

type HashPeersCache added in v1.0.0

type HashPeersCache struct {
	*lru.Cache
	// contains filtered or unexported fields
}

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

type LayerData struct {
	Ballots []types.BallotID
	Blocks  []types.BlockID
}

LayerData is the data response for a given layer ID.

func (*LayerData) DecodeScale added in v1.0.0

func (t *LayerData) DecodeScale(dec *scale.Decoder) (total int, err error)

func (*LayerData) EncodeScale added in v1.0.0

func (t *LayerData) EncodeScale(enc *scale.Encoder) (total int, err error)

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) Peer added in v1.0.0

func (lo *LayerOpinion) Peer() p2p.Peer

Peer ...

func (*LayerOpinion) SetPeer added in v1.0.0

func (lo *LayerOpinion) SetPeer(p p2p.Peer)

SetPeer ...

type LayerPromiseData

type LayerPromiseData struct {
	Err   error
	Layer types.LayerID
}

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

func (l *Logic) AddPeersFromHash(fromHash types.Hash32, toHashes []types.Hash32)

AddPeersFromHash is a wrapper around fetcher's AddPeersFromHash.

func (*Logic) Close

func (l *Logic) Close()

Close closes all running workers.

func (*Logic) GetAtxs

func (l *Logic) GetAtxs(ctx context.Context, ids []types.ATXID) error

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

func (l *Logic) GetBallots(ctx context.Context, ids []types.BallotID) error

GetBallots gets data for the specified BallotIDs and validates them.

func (*Logic) GetBlockTxs

func (l *Logic) GetBlockTxs(ctx context.Context, ids []types.TransactionID) error

GetBlockTxs fetches the txs provided as IDs and saves them, they will be validated before block is applied.

func (*Logic) GetBlocks

func (l *Logic) GetBlocks(ctx context.Context, ids []types.BlockID) error

GetBlocks gets the data for given block IDs from peers.

func (*Logic) GetEpochATXs

func (l *Logic) GetEpochATXs(ctx context.Context, eid types.EpochID) error

GetEpochATXs fetches all atxs received by peer for given layer.

func (*Logic) GetPoetProof

func (l *Logic) GetPoetProof(ctx context.Context, id types.Hash32) error

GetPoetProof gets poet proof from remote peer.

func (*Logic) GetProposalTxs

func (l *Logic) GetProposalTxs(ctx context.Context, ids []types.TransactionID) error

GetProposalTxs fetches the txs provided as IDs and validates them, returns an error if one TX failed to be fetched.

func (*Logic) GetProposals

func (l *Logic) GetProposals(ctx context.Context, ids []types.ProposalID) error

GetProposals gets the data for given proposal IDs from peers.

func (*Logic) PollLayerData

func (l *Logic) PollLayerData(ctx context.Context, layerID types.LayerID) chan LayerPromiseData

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

func (l *Logic) RegisterPeerHashes(peer p2p.Peer, hashes []types.Hash32)

RegisterPeerHashes is a wrapper around fetcher's RegisterPeerHashes.

func (*Logic) Start

func (l *Logic) Start()

Start starts fetcher logic and fetch component.

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

type RequestMessage struct {
	Hint datastore.Hint
	Hash types.Hash32
}

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

type ResponseMessage struct {
	Hash types.Hash32
	Data []byte
}

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)

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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