header

package
v0.20.0-arabica Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: Apache-2.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHeightZero = errors.New("height is equal to 0")

ErrHeightZero returned when the provided block height is equal to 0.

View Source
var MetricsEnabled = false

MetricsEnabled will be set during runtime if metrics are enabled on the node.

Functions

func ConstructModule

func ConstructModule[H libhead.Header[H]](tp node.Type, cfg *Config) fx.Option

func Flags

func Flags() *flag.FlagSet

Flags gives a set of hardcoded Header package flags.

func ParseFlags

func ParseFlags(cmd *cobra.Command, cfg *Config) error

ParseFlags parses Header package flags from the given cmd and applies them to the passed config.

func ParseTrustedHashFlags

func ParseTrustedHashFlags(
	cmd *cobra.Command,
	cfg *Config,
) error

ParseTrustedHashFlags parses Header package flags from the given cmd and saves them to the passed config.

func ParseTrustedPeerFlags

func ParseTrustedPeerFlags(
	cmd *cobra.Command,
	cfg *Config,
) error

ParseTrustedPeerFlags parses Header package flags from the given cmd and applies them to the passed config.

func TrustedHashFlags

func TrustedHashFlags() *flag.FlagSet

TrustedHashFlags returns a set of flags related to configuring a `TrustedHash`.

func TrustedPeersFlags

func TrustedPeersFlags() *flag.FlagSet

TrustedPeersFlags returns a set of flags.

Types

type API added in v0.5.0

type API struct {
	Internal struct {
		LocalHead func(context.Context) (*header.ExtendedHeader, error) `perm:"read"`
		GetByHash func(
			ctx context.Context,
			hash libhead.Hash,
		) (*header.ExtendedHeader, error) `perm:"read"`
		GetRangeByHeight func(
			context.Context,
			*header.ExtendedHeader,
			uint64,
		) ([]*header.ExtendedHeader, error) `perm:"read"`
		GetByHeight   func(context.Context, uint64) (*header.ExtendedHeader, error)    `perm:"read"`
		WaitForHeight func(context.Context, uint64) (*header.ExtendedHeader, error)    `perm:"read"`
		SyncState     func(ctx context.Context) (sync.State, error)                    `perm:"read"`
		SyncWait      func(ctx context.Context) error                                  `perm:"read"`
		NetworkHead   func(ctx context.Context) (*header.ExtendedHeader, error)        `perm:"read"`
		Subscribe     func(ctx context.Context) (<-chan *header.ExtendedHeader, error) `perm:"read"`
	}
}

API is a wrapper around Module for the RPC.

func (*API) GetByHash added in v0.7.0

func (api *API) GetByHash(ctx context.Context, hash libhead.Hash) (*header.ExtendedHeader, error)

func (*API) GetByHeight added in v0.5.0

func (api *API) GetByHeight(ctx context.Context, u uint64) (*header.ExtendedHeader, error)

func (*API) GetRangeByHeight added in v0.11.0

func (api *API) GetRangeByHeight(
	ctx context.Context,
	from *header.ExtendedHeader,
	to uint64,
) ([]*header.ExtendedHeader, error)

func (*API) LocalHead added in v0.7.0

func (api *API) LocalHead(ctx context.Context) (*header.ExtendedHeader, error)

func (*API) NetworkHead added in v0.7.0

func (api *API) NetworkHead(ctx context.Context) (*header.ExtendedHeader, error)

func (*API) Subscribe added in v0.8.0

func (api *API) Subscribe(ctx context.Context) (<-chan *header.ExtendedHeader, error)

func (*API) SyncState added in v0.7.0

func (api *API) SyncState(ctx context.Context) (sync.State, error)

func (*API) SyncWait added in v0.7.0

func (api *API) SyncWait(ctx context.Context) error

func (*API) WaitForHeight added in v0.10.0

func (api *API) WaitForHeight(ctx context.Context, u uint64) (*header.ExtendedHeader, error)

type Config

type Config struct {
	// TrustedHash is the Block/Header hash that Nodes use as starting point for header synchronization.
	// Only affects the node once on initial sync.
	TrustedHash string
	// TrustedPeers are the peers we trust to fetch headers from.
	// Note: The trusted does *not* imply Headers are not verified, but trusted as reliable to fetch
	// headers at any moment.
	TrustedPeers []string

	Store  store.Parameters
	Syncer sync.Parameters

	Server p2p_exchange.ServerParameters
	Client p2p_exchange.ClientParameters `toml:",omitempty"`
}

Config contains configuration parameters for header retrieval and management.

func DefaultConfig

func DefaultConfig(tp node.Type) Config

func (*Config) Validate

func (cfg *Config) Validate(tp node.Type) error

Validate performs basic validation of the config.

type Module

type Module interface {
	// LocalHead returns the ExtendedHeader of the chain head.
	LocalHead(context.Context) (*header.ExtendedHeader, error)

	// GetByHash returns the header of the given hash from the node's header store.
	GetByHash(ctx context.Context, hash libhead.Hash) (*header.ExtendedHeader, error)
	// GetRangeByHeight returns the given range (from:to) of ExtendedHeaders
	// from the node's header store and verifies that the returned headers are
	// adjacent to each other.
	GetRangeByHeight(
		ctx context.Context,
		from *header.ExtendedHeader,
		to uint64,
	) ([]*header.ExtendedHeader, error)
	// GetByHeight returns the ExtendedHeader at the given height if it is
	// currently available.
	GetByHeight(context.Context, uint64) (*header.ExtendedHeader, error)
	// WaitForHeight blocks until the header at the given height has been processed
	// by the store or context deadline is exceeded.
	WaitForHeight(context.Context, uint64) (*header.ExtendedHeader, error)

	// SyncState returns the current state of the header Syncer.
	SyncState(context.Context) (sync.State, error)
	// SyncWait blocks until the header Syncer is synced to network head.
	SyncWait(ctx context.Context) error
	// NetworkHead provides the Syncer's view of the current network head.
	NetworkHead(ctx context.Context) (*header.ExtendedHeader, error)

	// Subscribe to recent ExtendedHeaders from the network.
	Subscribe(ctx context.Context) (<-chan *header.ExtendedHeader, error)
}

Module exposes the functionality needed for querying headers from the network. Any method signature changed here needs to also be changed in the API struct.

type Service added in v0.5.0

type Service struct {
	// contains filtered or unexported fields
}

Service represents the header Service that can be started / stopped on a node. Service's main function is to manage its sub-services. Service can contain several sub-services, such as Exchange, ExchangeServer, Syncer, and so forth.

func (*Service) GetByHash added in v0.7.0

func (s *Service) GetByHash(ctx context.Context, hash libhead.Hash) (*header.ExtendedHeader, error)

func (*Service) GetByHeight added in v0.5.0

func (s *Service) GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error)

func (*Service) GetRangeByHeight added in v0.11.0

func (s *Service) GetRangeByHeight(
	ctx context.Context,
	from *header.ExtendedHeader,
	to uint64,
) ([]*header.ExtendedHeader, error)

func (*Service) LocalHead added in v0.7.0

func (s *Service) LocalHead(ctx context.Context) (*header.ExtendedHeader, error)

func (*Service) NetworkHead added in v0.7.0

func (s *Service) NetworkHead(ctx context.Context) (*header.ExtendedHeader, error)

func (*Service) Subscribe added in v0.8.0

func (s *Service) Subscribe(ctx context.Context) (<-chan *header.ExtendedHeader, error)

func (*Service) SyncState added in v0.7.0

func (s *Service) SyncState(context.Context) (sync.State, error)

func (*Service) SyncWait added in v0.7.0

func (s *Service) SyncWait(ctx context.Context) error

func (*Service) WaitForHeight added in v0.10.0

func (s *Service) WaitForHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, 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