cache

package
v3.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

README

Lava Protocol Cache Service

Lava's caching service is used to cut costs and improve the overall performance of your application, both provider and consumer processes benefit from the caching service.

In order to use the caching service all you need to do is run the following process:

ListenAddress="127.0.0.1:7777"
ListenMetricsAddress="127.0.0.1:5747"
lavap cache $ListenAddress --metrics_address $ListenMetricsAddress --log_level debug

now the cache service is running in the background. all you need to do is plug in the caching service with the consumer / provider process like so:

Provider:

lavap rpcprovider <your-regular-cli-options> --cache-be $ListenAddress

Consumer

lavap rpcconsumer <your-regular-cli-options> --cache-be $ListenAddress

Documentation

Index

Constants

View Source
const (
	FlagLogLevel       = "log_level"
	FlagMetricsAddress = "metrics_address"
)
View Source
const (
	DbValueConfirmationAttempts = 5
	SEP                         = ";"
)
View Source
const (
	ExpirationFlagName                           = "expiration"
	ExpirationTimeFinalizedMultiplierFlagName    = "expiration-multiplier"
	ExpirationNonFinalizedFlagName               = "expiration-non-finalized"
	ExpirationTimeNonFinalizedMultiplierFlagName = "expiration-non-finalized-multiplier"
	ExpirationBlocksHashesToHeightsFlagName      = "expiration-blocks-hashes-to-heights"
	ExpirationNodeErrorsOnFinalizedFlagName      = "expiration-finalized-node-errors"
	FlagCacheSizeName                            = "max-items"
	DefaultExpirationForNonFinalized             = 500 * time.Millisecond
	DefaultExpirationTimeFinalizedMultiplier     = 1.0
	DefaultExpirationTimeNonFinalizedMultiplier  = 1.0
	DefaultExpirationBlocksHashesToHeights       = 48 * time.Hour
	DefaultExpirationTimeFinalized               = time.Hour
	DefaultExpirationNodeErrors                  = 250 * time.Millisecond
	CacheNumCounters                             = 100000000 // expect 10M items

)
View Source
const (
	DisabledFlagOption = "disabled"
)

Variables

View Source
var (
	NotFoundError     = sdkerrors.New("Cache miss", 1, "cache entry for specific block and request wasn't found")                                                   // client could'nt connect to any provider.
	HashMismatchError = sdkerrors.New("Cache hit but hash mismatch", 2, "cache entry for specific block and request had a mismatching hash stored")                 // client could'nt connect to any provider.
	EntryTypeError    = sdkerrors.New("Cache hit but entry is a different object", 3, "cache entry for specific block and request had a mismatching object stored") // client could'nt connect to any provider.
)

Functions

func CreateCacheCobraCommand

func CreateCacheCobraCommand() *cobra.Command

func Server

func Server(
	ctx context.Context,
	listenAddr string,
	metricsAddr string,
	flags *pflag.FlagSet,
)

Types

type CacheMetrics

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

func NewCacheMetricsServer

func NewCacheMetricsServer(listenAddress string) *CacheMetrics

func (*CacheMetrics) AddApiSpecific

func (c *CacheMetrics) AddApiSpecific(block int64, chainId string, hit bool)

type CacheServer

type CacheServer struct {
	ExpirationFinalized             time.Duration
	ExpirationNonFinalized          time.Duration
	ExpirationNodeErrors            time.Duration
	ExpirationBlocksHashesToHeights time.Duration

	CacheMetrics *CacheMetrics
	CacheMaxCost int64
	// contains filtered or unexported fields
}

func (*CacheServer) ExpirationForChain

func (cs *CacheServer) ExpirationForChain(averageBlockTimeForChain time.Duration) time.Duration

func (*CacheServer) InitCache

func (cs *CacheServer) InitCache(
	ctx context.Context,
	expiration time.Duration,
	expirationNonFinalized time.Duration,
	expirationNodeErrorsOnFinalized time.Duration,
	expirationBlocksHashesToHeights time.Duration,
	metricsAddr string,
	expirationFinalizedMultiplier float64,
	expirationNonFinalizedMultiplier float64,
)

func (*CacheServer) Serve

func (cs *CacheServer) Serve(ctx context.Context,
	listenAddr string,
)

type CacheValue

type CacheValue struct {
	Response         pairingtypes.RelayReply
	Hash             []byte
	OptionalMetadata []pairingtypes.Metadata
	SeenBlock        int64
}

func (*CacheValue) Cost

func (cv *CacheValue) Cost() int64

func (*CacheValue) ToCacheReply

func (cv *CacheValue) ToCacheReply() *pairingtypes.CacheRelayReply

type LastestCacheStore

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

func (*LastestCacheStore) Cost

func (cv *LastestCacheStore) Cost() int64

type RelayerCacheServer

type RelayerCacheServer struct {
	pairingtypes.UnimplementedRelayerCacheServer
	CacheServer *CacheServer
	// contains filtered or unexported fields
}

func (*RelayerCacheServer) GetRelay

func (*RelayerCacheServer) Health

func (*RelayerCacheServer) PrintCacheStats

func (s *RelayerCacheServer) PrintCacheStats(ctx context.Context, desc string)

func (*RelayerCacheServer) SetRelay

func (s *RelayerCacheServer) SetRelay(ctx context.Context, relayCacheSet *pairingtypes.RelayCacheSet) (*emptypb.Empty, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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