fetch

package
v0.2.20-beta.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2022 License: MIT Imports: 24 Imported by: 1

Documentation

Overview

Package fetch contains mechanism to fetch Data from remote peers

nolint

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BatchTimeout         time.Duration // in milliseconds
	MaxRetriesForPeer    int
	BatchSize, QueueSize int
	RequestTimeout       time.Duration // 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 EpochData added in v1.0.0

type EpochData struct {
	AtxIDs []types.ATXID
}

func (*EpochData) DecodeScale added in v1.0.0

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

func (*EpochData) EncodeScale added in v1.0.0

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

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 NewFetch

func NewFetch(cdb *datastore.CachedDB, msh meshProvider, b system.BeaconGetter, host *p2p.Host, opts ...Option) *Fetch

NewFetch creates a new Fetch struct.

func (*Fetch) AddPeersFromHash

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

AddPeersFromHash adds peers from one hash to others.

func (*Fetch) GetAtxs added in v1.0.0

func (f *Fetch) 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 (*Fetch) GetBallots added in v1.0.0

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

GetBallots gets data for the specified BallotIDs and validates them.

func (*Fetch) GetBlockTxs added in v1.0.0

func (f *Fetch) 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 (*Fetch) GetBlocks added in v1.0.0

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

GetBlocks gets the data for given block IDs from peers.

func (*Fetch) GetLayerData added in v1.0.0

func (f *Fetch) GetLayerData(ctx context.Context, peers []p2p.Peer, lid types.LayerID, okCB func([]byte, p2p.Peer), errCB func(error, p2p.Peer)) error

GetLayerData get layer data from peers.

func (*Fetch) GetLayerOpinions added in v1.0.0

func (f *Fetch) GetLayerOpinions(ctx context.Context, peers []p2p.Peer, lid types.LayerID, okCB func([]byte, p2p.Peer), errCB func(error, p2p.Peer)) error

GetLayerOpinions get opinions on data in the specified layer from peers.

func (*Fetch) GetPeers added in v1.0.0

func (f *Fetch) GetPeers() []p2p.Peer

func (*Fetch) GetPoetProof added in v1.0.0

func (f *Fetch) GetPoetProof(ctx context.Context, id types.Hash32) error

GetPoetProof gets poet proof from remote peer.

func (*Fetch) GetProposalTxs added in v1.0.0

func (f *Fetch) 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 (*Fetch) GetProposals added in v1.0.0

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

GetProposals gets the data for given proposal IDs from peers.

func (*Fetch) PeerEpochInfo added in v1.0.0

func (f *Fetch) PeerEpochInfo(ctx context.Context, peer p2p.Peer, epoch types.EpochID) (*EpochData, error)

PeerEpochInfo get the epoch info published in the given epoch from the specified peer.

func (*Fetch) PeerMeshHashes added in v1.0.0

func (f *Fetch) PeerMeshHashes(ctx context.Context, peer p2p.Peer, req *MeshHashRequest) (*MeshHashes, error)

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 {
	PrevAggHash types.Hash32
	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 MeshHashRequest added in v1.0.0

type MeshHashRequest struct {
	From, To     types.LayerID
	Delta, Steps uint32
}

func (*MeshHashRequest) DecodeScale added in v1.0.0

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

func (*MeshHashRequest) EncodeScale added in v1.0.0

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

func (*MeshHashRequest) MarshalLogObject added in v1.0.0

func (r *MeshHashRequest) MarshalLogObject(encoder log.ObjectEncoder) error

type MeshHashes added in v1.0.0

type MeshHashes struct {
	Layers []types.LayerID
	Hashes []types.Hash32
}

func (*MeshHashes) DecodeScale added in v1.0.0

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

func (*MeshHashes) EncodeScale added in v1.0.0

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

type Option added in v1.0.0

type Option func(*Fetch)

Option is a type to configure a fetcher.

func WithATXHandler

func WithATXHandler(h atxHandler) Option

WithATXHandler configures the ATX handler of the fetcher.

func WithBallotHandler

func WithBallotHandler(h ballotHandler) Option

WithBallotHandler configures the Ballot handler of the fetcher.

func WithBlockHandler

func WithBlockHandler(h blockHandler) Option

WithBlockHandler configures the Block handler of the fetcher.

func WithConfig added in v1.0.0

func WithConfig(c Config) Option

WithConfig configures the config for the fetcher.

func WithContext added in v1.0.0

func WithContext(c context.Context) Option

WithContext configures the shutdown context for the fetcher.

func WithLogger added in v1.0.0

func WithLogger(log log.Log) Option

WithLogger configures logger for the fetcher.

func WithPoetHandler

func WithPoetHandler(h poetHandler) Option

WithPoetHandler configures the PoET handler of the fetcher.

func WithProposalHandler

func WithProposalHandler(h proposalHandler) Option

WithProposalHandler configures the Proposal handler of the fetcher.

func WithTXHandler

func WithTXHandler(h txHandler) Option

WithTXHandler configures the TX handler of the fetcher.

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