chaintracker

package
v5.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 33 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	BACKOFF_MAX_TIME = 10 * time.Minute

	GoodStabilityThreshold         = 0.3
	PollingUpdateLength            = 10
	MostFrequentPollingMultiplier  = 16
	LavaPollingMultiplierFrequency = 4
	PollingMultiplierFlagName      = "polling-multiplier"
)
View Source
const (
	DefaultAssumedBlockMemory      = 20
	DefaultBlockCheckpointDistance = 100
)
View Source
const (
	CacheMaxCost     = 100000 // each item cost would be 1
	CacheNumCounters = 100000 // expect 100000 items

)
View Source
const DummyChainTrackerLatestBlock = int64(math.MaxInt64)

Variables

View Source
var (
	ErrInvalidLengthChainTracker        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowChainTracker          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupChainTracker = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (
	InvalidConfigErrorBlocksToSave  = sdkerrors.New("Invalid blocks to save", 10701, "blocks to save wasn't defined in config")
	InvalidConfigBlockTime          = sdkerrors.New("Invalid average block time", 10702, "average block time wasn't defined in config")
	InvalidLatestBlockNumValue      = sdkerrors.New("Invalid value for latestBlockNum", 10703, "returned latest block num should be greater than 0, but it's not")
	InvalidReturnedHashes           = sdkerrors.New("Invalid value for requestedHashes length", 10704, "returned requestedHashes key count should be greater than 0, but it's not")
	ErrorFailedToFetchLatestBlock   = sdkerrors.New("Error FailedToFetchLatestBlock", 10705, "Failed to fetch latest block from node")
	InvalidRequestedBlocks          = sdkerrors.New("Error InvalidRequestedBlocks", 10706, "provided requested blocks for function do not compose a valid request")
	RequestedBlocksOutOfRange       = sdkerrors.New("RequestedBlocksOutOfRange", 10707, "requested blocks are outside the supported range by the state tracker")
	ErrorFailedToFetchTooEarlyBlock = sdkerrors.New("Error ErrorFailedToFetchTooEarlyBlock", 10708, "server memory protection triggered, requested block is too early")
	InvalidRequestedSpecificBlock   = sdkerrors.New("Error InvalidRequestedSpecificBlock", 10709, "provided requested specific blocks for function do not compose a stored entry")
)
View Source
var PollingMultiplier = uint64(1)

Functions

func BuildProofFromBlocks

func BuildProofFromBlocks(requestedHashes []*BlockStore) map[int64]interface{}

func FindRequestedBlockHash

func FindRequestedBlockHash(requestedHashes []*BlockStore, requestBlock, toBlock, fromBlock int64, finalizedBlockHashes map[int64]interface{}) (requestedBlockHash []byte, finalizedBlockHashesMapRet map[int64]interface{})

func LatestArgToBlockNum

func LatestArgToBlockNum(request, latestBlock int64) int64

func RegisterChainTrackerServiceServer

func RegisterChainTrackerServiceServer(s grpc1.Server, srv ChainTrackerServiceServer)

Types

type BlockRange

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

func NewBlockRange

func NewBlockRange(fromBlock, toBlock, earliestBlockSaved, latestBlock int64) (br *BlockRange, err error)

func (*BlockRange) IsWanted

func (br *BlockRange) IsWanted(blockNum int64) bool

func (*BlockRange) IterationIndexes

func (br *BlockRange) IterationIndexes() []int

type BlockStore

type BlockStore struct {
	Block int64  `protobuf:"varint,1,opt,name=block,proto3" json:"block,omitempty"`
	Hash  string `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
}

func (*BlockStore) Descriptor

func (*BlockStore) Descriptor() ([]byte, []int)

func (*BlockStore) GetBlock

func (m *BlockStore) GetBlock() int64

func (*BlockStore) GetHash

func (m *BlockStore) GetHash() string

func (*BlockStore) Marshal

func (m *BlockStore) Marshal() (dAtA []byte, err error)

func (*BlockStore) MarshalTo

func (m *BlockStore) MarshalTo(dAtA []byte) (int, error)

func (*BlockStore) MarshalToSizedBuffer

func (m *BlockStore) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*BlockStore) ProtoMessage

func (*BlockStore) ProtoMessage()

func (*BlockStore) Reset

func (m *BlockStore) Reset()

func (*BlockStore) Size

func (m *BlockStore) Size() (n int)

func (*BlockStore) String

func (m *BlockStore) String() string

func (*BlockStore) Unmarshal

func (m *BlockStore) Unmarshal(dAtA []byte) error

func (*BlockStore) XXX_DiscardUnknown

func (m *BlockStore) XXX_DiscardUnknown()

func (*BlockStore) XXX_Marshal

func (m *BlockStore) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*BlockStore) XXX_Merge

func (m *BlockStore) XXX_Merge(src proto.Message)

func (*BlockStore) XXX_Size

func (m *BlockStore) XXX_Size() int

func (*BlockStore) XXX_Unmarshal

func (m *BlockStore) XXX_Unmarshal(b []byte) error

type ChainFetcher

type ChainFetcher interface {
	FetchLatestBlockNum(ctx context.Context) (int64, error)
	FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)
	FetchEndpoint() lavasession.RPCProviderEndpoint
	CustomMessage(ctx context.Context, path string, data []byte, connectionType string, apiName string) ([]byte, error)
}

type ChainTracker

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

func (*ChainTracker) AddBlockGap

func (ct *ChainTracker) AddBlockGap(newData time.Duration, blocks uint64)

func (*ChainTracker) GetAtomicLatestBlockNum

func (cs *ChainTracker) GetAtomicLatestBlockNum() int64

func (*ChainTracker) GetLatestBlockData

func (cs *ChainTracker) GetLatestBlockData(fromBlock, toBlock, specificBlock int64) (latestBlock int64, requestedHashes []*BlockStore, changeTime time.Time, err error)

this function returns block hashes of the blocks: [from block - to block] inclusive. an additional specific block hash can be provided. order is sorted ascending it supports requests for [spectypes.LATEST_BLOCK-distance1, spectypes.LATEST_BLOCK-distance2) spectypes.NOT_APPLICABLE in fromBlock or toBlock results in only returning specific block. if specific block is spectypes.NOT_APPLICABLE it is ignored

func (*ChainTracker) GetLatestBlockNum

func (cs *ChainTracker) GetLatestBlockNum() (int64, time.Time)

func (*ChainTracker) GetServerBlockMemory

func (cs *ChainTracker) GetServerBlockMemory() uint64

func (*ChainTracker) IsDummy added in v5.3.0

func (cs *ChainTracker) IsDummy() bool

func (*ChainTracker) RegisterForBlockTimeUpdates

func (cs *ChainTracker) RegisterForBlockTimeUpdates(updatable blockTimeUpdatable)

func (*ChainTracker) StartAndServe

func (ct *ChainTracker) StartAndServe(ctx context.Context) error

type ChainTrackerConfig

type ChainTrackerConfig struct {
	ForkCallback             func(block int64)                                 // a function to be called when a fork is detected
	NewLatestCallback        func(blockFrom int64, blockTo int64, hash string) // a function to be called when a new block is detected
	ConsistencyCallback      func(oldBlock int64, block int64)
	OldBlockCallback         func(latestBlockTime time.Time)
	ServerAddress            string // if not empty will open up a grpc server for that address
	BlocksToSave             uint64
	AverageBlockTime         time.Duration // how often to query latest block
	ServerBlockMemory        uint64
	BlocksCheckpointDistance uint64 // this causes the chainTracker to trigger it's checkpoint every X blocks
	Pmetrics                 *metrics.ProviderMetricsManager
	PollingTimeMultiplier    int
	ChainId                  string
	ParseDirectiveEnabled    bool
}

type ChainTrackerService

type ChainTrackerService struct {
	UnimplementedChainTrackerServiceServer
	ChainTracker *ChainTracker
}

func (*ChainTrackerService) GetLatestBlockData

func (cts *ChainTrackerService) GetLatestBlockData(ctx context.Context, latestBlockData *LatestBlockData) (*LatestBlockDataResponse, error)

func (*ChainTrackerService) GetLatestBlockNum

type ChainTrackerServiceClient

type ChainTrackerServiceClient interface {
	GetLatestBlockNum(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*GetLatestBlockNumResponse, error)
	GetLatestBlockData(ctx context.Context, in *LatestBlockData, opts ...grpc.CallOption) (*LatestBlockDataResponse, error)
}

ChainTrackerServiceClient is the client API for ChainTrackerService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewChainTrackerServiceClient

func NewChainTrackerServiceClient(cc grpc1.ClientConn) ChainTrackerServiceClient

type ChainTrackerServiceServer

type ChainTrackerServiceServer interface {
	GetLatestBlockNum(context.Context, *emptypb.Empty) (*GetLatestBlockNumResponse, error)
	GetLatestBlockData(context.Context, *LatestBlockData) (*LatestBlockDataResponse, error)
}

ChainTrackerServiceServer is the server API for ChainTrackerService service.

type DefaultChainTrackerFetcher

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

func (*DefaultChainTrackerFetcher) FetchBlockHashByNum

func (cs *DefaultChainTrackerFetcher) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)

func (*DefaultChainTrackerFetcher) FetchLatestBlockNum

func (cs *DefaultChainTrackerFetcher) FetchLatestBlockNum(ctx context.Context) (int64, error)

type DummyChainTracker added in v5.3.0

type DummyChainTracker struct{}

func (*DummyChainTracker) AddBlockGap added in v5.3.0

func (dct *DummyChainTracker) AddBlockGap(newData time.Duration, blocks uint64)

AddBlockGap adds a new block gap measurement

func (*DummyChainTracker) GetAtomicLatestBlockNum added in v5.3.0

func (dct *DummyChainTracker) GetAtomicLatestBlockNum() int64

GetAtomicLatestBlockNum returns the current latest block number atomically

func (*DummyChainTracker) GetLatestBlockData added in v5.3.0

func (dct *DummyChainTracker) GetLatestBlockData(fromBlock, toBlock, specificBlock int64) (latestBlock int64, requestedHashes []*BlockStore, changeTime time.Time, err error)

GetLatestBlockData returns block hashes for the specified block range and a specific block

func (*DummyChainTracker) GetLatestBlockNum added in v5.3.0

func (dct *DummyChainTracker) GetLatestBlockNum() (int64, time.Time)

GetLatestBlockNum returns the current latest block number and the time it was last changed

func (*DummyChainTracker) IsDummy added in v5.3.0

func (dct *DummyChainTracker) IsDummy() bool

func (*DummyChainTracker) RegisterForBlockTimeUpdates added in v5.3.0

func (dct *DummyChainTracker) RegisterForBlockTimeUpdates(updatable blockTimeUpdatable)

RegisterForBlockTimeUpdates registers an updatable to receive block time updates

func (*DummyChainTracker) StartAndServe added in v5.3.0

func (dct *DummyChainTracker) StartAndServe(ctx context.Context) error

StartAndServe starts the chain tracker and serves gRPC if configured

type GetLatestBlockNumResponse

type GetLatestBlockNumResponse struct {
	Block     uint64 `protobuf:"varint,1,opt,name=block,proto3" json:"block,omitempty"`
	Timestamp int64  `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
}

func (*GetLatestBlockNumResponse) Descriptor

func (*GetLatestBlockNumResponse) Descriptor() ([]byte, []int)

func (*GetLatestBlockNumResponse) GetBlock

func (m *GetLatestBlockNumResponse) GetBlock() uint64

func (*GetLatestBlockNumResponse) GetTimestamp

func (m *GetLatestBlockNumResponse) GetTimestamp() int64

func (*GetLatestBlockNumResponse) Marshal

func (m *GetLatestBlockNumResponse) Marshal() (dAtA []byte, err error)

func (*GetLatestBlockNumResponse) MarshalTo

func (m *GetLatestBlockNumResponse) MarshalTo(dAtA []byte) (int, error)

func (*GetLatestBlockNumResponse) MarshalToSizedBuffer

func (m *GetLatestBlockNumResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*GetLatestBlockNumResponse) ProtoMessage

func (*GetLatestBlockNumResponse) ProtoMessage()

func (*GetLatestBlockNumResponse) Reset

func (m *GetLatestBlockNumResponse) Reset()

func (*GetLatestBlockNumResponse) Size

func (m *GetLatestBlockNumResponse) Size() (n int)

func (*GetLatestBlockNumResponse) String

func (m *GetLatestBlockNumResponse) String() string

func (*GetLatestBlockNumResponse) Unmarshal

func (m *GetLatestBlockNumResponse) Unmarshal(dAtA []byte) error

func (*GetLatestBlockNumResponse) XXX_DiscardUnknown

func (m *GetLatestBlockNumResponse) XXX_DiscardUnknown()

func (*GetLatestBlockNumResponse) XXX_Marshal

func (m *GetLatestBlockNumResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetLatestBlockNumResponse) XXX_Merge

func (m *GetLatestBlockNumResponse) XXX_Merge(src proto.Message)

func (*GetLatestBlockNumResponse) XXX_Size

func (m *GetLatestBlockNumResponse) XXX_Size() int

func (*GetLatestBlockNumResponse) XXX_Unmarshal

func (m *GetLatestBlockNumResponse) XXX_Unmarshal(b []byte) error

type IChainFetcherWrapper

type IChainFetcherWrapper interface {
	FetchLatestBlockNum(ctx context.Context) (int64, error)
	FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)
}

type IChainTracker

type IChainTracker interface {
	// GetLatestBlockData returns block hashes for the specified block range and a specific block
	GetLatestBlockData(fromBlock, toBlock, specificBlock int64) (latestBlock int64, requestedHashes []*BlockStore, changeTime time.Time, err error)

	// RegisterForBlockTimeUpdates registers an updatable to receive block time updates
	RegisterForBlockTimeUpdates(updatable blockTimeUpdatable)

	// GetLatestBlockNum returns the current latest block number and the time it was last changed
	GetLatestBlockNum() (int64, time.Time)

	// GetAtomicLatestBlockNum returns the current latest block number atomically
	GetAtomicLatestBlockNum() int64

	// StartAndServe starts the chain tracker and serves gRPC if configured
	StartAndServe(ctx context.Context) error

	// AddBlockGap adds a new block gap measurement
	AddBlockGap(newData time.Duration, blocks uint64)

	// IsDummy gets the chain tracker weight - a way to differntiate between trackers (dummy tracker with weight 0)
	IsDummy() bool
}

IChainTracker represents the interface for chain tracking functionality

func NewChainTracker

func NewChainTracker(ctx context.Context, chainFetcher ChainFetcher, config ChainTrackerConfig) (chainTracker IChainTracker, err error)

type IChainTrackerDataFetcher

type IChainTrackerDataFetcher interface {
	GetAtomicLatestBlockNum() int64
	GetServerBlockMemory() uint64
}

type LatestBlockData

type LatestBlockData struct {
	FromBlock     int64 `protobuf:"varint,1,opt,name=fromBlock,proto3" json:"fromBlock,omitempty"`
	ToBlock       int64 `protobuf:"varint,2,opt,name=toBlock,proto3" json:"toBlock,omitempty"`
	SpecificBlock int64 `protobuf:"varint,3,opt,name=specificBlock,proto3" json:"specificBlock,omitempty"`
}

func (*LatestBlockData) Descriptor

func (*LatestBlockData) Descriptor() ([]byte, []int)

func (*LatestBlockData) GetFromBlock

func (m *LatestBlockData) GetFromBlock() int64

func (*LatestBlockData) GetSpecificBlock

func (m *LatestBlockData) GetSpecificBlock() int64

func (*LatestBlockData) GetToBlock

func (m *LatestBlockData) GetToBlock() int64

func (*LatestBlockData) Marshal

func (m *LatestBlockData) Marshal() (dAtA []byte, err error)

func (*LatestBlockData) MarshalTo

func (m *LatestBlockData) MarshalTo(dAtA []byte) (int, error)

func (*LatestBlockData) MarshalToSizedBuffer

func (m *LatestBlockData) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*LatestBlockData) ProtoMessage

func (*LatestBlockData) ProtoMessage()

func (*LatestBlockData) Reset

func (m *LatestBlockData) Reset()

func (*LatestBlockData) Size

func (m *LatestBlockData) Size() (n int)

func (*LatestBlockData) String

func (m *LatestBlockData) String() string

func (*LatestBlockData) Unmarshal

func (m *LatestBlockData) Unmarshal(dAtA []byte) error

func (*LatestBlockData) XXX_DiscardUnknown

func (m *LatestBlockData) XXX_DiscardUnknown()

func (*LatestBlockData) XXX_Marshal

func (m *LatestBlockData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*LatestBlockData) XXX_Merge

func (m *LatestBlockData) XXX_Merge(src proto.Message)

func (*LatestBlockData) XXX_Size

func (m *LatestBlockData) XXX_Size() int

func (*LatestBlockData) XXX_Unmarshal

func (m *LatestBlockData) XXX_Unmarshal(b []byte) error

type LatestBlockDataResponse

type LatestBlockDataResponse struct {
	LatestBlock     int64         `protobuf:"varint,1,opt,name=latestBlock,proto3" json:"latestBlock,omitempty"`
	RequestedHashes []*BlockStore `protobuf:"bytes,2,rep,name=requestedHashes,proto3" json:"requestedHashes,omitempty"`
}

func (*LatestBlockDataResponse) Descriptor

func (*LatestBlockDataResponse) Descriptor() ([]byte, []int)

func (*LatestBlockDataResponse) GetLatestBlock

func (m *LatestBlockDataResponse) GetLatestBlock() int64

func (*LatestBlockDataResponse) GetRequestedHashes

func (m *LatestBlockDataResponse) GetRequestedHashes() []*BlockStore

func (*LatestBlockDataResponse) Marshal

func (m *LatestBlockDataResponse) Marshal() (dAtA []byte, err error)

func (*LatestBlockDataResponse) MarshalTo

func (m *LatestBlockDataResponse) MarshalTo(dAtA []byte) (int, error)

func (*LatestBlockDataResponse) MarshalToSizedBuffer

func (m *LatestBlockDataResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*LatestBlockDataResponse) ProtoMessage

func (*LatestBlockDataResponse) ProtoMessage()

func (*LatestBlockDataResponse) Reset

func (m *LatestBlockDataResponse) Reset()

func (*LatestBlockDataResponse) Size

func (m *LatestBlockDataResponse) Size() (n int)

func (*LatestBlockDataResponse) String

func (m *LatestBlockDataResponse) String() string

func (*LatestBlockDataResponse) Unmarshal

func (m *LatestBlockDataResponse) Unmarshal(dAtA []byte) error

func (*LatestBlockDataResponse) XXX_DiscardUnknown

func (m *LatestBlockDataResponse) XXX_DiscardUnknown()

func (*LatestBlockDataResponse) XXX_Marshal

func (m *LatestBlockDataResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*LatestBlockDataResponse) XXX_Merge

func (m *LatestBlockDataResponse) XXX_Merge(src proto.Message)

func (*LatestBlockDataResponse) XXX_Size

func (m *LatestBlockDataResponse) XXX_Size() int

func (*LatestBlockDataResponse) XXX_Unmarshal

func (m *LatestBlockDataResponse) XXX_Unmarshal(b []byte) error

type SVMChainTracker

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

func (*SVMChainTracker) FetchBlockHashByNum

func (cs *SVMChainTracker) FetchBlockHashByNum(ctx context.Context, blockNum int64) (string, error)

func (*SVMChainTracker) FetchLatestBlockNum

func (cs *SVMChainTracker) FetchLatestBlockNum(ctx context.Context) (int64, error)

type SVMLatestBlockResponse

type SVMLatestBlockResponse struct {
	Result struct {
		Context struct {
			Slot int64 `json:"slot"`
		} `json:"context"`
		Value struct {
			LastValidBlockHeight int64  `json:"lastValidBlockHeight"`
			BlockHash            string `json:"blockhash"`
		} `json:"value"`
	} `json:"result"`
}

type UnimplementedChainTrackerServiceServer

type UnimplementedChainTrackerServiceServer struct{}

UnimplementedChainTrackerServiceServer can be embedded to have forward compatible implementations.

func (*UnimplementedChainTrackerServiceServer) GetLatestBlockData

func (*UnimplementedChainTrackerServiceServer) GetLatestBlockNum

type WantedBlocksData

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

func (*WantedBlocksData) IsWanted

func (wbd *WantedBlocksData) IsWanted(blockNum int64) bool

func (*WantedBlocksData) IterationIndexes

func (wbd *WantedBlocksData) IterationIndexes() (returnedIdxs []int)

func (*WantedBlocksData) New

func (wbd *WantedBlocksData) New(fromBlock, toBlock, specificBlock, latestBlock, earliestBlockSaved int64) (err error)

func (*WantedBlocksData) String

func (wbd *WantedBlocksData) String() string

Jump to

Keyboard shortcuts

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