Documentation
¶
Index ¶
- Constants
- Variables
- func BuildProofFromBlocks(requestedHashes []*BlockStore) map[int64]interface{}
- func FindRequestedBlockHash(requestedHashes []*BlockStore, requestBlock, toBlock, fromBlock int64, ...) (requestedBlockHash []byte, finalizedBlockHashesMapRet map[int64]interface{})
- func LatestArgToBlockNum(request, latestBlock int64) int64
- func RegisterChainTrackerServiceServer(s *grpc.Server, srv ChainTrackerServiceServer)
- type BlockRange
- type BlockStore
- type ChainFetcher
- type ChainTracker
- func (ct *ChainTracker) AddBlockGap(newData time.Duration, blocks uint64)
- func (cs *ChainTracker) GetAtomicLatestBlockNum() int64
- func (cs *ChainTracker) GetLatestBlockData(fromBlock, toBlock, specificBlock int64) (latestBlock int64, requestedHashes []*BlockStore, changeTime time.Time, ...)
- func (cs *ChainTracker) GetLatestBlockNum() (int64, time.Time)
- func (cs *ChainTracker) GetServerBlockMemory() uint64
- func (cs *ChainTracker) IsDummy() bool
- func (cs *ChainTracker) RegisterForBlockTimeUpdates(updatable blockTimeUpdatable)
- func (ct *ChainTracker) StartAndServe(ctx context.Context) error
- type ChainTrackerConfig
- type ChainTrackerService
- type ChainTrackerServiceServer
- type DefaultChainTrackerFetcher
- type DummyChainTracker
- func (dct *DummyChainTracker) AddBlockGap(newData time.Duration, blocks uint64)
- func (dct *DummyChainTracker) GetAtomicLatestBlockNum() int64
- func (dct *DummyChainTracker) GetLatestBlockData(fromBlock, toBlock, specificBlock int64) (latestBlock int64, requestedHashes []*BlockStore, changeTime time.Time, ...)
- func (dct *DummyChainTracker) GetLatestBlockNum() (int64, time.Time)
- func (dct *DummyChainTracker) IsDummy() bool
- func (dct *DummyChainTracker) RegisterForBlockTimeUpdates(updatable blockTimeUpdatable)
- func (dct *DummyChainTracker) StartAndServe(ctx context.Context) error
- type GetLatestBlockNumResponse
- func (m *GetLatestBlockNumResponse) GetBlock() uint64
- func (m *GetLatestBlockNumResponse) GetTimestamp() int64
- func (m *GetLatestBlockNumResponse) Marshal() ([]byte, error)
- func (m *GetLatestBlockNumResponse) ProtoMessage()
- func (m *GetLatestBlockNumResponse) Reset()
- func (m *GetLatestBlockNumResponse) String() string
- func (m *GetLatestBlockNumResponse) Unmarshal(b []byte) error
- type IChainFetcherWrapper
- type IChainTracker
- type IChainTrackerDataFetcher
- type LatestBlockData
- func (m *LatestBlockData) GetFromBlock() int64
- func (m *LatestBlockData) GetSpecificBlock() int64
- func (m *LatestBlockData) GetToBlock() int64
- func (m *LatestBlockData) Marshal() ([]byte, error)
- func (m *LatestBlockData) ProtoMessage()
- func (m *LatestBlockData) Reset()
- func (m *LatestBlockData) String() string
- func (m *LatestBlockData) Unmarshal(b []byte) error
- type LatestBlockDataResponse
- func (m *LatestBlockDataResponse) GetLatestBlock() int64
- func (m *LatestBlockDataResponse) GetRequestedHashes() []*BlockStore
- func (m *LatestBlockDataResponse) Marshal() ([]byte, error)
- func (m *LatestBlockDataResponse) ProtoMessage()
- func (m *LatestBlockDataResponse) Reset()
- func (m *LatestBlockDataResponse) String() string
- func (m *LatestBlockDataResponse) Unmarshal(b []byte) error
- type SVMChainTracker
- type SVMLatestBlockResponse
- type UnimplementedChainTrackerServiceServer
- type WantedBlocksData
Constants ¶
const ( BACKOFF_MAX_TIME = 10 * time.Minute GoodStabilityThreshold = 0.3 PollingUpdateLength = 10 MostFrequentPollingMultiplier = 16 LavaPollingMultiplierFrequency = 4 PollingMultiplierFlagName = "polling-multiplier" )
const ( DefaultAssumedBlockMemory = 20 DefaultBlockCheckpointDistance = 100 )
const ( CacheMaxCost = 100000 // each item cost would be 1 CacheNumCounters = 100000 // expect 100000 items )
const (
// ChainTrackerDefaultMemory is the default number of blocks the chain tracker keeps in memory.
ChainTrackerDefaultMemory = 100
)
const DummyChainTrackerLatestBlock = int64(math.MaxInt64)
Variables ¶
var ( InvalidConfigErrorBlocksToSave = errors.New("blocks to save wasn't defined in config") InvalidConfigBlockTime = errors.New("average block time wasn't defined in config") InvalidLatestBlockNumValue = errors.New("returned latest block num should be greater than 0, but it's not") InvalidReturnedHashes = errors.New("returned requestedHashes key count should be greater than 0, but it's not") ErrorFailedToFetchLatestBlock = errors.New("Failed to fetch latest block from node") InvalidRequestedBlocks = errors.New("provided requested blocks for function do not compose a valid request") RequestedBlocksOutOfRange = errors.New("requested blocks are outside the supported range by the state tracker") ErrorFailedToFetchTooEarlyBlock = errors.New("server memory protection triggered, requested block is too early") InvalidRequestedSpecificBlock = errors.New("provided requested specific blocks for function do not compose a stored entry") )
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 RegisterChainTrackerServiceServer ¶
func RegisterChainTrackerServiceServer(s *grpc.Server, srv ChainTrackerServiceServer)
RegisterChainTrackerServiceServer registers srv with the gRPC server s.
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 ¶
BlockStore holds a block number and its hash.
func (*BlockStore) GetBlock ¶
func (m *BlockStore) GetBlock() int64
func (*BlockStore) GetHash ¶
func (m *BlockStore) GetHash() string
func (*BlockStore) Marshal ¶
func (m *BlockStore) Marshal() ([]byte, error)
func (*BlockStore) ProtoMessage ¶
func (m *BlockStore) ProtoMessage()
func (*BlockStore) Reset ¶
func (m *BlockStore) Reset()
func (*BlockStore) String ¶
func (m *BlockStore) String() string
func (*BlockStore) Unmarshal ¶
func (m *BlockStore) 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 ¶
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)
FetchErrorCallback func() // a function to be called when the latest-block fetch fails
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 ¶
func (cts *ChainTrackerService) GetLatestBlockNum(context.Context, *empty.Empty) (*GetLatestBlockNumResponse, error)
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.
type DefaultChainTrackerFetcher ¶
type DefaultChainTrackerFetcher struct {
// contains filtered or unexported fields
}
func (*DefaultChainTrackerFetcher) FetchBlockHashByNum ¶
func (*DefaultChainTrackerFetcher) FetchLatestBlockNum ¶
func (cs *DefaultChainTrackerFetcher) FetchLatestBlockNum(ctx context.Context) (int64, error)
type DummyChainTracker ¶
type DummyChainTracker struct{}
func (*DummyChainTracker) AddBlockGap ¶
func (dct *DummyChainTracker) AddBlockGap(newData time.Duration, blocks uint64)
AddBlockGap adds a new block gap measurement
func (*DummyChainTracker) GetAtomicLatestBlockNum ¶
func (dct *DummyChainTracker) GetAtomicLatestBlockNum() int64
GetAtomicLatestBlockNum returns the current latest block number atomically
func (*DummyChainTracker) GetLatestBlockData ¶
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 ¶
func (dct *DummyChainTracker) GetLatestBlockNum() (int64, time.Time)
GetLatestBlockNum returns the current latest block number and the time it was last changed
func (*DummyChainTracker) IsDummy ¶
func (dct *DummyChainTracker) IsDummy() bool
func (*DummyChainTracker) RegisterForBlockTimeUpdates ¶
func (dct *DummyChainTracker) RegisterForBlockTimeUpdates(updatable blockTimeUpdatable)
RegisterForBlockTimeUpdates registers an updatable to receive block time updates
func (*DummyChainTracker) StartAndServe ¶
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 `json:"block,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
}
GetLatestBlockNumResponse is the response for GetLatestBlockNum.
func (*GetLatestBlockNumResponse) GetBlock ¶
func (m *GetLatestBlockNumResponse) GetBlock() uint64
func (*GetLatestBlockNumResponse) GetTimestamp ¶
func (m *GetLatestBlockNumResponse) GetTimestamp() int64
func (*GetLatestBlockNumResponse) Marshal ¶
func (m *GetLatestBlockNumResponse) Marshal() ([]byte, error)
func (*GetLatestBlockNumResponse) ProtoMessage ¶
func (m *GetLatestBlockNumResponse) ProtoMessage()
func (*GetLatestBlockNumResponse) Reset ¶
func (m *GetLatestBlockNumResponse) Reset()
func (*GetLatestBlockNumResponse) String ¶
func (m *GetLatestBlockNumResponse) String() string
func (*GetLatestBlockNumResponse) Unmarshal ¶
func (m *GetLatestBlockNumResponse) Unmarshal(b []byte) error
type IChainFetcherWrapper ¶
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 LatestBlockData ¶
type LatestBlockData struct {
FromBlock int64 `json:"fromBlock,omitempty"`
ToBlock int64 `json:"toBlock,omitempty"`
SpecificBlock int64 `json:"specificBlock,omitempty"`
}
LatestBlockData is the request for GetLatestBlockData.
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() ([]byte, error)
func (*LatestBlockData) ProtoMessage ¶
func (m *LatestBlockData) ProtoMessage()
func (*LatestBlockData) Reset ¶
func (m *LatestBlockData) Reset()
func (*LatestBlockData) String ¶
func (m *LatestBlockData) String() string
func (*LatestBlockData) Unmarshal ¶
func (m *LatestBlockData) Unmarshal(b []byte) error
type LatestBlockDataResponse ¶
type LatestBlockDataResponse struct {
LatestBlock int64 `json:"latestBlock,omitempty"`
RequestedHashes []*BlockStore `json:"requestedHashes,omitempty"`
}
LatestBlockDataResponse is the response for GetLatestBlockData.
func (*LatestBlockDataResponse) GetLatestBlock ¶
func (m *LatestBlockDataResponse) GetLatestBlock() int64
func (*LatestBlockDataResponse) GetRequestedHashes ¶
func (m *LatestBlockDataResponse) GetRequestedHashes() []*BlockStore
func (*LatestBlockDataResponse) Marshal ¶
func (m *LatestBlockDataResponse) Marshal() ([]byte, error)
func (*LatestBlockDataResponse) ProtoMessage ¶
func (m *LatestBlockDataResponse) ProtoMessage()
func (*LatestBlockDataResponse) Reset ¶
func (m *LatestBlockDataResponse) Reset()
func (*LatestBlockDataResponse) String ¶
func (m *LatestBlockDataResponse) String() string
func (*LatestBlockDataResponse) Unmarshal ¶
func (m *LatestBlockDataResponse) Unmarshal(b []byte) error
type SVMChainTracker ¶
type SVMChainTracker struct {
// contains filtered or unexported fields
}
func (*SVMChainTracker) FetchBlockHashByNum ¶
On Solana the interface's `blockNum` parameter is a slot.
func (*SVMChainTracker) FetchLatestBlockNum ¶
func (cs *SVMChainTracker) FetchLatestBlockNum(ctx context.Context) (int64, error)
type SVMLatestBlockResponse ¶
type UnimplementedChainTrackerServiceServer ¶
type UnimplementedChainTrackerServiceServer struct{}
UnimplementedChainTrackerServiceServer can be embedded for forward compatibility.
func (*UnimplementedChainTrackerServiceServer) GetLatestBlockData ¶
func (*UnimplementedChainTrackerServiceServer) GetLatestBlockData(_ context.Context, _ *LatestBlockData) (*LatestBlockDataResponse, error)
func (*UnimplementedChainTrackerServiceServer) GetLatestBlockNum ¶
func (*UnimplementedChainTrackerServiceServer) GetLatestBlockNum(_ context.Context, _ *emptypb.Empty) (*GetLatestBlockNumResponse, error)
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