info

package
v1.6.8 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultInfoResponseFiller = func(firstStreamableBlock *pbbstream.Block, resp *pbfirehose.InfoResponse, validate bool) error {
	resp.FirstStreamableBlockId = firstStreamableBlock.Id

	shortTypeURL := strings.TrimPrefix(firstStreamableBlock.Payload.TypeUrl, "type.googleapis.com/")
	for _, protocol := range wellknown.WellKnownProtocols {
		if protocol.BlockType == shortTypeURL {
			resp.BlockIdEncoding = protocol.BytesEncoding
			break
		}
	}

	if !validate {
		if resp.ChainName == "" {

			if chain := wellknown.WellKnownProtocols.ChainByGenesisBlock(firstStreamableBlock.Number, firstStreamableBlock.Id); chain != nil {
				resp.ChainName = chain.Name
				resp.ChainNameAliases = chain.Aliases
			}
		}
		return nil
	}

	if resp.ChainName != "" {
		if chain := wellknown.WellKnownProtocols.ChainByName(resp.ChainName); chain != nil {
			if firstStreamableBlock.Number == chain.GenesisBlockNumber && chain.GenesisBlockID != firstStreamableBlock.Id {
				return fmt.Errorf("chain name defined in flag: %q inconsistent with the genesis block ID %q (expected: %q)", resp.ChainName, ox(firstStreamableBlock.Id), ox(chain.GenesisBlockID))
			}
			resp.ChainName = chain.Name
			resp.ChainNameAliases = chain.Aliases
		} else if chain := wellknown.WellKnownProtocols.ChainByGenesisBlock(firstStreamableBlock.Number, firstStreamableBlock.Id); chain != nil {
			return fmt.Errorf("chain name defined in flag: %q inconsistent with the one discovered from genesis block %q", resp.ChainName, chain.Name)
		}
	} else {
		if chain := wellknown.WellKnownProtocols.ChainByGenesisBlock(firstStreamableBlock.Number, firstStreamableBlock.Id); chain != nil {
			resp.ChainName = chain.Name
			resp.ChainNameAliases = chain.Aliases
		}
	}

	if firstStreamableBlock.Payload.TypeUrl == "type.googleapis.com/sf.ethereum.type.v2.Block" {
		var seenDetailLevel bool
		for _, feature := range resp.BlockFeatures {
			if feature == "base" || feature == "extended" || feature == "hybrid" {
				seenDetailLevel = true
				break
			}
		}
		if !seenDetailLevel {
			return fmt.Errorf("ethereum blocks are used without setting detail level in 'advertise-block-features': expected one of 'base', 'extended' or 'hybrid' (or use 'firehose-ethereum' binary instead to serve this chain and get automatic detection/validation)")
		}
	}

	return nil
}

Functions

This section is empty.

Types

type InfoServer

type InfoServer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewInfoServer

func NewInfoServer(
	chainName string,
	chainNameAliases []string,
	blockIDEncoding pbfirehose.InfoResponse_BlockIdEncoding,
	blockFeatures []string,
	firstStreamableBlock uint64,
	validate bool,
	responseFiller func(block *pbbstream.Block, resp *pbfirehose.InfoResponse, validate bool) error,
	logger *zap.Logger,
) *InfoServer

func (*InfoServer) Info

func (*InfoServer) Init

func (s *InfoServer) Init(ctx context.Context, fhub *hub.ForkableHub, mergedBlocksStore dstore.Store, oneBlockStore dstore.Store, logger *zap.Logger) error

multiple apps (firehose, substreams...) can initialize the same server, we only need one

Jump to

Keyboard shortcuts

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